Debian Codegraph @

current/driver/EstherFilter.java

raw symbols SCIP
1 package driver;
2
3 import java.io.BufferedReader;
4 import java.io.IOException;
5 import java.io.InputStream;
6 import java.io.InputStreamReader;
7 import java.util.ArrayList;
8 import java.util.Collections;
9
10 import fileIO.FileFormat;
11 import fileIO.ReadWrite;
12 import shared.Shared;
13 import stream.ConcurrentReadInputStream;
14 import stream.Read;
15 import structures.ListNum;
16
17 /**
18 * @author Brian Bushnell
19 * @date Jul 29, 2014
20 *
21 */
22 public class EstherFilter {
23
24 public static void main(String[] args){
25 String query=args[0];
26 String ref=args[1];
27 float cutoff=Float.parseFloat(args[2]);
28 boolean outputFasta=false;
29 if(args.length>3 && args[3].equalsIgnoreCase("fasta")){
30 outputFasta=true;
31 }
32 String command="blastall -p blastn -i "+query+" -d "+ref+" -e 0.00001 -m 8";
33
34 ReadWrite.FORCE_KILL=true;
35
36 // InputStream is=ReadWrite.getInputStreamFromProcess("stdin", command, false);
37 // InputStream is=ReadWrite.getInputStreamFromProcess("", command, false);
38 InputStream is=ReadWrite.getInputStreamFromProcess("foo", command, false, false, true);
39
40 InputStreamReader isr=new InputStreamReader(is);
41 BufferedReader b=new BufferedReader(isr, 32768);
42
43 // System.out.println("Before");
44
45 if(outputFasta){
46 // System.out.println("A");
47 processToFasta(b, cutoff, query);
48 }else{
49 // System.out.println("B");
50 processToNames(b, cutoff);
51 }
52
53 // System.out.println("Finished");
54
55 // ReadWrite.finishReading(is, "stdin", true, b, isr);
56 // ReadWrite.finishReading(is, "", true, b, isr);
57 ReadWrite.finishReading(is, "foo", true, b, isr);
58
59 }
60
61 public static void processToFasta(BufferedReader b, float cutoff, String query){
62 String s=null;
63
64 ArrayList<String> names=new ArrayList<String>();
65 // System.out.println("Reading line 0");
66 try {
67 s=b.readLine();
68 } catch (IOException e1) {
69 // TODO Auto-generated catch block
70 e1.printStackTrace();
71 }
72 // System.out.println("Starting");
73 String prev="";
74
75 while(s!=null){
76 String[] split=s.split("\t");
77 float value=0;
78 try {
79 value=Float.parseFloat(split[11].trim());
80 } catch (NumberFormatException e) {
81 e.printStackTrace();
82 // System.err.println("Bad line:\n"+s);
83 }
84 if(value>=cutoff){
85 if(!prev.equals(split[0])){
86 prev=split[0];
87 names.add(split[0]);
88 }
89 }
90 // System.out.println("Reading line");
91 try {
92 s=b.readLine();
93 } catch (IOException e) {
94 // TODO Auto-generated catch block
95 e.printStackTrace();
96 }
97 }
98
99 outputFasta(query, names);
100 }
101
102 public static void processToNames(BufferedReader b, float cutoff){
103 String s=null;
104 // System.out.println("Reading line 0");
105 try {
106 s=b.readLine();
107 } catch (IOException e1) {
108 // TODO Auto-generated catch block
109 e1.printStackTrace();
110 }
111 // System.out.println("Starting");
112 String prev="";
113 while(s!=null){
114 String[] split=s.split("\t");
115 float value=0;
116 try {
117 value=Float.parseFloat(split[11].trim());
118 } catch (NumberFormatException e) {
119 e.printStackTrace();
120 // System.err.println("Bad line:\n"+s);
121 }
122 if(value>=cutoff){
123 System.out.println(split[0]);
124 }
125 // System.out.println("Reading line");
126 try {
127 s=b.readLine();
128 } catch (IOException e) {
129 // TODO Auto-generated catch block
130 e.printStackTrace();
131 }
132 }
133 }
134
135 public static void outputFasta(String fname, ArrayList<String> names){
136
137 Shared.sort(names);
138
139 FileFormat ff=FileFormat.testInput(fname, FileFormat.FASTA, null, false, true);
140 ConcurrentReadInputStream cris=ConcurrentReadInputStream.getReadInputStream(-1L, false, ff, null);
141 cris.start(); //4567
142 ListNum<Read> ln=cris.nextList();
143 ArrayList<Read> reads=(ln!=null ? ln.list : null);
144
145 /* Iterate through read lists from the input stream */
146 while(ln!=null && reads!=null && reads.size()>0){//ln!=null prevents a compiler potential null access warning
147
148 for(Read r : reads){
149 if(Collections.binarySearch(names, r.id)>=0){
150 System.out.println(r.toFasta(70));
151 }
152 }
153
154 /* Dispose of the old list and fetch a new one */
155 cris.returnList(ln);
156 ln=cris.nextList();
157 reads=(ln!=null ? ln.list : null);
158 }
159 /* Cleanup */
160 cris.returnList(ln);
161 }
162
163
164 }