| 1 |
package align2; |
| 2 |
|
| 3 |
import java.util.ArrayList; |
| 4 |
|
| 5 |
import fileIO.ReadWrite; |
| 6 |
import shared.Tools; |
| 7 |
import stream.ConcurrentLegacyReadInputStream; |
| 8 |
import stream.RTextInputStream; |
| 9 |
import stream.Read; |
| 10 |
import stream.SiteScore; |
| 11 |
import structures.ListNum; |
| 12 |
|
| 13 |
public class MakeQualityHistogram { |
| 14 |
|
| 15 |
public static void main(String[] args){ |
| 16 |
|
| 17 |
String fname1=args[0]; |
| 18 |
String fname2=(args.length>1 ? args[1] : null); |
| 19 |
assert(fname2==null || !fname1.equals(fname2)) : "Error - input files have same name."; |
| 20 |
|
| 21 |
long maxReads=0; |
| 22 |
RTextInputStream rtis=new RTextInputStream(fname1, fname2, maxReads); |
| 23 |
ConcurrentLegacyReadInputStream cris=new ConcurrentLegacyReadInputStream(rtis, maxReads); |
| 24 |
|
| 25 |
int[][][] counts=process(cris); |
| 26 |
printMappedHistogram(counts[0]); |
| 27 |
System.out.println(); |
| 28 |
printPairedHistogram(counts[1]); |
| 29 |
|
| 30 |
} |
| 31 |
|
| 32 |
public static void printMappedHistogram(int[][] mapped){ |
| 33 |
System.out.println("#Error Quality Histogram"); |
| 34 |
System.out.println("Quality\tMapped\tUnmapped\tPercent Mapped"); |
| 35 |
for(int i=0; i<mapped[0].length; i++){ |
| 36 |
int e=mapped[0][i]; |
| 37 |
int m=mapped[1][i]; |
| 38 |
float percent=e*100f/(e+m); |
| 39 |
System.out.println(i+"\t"+e+"\t"+m+"\t"+Tools.format("%.3f", percent)); |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
public static void printPairedHistogram(int[][] paired){ |
| 44 |
System.out.println("#Error Quality Histogram"); |
| 45 |
System.out.println("Quality\tPaired\tSingle\tPercent Paired"); |
| 46 |
for(int i=0; i<paired[0].length; i++){ |
| 47 |
int e=paired[0][i]; |
| 48 |
int m=paired[1][i]; |
| 49 |
float percent=e*100f/(e+m); |
| 50 |
System.out.println(i+"\t"+e+"\t"+m+"\t"+Tools.format("%.3f", percent)); |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
public static int[][][] process(ConcurrentLegacyReadInputStream cris){ |
| 55 |
|
| 56 |
cris.start(); |
| 57 |
|
| 58 |
int[][] mapped=new int[2][50]; |
| 59 |
int[][] paired=new int[2][50]; |
| 60 |
|
| 61 |
ListNum<Read> ln=cris.nextList(); |
| 62 |
ArrayList<Read> readlist=ln.list; |
| 63 |
while(!readlist.isEmpty()){ |
| 64 |
|
| 65 |
processList(readlist, mapped, paired); |
| 66 |
|
| 67 |
cris.returnList(ln.id, readlist.isEmpty()); |
| 68 |
|
| 69 |
ln=cris.nextList(); |
| 70 |
readlist=ln.list; |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
assert(readlist.isEmpty()); |
| 75 |
cris.returnList(ln.id, readlist.isEmpty()); |
| 76 |
ReadWrite.closeStream(cris); |
| 77 |
|
| 78 |
return new int[][][] {mapped, paired}; |
| 79 |
} |
| 80 |
|
| 81 |
private static void processList(ArrayList<Read> list, int[][] mapped, int[][] paired) { |
| 82 |
for(Read r : list){ |
| 83 |
processRead(r, mapped, paired); |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
private static void processRead(Read r, int[][] mapped, int[][] paired) { |
| 91 |
|
| 92 |
if(r.chrom<1 && r.numSites()>0){ |
| 93 |
SiteScore ss=r.topSite(); |
| 94 |
r.start=ss.start; |
| 95 |
r.stop=ss.stop; |
| 96 |
r.chrom=ss.chrom; |
| 97 |
r.setStrand(ss.strand); |
| 98 |
} |
| 99 |
|
| 100 |
int avgQ=r.avgQualityInt(true, 0); |
| 101 |
if(r.chrom>0){ |
| 102 |
mapped[0][avgQ]++; |
| 103 |
}else{ |
| 104 |
mapped[1][avgQ]++; |
| 105 |
} |
| 106 |
if(r.paired()){ |
| 107 |
paired[0][avgQ]++; |
| 108 |
}else{ |
| 109 |
paired[1][avgQ]++; |
| 110 |
} |
| 111 |
|
| 112 |
} |
| 113 |
|
| 114 |
} |