jpayne@68: package bloom; jpayne@68: jpayne@68: import java.util.ArrayList; jpayne@68: import java.util.Locale; jpayne@68: jpayne@68: import dna.AminoAcid; jpayne@68: import fileIO.FileFormat; jpayne@68: import fileIO.ReadWrite; jpayne@68: import shared.Timer; jpayne@68: import stream.ConcurrentReadInputStream; jpayne@68: import stream.FastaReadInputStream; jpayne@68: import stream.Read; jpayne@68: import structures.ListNum; jpayne@68: jpayne@68: /** jpayne@68: * @author Brian Bushnell jpayne@68: * @date Jul 5, 2012 jpayne@68: * jpayne@68: */ jpayne@68: public class KmerCount3 extends KmerCountAbstract { jpayne@68: jpayne@68: public static void main(String[] args){ jpayne@68: jpayne@68: Timer t=new Timer(); jpayne@68: jpayne@68: String fname1=args[0]; jpayne@68: String fname2=(args.length>3 || args[1].contains(".") ? args[1] : null); jpayne@68: int k=Integer.parseInt(args[args.length-2]); jpayne@68: int cbits=Integer.parseInt(args[args.length-1]); jpayne@68: jpayne@68: KCountArray2 count=null; jpayne@68: jpayne@68: if(fileIO.FileFormat.hasFastaExtension(fname1)){ jpayne@68: FastaReadInputStream.MIN_READ_LEN=k; jpayne@68: } jpayne@68: count=countFastq(fname1, fname2, k, cbits); jpayne@68: jpayne@68: jpayne@68: t.stop(); jpayne@68: System.out.println("Finished counting; time = "+t); jpayne@68: jpayne@68: long[] freq=count.transformToFrequency(); jpayne@68: jpayne@68: // System.out.println(count+"\n"); jpayne@68: // System.out.println(Arrays.toString(freq)+"\n"); jpayne@68: jpayne@68: long sum=sum(freq); jpayne@68: System.out.println("Kmer fraction:"); jpayne@68: int lim1=8, lim2=16; jpayne@68: for(int i=0; i=freq.length){prefix=lim1+"+";} jpayne@68: while(prefix.length()<8){prefix=prefix+" ";} jpayne@68: System.out.println(prefix+"\t"+String.format(Locale.ROOT, "%.3f%% ",(100l*x/(double)sum))+"\t"+x); jpayne@68: lim1*=2; jpayne@68: lim2=min(lim2*2, freq.length); jpayne@68: } jpayne@68: } jpayne@68: jpayne@68: public static KCountArray2 countFastq(String reads1, String reads2, int k, int cbits){ jpayne@68: assert(k>=1 && k<20); jpayne@68: final int kbits=2*k; jpayne@68: final long mask=(kbits>63 ? -1L : ~((-1L)< ln=cris.nextList(); jpayne@68: ArrayList reads=(ln!=null ? ln.list : null); jpayne@68: jpayne@68: if(reads!=null && !reads.isEmpty()){ jpayne@68: Read r=reads.get(0); jpayne@68: assert(paired==(r.mate!=null)); jpayne@68: } jpayne@68: jpayne@68: while(ln!=null && reads!=null && reads.size()>0){//ln!=null prevents a compiler potential null access warning jpayne@68: //System.err.println("reads.size()="+reads.size()); jpayne@68: for(Read r : reads){ jpayne@68: readsProcessed++; jpayne@68: jpayne@68: len=0; jpayne@68: kmer=0; jpayne@68: byte[] bases=r.bases; jpayne@68: byte[] quals=r.quality; jpayne@68: for(int i=0; i=k){ jpayne@68: // System.out.print("Incrementing "+Long.toHexString(kmer)+": "+count.read(kmer)); jpayne@68: count.increment(kmer, 1); jpayne@68: // System.out.println(" -> "+count.read(kmer)); jpayne@68: // System.out.print("Incrementing array for "+Long.toHexString(kmer)+": "+array[(int)kmer]); jpayne@68: // array[(int)kmer]++; jpayne@68: // System.out.println(" -> "+array[(int)kmer]+"\n"); jpayne@68: // assert(array[(int)kmer]==count.read(kmer) || array[(int)kmer]>3); jpayne@68: } jpayne@68: } jpayne@68: } jpayne@68: jpayne@68: if(r.mate!=null){ jpayne@68: len=0; jpayne@68: kmer=0; jpayne@68: bases=r.mate.bases; jpayne@68: quals=r.mate.quality; jpayne@68: for(int i=0; i=k){ jpayne@68: count.increment(kmer, 1); jpayne@68: } jpayne@68: } jpayne@68: } jpayne@68: } jpayne@68: jpayne@68: } jpayne@68: //System.err.println("returning list"); jpayne@68: cris.returnList(ln); jpayne@68: //System.err.println("fetching list"); jpayne@68: ln=cris.nextList(); jpayne@68: reads=(ln!=null ? ln.list : null); jpayne@68: } jpayne@68: System.err.println("Finished reading"); jpayne@68: cris.returnList(ln); jpayne@68: System.err.println("Returned list"); jpayne@68: ReadWrite.closeStream(cris); jpayne@68: System.err.println("Closed stream"); jpayne@68: System.err.println("Processed "+readsProcessed+" reads."); jpayne@68: } jpayne@68: jpayne@68: return count; jpayne@68: } jpayne@68: jpayne@68: }