| 1 |
package prok; |
| 2 |
|
| 3 |
import java.io.File; |
| 4 |
import java.io.PrintStream; |
| 5 |
import java.util.ArrayList; |
| 6 |
import java.util.Arrays; |
| 7 |
|
| 8 |
import dna.AminoAcid; |
| 9 |
import dna.Data; |
| 10 |
import fileIO.ByteFile; |
| 11 |
import fileIO.ByteStreamWriter; |
| 12 |
import fileIO.FileFormat; |
| 13 |
import fileIO.ReadWrite; |
| 14 |
import gff.CompareGff; |
| 15 |
import gff.GffLine; |
| 16 |
import jgi.BBMerge; |
| 17 |
import json.JsonObject; |
| 18 |
import shared.Parse; |
| 19 |
import shared.Parser; |
| 20 |
import shared.PreParser; |
| 21 |
import shared.Shared; |
| 22 |
import shared.Timer; |
| 23 |
import shared.Tools; |
| 24 |
import stream.ConcurrentReadInputStream; |
| 25 |
import stream.ConcurrentReadOutputStream; |
| 26 |
import stream.Read; |
| 27 |
import stream.ReadInputStream; |
| 28 |
import structures.ByteBuilder; |
| 29 |
import structures.ListNum; |
| 30 |
import tracker.ReadStats; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public class CallGenes extends ProkObject { |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
public static void main(String[] args){ |
| 49 |
|
| 50 |
Timer t=new Timer(); |
| 51 |
|
| 52 |
|
| 53 |
CallGenes x=new CallGenes(args); |
| 54 |
|
| 55 |
|
| 56 |
x.process(t); |
| 57 |
|
| 58 |
|
| 59 |
Shared.closeStream(x.outstream); |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
public CallGenes(String[] args){ |
| 67 |
|
| 68 |
{ |
| 69 |
PreParser pp=new PreParser(args, (args.length>40 ? null : getClass()), false); |
| 70 |
args=pp.args; |
| 71 |
outstream=pp.outstream; |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
ReadWrite.USE_PIGZ=ReadWrite.USE_UNPIGZ=true; |
| 76 |
ReadWrite.setZipThreads(Shared.threads()); |
| 77 |
|
| 78 |
{ |
| 79 |
final Parser parser=parse(args); |
| 80 |
overwrite=parser.overwrite; |
| 81 |
append=parser.append; |
| 82 |
|
| 83 |
outGff=parser.out1; |
| 84 |
maxReads=parser.maxReads; |
| 85 |
} |
| 86 |
|
| 87 |
fixExtensions(); |
| 88 |
checkFileExistence(); |
| 89 |
checkStatics(); |
| 90 |
|
| 91 |
ffoutGff=FileFormat.testOutput(outGff, FileFormat.GFF, null, true, overwrite, append, ordered); |
| 92 |
ffoutAmino=FileFormat.testOutput(outAmino, FileFormat.FA, null, true, overwrite, append, ordered); |
| 93 |
ffout16S=FileFormat.testOutput(out16S, FileFormat.FA, null, true, overwrite, append, ordered); |
| 94 |
ffout18S=FileFormat.testOutput(out18S, FileFormat.FA, null, true, overwrite, append, ordered); |
| 95 |
|
| 96 |
if(ffoutGff!=null){ |
| 97 |
assert(!ffoutGff.isSequence()) : "\nout is for gff files. To output sequence, please use outa."; |
| 98 |
} |
| 99 |
if(ffoutAmino!=null){ |
| 100 |
assert(!ffoutAmino.gff()) : "\nouta is for sequence data. To output gff, please use out."; |
| 101 |
} |
| 102 |
if(ffout16S!=null){ |
| 103 |
assert(!ffout16S.gff()) : "\nout16S is for sequence data. To output gff, please use out."; |
| 104 |
} |
| 105 |
if(ffout18S!=null){ |
| 106 |
assert(!ffout18S.gff()) : "\nout18S is for sequence data. To output gff, please use out."; |
| 107 |
} |
| 108 |
|
| 109 |
if(geneHistFile==null){geneHistBins=0;} |
| 110 |
else{ |
| 111 |
assert(geneHistBins>1) : "geneHistBins="+geneHistBins+"; should be >1"; |
| 112 |
assert(geneHistDiv>=1) : "geneHistDiv="+geneHistDiv+"; should be >=1"; |
| 113 |
} |
| 114 |
geneHist=geneHistBins>1 ? new long[geneHistBins] : null; |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
private Parser parse(String[] args){ |
| 123 |
|
| 124 |
Parser parser=new Parser(); |
| 125 |
for(int i=0; i<args.length; i++){ |
| 126 |
String arg=args[i]; |
| 127 |
String[] split=arg.split("="); |
| 128 |
String a=split[0].toLowerCase(); |
| 129 |
String b=split.length>1 ? split[1] : null; |
| 130 |
if(b!=null && b.equalsIgnoreCase("null")){b=null;} |
| 131 |
|
| 132 |
|
| 133 |
if(PGMTools.parseStatic(arg, a, b)){ |
| 134 |
|
| 135 |
}else if(a.equals("in") || a.equals("infna") || |
| 136 |
a.equals("fnain") || a.equals("fna") || a.equals("ref")){ |
| 137 |
assert(b!=null); |
| 138 |
Tools.addFiles(b, fnaList); |
| 139 |
}else if(b==null && new File(arg).exists() && FileFormat.isFastaFile(arg)){ |
| 140 |
fnaList.add(arg); |
| 141 |
}else if(a.equals("pgm") || a.equals("gm") || a.equals("model")){ |
| 142 |
assert(b!=null); |
| 143 |
if(b.equalsIgnoreCase("auto") || b.equalsIgnoreCase("default")){ |
| 144 |
b=Data.findPath("?model.pgm"); |
| 145 |
pgmList.add(b); |
| 146 |
}else{ |
| 147 |
Tools.addFiles(b, pgmList); |
| 148 |
} |
| 149 |
}else if(b==null && new File(arg).exists() && FileFormat.isPgmFile(arg)){ |
| 150 |
pgmList.add(b); |
| 151 |
}else if(a.equals("outamino") || a.equals("aminoout") || a.equals("outa") || a.equals("outaa") || a.equals("aaout") || a.equals("amino")){ |
| 152 |
outAmino=b; |
| 153 |
}else if(a.equalsIgnoreCase("out16s") || a.equalsIgnoreCase("16sout")){ |
| 154 |
out16S=b; |
| 155 |
}else if(a.equalsIgnoreCase("out18s") || a.equalsIgnoreCase("18sout")){ |
| 156 |
out18S=b; |
| 157 |
}else if(a.equals("verbose")){ |
| 158 |
verbose=Parse.parseBoolean(b); |
| 159 |
|
| 160 |
GeneCaller.verbose=verbose; |
| 161 |
}else if(a.equalsIgnoreCase("ingff") || a.equalsIgnoreCase("gffin")){ |
| 162 |
Tools.addFiles(b, inGffList); |
| 163 |
} |
| 164 |
|
| 165 |
else if(a.equals("json_out") || a.equalsIgnoreCase("json")){ |
| 166 |
json_out=Parse.parseBoolean(b); |
| 167 |
}else if(a.equals("stats") || a.equalsIgnoreCase("outstats")){ |
| 168 |
outStats=b; |
| 169 |
}else if(a.equals("hist") || a.equalsIgnoreCase("outhist") || a.equalsIgnoreCase("lengthhist") || a.equalsIgnoreCase("lhist") || a.equalsIgnoreCase("genehist")){ |
| 170 |
geneHistFile=b; |
| 171 |
}else if(a.equals("bins")){ |
| 172 |
geneHistBins=Integer.parseInt(b); |
| 173 |
}else if(a.equals("binlen") || a.equals("binlength") || a.equals("histdiv")){ |
| 174 |
geneHistDiv=Integer.parseInt(b); |
| 175 |
}else if(a.equals("printzero") || a.equals("pz")){ |
| 176 |
printZeroCountHist=Parse.parseBoolean(b); |
| 177 |
} |
| 178 |
|
| 179 |
else if(a.equals("merge")){ |
| 180 |
merge=Parse.parseBoolean(b); |
| 181 |
}else if(a.equals("ecco")){ |
| 182 |
ecco=Parse.parseBoolean(b); |
| 183 |
}else if(a.equals("2pass") || a.equals("twopass")){ |
| 184 |
if(Parse.parseBoolean(b)) {passes=2;} |
| 185 |
}else if(a.equals("passes")){ |
| 186 |
passes=Integer.parseInt(b); |
| 187 |
} |
| 188 |
|
| 189 |
else if(a.equals("extended") || a.equals("extendedstats") || a.equals("verbosestats")){ |
| 190 |
extendedStats=Parse.parseBoolean(b); |
| 191 |
} |
| 192 |
|
| 193 |
else if(a.equalsIgnoreCase("setbias16s")) { |
| 194 |
GeneCaller.biases[r16S]=Float.parseFloat(b); |
| 195 |
}else if(a.equalsIgnoreCase("setbias18s")) { |
| 196 |
GeneCaller.biases[r18S]=Float.parseFloat(b); |
| 197 |
}else if(a.equalsIgnoreCase("setbias23s")) { |
| 198 |
GeneCaller.biases[r23S]=Float.parseFloat(b); |
| 199 |
}else if(a.equalsIgnoreCase("setbias5s")) { |
| 200 |
GeneCaller.biases[r5S]=Float.parseFloat(b); |
| 201 |
}else if(a.equalsIgnoreCase("setbiastRNA")) { |
| 202 |
GeneCaller.biases[tRNA]=Float.parseFloat(b); |
| 203 |
}else if(a.equalsIgnoreCase("setbiasCDS")) { |
| 204 |
GeneCaller.biases[CDS]=Float.parseFloat(b); |
| 205 |
} |
| 206 |
|
| 207 |
else if(a.equals("ordered")){ |
| 208 |
ordered=Parse.parseBoolean(b); |
| 209 |
} |
| 210 |
|
| 211 |
else if(a.equals("translate")){ |
| 212 |
mode=TRANSLATE; |
| 213 |
}else if(a.equals("retranslate") || a.equals("detranslate")){ |
| 214 |
mode=RETRANSLATE; |
| 215 |
}else if(a.equals("recode")){ |
| 216 |
mode=RECODE; |
| 217 |
} |
| 218 |
|
| 219 |
else if(a.equalsIgnoreCase("minlen") || a.equals("minlength")){ |
| 220 |
minLen=Integer.parseInt(b); |
| 221 |
}else if(a.equals("maxoverlapss") || a.equals("overlapss") || a.equals("overlapsamestrand") || a.equals("moss") || a.equalsIgnoreCase("maxOverlapSameStrand")){ |
| 222 |
maxOverlapSameStrand=Integer.parseInt(b); |
| 223 |
}else if(a.equals("maxoverlapos") || a.equals("overlapos") || a.equals("overlapoppositestrand") || a.equals("moos") || a.equalsIgnoreCase("maxOverlapOppositeStrand")){ |
| 224 |
maxOverlapOppositeStrand=Integer.parseInt(b); |
| 225 |
}else if(a.equalsIgnoreCase("minStartScore")){ |
| 226 |
minStartScore=Float.parseFloat(b); |
| 227 |
}else if(a.equalsIgnoreCase("minStopScore")){ |
| 228 |
minStopScore=Float.parseFloat(b); |
| 229 |
}else if(a.equalsIgnoreCase("minInnerScore") || a.equalsIgnoreCase("minKmerScore")){ |
| 230 |
minKmerScore=Float.parseFloat(b); |
| 231 |
}else if(a.equalsIgnoreCase("minOrfScore") || a.equalsIgnoreCase("minScore")){ |
| 232 |
minOrfScore=Float.parseFloat(b); |
| 233 |
}else if(a.equalsIgnoreCase("minAvgScore")){ |
| 234 |
minAvgScore=Float.parseFloat(b); |
| 235 |
}else if(a.equalsIgnoreCase("breakLimit")){ |
| 236 |
GeneCaller.breakLimit=Integer.parseInt(b); |
| 237 |
}else if(a.equalsIgnoreCase("clearcutoffs") || a.equalsIgnoreCase("clearfilters")){ |
| 238 |
GeneCaller.breakLimit=9999; |
| 239 |
minOrfScore=-9999; |
| 240 |
minAvgScore=-9999; |
| 241 |
minKmerScore=-9999; |
| 242 |
minStopScore=-9999; |
| 243 |
minStartScore=-9999; |
| 244 |
} |
| 245 |
|
| 246 |
else if(a.equalsIgnoreCase("e1")){ |
| 247 |
Orf.e1=Float.parseFloat(b); |
| 248 |
}else if(a.equalsIgnoreCase("e2")){ |
| 249 |
Orf.e2=Float.parseFloat(b); |
| 250 |
}else if(a.equalsIgnoreCase("e3")){ |
| 251 |
Orf.e3=Float.parseFloat(b); |
| 252 |
} |
| 253 |
else if(a.equalsIgnoreCase("f1")){ |
| 254 |
Orf.f1=Float.parseFloat(b); |
| 255 |
}else if(a.equalsIgnoreCase("f2")){ |
| 256 |
Orf.f2=Float.parseFloat(b); |
| 257 |
}else if(a.equalsIgnoreCase("f3")){ |
| 258 |
Orf.f3=Float.parseFloat(b); |
| 259 |
} |
| 260 |
else if(a.equalsIgnoreCase("p0")){ |
| 261 |
GeneCaller.p0=Float.parseFloat(b); |
| 262 |
}else if(a.equalsIgnoreCase("p1")){ |
| 263 |
GeneCaller.p1=Float.parseFloat(b); |
| 264 |
}else if(a.equalsIgnoreCase("p2")){ |
| 265 |
GeneCaller.p2=Float.parseFloat(b); |
| 266 |
}else if(a.equalsIgnoreCase("p3")){ |
| 267 |
GeneCaller.p3=Float.parseFloat(b); |
| 268 |
}else if(a.equalsIgnoreCase("p4")){ |
| 269 |
GeneCaller.p4=Float.parseFloat(b); |
| 270 |
}else if(a.equalsIgnoreCase("p5")){ |
| 271 |
GeneCaller.p5=Float.parseFloat(b); |
| 272 |
}else if(a.equalsIgnoreCase("p6")){ |
| 273 |
GeneCaller.p6=Float.parseFloat(b); |
| 274 |
} |
| 275 |
else if(a.equalsIgnoreCase("q1")){ |
| 276 |
GeneCaller.q1=Float.parseFloat(b); |
| 277 |
}else if(a.equalsIgnoreCase("q2")){ |
| 278 |
GeneCaller.q2=Float.parseFloat(b); |
| 279 |
}else if(a.equalsIgnoreCase("q3")){ |
| 280 |
GeneCaller.q3=Float.parseFloat(b); |
| 281 |
}else if(a.equalsIgnoreCase("q4")){ |
| 282 |
GeneCaller.q4=Float.parseFloat(b); |
| 283 |
}else if(a.equalsIgnoreCase("q5")){ |
| 284 |
GeneCaller.q5=Float.parseFloat(b); |
| 285 |
} |
| 286 |
else if(a.equalsIgnoreCase("lookback")){ |
| 287 |
GeneCaller.lookbackPlus=GeneCaller.lookbackMinus=Integer.parseInt(b); |
| 288 |
}else if(a.equalsIgnoreCase("lookbackplus")){ |
| 289 |
GeneCaller.lookbackPlus=Integer.parseInt(b); |
| 290 |
}else if(a.equalsIgnoreCase("lookbackminus")){ |
| 291 |
GeneCaller.lookbackMinus=Integer.parseInt(b); |
| 292 |
} |
| 293 |
|
| 294 |
else if(a.equalsIgnoreCase("compareto")){ |
| 295 |
compareToGff=b; |
| 296 |
} |
| 297 |
|
| 298 |
else if(ProkObject.parse(arg, a, b)){} |
| 299 |
|
| 300 |
else if(parser.parse(arg, a, b)){ |
| 301 |
|
| 302 |
}else{ |
| 303 |
outstream.println("Unknown parameter "+args[i]); |
| 304 |
assert(false) : "Unknown parameter "+args[i]; |
| 305 |
|
| 306 |
} |
| 307 |
} |
| 308 |
|
| 309 |
if(pgmList.isEmpty()){ |
| 310 |
String b=Data.findPath("?model.pgm"); |
| 311 |
pgmList.add(b); |
| 312 |
} |
| 313 |
for(int i=0; i<pgmList.size(); i++){ |
| 314 |
String s=pgmList.get(i); |
| 315 |
if(s.equalsIgnoreCase("auto") || s.equalsIgnoreCase("default")){ |
| 316 |
pgmList.set(i, Data.findPath("?model.pgm")); |
| 317 |
} |
| 318 |
} |
| 319 |
|
| 320 |
if(Shared.threads()<2){ordered=false;} |
| 321 |
assert(!fnaList.isEmpty()) : "At least 1 fasta file is required."; |
| 322 |
assert(!pgmList.isEmpty()) : "At least 1 pgm file is required."; |
| 323 |
return parser; |
| 324 |
} |
| 325 |
|
| 326 |
|
| 327 |
private void fixExtensions(){ |
| 328 |
fnaList=Tools.fixExtension(fnaList); |
| 329 |
pgmList=Tools.fixExtension(pgmList); |
| 330 |
if(fnaList.isEmpty()){throw new RuntimeException("Error - at least one input file is required.");} |
| 331 |
} |
| 332 |
|
| 333 |
|
| 334 |
private void checkFileExistence(){ |
| 335 |
|
| 336 |
if(!Tools.testOutputFiles(overwrite, append, false, outGff, outAmino, out16S, out18S, outStats, geneHistFile)){ |
| 337 |
outstream.println((outGff==null)+", "+outGff); |
| 338 |
throw new RuntimeException("\n\noverwrite="+overwrite+"; Can't write to output files " |
| 339 |
+outGff+", "+outAmino+", "+out16S+", "+out18S+", "+outStats+", "+geneHistFile+"\n"); |
| 340 |
} |
| 341 |
|
| 342 |
|
| 343 |
ArrayList<String> foo=new ArrayList<String>(); |
| 344 |
foo.addAll(fnaList); |
| 345 |
foo.addAll(pgmList); |
| 346 |
if(!Tools.testInputFiles(false, true, foo.toArray(new String[0]))){ |
| 347 |
throw new RuntimeException("\nCan't read some input files.\n"); |
| 348 |
} |
| 349 |
|
| 350 |
|
| 351 |
foo.add(outGff); |
| 352 |
foo.add(outAmino); |
| 353 |
foo.add(out16S); |
| 354 |
foo.add(out18S); |
| 355 |
foo.add(outStats); |
| 356 |
foo.add(geneHistFile); |
| 357 |
if(!Tools.testForDuplicateFiles(true, foo.toArray(new String[0]))){ |
| 358 |
throw new RuntimeException("\nSome file names were specified multiple times.\n"); |
| 359 |
} |
| 360 |
} |
| 361 |
|
| 362 |
|
| 363 |
private static void checkStatics(){ |
| 364 |
|
| 365 |
if(!ByteFile.FORCE_MODE_BF1 && !ByteFile.FORCE_MODE_BF2 && Shared.threads()>2){ |
| 366 |
ByteFile.FORCE_MODE_BF2=true; |
| 367 |
} |
| 368 |
} |
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
void process(Timer t){ |
| 376 |
|
| 377 |
final GeneModel pgm0=PGMTools.loadAndMerge(pgmList); |
| 378 |
|
| 379 |
if(call16S || call18S || call23S || calltRNA || call5S){ |
| 380 |
loadLongKmers(); |
| 381 |
loadConsensusSequenceFromFile(false, false); |
| 382 |
} |
| 383 |
|
| 384 |
ByteStreamWriter bsw=makeBSW(ffoutGff); |
| 385 |
if(bsw!=null){ |
| 386 |
bsw.forcePrint("##gff-version 3\n"); |
| 387 |
} |
| 388 |
|
| 389 |
ConcurrentReadOutputStream rosAmino=makeCros(ffoutAmino); |
| 390 |
ConcurrentReadOutputStream ros16S=makeCros(ffout16S); |
| 391 |
ConcurrentReadOutputStream ros18S=makeCros(ffout18S); |
| 392 |
|
| 393 |
|
| 394 |
final boolean vic=Read.VALIDATE_IN_CONSTRUCTOR; |
| 395 |
Read.VALIDATE_IN_CONSTRUCTOR=Shared.threads()<4; |
| 396 |
|
| 397 |
|
| 398 |
readsIn=genesOut=0; |
| 399 |
basesIn=bytesOut=0; |
| 400 |
|
| 401 |
for(int fnum=0; fnum<fnaList.size(); fnum++){ |
| 402 |
final String fna=fnaList.get(fnum); |
| 403 |
String gffIn=(inGffList!=null && !inGffList.isEmpty()) ? inGffList.set(fnum, null) : null; |
| 404 |
|
| 405 |
final GeneModel pgm=makeMultipassModel(pgm0, fna, gffIn, passes); |
| 406 |
|
| 407 |
final ConcurrentReadInputStream cris=makeCris(fna); |
| 408 |
|
| 409 |
|
| 410 |
spawnThreads(cris, bsw, rosAmino, ros16S, ros18S, pgm); |
| 411 |
|
| 412 |
|
| 413 |
errorState|=ReadWrite.closeStream(cris); |
| 414 |
} |
| 415 |
|
| 416 |
|
| 417 |
errorState|=ReadWrite.closeStreams(null, rosAmino, ros16S, ros18S); |
| 418 |
|
| 419 |
if(verbose){outstream.println("Finished; closing streams.");} |
| 420 |
|
| 421 |
|
| 422 |
errorState|=ReadStats.writeAll(); |
| 423 |
|
| 424 |
if(bsw!=null){errorState|=bsw.poisonAndWait();} |
| 425 |
|
| 426 |
|
| 427 |
Read.VALIDATE_IN_CONSTRUCTOR=vic; |
| 428 |
|
| 429 |
|
| 430 |
t.stop(); |
| 431 |
outstream.println(Tools.timeReadsBasesProcessed(t, readsIn, basesIn, 8)); |
| 432 |
outstream.println(Tools.linesBytesOut(readsIn, basesIn, genesOut, bytesOut, 8, false)); |
| 433 |
outstream.println(); |
| 434 |
|
| 435 |
if(json_out){ |
| 436 |
printStatsJson(outStats); |
| 437 |
}else{ |
| 438 |
printStats(outStats); |
| 439 |
} |
| 440 |
|
| 441 |
if(geneHistFile!=null){ |
| 442 |
printHist(geneHistFile); |
| 443 |
} |
| 444 |
|
| 445 |
|
| 446 |
if(errorState){ |
| 447 |
throw new RuntimeException(getClass().getName()+" terminated in an error state; the output may be corrupt."); |
| 448 |
} |
| 449 |
|
| 450 |
if(compareToGff!=null){ |
| 451 |
if(compareToGff.equals("auto")){ |
| 452 |
compareToGff=fnaList.get(0).replace(".fna", ".gff"); |
| 453 |
compareToGff=compareToGff.replace(".fa", ".gff"); |
| 454 |
compareToGff=compareToGff.replace(".fasta", ".gff"); |
| 455 |
} |
| 456 |
CompareGff.main(new String[] {outGff, compareToGff}); |
| 457 |
} |
| 458 |
} |
| 459 |
|
| 460 |
private void printStats(String fname){ |
| 461 |
if(fname==null){return;} |
| 462 |
ByteStreamWriter bsw=new ByteStreamWriter(fname, overwrite, append, false); |
| 463 |
bsw.start(); |
| 464 |
|
| 465 |
if(callCDS){ |
| 466 |
if(extendedStats || verbose) { |
| 467 |
bsw.println("Gene Starts Made: \t "+Tools.padLeft(geneStartsMade, 12)); |
| 468 |
bsw.println("Gene Stops Made: \t "+Tools.padLeft(geneStopsMade, 12)); |
| 469 |
bsw.println("Gene Starts Retained: \t "+Tools.padLeft(geneStartsRetained, 12)); |
| 470 |
bsw.println("Gene Stops Retained: \t "+Tools.padLeft(geneStopsRetained, 12)); |
| 471 |
} |
| 472 |
bsw.print("Approx Coding Fraction:\t "); |
| 473 |
bsw.print(Tools.padLeft(Tools.format("%.4f", Tools.min(1.0, stCdsPass.lengthSum/(double)basesIn)), 12)).nl(); |
| 474 |
bsw.println("CDS Out: \t "+Tools.padLeft(geneStartsOut, 12)); |
| 475 |
} |
| 476 |
if(call16S){bsw.println("16S Out: \t "+Tools.padLeft(r16SOut, 12));} |
| 477 |
if(call18S){bsw.println("18S Out: \t "+Tools.padLeft(r18SOut, 12));} |
| 478 |
if(call23S){bsw.println("23S Out: \t "+Tools.padLeft(r23SOut, 12));} |
| 479 |
if(call5S){bsw.println("5S Out: \t "+Tools.padLeft(r5SOut, 12));} |
| 480 |
if(calltRNA){bsw.println("tRNA Out: \t "+Tools.padLeft(tRNAOut, 12));} |
| 481 |
|
| 482 |
if(extendedStats || verbose) { |
| 483 |
if(callCDS){ |
| 484 |
bsw.println(); |
| 485 |
bsw.println("All ORF Stats:"); |
| 486 |
bsw.print(stCds.toString()); |
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
bsw.println(); |
| 493 |
bsw.println("Called ORF Stats:"); |
| 494 |
stCdsPass.genomeSize=basesIn; |
| 495 |
bsw.print(stCdsPass.toString()); |
| 496 |
} |
| 497 |
|
| 498 |
if(call16S && r16SOut>0){ |
| 499 |
bsw.println(); |
| 500 |
bsw.println("Called 16S Stats:"); |
| 501 |
bsw.print(st16s.toString()); |
| 502 |
} |
| 503 |
if(call23S && r23SOut>0){ |
| 504 |
bsw.println(); |
| 505 |
bsw.println("Called 23S Stats:"); |
| 506 |
bsw.print(st23s.toString()); |
| 507 |
} |
| 508 |
if(call5S && r5SOut>0){ |
| 509 |
bsw.println(); |
| 510 |
bsw.println("Called 5S Stats:"); |
| 511 |
bsw.print(st5s.toString()); |
| 512 |
} |
| 513 |
if(call18S && r18SOut>0){ |
| 514 |
bsw.println(); |
| 515 |
bsw.println("Called 18S Stats:"); |
| 516 |
bsw.print(st18s.toString()); |
| 517 |
} |
| 518 |
if(calltRNA && tRNAOut>0){ |
| 519 |
bsw.println(); |
| 520 |
bsw.println("Called tRNA Stats:"); |
| 521 |
bsw.print(sttRNA.toString()); |
| 522 |
} |
| 523 |
} |
| 524 |
bsw.poisonAndWait(); |
| 525 |
} |
| 526 |
|
| 527 |
private void printStatsJson(String fname){ |
| 528 |
if(fname==null){return;} |
| 529 |
|
| 530 |
JsonObject outer=new JsonObject(); |
| 531 |
|
| 532 |
{ |
| 533 |
JsonObject jo=new JsonObject(); |
| 534 |
if(callCDS){ |
| 535 |
jo.add("Gene Starts Made", geneStartsMade); |
| 536 |
jo.add("Gene Stops Made", geneStopsMade); |
| 537 |
jo.add("Gene Starts Retained", geneStartsRetained); |
| 538 |
jo.add("Gene Stops Retained", geneStopsRetained); |
| 539 |
jo.add("CDS Out", geneStartsOut); |
| 540 |
} |
| 541 |
if(call16S){jo.add("16S Out", r16SOut);} |
| 542 |
if(call18S){jo.add("18S Out", r18SOut);} |
| 543 |
if(call23S){jo.add("23S Out", r23SOut);} |
| 544 |
if(call5S){jo.add("5S Out", r5SOut);} |
| 545 |
if(calltRNA){jo.add("tRNA Out", tRNAOut);} |
| 546 |
outer.add("Overall", jo); |
| 547 |
} |
| 548 |
|
| 549 |
if(callCDS){ |
| 550 |
outer.add("All ORF Stats", stCds.toJson()); |
| 551 |
outer.add("Retained ORF Stats", stCds2.toJson()); |
| 552 |
stCdsPass.genomeSize=basesIn; |
| 553 |
outer.add("Called ORF Stats", stCdsPass.toJson()); |
| 554 |
} |
| 555 |
|
| 556 |
if(call16S){outer.add("Called 16S Stats", st16s.toJson());} |
| 557 |
if(call18S){outer.add("Called 18S Stats", st18s.toJson());} |
| 558 |
if(call23S){outer.add("Called 23S Stats", st23s.toJson());} |
| 559 |
if(call5S){outer.add("Called 5S Stats", st5s.toJson());} |
| 560 |
if(calltRNA){outer.add("Called tRNA Stats", sttRNA.toJson());} |
| 561 |
|
| 562 |
|
| 563 |
ByteStreamWriter bsw=new ByteStreamWriter(fname, overwrite, append, false); |
| 564 |
bsw.start(); |
| 565 |
bsw.println(outer.toText()); |
| 566 |
bsw.poisonAndWait(); |
| 567 |
} |
| 568 |
|
| 569 |
private void printHist(String fname){ |
| 570 |
if(fname==null || geneHist==null){return;} |
| 571 |
ByteStreamWriter bsw=new ByteStreamWriter(fname, overwrite, append, false); |
| 572 |
bsw.start(); |
| 573 |
long sum=shared.Vector.sum(geneHist); |
| 574 |
double mean=Tools.averageHistogram(geneHist)*geneHistDiv; |
| 575 |
int median=Tools.medianHistogram(geneHist)*geneHistDiv; |
| 576 |
double std=Tools.standardDeviationHistogram(geneHist)*geneHistDiv; |
| 577 |
bsw.println("#Gene Length Histogram"); |
| 578 |
bsw.print("#Genes:\t").println(sum); |
| 579 |
bsw.print("#Mean:\t").println(mean, 4); |
| 580 |
bsw.print("#Median:\t").println(median); |
| 581 |
bsw.print("#STDDev:\t").println(std, 4); |
| 582 |
bsw.print("#Length\tCount\n"); |
| 583 |
long cum=0; |
| 584 |
for(int i=0; i<geneHist.length && cum<sum; i++){ |
| 585 |
int len=i*geneHistDiv; |
| 586 |
long count=geneHist[i]; |
| 587 |
cum+=count; |
| 588 |
if(count>0 || printZeroCountHist){ |
| 589 |
bsw.print(len).tab().println(count); |
| 590 |
} |
| 591 |
} |
| 592 |
bsw.poisonAndWait(); |
| 593 |
} |
| 594 |
|
| 595 |
private ConcurrentReadInputStream makeCris(String fname){ |
| 596 |
FileFormat ffin=FileFormat.testInput(fname, FileFormat.FA, null, true, true); |
| 597 |
ConcurrentReadInputStream cris=ConcurrentReadInputStream.getReadInputStream(maxReads, false, ffin, null); |
| 598 |
cris.start(); |
| 599 |
if(verbose){outstream.println("Started cris");} |
| 600 |
return cris; |
| 601 |
} |
| 602 |
|
| 603 |
|
| 604 |
private void spawnThreads(final ConcurrentReadInputStream cris, final ByteStreamWriter bsw, |
| 605 |
ConcurrentReadOutputStream rosAmino, ConcurrentReadOutputStream ros16S, ConcurrentReadOutputStream ros18S, GeneModel pgm){ |
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
final int threads=Shared.threads(); |
| 611 |
|
| 612 |
|
| 613 |
ArrayList<ProcessThread> alpt=new ArrayList<ProcessThread>(threads); |
| 614 |
for(int i=0; i<threads; i++){ |
| 615 |
alpt.add(new ProcessThread(cris, bsw, rosAmino, ros16S, ros18S, pgm, minLen, i)); |
| 616 |
} |
| 617 |
|
| 618 |
|
| 619 |
for(ProcessThread pt : alpt){ |
| 620 |
pt.start(); |
| 621 |
} |
| 622 |
|
| 623 |
|
| 624 |
waitForThreads(alpt); |
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
} |
| 629 |
|
| 630 |
private void waitForThreads(ArrayList<ProcessThread> alpt){ |
| 631 |
|
| 632 |
|
| 633 |
boolean success=true; |
| 634 |
for(ProcessThread pt : alpt){ |
| 635 |
|
| 636 |
|
| 637 |
while(pt.getState()!=Thread.State.TERMINATED){ |
| 638 |
try { |
| 639 |
|
| 640 |
pt.join(); |
| 641 |
} catch (InterruptedException e) { |
| 642 |
|
| 643 |
e.printStackTrace(); |
| 644 |
} |
| 645 |
} |
| 646 |
|
| 647 |
|
| 648 |
readsIn+=pt.readsInT; |
| 649 |
basesIn+=pt.basesInT; |
| 650 |
genesOut+=pt.genesOutT; |
| 651 |
bytesOut+=pt.bytesOutT; |
| 652 |
|
| 653 |
geneStopsMade+=pt.caller.geneStopsMade; |
| 654 |
geneStartsMade+=pt.caller.geneStartsMade; |
| 655 |
geneStartsRetained+=pt.caller.geneStartsRetained; |
| 656 |
geneStopsRetained+=pt.caller.geneStopsRetained; |
| 657 |
geneStartsOut+=pt.caller.geneStartsOut; |
| 658 |
|
| 659 |
r16SOut+=pt.caller.r16SOut; |
| 660 |
r18SOut+=pt.caller.r18SOut; |
| 661 |
r23SOut+=pt.caller.r23SOut; |
| 662 |
r5SOut+=pt.caller.r5SOut; |
| 663 |
tRNAOut+=pt.caller.tRNAOut; |
| 664 |
|
| 665 |
stCds.add(pt.caller.stCds); |
| 666 |
stCds2.add(pt.caller.stCds2); |
| 667 |
|
| 668 |
|
| 669 |
for(int i=0; i<trackers.length; i++){ |
| 670 |
trackers[i].add(pt.caller.trackers[i]); |
| 671 |
} |
| 672 |
|
| 673 |
if(geneHist!=null){Tools.add(geneHist, pt.geneHistT);} |
| 674 |
|
| 675 |
success&=pt.success; |
| 676 |
} |
| 677 |
|
| 678 |
|
| 679 |
if(!success){errorState=true;} |
| 680 |
} |
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
public static GeneModel makeMultipassModel(GeneModel pgm0, String fna, String gff, int passes) { |
| 687 |
if(passes<2) {return pgm0;} |
| 688 |
ArrayList<Read> reads=ReadInputStream.toReads(fna, FileFormat.FASTA, -1); |
| 689 |
return makeMultipassModel(pgm0, reads, gff, passes); |
| 690 |
} |
| 691 |
|
| 692 |
public static GeneModel makeMultipassModel(GeneModel pgm0, ArrayList<Read> reads, String gff, int passes) { |
| 693 |
GeneModel pgm=pgm0; |
| 694 |
for(int i=1; i<passes; i++) { |
| 695 |
pgm=runOnePass(reads, gff, pgm); |
| 696 |
if(i==1 && passes==2) { |
| 697 |
pgm=PGMTools.mix(0.50, 0.10, 0.10, true, pgm0, pgm); |
| 698 |
}else if(i==passes-1) { |
| 699 |
pgm=PGMTools.mix(0.50, 0.12, 0.12, true, pgm0, pgm); |
| 700 |
}else if(i==1 && passes>2) { |
| 701 |
pgm=PGMTools.mix(0.10, 0.01, 0.01, true, pgm0, pgm); |
| 702 |
}else { |
| 703 |
pgm=PGMTools.mix(0.20, 0.02, 0.02, true, pgm0, pgm); |
| 704 |
} |
| 705 |
} |
| 706 |
return pgm; |
| 707 |
} |
| 708 |
|
| 709 |
|
| 710 |
public static GeneModel runOnePass(String fna, String gff, GeneModel pgm0) { |
| 711 |
ArrayList<Read> reads=ReadInputStream.toReads(fna, FileFormat.FASTA, -1); |
| 712 |
return runOnePass(reads, gff, pgm0); |
| 713 |
} |
| 714 |
|
| 715 |
|
| 716 |
public static GeneModel runOnePass(ArrayList<Read> reads, String gff, GeneModel pgm0) { |
| 717 |
GeneCaller caller=new GeneCaller(minLen, maxOverlapSameStrand, maxOverlapOppositeStrand, |
| 718 |
minStartScore, minStopScore, minKmerScore, minOrfScore, minAvgScore, pgm0); |
| 719 |
|
| 720 |
final ArrayList<GffLine> cds, rrna, trna; |
| 721 |
if(gff!=null && !"null".equalsIgnoreCase(gff)) { |
| 722 |
ArrayList<GffLine>[] allGffLines=GffLine.loadGffFileByType(gff, "CDS,rRNA,tRNA", true); |
| 723 |
cds=allGffLines[0]; |
| 724 |
rrna=allGffLines[1]; |
| 725 |
trna=allGffLines[2]; |
| 726 |
|
| 727 |
}else { |
| 728 |
ArrayList<Orf> orfs=caller.callGenes(reads); |
| 729 |
ArrayList<GffLine>[] allGffLines=Orf.toGffLinesByType(orfs, "CDS,rRNA,tRNA"); |
| 730 |
cds=allGffLines[0]; |
| 731 |
rrna=allGffLines[1]; |
| 732 |
trna=allGffLines[2]; |
| 733 |
|
| 734 |
} |
| 735 |
|
| 736 |
GeneModel pgm=new GeneModel(true); |
| 737 |
pgm.process(reads, cds, rrna, trna); |
| 738 |
for(StatsContainer sc : pgm.allContainers) { |
| 739 |
sc.calculate(); |
| 740 |
} |
| 741 |
return pgm; |
| 742 |
} |
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
private static ByteStreamWriter makeBSW(FileFormat ff){ |
| 749 |
if(ff==null){return null;} |
| 750 |
ByteStreamWriter bsw=new ByteStreamWriter(ff); |
| 751 |
bsw.start(); |
| 752 |
return bsw; |
| 753 |
} |
| 754 |
|
| 755 |
private ConcurrentReadOutputStream makeCros(FileFormat ff){ |
| 756 |
if(ff==null){return null;} |
| 757 |
|
| 758 |
|
| 759 |
final int buff=(ordered ? Tools.mid(4, 64, (Shared.threads()*2)/3) : 4); |
| 760 |
|
| 761 |
final ConcurrentReadOutputStream ros=ConcurrentReadOutputStream.getStream(ff, null, buff, null, false); |
| 762 |
ros.start(); |
| 763 |
return ros; |
| 764 |
} |
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
private class ProcessThread extends Thread { |
| 773 |
|
| 774 |
|
| 775 |
ProcessThread(final ConcurrentReadInputStream cris_, final ByteStreamWriter bsw_, |
| 776 |
ConcurrentReadOutputStream rosAmino_, ConcurrentReadOutputStream ros16S_, ConcurrentReadOutputStream ros18S_, |
| 777 |
GeneModel pgm_, final int minLen, final int tid_){ |
| 778 |
cris=cris_; |
| 779 |
bsw=bsw_; |
| 780 |
rosAmino=rosAmino_; |
| 781 |
ros16S=ros16S_; |
| 782 |
ros18S=ros18S_; |
| 783 |
pgm=pgm_; |
| 784 |
tid=tid_; |
| 785 |
geneHistT=(geneHistBins>1 ? new long[geneHistBins] : null); |
| 786 |
caller=new GeneCaller(minLen, maxOverlapSameStrand, maxOverlapOppositeStrand, |
| 787 |
minStartScore, minStopScore, minKmerScore, minOrfScore, minAvgScore, pgm); |
| 788 |
} |
| 789 |
|
| 790 |
|
| 791 |
@Override |
| 792 |
public void run(){ |
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
processInner(); |
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
success=true; |
| 802 |
} |
| 803 |
|
| 804 |
|
| 805 |
void processInner(){ |
| 806 |
|
| 807 |
|
| 808 |
ListNum<Read> ln=cris.nextList(); |
| 809 |
|
| 810 |
|
| 811 |
if(ln!=null && !ln.isEmpty()){ |
| 812 |
Read r=ln.get(0); |
| 813 |
|
| 814 |
} |
| 815 |
|
| 816 |
|
| 817 |
while(ln!=null && ln.size()>0){ |
| 818 |
|
| 819 |
|
| 820 |
processList(ln); |
| 821 |
|
| 822 |
|
| 823 |
ln=cris.nextList(); |
| 824 |
} |
| 825 |
|
| 826 |
|
| 827 |
if(ln!=null){ |
| 828 |
cris.returnList(ln.id, ln.list==null || ln.list.isEmpty()); |
| 829 |
} |
| 830 |
} |
| 831 |
|
| 832 |
void processList(ListNum<Read> ln){ |
| 833 |
|
| 834 |
final ArrayList<Read> reads=ln.list; |
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
ArrayList<Orf> orfList=new ArrayList<Orf>(); |
| 839 |
|
| 840 |
|
| 841 |
for(int idx=0; idx<reads.size(); idx++){ |
| 842 |
Read r1=reads.get(idx); |
| 843 |
Read r2=r1.mate; |
| 844 |
|
| 845 |
|
| 846 |
if(!r1.validated()){r1.validate(true);} |
| 847 |
if(r2!=null && !r2.validated()){r2.validate(true);} |
| 848 |
|
| 849 |
|
| 850 |
final int initialLength1=r1.length(); |
| 851 |
final int initialLength2=r1.mateLength(); |
| 852 |
|
| 853 |
|
| 854 |
readsInT+=r1.pairCount(); |
| 855 |
basesInT+=initialLength1+initialLength2; |
| 856 |
|
| 857 |
if(r2!=null){ |
| 858 |
if(merge){ |
| 859 |
final int insert=BBMerge.findOverlapStrict(r1, r2, false); |
| 860 |
if(insert>0){ |
| 861 |
r2.reverseComplement(); |
| 862 |
r1=r1.joinRead(insert); |
| 863 |
r2=null; |
| 864 |
} |
| 865 |
}else if(ecco){ |
| 866 |
BBMerge.findOverlapStrict(r1, r2, true); |
| 867 |
} |
| 868 |
} |
| 869 |
|
| 870 |
{ |
| 871 |
|
| 872 |
{ |
| 873 |
ArrayList<Orf> list=processRead(r1); |
| 874 |
if(list!=null){orfList.addAll(list);} |
| 875 |
} |
| 876 |
if(r2!=null){ |
| 877 |
ArrayList<Orf> list=processRead(r2); |
| 878 |
if(list!=null){orfList.addAll(list);} |
| 879 |
} |
| 880 |
} |
| 881 |
} |
| 882 |
|
| 883 |
genesOutT+=orfList.size(); |
| 884 |
ByteBuilder bb=new ByteBuilder(); |
| 885 |
|
| 886 |
if(bsw!=null){ |
| 887 |
if(bsw.ordered){ |
| 888 |
for(Orf orf : orfList){ |
| 889 |
orf.appendGff(bb); |
| 890 |
bb.nl(); |
| 891 |
} |
| 892 |
bsw.add(bb, ln.id); |
| 893 |
bytesOutT+=bb.length(); |
| 894 |
}else{ |
| 895 |
for(Orf orf : orfList){ |
| 896 |
orf.appendGff(bb); |
| 897 |
bb.nl(); |
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
} |
| 904 |
if(bb.length()>0){ |
| 905 |
bsw.addJob(bb); |
| 906 |
bytesOutT+=bb.length(); |
| 907 |
} |
| 908 |
} |
| 909 |
} |
| 910 |
|
| 911 |
|
| 912 |
cris.returnList(ln); |
| 913 |
|
| 914 |
} |
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
ArrayList<Orf> processRead(final Read r){ |
| 923 |
ArrayList<Orf> list=caller.callGenes(r, pgm, true); |
| 924 |
|
| 925 |
if(geneHistT!=null && list!=null){ |
| 926 |
for(Orf o : list){ |
| 927 |
int bin=Tools.min(geneHistT.length-1, o.length()/geneHistDiv); |
| 928 |
geneHistT[bin]++; |
| 929 |
} |
| 930 |
} |
| 931 |
|
| 932 |
if(ros16S!=null){ |
| 933 |
if(list!=null && !list.isEmpty()){ |
| 934 |
|
| 935 |
ArrayList<Read> ssu=fetchType(r, list, r16S); |
| 936 |
if(ssu!=null && !ssu.isEmpty()){ |
| 937 |
|
| 938 |
ros16S.add(ssu, r.numericID); |
| 939 |
} |
| 940 |
} |
| 941 |
} |
| 942 |
if(ros18S!=null){ |
| 943 |
if(list!=null && !list.isEmpty()){ |
| 944 |
ArrayList<Read> ssu=fetchType(r, list, r18S); |
| 945 |
if(ssu!=null && !ssu.isEmpty()){ros18S.add(ssu, r.numericID);} |
| 946 |
} |
| 947 |
} |
| 948 |
|
| 949 |
if(rosAmino!=null){ |
| 950 |
if(mode==TRANSLATE){ |
| 951 |
if(list!=null && !list.isEmpty()){ |
| 952 |
ArrayList<Read> prots=translate(r, list); |
| 953 |
if(prots!=null){rosAmino.add(prots, r.numericID);} |
| 954 |
} |
| 955 |
}else if(mode==RETRANSLATE) { |
| 956 |
if(list!=null && !list.isEmpty()){ |
| 957 |
ArrayList<Read> prots=translate(r, list); |
| 958 |
ArrayList<Read> ret=detranslate(prots); |
| 959 |
if(ret!=null){rosAmino.add(ret, r.numericID);} |
| 960 |
} |
| 961 |
}else if(mode==RECODE) { |
| 962 |
if(list!=null && !list.isEmpty()){ |
| 963 |
Read recoded=recode(r, list); |
| 964 |
r.mate=null; |
| 965 |
ArrayList<Read> rec=new ArrayList<Read>(1); |
| 966 |
rec.add(recoded); |
| 967 |
if(rec!=null){rosAmino.add(rec, r.numericID);} |
| 968 |
} |
| 969 |
}else{ |
| 970 |
assert(false) : mode; |
| 971 |
} |
| 972 |
} |
| 973 |
|
| 974 |
return list; |
| 975 |
} |
| 976 |
|
| 977 |
|
| 978 |
protected long readsInT=0; |
| 979 |
|
| 980 |
protected long basesInT=0; |
| 981 |
|
| 982 |
|
| 983 |
protected long genesOutT=0; |
| 984 |
|
| 985 |
protected long bytesOutT=0; |
| 986 |
|
| 987 |
final long[] geneHistT; |
| 988 |
|
| 989 |
protected ConcurrentReadOutputStream rosAmino; |
| 990 |
protected ConcurrentReadOutputStream ros16S; |
| 991 |
protected ConcurrentReadOutputStream ros18S; |
| 992 |
|
| 993 |
|
| 994 |
boolean success=false; |
| 995 |
|
| 996 |
|
| 997 |
private final ConcurrentReadInputStream cris; |
| 998 |
|
| 999 |
private final ByteStreamWriter bsw; |
| 1000 |
|
| 1001 |
private final GeneModel pgm; |
| 1002 |
|
| 1003 |
final GeneCaller caller; |
| 1004 |
|
| 1005 |
final int tid; |
| 1006 |
} |
| 1007 |
|
| 1008 |
public static ArrayList<Read> fetchType(final Read r, final ArrayList<Orf> list, int type){ |
| 1009 |
if(list==null || list.isEmpty()){return null;} |
| 1010 |
ArrayList<Read> ret=new ArrayList<Read>(list.size()); |
| 1011 |
for(int strand=0; strand<2; strand++){ |
| 1012 |
for(Orf orf : list){ |
| 1013 |
if(orf.strand==strand && orf.type==type){ |
| 1014 |
Read sequence=fetch(orf, r.bases, r.id); |
| 1015 |
ret.add(sequence); |
| 1016 |
} |
| 1017 |
} |
| 1018 |
r.reverseComplement(); |
| 1019 |
} |
| 1020 |
return (ret.size()>0 ? ret : null); |
| 1021 |
} |
| 1022 |
|
| 1023 |
public static ArrayList<Read> translate(final Read r, final ArrayList<Orf> list){ |
| 1024 |
if(list==null || list.isEmpty()){return null;} |
| 1025 |
ArrayList<Read> prots=new ArrayList<Read>(list.size()); |
| 1026 |
for(int strand=0; strand<2; strand++){ |
| 1027 |
for(Orf orf : list){ |
| 1028 |
if(orf.strand==strand && orf.type==CDS){ |
| 1029 |
Read aa=translate(orf, r.bases, r.id); |
| 1030 |
prots.add(aa); |
| 1031 |
} |
| 1032 |
} |
| 1033 |
r.reverseComplement(); |
| 1034 |
} |
| 1035 |
return prots.isEmpty() ? null : prots; |
| 1036 |
} |
| 1037 |
|
| 1038 |
public static Read recode(final Read r, final ArrayList<Orf> list){ |
| 1039 |
if(list==null || list.isEmpty()){return r;} |
| 1040 |
for(int strand=0; strand<2; strand++){ |
| 1041 |
for(Orf orf : list){ |
| 1042 |
if(orf.strand==strand && orf.type==CDS){ |
| 1043 |
recode(orf, r.bases); |
| 1044 |
} |
| 1045 |
} |
| 1046 |
r.reverseComplement(); |
| 1047 |
} |
| 1048 |
return r; |
| 1049 |
} |
| 1050 |
|
| 1051 |
public static ArrayList<Read> detranslate(final ArrayList<Read> prots){ |
| 1052 |
if(prots==null || prots.isEmpty()){return null;} |
| 1053 |
ArrayList<Read> nucs=new ArrayList<Read>(prots.size()); |
| 1054 |
for(int strand=0; strand<2; strand++){ |
| 1055 |
for(Read prot : prots){ |
| 1056 |
Read nuc=detranslate(prot); |
| 1057 |
nucs.add(nuc); |
| 1058 |
} |
| 1059 |
} |
| 1060 |
return nucs; |
| 1061 |
} |
| 1062 |
|
| 1063 |
public static Read translate(Orf orf, byte[] bases, String id){ |
| 1064 |
|
| 1065 |
if(orf.strand==1){orf.flip();} |
| 1066 |
byte[] acids=AminoAcid.toAAs(bases, orf.start, orf.stop); |
| 1067 |
if(orf.strand==1){orf.flip();} |
| 1068 |
Read r=new Read(acids, null, id+"\t"+(Shared.strandCodes[orf.strand]+"\t"+orf.start+"-"+orf.stop), 0, Read.AAMASK); |
| 1069 |
|
| 1070 |
return r; |
| 1071 |
} |
| 1072 |
|
| 1073 |
public static ArrayList<Read> fetch(final Read r, final ArrayList<Orf> list){ |
| 1074 |
if(list==null || list.isEmpty()){return null;} |
| 1075 |
ArrayList<Read> genes=new ArrayList<Read>(list.size()); |
| 1076 |
for(int strand=0; strand<2; strand++){ |
| 1077 |
for(Orf orf : list){ |
| 1078 |
if(orf.strand==strand && orf.type==CDS){ |
| 1079 |
Read gene=fetch(orf, r.bases, r.id); |
| 1080 |
genes.add(gene); |
| 1081 |
} |
| 1082 |
} |
| 1083 |
r.reverseComplement(); |
| 1084 |
} |
| 1085 |
return genes.isEmpty() ? null : genes; |
| 1086 |
} |
| 1087 |
|
| 1088 |
public static Read fetch(Orf orf, Read source){ |
| 1089 |
assert(orf.start>=0 && orf.stop<source.length()) : source.length()+"\n"+orf; |
| 1090 |
if(orf.strand==1){source.reverseComplement();} |
| 1091 |
Read r=fetch(orf, source.bases, source.id); |
| 1092 |
if(orf.strand==1){source.reverseComplement();} |
| 1093 |
return r; |
| 1094 |
} |
| 1095 |
|
| 1096 |
public static Read fetch(Orf orf, byte[] bases, String id){ |
| 1097 |
assert(orf.start>=0 && orf.stop<bases.length) : bases.length+"\n"+orf; |
| 1098 |
if(orf.strand==1){orf.flip();} |
| 1099 |
byte[] sub=Arrays.copyOfRange(bases, orf.start, orf.stop+1); |
| 1100 |
if(orf.strand==1){orf.flip();} |
| 1101 |
Read r=new Read(sub, null, id+"\t"+(Shared.strandCodes[orf.strand]+"\t"+orf.start+"-"+orf.stop), 0, 0); |
| 1102 |
assert(r.length()==orf.length()) : r.length()+", "+orf.length(); |
| 1103 |
return r; |
| 1104 |
} |
| 1105 |
|
| 1106 |
public static void recode(Orf orf, byte[] bases){ |
| 1107 |
if(orf.strand==1){orf.flip();} |
| 1108 |
byte[] acids=AminoAcid.toAAs(bases, orf.start, orf.stop); |
| 1109 |
for(int apos=0, bpos=orf.start; apos<acids.length; apos++){ |
| 1110 |
byte aa=acids[apos]; |
| 1111 |
int number=AminoAcid.acidToNumber[aa]; |
| 1112 |
String codon=(number>=0 ? AminoAcid.canonicalCodons[number] : "NNN"); |
| 1113 |
for(int i=0; i<3; i++, bpos++) { |
| 1114 |
bases[bpos]=(byte)codon.charAt(i); |
| 1115 |
} |
| 1116 |
} |
| 1117 |
if(orf.strand==1){orf.flip();} |
| 1118 |
} |
| 1119 |
|
| 1120 |
public static Read detranslate(Read prot){ |
| 1121 |
ByteBuilder bb=new ByteBuilder(prot.length()*3); |
| 1122 |
for(byte aa : prot.bases){ |
| 1123 |
int number=AminoAcid.acidToNumber[aa]; |
| 1124 |
String codon=(number>=0 ? AminoAcid.canonicalCodons[number] : "NNN"); |
| 1125 |
bb.append(codon); |
| 1126 |
} |
| 1127 |
Read r=new Read(bb.array, null, prot.id, prot.numericID, 0); |
| 1128 |
return r; |
| 1129 |
} |
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
public static GeneCaller makeGeneCaller(GeneModel pgm){ |
| 1136 |
GeneCaller caller=new GeneCaller(minLen, maxOverlapSameStrand, maxOverlapOppositeStrand, |
| 1137 |
minStartScore, minStopScore, minKmerScore, minOrfScore, minAvgScore, pgm); |
| 1138 |
return caller; |
| 1139 |
} |
| 1140 |
|
| 1141 |
private long maxReads=-1; |
| 1142 |
private boolean merge; |
| 1143 |
private boolean ecco; |
| 1144 |
private int passes=1; |
| 1145 |
|
| 1146 |
private long readsIn=0; |
| 1147 |
private long basesIn=0; |
| 1148 |
private long genesOut=0; |
| 1149 |
private long bytesOut=0; |
| 1150 |
|
| 1151 |
private static int minLen=80; |
| 1152 |
private static int maxOverlapSameStrand=80; |
| 1153 |
private static int maxOverlapOppositeStrand=110; |
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
|
| 1158 |
|
| 1159 |
|
| 1160 |
|
| 1161 |
|
| 1162 |
|
| 1163 |
private static float minStartScore=-0.10f; |
| 1164 |
private static float minStopScore=-0.5f; |
| 1165 |
private static float minKmerScore=0.02f; |
| 1166 |
private static float minOrfScore=50f; |
| 1167 |
private static float minAvgScore=0.08f; |
| 1168 |
|
| 1169 |
long geneStopsMade=0; |
| 1170 |
long geneStartsMade=0; |
| 1171 |
long geneStartsRetained=0; |
| 1172 |
long geneStopsRetained=0; |
| 1173 |
long geneStartsOut=0; |
| 1174 |
|
| 1175 |
long tRNAOut=0; |
| 1176 |
long r16SOut=0; |
| 1177 |
long r23SOut=0; |
| 1178 |
long r5SOut=0; |
| 1179 |
long r18SOut=0; |
| 1180 |
|
| 1181 |
ScoreTracker stCds=new ScoreTracker(CDS); |
| 1182 |
ScoreTracker stCds2=new ScoreTracker(CDS); |
| 1183 |
ScoreTracker stCdsPass=new ScoreTracker(CDS); |
| 1184 |
ScoreTracker sttRNA=new ScoreTracker(tRNA); |
| 1185 |
ScoreTracker st16s=new ScoreTracker(r16S); |
| 1186 |
ScoreTracker st23s=new ScoreTracker(r23S); |
| 1187 |
ScoreTracker st5s=new ScoreTracker(r5S); |
| 1188 |
ScoreTracker st18s=new ScoreTracker(r18S); |
| 1189 |
|
| 1190 |
ScoreTracker[] trackers=new ScoreTracker[] {stCdsPass, sttRNA, st16s, st23s, st5s, st18s}; |
| 1191 |
|
| 1192 |
private int geneHistBins=1000; |
| 1193 |
private int geneHistDiv=21; |
| 1194 |
private final long[] geneHist; |
| 1195 |
private boolean printZeroCountHist=false; |
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
private ArrayList<String> fnaList=new ArrayList<String>(); |
| 1200 |
private ArrayList<String> pgmList=new ArrayList<String>(); |
| 1201 |
private ArrayList<String> inGffList=new ArrayList<String>(); |
| 1202 |
private String outGff=null; |
| 1203 |
private String outAmino=null; |
| 1204 |
private String out16S=null; |
| 1205 |
private String out18S=null; |
| 1206 |
private String compareToGff=null; |
| 1207 |
private String outStats="stderr"; |
| 1208 |
private String geneHistFile=null; |
| 1209 |
private boolean json_out=false; |
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
private final FileFormat ffoutGff; |
| 1216 |
private final FileFormat ffoutAmino; |
| 1217 |
private final FileFormat ffout16S; |
| 1218 |
private final FileFormat ffout18S; |
| 1219 |
|
| 1220 |
|
| 1221 |
int mode=TRANSLATE; |
| 1222 |
|
| 1223 |
|
| 1224 |
private static final int TRANSLATE=1; |
| 1225 |
|
| 1226 |
|
| 1227 |
private static final int RETRANSLATE=2; |
| 1228 |
|
| 1229 |
|
| 1230 |
private static final int RECODE=3; |
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
private PrintStream outstream=System.err; |
| 1235 |
public boolean verbose=false; |
| 1236 |
public boolean extendedStats=false; |
| 1237 |
public boolean errorState=false; |
| 1238 |
private boolean overwrite=true; |
| 1239 |
private boolean append=false; |
| 1240 |
private boolean ordered=false; |
| 1241 |
|
| 1242 |
|
| 1243 |
} |