package io.compgen.ngsutils.cli.fastq;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

import io.compgen.cmdline.annotation.Command;
import io.compgen.cmdline.annotation.Exec;
import io.compgen.cmdline.annotation.UnnamedArg;
import io.compgen.cmdline.impl.AbstractCommand;
import io.compgen.ngsutils.fastq.Fastq;
import io.compgen.ngsutils.fastq.FastqRead;
import io.compgen.ngsutils.fastq.FastqReader;

@Command(name = "fastq-tofasta", desc = "Convert FASTQ sequences to FASTA format", category="fastq")
public class FastqToFasta extends AbstractCommand {
	private String filename;

	public FastqToFasta() {
	}

	@UnnamedArg(name = "FILE")
	public void setFilename(String filename) throws IOException {
	    this.filename = filename;
	}
	
	@Exec
    public void exec() throws IOException {
	    long count=0;

        File file1 = new File(filename);
        FileInputStream fis1 = new FileInputStream(file1);
        FileChannel channel1 = fis1.getChannel();
    
        FastqReader reader = Fastq.open(fis1, null, channel1, filename);
        for (FastqRead read : reader) {
            count++;
            if (read.getComment()!=null) {
                System.out.println(">"+read.getName()+" " +read.getComment());
            } else {
                System.out.println(">"+read.getName());
            }
            System.out.println(read.getSeq());
        }

	    System.err.println(count+" reads found.");
	}
}

@@ -634,24 +634,26 @@
 ivate String
+%5B%5D
  filename;%0A%0A
@@ -649,16 +649,17 @@
 filename
+s
 ;%0A%0A%09publ
@@ -741,16 +741,18 @@
 e(String
+%5B%5D
  filenam
@@ -752,16 +752,17 @@
 filename
+s
 ) throws
@@ -794,16 +794,17 @@
 filename
+s
  = filen
@@ -806,16 +806,17 @@
 filename
+s
 ;%0A%09%7D%0A%09%0A%09
@@ -885,16 +885,60 @@
 unt=0;%0A%0A
+%09    for (String filename: filenames) %7B%0A    
         
@@ -974,24 +974,28 @@
 e);%0A        
+  
+  
 FileInputStr
@@ -1037,24 +1037,28 @@
 1);%0A        
+    
 FileChannel 
@@ -1091,17 +1091,25 @@
 ();%0A    
+ 
-%0A
+   %0A    
         
@@ -1177,24 +1177,28 @@
 e);%0A        
+    
 for (FastqRe
@@ -1213,24 +1213,28 @@
 : reader) %7B%0A
+    
             
@@ -1254,16 +1254,20 @@
         
+    
 if (read
@@ -1285,24 +1285,28 @@
 ()!=null) %7B%0A
+    
             
@@ -1384,16 +1384,20 @@
         
+    
 %7D else %7B
@@ -1405,32 +1405,36 @@
                 
+  
+  
 System.out.print
@@ -1469,18 +1469,24 @@
         
-%7D%0A
+    %7D%0A  
         
@@ -1481,32 +1481,34 @@
 %7D%0A              
+  
 System.out.print
@@ -1534,19 +1534,31 @@
         
-%7D%0A%0A
+    %7D%0A    %0A    
 %09    Sys
@@ -1597,13 +1597,20 @@
 und.%22);%0A
+%09    %7D%0A
 %09%7D%0A%7D%0A

Convert more than one fastq to fasta at a time