package jgi; import java.io.File; import java.io.PrintStream; import java.lang.Thread.State; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.concurrent.atomic.AtomicLong; import bloom.KCountArray; import bloom.KmerCountAbstract; import bloom.ReadCounter; import dna.AminoAcid; import fileIO.FileFormat; import fileIO.ReadWrite; import fileIO.TextStreamWriter; import shared.Parse; import shared.Parser; import shared.PreParser; import shared.Shared; import shared.Timer; import shared.Tools; import stream.ConcurrentReadInputStream; import stream.ConcurrentReadOutputStream; import stream.FastaReadInputStream; import stream.Read; import structures.ByteBuilder; import structures.ListNum; import tracker.ReadStats; /** * @author Brian Bushnell * @date Oct 11, 2012 * */ public class KmerCoverage { public static void main(String[] args){ {//Preparse block for help, config files, and outstream PreParser pp=new PreParser(args, new Object() { }.getClass().getEnclosingClass(), false); args=pp.args; outstream=pp.outstream; } String in1=(args[0].indexOf("=")>0 ? null : args[0]); String in2=(in1!=null && args.length>1 ? args[1] : null); if(in2!=null && "null".equalsIgnoreCase(in2)){in2=null;} { if(in1!=null && !in1.contains(",")){ File f=new File(in1); if(!f.exists() || !f.isFile()){throw new RuntimeException(in1+" does not exist.");} } if(in2!=null && !in2.contains(",")){ File f=new File(in2); if(!f.exists() || !f.isFile()){throw new RuntimeException(in2+" does not exist.");} if(in1.equalsIgnoreCase(in2)){ throw new RuntimeException("Both input files are the same."); } } } KmerCountAbstract.minQuality=4; KmerCountAbstract.minProb=0.1f; KmerCountAbstract.CANONICAL=true; int k=31; int cbits=16; // int gap=0; int hashes=4; long cells=-1; long maxReads=-1; int buildpasses=1; long tablereads=-1; //How many reads to process when building the hashtable int buildStepsize=4; String output=null; int prehashes=-1; long precells=-1; String histFile=null; int threads=-1; int minq=KmerCountAbstract.minQuality; boolean auto=true; List extra=null; Parser parser=new Parser(); long memory=Runtime.getRuntime().maxMemory(); for(int i=(in1==null ? 0 : 1); i1 ? split[1] : null; if(Parser.parseCommonStatic(arg, a, b)){ //do nothing }else if(Parser.parseZip(arg, a, b)){ //do nothing }else if(Parser.parseQuality(arg, a, b)){ //do nothing }else if(Parser.parseFasta(arg, a, b)){ //do nothing }else if(parser.parseInterleaved(arg, a, b)){ //do nothing }else if(a.equals("k") || a.equals("kmer")){ k=Integer.parseInt(b); }else if(a.equals("in") || a.equals("in1")){ in1=b; }else if(a.equals("in2")){ in2=b; }else if(a.startsWith("bits") ||a.startsWith("cbits") || a.startsWith("cellbits")){ cbits=Integer.parseInt(b); }else if(a.startsWith("histlen") ||a.startsWith("histogramlen")){ HIST_LEN_PRINT=Tools.min(Integer.MAX_VALUE, Long.parseLong(b)+1); }else if(a.startsWith("matrixbits")){ int matrixbits=Integer.parseInt(b); assert(matrixbits<63); cells=1L<(); extra.add(b); }else{ extra=Arrays.asList(b.split(",")); } } }else{ throw new RuntimeException("Unknown parameter "+arg); } } {//Process parser fields Parser.processQuality(); } assert(FastaReadInputStream.settingsOK()); if(k>31){CANONICAL=KmerCountAbstract.CANONICAL=false;} assert(CANONICAL==KmerCountAbstract.CANONICAL); // if(output!=null && reads1.contains(",")){ // throw new RuntimeException("\nLists of input files can only be used with histogram output, not full output.\n" + // "Please set output=null or move the extra input files to 'extra=file1,file2,...fileN'"); // } { if(histFile==null){ }else{ USE_HISTOGRAM=true; } final int maxCount=(int)(cbits>16 ? Integer.MAX_VALUE : (1L<0); HIST_LEN_PRINT=Tools.max(1, Tools.min(HIST_LEN_PRINT, maxCount+1)); assert(HIST_LEN_PRINT<=Integer.MAX_VALUE) : HIST_LEN_PRINT+", "+Integer.MAX_VALUE; HIST_LEN=(int)Tools.min(maxCount+1, Tools.max(HIST_LEN_PRINT, HIST_LEN)); histogram_total=new long[HIST_LEN]; } if(extra!=null){ for(String s : extra){ File f=new File(s); if(!f.exists() || !f.isFile()){throw new RuntimeException(s+" does not exist.");} assert(!s.equalsIgnoreCase(in1) && (in2==null || !s.equalsIgnoreCase(in2))) : "\nInput file "+s+" should not be included as an extra file.\n"; } } // outstream.println("ForceInterleaved = "+FASTQ.FORCE_INTERLEAVED); // assert(false) : reads1+", "+reads2+", "+output; // if(FASTQ.FORCE_INTERLEAVED && in2==null){ // outstream.println() // } if(threads<=0){ if(auto){THREADS=Shared.LOGICAL_PROCESSORS;} else{THREADS=8;} }else{ THREADS=threads; } // System.err.println("THREADS="+THREADS+", KmerCountAbstract.THREADS="+KmerCountAbstract.THREADS); if(auto && cells==-1){ final long usable=(long)Tools.max(((memory-96000000)*.73), memory*0.45); long mem=usable-(USE_HISTOGRAM ? (HIST_LEN*8*(THREADS+1)) : 0); if(buildpasses>1){mem/=2;} cells=(mem*8)/cbits; // // long tablebytes=((1L<0 && prehashes>0 ? Tools.toKMG(precells) : "?")); outstream.println("prefilter hashes: \t"+(precells>0 && prehashes>0 ? ""+prehashes : "?")); } outstream.println("base min quality: \t"+KmerCountAbstract.minQuality); outstream.println("kmer min prob: \t"+KmerCountAbstract.minProb); outstream.println(); outstream.println("remove duplicates:\t"+!KmerCountAbstract.KEEP_DUPLICATE_KMERS); outstream.println("fix spikes: \t"+FIX_SPIKES); if(USE_HISTOGRAM && HIST_LEN>0){ outstream.println("histogram length: \t"+(USE_HISTOGRAM ? HIST_LEN : 0)); } if(histFile!=null){ outstream.println("print zero cov: \t"+PRINT_ZERO_COVERAGE); } outstream.println(); } if(!prefilter && k<32 && cells>(1L<<(2*k))){cells=(1L<<(2*k));} assert(cells>0); // KmerCountAbstract.THREADS=Tools.max(THREADS/2, KmerCountAbstract.THREADS); //Seems like 4 is actually optimal... FastaReadInputStream.MIN_READ_LEN=k; Timer t=new Timer(); Timer ht=new Timer(); t.start(); ht.start(); KCountArray kca; KCountArray prefilterArray=null; outstream.println(); ReadCounter rc=new ReadCounter(k, true, false, false, Shared.AMINO_IN); rc.detectStepsize=buildStepsize; if(prefilter){ prefilterArray=rc.makeKca(in1, in2, extra, 2, precells, prehashes, minq, tablereads, 1, 1, 1, null, 0); outstream.println("Made prefilter: \t"+prefilterArray.toShortString(prehashes)); } kca=rc.makeKca(in1, in2, extra, cbits, cells, hashes, minq, tablereads, buildpasses, 2, 2, prefilterArray, (prefilterArray==null ? 0 : prefilterArray.maxValue)); ht.stop(); outstream.println("Made hash table: \t"+kca.toShortString(hashes)); long estUnique; outstream.println(); if(prefilterArray!=null){ int lim1=prefilterArray.maxValue, lim2=prefilterArray.maxValue+1; double a=prefilterArray.estimateUniqueKmers(prehashes); double b=kca.estimateUniqueKmers(hashes, lim2); a=a-b; if(CANONICAL){ // a=(a*KCountArray.canonMask)/(KCountArray.canonMask+1); // b=(b*KCountArray.canonMask)/(KCountArray.canonMask+1); }else{ a/=2; b/=2; } estUnique=((long)((a+b))); outstream.println("Estimated kmers of depth 1-"+lim1+": \t"+(long)a); outstream.println("Estimated kmers of depth "+lim2+"+ : \t"+(long)b); }else{ // double est=kca.cells*(1-Math.pow(1-Math.sqrt(kca.usedFraction()), 1.0/hashes)); // double est=kca.cells*(1-Math.pow(1-kca.usedFraction(), 1.0/hashes)); double est=kca.estimateUniqueKmers(hashes); // System.out.println("Used cells: "+kca.cellsUsed(1)); if(CANONICAL){ // est=(est*KCountArray.canonMask)/(KCountArray.canonMask+1); }else{ est/=2; } estUnique=((long)((est))); } outstream.println("Estimated unique kmers: \t"+estUnique);//+", or "+estUnique+" counting forward kmers only."); // outstream.println("(Includes forward and reverse kmers)"); outstream.println(); outstream.println("Table creation time:\t\t"+ht);//+" \t"+Tools.format("%.2f", totalBases*1000000.0/(ht.elapsed))+" kb/sec"); long bases=0; if(in1!=null && in1.contains(",") && !new File(in1).exists()){ String[] list1=in1.split(","); String[] list2=(in2==null ? null : in2.split(",")); bases=count(list1, list2, kca, k, maxReads, output, ordered, overwrite, histFile, estUnique); }else{ bases=count(in1, in2, kca, k, maxReads, output, ordered, overwrite, histFile, estUnique); } printTopology(); t.stop(); outstream.println("\nTotal time: \t\t"+t+" \t"+Tools.format("%.2f", bases*1000000.0/(t.elapsed))+" kb/sec"); //Close the print stream if it was redirected Shared.closeStream(outstream); } public static void printTopology(){ long total=peaks.get()+spikes.get()+flats.get()+valleys.get()+slopes.get(); double mult=100.0/total; long sp=spikes.get(); long pe=peaks.get(); long va=valleys.get(); long sl=slopes.get(); long fl=flats.get(); double dsp=mult*sp; double dpe=mult*pe; double dva=mult*va; double dsl=mult*sl; double dfl=mult*fl; System.err.println("\nDepth Topology\t"); System.err.println("Spikes: \t\t\t"+(dsp<10 ? " " : "")+Tools.format("%.3f%% \t%d",dsp,sp)); System.err.println("Peaks: \t\t\t"+(dpe<10 ? " " : "")+Tools.format("%.3f%% \t%d",dpe,pe)); System.err.println("Valleys: \t\t\t"+(dva<10 ? " " : "")+Tools.format("%.3f%% \t%d",dva,va)); System.err.println("Slopes: \t\t\t"+(dsl<10 ? " " : "")+Tools.format("%.3f%% \t%d",dsl,sl)); System.err.println("Flats: \t\t\t"+(dfl<10 ? " " : "")+Tools.format("%.3f%% \t%d",dfl,fl)); } public static long count(String reads1, String reads2, KCountArray kca, int k, long maxReads, String output, boolean ordered, boolean overwrite, String histFile, long estUnique) { final ConcurrentReadInputStream cris; { FileFormat ff1=FileFormat.testInput(reads1, FileFormat.FASTQ, null, true, true); FileFormat ff2=FileFormat.testInput(reads2, FileFormat.FASTQ, null, true, true); cris=ConcurrentReadInputStream.getReadInputStream(maxReads, true, ff1, ff2); cris.start(); //4567 } assert(cris!=null) : reads1; if(fileIO.FileFormat.hasFastaExtension(reads1)){ ADD_CARROT=false; } if(verbose){System.err.println("Started cris");} boolean paired=cris.paired(); if(verbose){System.err.println("Paired: "+paired);} final ConcurrentReadOutputStream ros; if(output!=null){ final int buff=(!ordered ? 8 : Tools.max(16, 2*THREADS)); String out1=output.replaceFirst("#", "1"); String out2=null; if(cris.paired()){ if(output.contains("#")){ out2=output.replaceFirst("#", "2"); }else{ outstream.println("Writing interleaved."); } } assert(!out1.equalsIgnoreCase(reads1) && !out1.equalsIgnoreCase(reads1)); assert(out2==null || (!out2.equalsIgnoreCase(reads1) && !out2.equalsIgnoreCase(reads2))); FileFormat ff1=FileFormat.testOutput(out1, FileFormat.FASTQ, OUTPUT_ATTACHMENT ? "attachment" : null, true, overwrite, append, ordered); FileFormat ff2=FileFormat.testOutput(out2, FileFormat.FASTQ, OUTPUT_ATTACHMENT ? "attachment" : null, true, overwrite, append, ordered); ros=ConcurrentReadOutputStream.getStream(ff1, ff2, buff, null, true); ros.start(); outstream.println("Started output threads."); }else{ ros=null; } long bases=calcCoverage(cris, kca, k, maxReads, ros, histFile, overwrite, estUnique); ReadWrite.closeStreams(cris, ros); if(verbose){System.err.println("Closed stream");} return bases; } public static long count(String[] list1, String[] list2, KCountArray kca, int k, long maxReads, String output, boolean ordered, boolean overwrite, String histFile, long estUnique) { ConcurrentReadOutputStream ros=null; String[] out1=null, out2=null; final int buff=(!ordered ? 8 : Tools.max(16, 2*THREADS)); if(output!=null){ if(!new File(output).exists()){ out1=output.split(","); }else{ out1=new String[] {output}; } out2=new String[out1.length]; for(int i=0; i1){ if(ros!=null){ ReadWrite.closeStream(ros); } FileFormat ff1=FileFormat.testOutput(out1[x], FileFormat.FASTQ, OUTPUT_ATTACHMENT ? "attachment" : null, true, overwrite, append, ordered); FileFormat ff2=out2==null ? null : FileFormat.testOutput(out2[x], FileFormat.FASTQ, OUTPUT_ATTACHMENT ? "attachment" : null, true, overwrite, append, ordered); ros=ConcurrentReadOutputStream.getStream(ff1, ff2, buff, null, true); ros.start(); outstream.println("Started output threads."); }else if(ros!=null){ ros.resetNextListID(); } } String reads1=list1[x]; String reads2=(list2==null || list2.length<=x ? null : list2[x]); final ConcurrentReadInputStream cris; { FileFormat ff1=FileFormat.testInput(reads1, FileFormat.FASTQ, null, true, true); FileFormat ff2=FileFormat.testInput(reads2, FileFormat.FASTQ, null, true, true); cris=ConcurrentReadInputStream.getReadInputStream(maxReads, true, ff1, ff2); if(verbose){System.err.println("Started cris");} cris.start(); //4567 if(ff1.fasta()){ADD_CARROT=false;} } boolean paired=cris.paired(); if(verbose){System.err.println("Paired: "+paired);} bases+=calcCoverage(cris, kca, k, maxReads, ros, histFile, overwrite, estUnique); ReadWrite.closeStream(cris); if(verbose){System.err.println("Closed stream");} } //Wait until threads finish! ReadWrite.closeStream(ros); return bases; } public static long calcCoverage(ConcurrentReadInputStream cris, KCountArray kca, int k, long maxReads, ConcurrentReadOutputStream ros, String histFile, boolean overwrite, long estUnique) { Timer tdetect=new Timer(); tdetect.start(); long totalBases=0; long totalReads=0; // assert(false) : THREADS; ProcessThread[] pta=new ProcessThread[THREADS]; for(int i=0; i1){ histogram_total[1]+=histogram_total[0]; histogram_total[0]=0; } // outstream.println(); tdetect.stop(); outstream.println("Table read time: \t\t"+tdetect+" \t"+Tools.format("%.2f", totalBases*1000000.0/(tdetect.elapsed))+" kb/sec"); outstream.println("Total reads: \t\t"+totalReads); outstream.println("Total bases: \t\t"+totalBases); // outstream.println(); if(histogram_total!=null){ TextStreamWriter tswh=null; StringBuilder sb=new StringBuilder(100); if(USE_HISTOGRAM){ tswh=new TextStreamWriter(histFile, overwrite, false, false); tswh.start(); tswh.print("#Depth\tRaw_Count\tUnique_Kmers\n"); } int lim=(int)(HIST_LEN_PRINT-1); long remaining=shared.Vector.sum(histogram_total); long sumRaw1=0; long sumRaw2=0; long sum1=0; long sum2=0; long sumsquare=0; for(int i=0; i0 || y>0){ sb.append(i).append('\t'); sb.append(x).append('\t'); sb.append(y).append('\n'); } tswh.print(sb.toString()); sb.setLength(0); } if(sumRaw1>=remaining){break;} //Stop once there is no more coverage, even if PRINT_ZERO_COVERAGE is not set. } for(int i=lim; i0 || sum2>0){ sb.append(lim).append('\t'); sb.append(sumRaw2).append('\t'); sb.append(sum2).append('\n'); } tswh.print(sb.toString()); tswh.poison(); tswh.waitForFinish(); outstream.println("Wrote histogram to "+histFile); } long histCount=shared.Vector.sum(histogram_total); //Total number of kmers counted long halfCount=(histCount+1)/2; double histCountU=0; //Unique kmers counted long temp1=0; double temp2=0; int median_all=-1; int median_unique=-1; for(int i=0; i=halfCount && median_all<0){median_all=i;} // histSum+=(x*(double)i); histCountU+=(x/(double)Tools.max(1, i)); } double halfCount2=(histCountU)/2; for(int i=0; i=halfCount2 && median_unique<0){ median_unique=i; break; } } if(median_all<0){median_all=0;} double avg_all=sumsquare/(double)histCount; double avg_unique=histCount/histCountU; double stdev_unique=Tools.standardDeviationHistogramKmer(histogram_total); double stdev_all=Tools.standardDeviationHistogram(histogram_total); outstream.println("Total kmers counted: \t"+(sumRaw1+sumRaw2)); double uniqueC=((sum1+sum2)*100.0/(sumRaw1+sumRaw2)); double uniqueE=((estUnique)*100.0/(sumRaw1+sumRaw2)); double uniqueM=Tools.max(uniqueC, uniqueE); outstream.println("Total unique kmer count: \t"+(sum1+sum2)); if(CANONICAL){outstream.println("Includes forward kmers only.");} outstream.println("The unique kmer estimate can be more accurate than the unique count, if the tables are very full."); outstream.println("The most accurate value is the greater of the two."); outstream.println(); outstream.println("Percent unique: \t"+(uniqueM<10 ? " " : "")+Tools.format("%.2f%%", uniqueM)); outstream.println("Depth average: \t"+Tools.format("%.2f\t(unique kmers)", avg_unique)); outstream.println("Depth median: \t"+Tools.format("%d\t(unique kmers)", median_unique)); outstream.println("Depth standard deviation: \t"+Tools.format("%.2f\t(unique kmers)", stdev_unique)); outstream.println("\nDepth average: \t"+Tools.format("%.2f\t(all kmers)", avg_all)); outstream.println("Depth median: \t"+Tools.format("%d\t(all kmers)", median_all)); outstream.println("Depth standard deviation: \t"+Tools.format("%.2f\t(all kmers)", stdev_all)); } return totalBases; } /** * Locates and fixes spikes in a coverage profile (potentially) caused by false positives in a bloom filter. * Theory: If a high-count kmer is adjacent on both sides to low-count kmers, it may be a false positive. * It could either be reduced to the max of the two flanking points or examined in more detail. * @param array An array of kmer counts for adjacent kmers in a read. */ private static void fixSpikes(int[] array){ for(int i=1; i1 && b>a && b>c){ //peak if((b>=2*a || b>a+2) && (b>=2*c || b>c+2)){ //spike array[i]=(int)Tools.max(a, c); } } } } private static void fixSpikes(int[] array, long[] kmers, KCountArray kca, int k){ if(array.length<3){return;} if(array[1]-array[0]>1){ array[0]=kca.readPrecise(kmers[0], k, CANONICAL); } if(array[array.length-1]-array[array.length-2]>1){ array[array.length-1]=kca.readPrecise(kmers[array.length-1], k, CANONICAL); } for(int i=1; i1){ long a=Tools.max(1, array[i-1]); long c=Tools.max(1, array[i+1]); long key=kmers[i]; if(b>a && b>c){ //peak if(b<6 || b>a+1 || b>c+1){ array[i]=kca.readPreciseMin(key, k, CANONICAL); } // if((b>=2*a || b>a+2) && (b>=2*c || b>c+2)){ // //spike // int b1=(int)((a+c)/2); // int b2=kca.readLeft(key, k, CANONICAL); // int b3=kca.readRight(key, k, CANONICAL); // array[i]=Tools.min(b, b1, b2, b3); // } // else // { //// array[i]=kca.readPreciseMin(key, k, CANONICAL); // } } // else // if(Tools.max(ada, adc)>=Tools.max(2, Tools.min((int)a, b, (int)c)/4)){ // array[i]=kca.readPrecise(key, k, CANONICAL); // } // else // if(b>a+1 || b>c+1){ // //steep // array[i]=kca.readPrecise(key, k, CANONICAL); // } } } } private static void analyzeSpikes(int[] array, int width){ if(array.length<3){return;} int peakcount=0, valleycount=0, spikecount=0, flatcount=0, slopecount=0; for(int i=1; ia && b>c){ peakcount++; if((b>=2*a || b>a+2) && (b>=2*c || b>c+2)){ spikecount++; } }else if(b0){peaks.addAndGet(peakcount);} if(valleycount>0){valleys.addAndGet(valleycount);} if(spikecount>0){spikes.addAndGet(spikecount);} if(flatcount>0){flats.addAndGet(flatcount);} if(slopecount>0){slopes.addAndGet(slopecount);} } public static int[] generateCoverage(Read r, KCountArray kca, int k) { if(k>31){return generateCoverageLong(r, kca, k);} if(r==null || r.bases==null || r.length()63 ? -1L : ~((-1L)<=k){ // int count=kca.readPrecise(kmer, k, CANONICAL); int count=kca.read(kmer, k, CANONICAL); out[i-k+1]=count; if(kmers!=null){kmers[i-k+1]=kmer;} } } } }else{ out=new int[(r.length()-k+1+(kmersamplerate-1))/kmersamplerate]; Arrays.fill(out, -1); for(int i=0; i=k && i%kmersamplerate==0){ // int count=kca.readPrecise(kmer, k, CANONICAL); int count=kca.read(kmer, k, CANONICAL); out[(i-k+1)/kmersamplerate]=count; if(kmers!=null){kmers[(i-k+1)/kmersamplerate]=kmer;} } } } } if(FIX_SPIKES){fixSpikes(out, kmers, kca, k);} // fixSpikes(out, 1); analyzeSpikes(out, 1); return out; } public static int[] generateCoverageLong(Read r, KCountArray kca, int k) { if(r==null || r.bases==null || r.length()k){ long x2=AminoAcid.baseToNumber[bases[i-k]]; kmer=kmer^(x2<=k){ int count=kca.read(kmer); out[i-k+1]=count; } } } }else{ out=new int[(r.length()-k+1+(kmersamplerate-1))/kmersamplerate]; Arrays.fill(out, -1); for(int i=0; ik){ long x2=AminoAcid.baseToNumber[bases[i-k]]; kmer=kmer^(x2<=k && i%kmersamplerate==0){ int count=kca.read(kmer); out[(i-k+1)/kmersamplerate]=count; } } } } fixSpikes(out); analyzeSpikes(out, 1); return out; } private static class ProcessThread extends Thread{ ProcessThread(ConcurrentReadInputStream cris_, KCountArray kca_, int k_, ConcurrentReadOutputStream ros_){ cris=cris_; kca=kca_; k=k_; ros=ros_; } @Override public void run(){ countInThread(); } void countInThread() { ListNum ln=cris.nextList(); ArrayList reads=(ln!=null ? ln.list : null); while(ln!=null && reads!=null && reads.size()>0){//ln!=null prevents a compiler potential null access warning for(int rnum=0; rnum=0){hist[x]++;} } } return cov; } } private String toFastaString(Read r){ if(r.bases==null || r.length()0 || MIN_AVERAGE>0){r.setDiscarded(true);} if(USE_HEADER){ return (ADD_CARROT ? ">" : "")+r.id+";0;0 0 0 0 0\n"+r.bases==null ? "" : new String(r.bases); }else{ return (ADD_CARROT ? ">" : "")+r.id+"\n"+(r.bases==null ? "" : new String(r.bases))+"\n0\n0 0 0 0 0"; } }else{ totalBases+=r.length(); int[] cov=generateCoverage(r, kca, k); if(hist!=null){ for(int i=0; i');} sb.append(r.id).append(';'); int min=cov[0], max=cov[0], sum=0; for(int i=0; i');} sb.append(r.id).append('\n'); sb.append(new String(r.bases)).append('\n'); int min=cov[0], max=cov[0], sum=0; for(int i=0; i0 || MIN_AVERAGE>0){r.setDiscarded(true);} sb.append("\n0\n0 0 0 0 0"); return sb; }else{ totalBases+=r.length(); int[] cov=generateCoverage(r, kca, k); if(hist!=null){ for(int i=0; i=0) : i+", "+cov[i]+", "+HIST_LEN; hist[x]++; } } sb.append('\n'); int min=cov[0], max=cov[0], sum=0; for(int i=0; i