| 1 |
package driver; |
| 2 |
|
| 3 |
import java.util.ArrayList; |
| 4 |
import java.util.HashSet; |
| 5 |
|
| 6 |
import dna.AminoAcid; |
| 7 |
import dna.ChromosomeArray; |
| 8 |
import dna.Data; |
| 9 |
import dna.Exon; |
| 10 |
import dna.Gene; |
| 11 |
import dna.MotifMulti; |
| 12 |
import dna.MotifProbsN; |
| 13 |
import shared.Shared; |
| 14 |
import shared.Tools; |
| 15 |
|
| 16 |
public class MeasureGene { |
| 17 |
|
| 18 |
|
| 19 |
public static void main(String[] args){ |
| 20 |
|
| 21 |
byte minChrom=19; |
| 22 |
byte maxChrom=22; |
| 23 |
|
| 24 |
double sum=0; |
| 25 |
long count=0; |
| 26 |
|
| 27 |
|
| 28 |
for(byte chrom=minChrom; chrom<=maxChrom; chrom++){ |
| 29 |
Data.getChromosome(chrom); |
| 30 |
Gene[] genes=Data.getGenes(chrom, Shared.PLUS); |
| 31 |
genes=toNormalGenes(genes); |
| 32 |
|
| 33 |
for(Gene g : genes){ |
| 34 |
|
| 35 |
|
| 36 |
analyzeGene(g); |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
} |
| 69 |
|
| 70 |
System.out.println("Sum: "+sum); |
| 71 |
System.out.println("Count: "+count); |
| 72 |
System.out.println("Average: "+sum/count); |
| 73 |
|
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
public static float analyzeGene(Gene g){ |
| 78 |
assert(g.strand==Shared.PLUS) : "TODO"; |
| 79 |
ChromosomeArray ca=Data.getChromosome(g.chromosome); |
| 80 |
|
| 81 |
System.out.println("\nchr"+g.chromosome+"\t"+g.symbol+"\t"+g.mrnaAcc); |
| 82 |
|
| 83 |
double sum=0; |
| 84 |
|
| 85 |
for(int i=0; i<g.exons.length; i++){ |
| 86 |
Exon e=g.exons[i]; |
| 87 |
|
| 88 |
float f2=measureExonFrequency(e.a, e.b, e.chromosome, e.strand); |
| 89 |
float f1, f3; |
| 90 |
|
| 91 |
if(i==0 && g.exons.length==1){ |
| 92 |
f1=mGStart.matchStrength(ca.array, e.a); |
| 93 |
f3=mGStop.matchStrength(ca.array, e.b); |
| 94 |
}else if(i==0){ |
| 95 |
f1=mGStart.matchStrength(ca.array, e.a); |
| 96 |
f3=mEStop.matchStrength(ca.array, e.b); |
| 97 |
}else if(i==g.exons.length-1){ |
| 98 |
f1=mEStart.matchStrength(ca.array, e.a); |
| 99 |
f3=mGStop.matchStrength(ca.array, e.b); |
| 100 |
}else{ |
| 101 |
f1=mEStart.matchStrength(ca.array, e.a); |
| 102 |
f3=mEStop.matchStrength(ca.array, e.b); |
| 103 |
} |
| 104 |
|
| 105 |
sum=sum+f1+f3; |
| 106 |
|
| 107 |
|
| 108 |
} |
| 109 |
|
| 110 |
float avg=(float)(sum/(2*g.exons.length)); |
| 111 |
|
| 112 |
System.out.println(Tools.format("Average: %.3f", avg)); |
| 113 |
return avg; |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
public static Gene[] toNormalGenes(Gene[] genes){ |
| 118 |
ArrayList<Gene> normal=new ArrayList<Gene>(genes.length); |
| 119 |
for(Gene g : genes){ |
| 120 |
if(g.isNormalGene()){normal.add(g);} |
| 121 |
} |
| 122 |
return normal.toArray(new Gene[normal.size()]); |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
public static ArrayList<Exon> getExons(Gene...genes){ |
| 127 |
HashSet<Exon> exonTable=new HashSet<Exon>(); |
| 128 |
for(Gene g : genes){ |
| 129 |
for(int i=0; i<g.exons.length; i++){ |
| 130 |
Exon e=g.exons[i]; |
| 131 |
exonTable.add(e); |
| 132 |
} |
| 133 |
} |
| 134 |
ArrayList<Exon> exons=new ArrayList<Exon>(exonTable.size()); |
| 135 |
exons.addAll(exonTable); |
| 136 |
exonTable=null; |
| 137 |
Shared.sort(exons); |
| 138 |
return exons; |
| 139 |
} |
| 140 |
|
| 141 |
|
| 142 |
public static float measureExonFrequency(int a, int b, byte chrom, byte strand){ |
| 143 |
|
| 144 |
|
| 145 |
int start=a; |
| 146 |
int stop=b-1; |
| 147 |
|
| 148 |
double sum=0; |
| 149 |
int count=0; |
| 150 |
|
| 151 |
assert(strand==Shared.PLUS) : "TODO"; |
| 152 |
ChromosomeArray ca=Data.getChromosome(chrom); |
| 153 |
|
| 154 |
for(int i=start; i<stop; i++){ |
| 155 |
int number=0; |
| 156 |
boolean invalid=false; |
| 157 |
for(int j=0; j<length; j++){ |
| 158 |
int code=AminoAcid.baseToNumberACGTN[ca.get(i+j)]; |
| 159 |
invalid=invalid || (code<0 || code>3); |
| 160 |
number=((number<<2)|code); |
| 161 |
} |
| 162 |
if(!invalid){ |
| 163 |
count++; |
| 164 |
sum+=freqDif[number]; |
| 165 |
}else{ |
| 166 |
return 0; |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
return count>0 ? (float)(sum/count) : 0; |
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
private static final MotifProbsN mAG=MotifProbsN.makeMotif("AG Exon Starts MP2", 13, 11, 2); |
| 178 |
private static final MotifProbsN mAC=MotifProbsN.makeMotif("AC Exon Starts MP2", 13, 11, 2); |
| 179 |
private static final MotifProbsN mATG=MotifProbsN.makeMotif("ATG Exon Starts MP2", 13, 11, 2); |
| 180 |
|
| 181 |
private static final MotifProbsN mGT=MotifProbsN.makeMotif("GT Exon Stops MP2", 10, 3, 2); |
| 182 |
private static final MotifProbsN mGC=MotifProbsN.makeMotif("GC Exon Stops MP2", 10, 3, 2); |
| 183 |
|
| 184 |
private static final MotifProbsN mGStartATG=MotifProbsN.makeMotif("Gene Starts MP2", 13, 11, 2); |
| 185 |
|
| 186 |
private static final MotifProbsN mGStopTAA=MotifProbsN.makeMotif("TAA Gene Stops MP2", 13, 11, 2); |
| 187 |
private static final MotifProbsN mGStopTAG=MotifProbsN.makeMotif("TAG Gene Stops MP2", 13, 11, 2); |
| 188 |
private static final MotifProbsN mGStopTGA=MotifProbsN.makeMotif("TGA Gene Stops MP2", 13, 11, 2); |
| 189 |
|
| 190 |
private static final MotifMulti mGStart=new MotifMulti("Gene Starts MP2", mGStartATG); |
| 191 |
private static final MotifMulti mEStart=new MotifMulti("Exon Starts MP2", mAG, mAC); |
| 192 |
private static final MotifMulti mEStop=new MotifMulti("Exon Stops MP2", mGT, mGC); |
| 193 |
private static final MotifMulti mGStop=new MotifMulti("Gene Stops MP2", mGStopTAA, mGStopTAG, mGStopTGA); |
| 194 |
|
| 195 |
|
| 196 |
private static final int length=2; |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
public static final float[] exonicFreq1={0.259195f, 0.260530f, 0.260441f, 0.219835f}; |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
public static final float[] nonExonicFreq1={0.277111f, 0.204189f, 0.213443f, 0.305257f}; |
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
public static final float[] exonicFreq2={0.071395f, 0.055355f, 0.077256f, 0.052618f, |
| 209 |
0.079593f, 0.077505f, 0.032685f, 0.071248f, 0.075189f, 0.070017f, 0.070666f, |
| 210 |
0.045554f, 0.032210f, 0.057977f, 0.079080f, 0.051651f}; |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
public static final float[] nonExonicFreq2={0.086472f, 0.047310f, 0.070451f, 0.072291f, |
| 215 |
0.069003f, 0.055260f, 0.011722f, 0.071913f, 0.058469f, 0.045772f, 0.056984f, |
| 216 |
0.054175f, 0.062555f, 0.059560f, 0.076273f, 0.101790f}; |
| 217 |
|
| 218 |
public static final float[] freqDif=( |
| 219 |
length==2 ? makeDif(exonicFreq2, nonExonicFreq2) : |
| 220 |
length==1 ? makeDif(exonicFreq1, nonExonicFreq1) : |
| 221 |
null); |
| 222 |
|
| 223 |
public static final float[] makeDif(float[] a, float[] b){ |
| 224 |
float[] dif=new float[a.length]; |
| 225 |
for(int i=0; i<a.length; i++){ |
| 226 |
dif[i]=a[i]-b[i]; |
| 227 |
} |
| 228 |
return dif; |
| 229 |
} |
| 230 |
|
| 231 |
} |