1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
44
45
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 }