Debian Codegraph @

current/driver/RenameNcbiToTid.java

raw symbols SCIP
1 package driver;
2
3 import java.io.File;
4 import java.io.PrintStream;
5
6 import fileIO.FileFormat;
7 import fileIO.ReadWrite;
8 import fileIO.TextFile;
9 import fileIO.TextStreamWriter;
10 import shared.Parse;
11 import shared.Parser;
12 import shared.PreParser;
13 import shared.Shared;
14 import shared.Timer;
15 import shared.Tools;
16
17 /**
18 * @author Brian Bushnell
19 * @date Oct 17, 2014
20 *
21 */
22 public class RenameNcbiToTid {
23
24 public static void main(String[] args){
25 Timer t=new Timer();
26 RenameNcbiToTid x=new RenameNcbiToTid(args);
27 x.process(t);
28
29 //Close the print stream if it was redirected
30 Shared.closeStream(x.outstream);
31 }
32
33 public RenameNcbiToTid(String[] args){
34
35 {//Preparse block for help, config files, and outstream
36 PreParser pp=new PreParser(args, getClass(), false);
37 args=pp.args;
38 outstream=pp.outstream;
39 }
40
41 Shared.capBuffers(4);
42 ReadWrite.USE_PIGZ=ReadWrite.USE_UNPIGZ=true;
43 ReadWrite.setZipThreads(Shared.threads());
44
45 Parser parser=new Parser();
46 for(int i=0; i<args.length; i++){
47 String arg=args[i];
48 String[] split=arg.split("=");
49 String a=split[0].toLowerCase();
50 String b=split.length>1 ? split[1] : null;
51
52 if(parser.parse(arg, a, b)){
53 //do nothing
54 }else if(a.equals("verbose")){
55 verbose=Parse.parseBoolean(b);
56 ReadWrite.verbose=verbose;
57 }else if(parser.in1==null && i==0 && Tools.looksLikeInputStream(arg)){
58 parser.in1=arg;
59 }else{
60 outstream.println("Unknown parameter "+args[i]);
61 assert(false) : "Unknown parameter "+args[i];
62 // throw new RuntimeException("Unknown parameter "+args[i]);
63 }
64 }
65
66 {//Process parser fields
67 Parser.processQuality();
68
69 maxReads=parser.maxReads;
70
71 overwrite=parser.overwrite;
72 append=parser.append;
73
74 in1=parser.in1;
75
76 out1=parser.out1;
77 }
78
79 if(in1==null){throw new RuntimeException("Error - at least one input file is required.");}
80
81 if(out1!=null && out1.equalsIgnoreCase("null")){out1=null;}
82
83 if(!Tools.testOutputFiles(overwrite, append, false, out1)){
84 outstream.println((out1==null)+", "+out1);
85 throw new RuntimeException("\n\noverwrite="+overwrite+"; Can't write to output files "+out1+"\n");
86 }
87
88 ffout1=FileFormat.testOutput(out1, FileFormat.TEXT, null, true, overwrite, append, false);
89
90 ffin1=FileFormat.testInput(in1, FileFormat.TEXT, null, true, true);
91 }
92
93 void process(Timer t){
94
95 final TextFile tf;
96 {
97 tf=new TextFile(ffin1);
98 if(verbose){outstream.println("Started tf");}
99 }
100
101 final TextStreamWriter tsw;
102 {
103 tsw=new TextStreamWriter(ffout1);
104 tsw.start();
105 if(verbose){outstream.println("Started tsw");}
106 }
107
108 long linesProcessed=0;
109 long charsProcessed=0;
110
111 {
112 String line;
113 while((maxReads<0 || linesProcessed<maxReads) && (line=tf.nextLine())!=null){
114 linesProcessed++;
115 charsProcessed+=line.length();
116 String result=processLine(line);
117 if(tsw!=null && result!=null){tsw.println(result);}
118 }
119 }
120
121 errorState|=tsw.poisonAndWait();
122 errorState|=tf.close();
123
124 t.stop();
125 outstream.println(Tools.timeLinesBytesProcessed(t, linesProcessed, charsProcessed, 8));
126
127 if(errorState){
128 throw new RuntimeException(getClass().getName()+" terminated in an error state; the output may be corrupt.");
129 }
130 }
131
132
133 private static String processLine(String line){
134 if(line.startsWith(">ncbi")){
135 line=line.replaceFirst(">ncbi", ">tid");
136 int firstSpace=line.indexOf(' ');
137 line=line.substring(0, firstSpace)+"|"+line.substring(firstSpace+1);
138 }
139 return line;
140 }
141
142
143 /*--------------------------------------------------------------*/
144
145 /*--------------------------------------------------------------*/
146
147 private String in1=null;
148 private String out1=null;
149
150 /*--------------------------------------------------------------*/
151
152 private long maxReads=-1;
153
154 /*--------------------------------------------------------------*/
155
156 private final FileFormat ffin1;
157 private final FileFormat ffout1;
158
159
160 /*--------------------------------------------------------------*/
161
162 private PrintStream outstream=System.err;
163 public static boolean verbose=false;
164 public boolean errorState=false;
165 private boolean overwrite=true;
166 private boolean append=false;
167
168 }