View Javadoc

1   /*--------------------------------------------------------------------------
2    *  Copyright 2010 utgenome.org
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   *--------------------------------------------------------------------------*/
16  //--------------------------------------
17  // utgb-shell Project
18  //
19  // FastqToFasta.java
20  // Since: 2010/10/06
21  //
22  // $URL$ 
23  // $Author$
24  //--------------------------------------
25  package org.utgenome.shell;
26  
27  import java.io.BufferedReader;
28  import java.io.BufferedWriter;
29  import java.io.FileInputStream;
30  import java.io.FileOutputStream;
31  import java.io.InputStreamReader;
32  import java.io.OutputStreamWriter;
33  import java.io.Reader;
34  import java.io.Writer;
35  
36  import org.utgenome.format.fastq.FastqRead;
37  import org.utgenome.format.fastq.FastqReader;
38  import org.utgenome.util.StandardInputStream;
39  import org.utgenome.util.StandardOutputStream;
40  import org.xerial.util.opt.Argument;
41  
42  /**
43   * fastq2fasta command
44   * 
45   * @author leo
46   * 
47   */
48  public class FastqToFasta extends UTGBShellCommand {
49  
50  	@Argument(index = 0, name = "input")
51  	private String input = "-";
52  
53  	@Argument(index = 1, name = "output")
54  	private String output = "-";
55  
56  	@Override
57  	public void execute(String[] args) throws Exception {
58  
59  		Reader in = new BufferedReader(new InputStreamReader("-".equals(input) ? new StandardInputStream() : new FileInputStream(input)));
60  		Writer out = new BufferedWriter(new OutputStreamWriter("-".equals(output) ? new StandardOutputStream() : new FileOutputStream(output)));
61  
62  		FastqReader fastqReader = new FastqReader(in);
63  		for (FastqRead read; (read = fastqReader.next()) != null;) {
64  			out.append(">");
65  			out.append(read.seqname);
66  			out.append("\n");
67  			out.append(read.seq);
68  			out.append("\n");
69  		}
70  
71  		out.flush();
72  		out.close();
73  		in.close();
74  	}
75  
76  	@Override
77  	public String name() {
78  		return "fastq2fasta";
79  	}
80  
81  	@Override
82  	public String getOneLinerDescription() {
83  		return "convert FASTQ to FASTA format";
84  	}
85  
86  }