| 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 |
|
| 19 |
|
| 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 |
|
| 37 |
|
| 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 |
|
| 44 |
|
| 45 |
if(outputFasta){ |
| 46 |
|
| 47 |
processToFasta(b, cutoff, query); |
| 48 |
}else{ |
| 49 |
|
| 50 |
processToNames(b, cutoff); |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 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 |
|
| 66 |
try { |
| 67 |
s=b.readLine(); |
| 68 |
} catch (IOException e1) { |
| 69 |
|
| 70 |
e1.printStackTrace(); |
| 71 |
} |
| 72 |
|
| 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 |
|
| 83 |
} |
| 84 |
if(value>=cutoff){ |
| 85 |
if(!prev.equals(split[0])){ |
| 86 |
prev=split[0]; |
| 87 |
names.add(split[0]); |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
try { |
| 92 |
s=b.readLine(); |
| 93 |
} catch (IOException e) { |
| 94 |
|
| 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 |
|
| 105 |
try { |
| 106 |
s=b.readLine(); |
| 107 |
} catch (IOException e1) { |
| 108 |
|
| 109 |
e1.printStackTrace(); |
| 110 |
} |
| 111 |
|
| 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 |
|
| 121 |
} |
| 122 |
if(value>=cutoff){ |
| 123 |
System.out.println(split[0]); |
| 124 |
} |
| 125 |
|
| 126 |
try { |
| 127 |
s=b.readLine(); |
| 128 |
} catch (IOException e) { |
| 129 |
|
| 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(); |
| 142 |
ListNum<Read> ln=cris.nextList(); |
| 143 |
ArrayList<Read> reads=(ln!=null ? ln.list : null); |
| 144 |
|
| 145 |
|
| 146 |
while(ln!=null && reads!=null && reads.size()>0){ |
| 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 |
|
| 155 |
cris.returnList(ln); |
| 156 |
ln=cris.nextList(); |
| 157 |
reads=(ln!=null ? ln.list : null); |
| 158 |
} |
| 159 |
|
| 160 |
cris.returnList(ln); |
| 161 |
} |
| 162 |
|
| 163 |
|
| 164 |
} |