| 1 |
package driver; |
| 2 |
import java.util.ArrayList; |
| 3 |
import java.util.HashSet; |
| 4 |
|
| 5 |
import dna.ChromosomeArray; |
| 6 |
import dna.Data; |
| 7 |
import dna.GeneSet; |
| 8 |
import dna.Motif; |
| 9 |
import dna.MotifProbsN; |
| 10 |
import shared.Shared; |
| 11 |
|
| 12 |
|
| 13 |
public class FindMotifs { |
| 14 |
|
| 15 |
|
| 16 |
public static void main(String[] args){ |
| 17 |
|
| 18 |
int chrom=1; |
| 19 |
if(args.length>0){ |
| 20 |
chrom=Integer.parseInt(args[0]); |
| 21 |
} |
| 22 |
|
| 23 |
int maxChrom=22; |
| 24 |
|
| 25 |
|
| 26 |
float[][] grid={ |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
{0.19519f, 0.23856f, 0.38961f, 0.17664f}, |
| 33 |
{0.17382f, 0.33995f, 0.30720f, 0.17903f}, |
| 34 |
{0.24452f, 0.38376f, 0.25710f, 0.11462f}, |
| 35 |
|
| 36 |
{0.46075f, 0.09954f, 0.38018f, 0.05953f}, |
| 37 |
{0.29028f, 0.38874f, 0.19941f, 0.12156f}, |
| 38 |
{0.17610f, 0.46129f, 0.28953f, 0.07309f}, |
| 39 |
|
| 40 |
{0.99859f, 0.00108f, 0.00011f, 0.00022f}, |
| 41 |
{0.00001f, 0.00001f, 0.00076f, 0.99924f}, |
| 42 |
{0.00001f, 0.00001f, 0.99924f, 0.00076f}, |
| 43 |
|
| 44 |
{0.20993f, 0.14877f, 0.51269f, 0.12861f}, |
| 45 |
{0.26903f, 0.39861f, 0.18337f, 0.14899f}, |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
}; |
| 52 |
|
| 53 |
|
| 54 |
float[][] gridATG={ |
| 55 |
{1, 0, 0, 0}, |
| 56 |
{0, 0, 0, 1}, |
| 57 |
{0, 0, 1, 0}, |
| 58 |
}; |
| 59 |
|
| 60 |
|
| 61 |
float[][] grid2={ |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
{0.04598f, 0.04015f, 0.07321f, 0.02892f, 0.06261f, 0.12575f, 0.07331f, 0.07935f, 0.06282f, 0.10637f, 0.08370f, 0.03687f, 0.02246f, 0.05721f, 0.05318f, 0.04810f}, |
| 72 |
{0.03952f, 0.03189f, 0.09704f, 0.02543f, 0.07639f, 0.08666f, 0.10266f, 0.06378f, 0.05424f, 0.07850f, 0.11166f, 0.03899f, 0.02426f, 0.04270f, 0.07819f, 0.04810f}, |
| 73 |
|
| 74 |
{0.04312f, 0.04291f, 0.08878f, 0.01960f, 0.03666f, 0.09800f, 0.04577f, 0.05933f, 0.07098f, 0.14207f, 0.12395f, 0.05255f, 0.02129f, 0.05795f, 0.04990f, 0.04714f}, |
| 75 |
{0.04662f, 0.04672f, 0.06335f, 0.01536f, 0.09069f, 0.14980f, 0.05488f, 0.04556f, 0.07670f, 0.11654f, 0.09026f, 0.02490f, 0.03009f, 0.07162f, 0.04895f, 0.02797f}, |
| 76 |
{0.09503f, 0.01695f, 0.11802f, 0.01409f, 0.20945f, 0.03856f, 0.11622f, 0.02045f, 0.11929f, 0.02998f, 0.09440f, 0.01377f, 0.03464f, 0.01504f, 0.05255f, 0.01155f}, |
| 77 |
|
| 78 |
{0.16580f, 0.13751f, 0.11325f, 0.04185f, 0.02532f, 0.03687f, 0.01409f, 0.02426f, 0.08645f, 0.19578f, 0.05700f, 0.04195f, 0.01165f, 0.01992f, 0.01451f, 0.01377f}, |
| 79 |
{0.07257f, 0.06929f, 0.13042f, 0.01695f, 0.04693f, 0.25532f, 0.05943f, 0.02839f, 0.04079f, 0.06918f, 0.07649f, 0.01240f, 0.01420f, 0.06876f, 0.02373f, 0.01515f}, |
| 80 |
{0.17417f, 0.00021f, 0.00011f, 0.00001f, 0.46213f, 0.00021f, 0.00001f, 0.00021f, 0.28944f, 0.00064f, 0.00001f, 0.00001f, 0.07289f, 0.00001f, 0.00001f, 0.00001f}, |
| 81 |
|
| 82 |
{0.00001f, 0.00001f, 0.00074f, 0.99788f, 0.00001f, 0.00001f, 0.00001f, 0.00106f, 0.00001f, 0.00001f, 0.00001f, 0.00011f, 0.00001f, 0.00001f, 0.00001f, 0.00021f}, |
| 83 |
{0.00001f, 0.00001f, 0.00001f, 0.00001f, 0.00001f, 0.00001f, 0.00001f, 0.00001f, 0.00001f, 0.00001f, 0.00001f, 0.00074f, 0.00001f, 0.00001f, 0.99926f, 0.00001f}, |
| 84 |
{0.00001f, 0.00001f, 0.00001f, 0.00001f, 0.00001f, 0.00001f, 0.00001f, 0.00001f, 0.20934f, 0.14769f, 0.51330f, 0.12893f, 0.00032f, 0.00001f, 0.00042f, 0.00001f}, |
| 85 |
|
| 86 |
{0.07416f, 0.04132f, 0.06346f, 0.03072f, 0.03252f, 0.05265f, 0.01843f, 0.04407f, 0.15447f, 0.23382f, 0.07946f, 0.04598f, 0.00795f, 0.07194f, 0.02182f, 0.02723f}, |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
}; |
| 94 |
|
| 95 |
|
| 96 |
Motif gstartMotif=new MotifProbsN("Gene Starts MP1", grid, 6, 1); |
| 97 |
Motif gstartATG=new MotifProbsN("ATG Gene Starts MP1", gridATG, 0, 1); |
| 98 |
|
| 99 |
Motif gstartMotif2=new MotifProbsN("Gene Starts MP2", grid2, 8, 2); |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
Motif m=gstartMotif2; |
| 114 |
|
| 115 |
|
| 116 |
ArrayList<Integer> firstBeaten=new ArrayList<Integer>(); |
| 117 |
|
| 118 |
long count=0; |
| 119 |
for(chrom=1; chrom<=maxChrom; chrom++){ |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
count+=analyzeChromosomeGStartsStrongerInFrame(chrom, m, locations, firstBeaten, true, Shared.MINUS); |
| 124 |
Data.unload(chrom, true); |
| 125 |
} |
| 126 |
|
| 127 |
Shared.sort(locations); |
| 128 |
|
| 129 |
int[] histogram=new int[CLEN+1]; |
| 130 |
int[] histogramBeaten=new int[CLEN+1]; |
| 131 |
for(Integer i : locations){ |
| 132 |
histogram[i]++; |
| 133 |
} |
| 134 |
for(Integer i : firstBeaten){ |
| 135 |
histogramBeaten[i]++; |
| 136 |
} |
| 137 |
|
| 138 |
System.out.println(count+" sites analyzed. ATG occurances:"); |
| 139 |
for(int i=0; i<histogram.length; i++){ |
| 140 |
System.out.println(i+"\t"+histogram[i]+(firstBeaten.size()==0 ? "" : "\t"+histogramBeaten[i])); |
| 141 |
} |
| 142 |
|
| 143 |
} |
| 144 |
|
| 145 |
|
| 146 |
public static long analyzeChromosomeGStarts(int chrom, Motif m, ArrayList<Integer> list, byte strand){ |
| 147 |
GeneSet[] genes=Data.getGeneSets(chrom); |
| 148 |
assert(strand==Shared.PLUS) : "TODO"; |
| 149 |
ChromosomeArray ca=Data.getChromosome(chrom); |
| 150 |
|
| 151 |
HashSet<Integer> eset=new HashSet<Integer>(); |
| 152 |
for(GeneSet g : genes){ |
| 153 |
if(g.strand==strand){ |
| 154 |
if(strand==Shared.PLUS){ |
| 155 |
eset.add(g.minStart); |
| 156 |
}else{ |
| 157 |
eset.add(ca.maxIndex-g.maxEnd); |
| 158 |
} |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
ArrayList<Integer> list2=new ArrayList<Integer>(eset.size()); |
| 163 |
list2.addAll(eset); |
| 164 |
Shared.sort(list2); |
| 165 |
|
| 166 |
for(Integer x : list2){ |
| 167 |
|
| 168 |
for(int i=CLEN; i>=0; i--){ |
| 169 |
int pos=x-i; |
| 170 |
float f=analyze(pos, m, ca); |
| 171 |
if(f>=THRESH){ |
| 172 |
list.add(i); |
| 173 |
} |
| 174 |
} |
| 175 |
} |
| 176 |
return list2.size(); |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
public static long analyzeChromosomeGStartsStronger(int chrom, Motif m, ArrayList<Integer> list, ArrayList<Integer> listBeat, byte strand){ |
| 181 |
GeneSet[] genes=Data.getGeneSets(chrom); |
| 182 |
assert(strand==Shared.PLUS) : "TODO"; |
| 183 |
ChromosomeArray ca=Data.getChromosome(chrom); |
| 184 |
|
| 185 |
HashSet<Integer> eset=new HashSet<Integer>(); |
| 186 |
for(GeneSet g : genes){ |
| 187 |
if(g.strand==strand){ |
| 188 |
if(strand==Shared.PLUS){ |
| 189 |
eset.add(g.minStart); |
| 190 |
}else{ |
| 191 |
eset.add(ca.maxIndex-g.maxEnd); |
| 192 |
} |
| 193 |
} |
| 194 |
} |
| 195 |
|
| 196 |
ArrayList<Integer> list2=new ArrayList<Integer>(eset.size()); |
| 197 |
list2.addAll(eset); |
| 198 |
Shared.sort(list2); |
| 199 |
|
| 200 |
for(Integer x : list2){ |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
int firstBeaten=CLEN+1; |
| 211 |
float basis=analyze(x, m, ca); |
| 212 |
for(int i=0; i<=CLEN; i++){ |
| 213 |
int pos=x-i; |
| 214 |
float f=analyze(pos, m, ca); |
| 215 |
if(f>=basis){ |
| 216 |
if(i>0 && i<firstBeaten){ |
| 217 |
firstBeaten=i; |
| 218 |
listBeat.add(firstBeaten); |
| 219 |
} |
| 220 |
list.add(i); |
| 221 |
} |
| 222 |
} |
| 223 |
} |
| 224 |
return list2.size(); |
| 225 |
} |
| 226 |
|
| 227 |
|
| 228 |
public static long analyzeChromosomeGStartsStrongerInFrame(int chrom, Motif m, ArrayList<Integer> list, ArrayList<Integer> listBeat, boolean in, byte strand){ |
| 229 |
GeneSet[] genes=Data.getGeneSets(chrom); |
| 230 |
assert(strand==Shared.PLUS) : "TODO"; |
| 231 |
ChromosomeArray ca=Data.getChromosome(chrom); |
| 232 |
|
| 233 |
HashSet<Integer> eset=new HashSet<Integer>(); |
| 234 |
for(GeneSet g : genes){ |
| 235 |
if(g.strand==strand){ |
| 236 |
if(strand==Shared.PLUS){ |
| 237 |
eset.add(g.minStart); |
| 238 |
}else{ |
| 239 |
eset.add(ca.maxIndex-g.maxEnd); |
| 240 |
} |
| 241 |
} |
| 242 |
} |
| 243 |
|
| 244 |
ArrayList<Integer> list2=new ArrayList<Integer>(eset.size()); |
| 245 |
list2.addAll(eset); |
| 246 |
Shared.sort(list2); |
| 247 |
|
| 248 |
for(Integer x : list2){ |
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
int firstBeaten=CLEN+1; |
| 259 |
float basis=analyze(x, m, ca); |
| 260 |
for(int i=0; i<=CLEN; i++){ |
| 261 |
int pos=x-i; |
| 262 |
|
| 263 |
|
| 264 |
if((in && i%3==0) || (!in && i%3==1)){ |
| 265 |
float f=analyze(pos, m, ca); |
| 266 |
if(f>=basis){ |
| 267 |
if(i>0 && i<firstBeaten){ |
| 268 |
firstBeaten=i; |
| 269 |
listBeat.add(firstBeaten); |
| 270 |
} |
| 271 |
list.add(i); |
| 272 |
} |
| 273 |
} |
| 274 |
|
| 275 |
|
| 276 |
} |
| 277 |
} |
| 278 |
return list2.size(); |
| 279 |
} |
| 280 |
|
| 281 |
|
| 282 |
public static float analyze(int point, Motif m, ChromosomeArray ca){ |
| 283 |
|
| 284 |
float f=m.matchStrength(ca.array, point); |
| 285 |
f=m.normalize(f); |
| 286 |
return f; |
| 287 |
} |
| 288 |
|
| 289 |
|
| 290 |
private static String padFront(String s, int len){ |
| 291 |
int spaces=len-s.length(); |
| 292 |
for(int i=0; i<spaces; i++){ |
| 293 |
s=" "+s; |
| 294 |
} |
| 295 |
return s; |
| 296 |
} |
| 297 |
|
| 298 |
public static void swap(long[] a, int x, int y){ |
| 299 |
long temp=a[x]; |
| 300 |
a[x]=a[y]; |
| 301 |
a[y]=temp; |
| 302 |
} |
| 303 |
|
| 304 |
public static void swap(char[] a, int x, int y){ |
| 305 |
char temp=a[x]; |
| 306 |
a[x]=a[y]; |
| 307 |
a[y]=temp; |
| 308 |
} |
| 309 |
|
| 310 |
|
| 311 |
public static float THRESH=.2f; |
| 312 |
|
| 313 |
|
| 314 |
public static long analyses=0; |
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
public static final int ESTART=0; |
| 319 |
|
| 320 |
|
| 321 |
public static final int ESTOP=1; |
| 322 |
|
| 323 |
|
| 324 |
public static final int GSTART=2; |
| 325 |
|
| 326 |
|
| 327 |
public static final int GSTOP=3; |
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
public static final int ESTARTAG=4; |
| 332 |
|
| 333 |
|
| 334 |
public static final int ESTOPGT=5; |
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
public static final int ESTARTATG=6; |
| 339 |
|
| 340 |
|
| 341 |
public static final int ESTOPNONGT=7; |
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
public static final int ESTARTNON=8; |
| 346 |
|
| 347 |
|
| 348 |
public static final int ESTARTAC=9; |
| 349 |
|
| 350 |
private static final int CLEN=200; |
| 351 |
|
| 352 |
public static ArrayList<Integer> locations=new ArrayList<Integer>(); |
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
private static final int min(int x, int y){return x<y ? x : y;} |
| 357 |
private static final int max(int x, int y){return x>y ? x : y;} |
| 358 |
|
| 359 |
} |