View Javadoc

1   /*--------------------------------------------------------------------------
2    *  Copyright 2008 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  // QSeqToFastq.java
20  // Since: Jul 20, 2010
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.FileReader;
30  import java.io.FileWriter;
31  import java.io.InputStreamReader;
32  import java.io.OutputStreamWriter;
33  
34  import org.utgenome.format.illumina.QSeqToFASTQ;
35  import org.xerial.util.opt.Argument;
36  import org.xerial.util.opt.Option;
37  
38  public class QSeqToFastq extends UTGBShellCommand {
39  
40  	@Option(symbol = "g", longName = "readgroup", varName = "RG", description = "read group name (e.g., HG0001SE:L3)")
41  	private String readGroup;
42  
43  	@Argument(index = 0, name = "input")
44  	private String input = "-";
45  	@Argument(index = 1, name = "output")
46  	private String output = "-";
47  
48  	@Option(longName = "nofilter", description = "do not apply quality filter (default: false)")
49  	private boolean disableQualityFilter = false;
50  
51  	@Override
52  	public void execute(String[] args) throws Exception {
53  
54  		QSeqToFASTQ converter = readGroup == null ? new QSeqToFASTQ(disableQualityFilter) : new QSeqToFASTQ(readGroup, disableQualityFilter);
55  
56  		boolean closeIn = false;
57  		boolean closeOut = false;
58  
59  		BufferedReader inputReader = null;
60  		BufferedWriter outputWriter = null;
61  
62  		try {
63  			if ("-".equals(input)) {
64  				inputReader = new BufferedReader(new InputStreamReader(System.in));
65  			}
66  			else {
67  				inputReader = new BufferedReader(new FileReader(input));
68  				closeIn = true;
69  			}
70  
71  			if ("-".equals(output)) {
72  				outputWriter = new BufferedWriter(new OutputStreamWriter(System.out));
73  			}
74  			else {
75  				outputWriter = new BufferedWriter(new FileWriter(output));
76  				closeOut = true;
77  			}
78  
79  			converter.convert(inputReader, outputWriter);
80  		}
81  		finally {
82  			if (closeIn && inputReader != null)
83  				inputReader.close();
84  
85  			if (closeOut && outputWriter != null)
86  				outputWriter.close();
87  		}
88  	}
89  
90  	@Override
91  	public String getOneLinerDescription() {
92  		return "convert Illumina's qseq format into FASTQ";
93  	}
94  
95  	@Override
96  	public String name() {
97  		return "qseq2fastq";
98  	}
99  
100 }