diff sam_to_fastq.py @ 0:4c60ceadc414 draft

planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sam_to_fastq commit 8a467239b4e3aa42c448f5a088c399e53d50c3fd-dirty
author drosofff
date Mon, 21 Mar 2016 14:40:06 -0400
parents
children c1ab6747fb66
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sam_to_fastq.py	Mon Mar 21 14:40:06 2016 -0400
@@ -0,0 +1,33 @@
+#!/usr/bin/python
+#
+import sys
+import argparse
+
+def Parser():
+    the_parser = argparse.ArgumentParser()
+    the_parser.add_argument(
+        '--input', action="store", type=str, help="input SAM file")
+    the_parser.add_argument(
+        '--output', action="store", type=str, help="output FASTQ file")
+    args = the_parser.parse_args()
+    return args
+    
+        
+def print_fastq_sequence(samline, file):
+  samfields = samline[:-1].split("\t")
+  print >> file, '@%s\n%s\n+\n%s' % (samfields[0], samfields[9], samfields[10])
+
+def main(input, output):
+    infile = open (input, "r")
+    outfile = open (output, "w")
+    for line in infile:
+        if line[0] == "@":
+            continue
+        if line.split("\t")[1] != "4":
+            print_fastq_sequence (line, outfile)
+    infile.close()
+    outfile.close()
+
+if __name__ == "__main__":
+    args = Parser()
+    main (args.input, args.output)