comparison sam_to_fastq.py @ 0:55107d4a728c draft

planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sam_to_fastq commit 0651eb8c86d890e4b223fec82ab3980932710030
author drosofff
date Mon, 21 Mar 2016 17:33:26 -0400
parents
children 8acb72264319
comparison
equal deleted inserted replaced
-1:000000000000 0:55107d4a728c
1 #!/usr/bin/python
2 #
3 import sys
4 import argparse
5
6 def Parser():
7 the_parser = argparse.ArgumentParser()
8 the_parser.add_argument(
9 '--input', action="store", type=str, help="input SAM file")
10 the_parser.add_argument(
11 '--output', action="store", type=str, help="output FASTQ file")
12 args = the_parser.parse_args()
13 return args
14
15
16 def print_fastq_sequence(samline, file):
17 samfields = samline[:-1].split("\t")
18 file.write ( '@%s\n%s\n+\n%s' % (samfields[0], samfields[9], samfields[10]) )
19
20 def main(input, output):
21 infile = open (input, "r")
22 outfile = open (output, "w")
23 with open (input, "r") as infile:
24 with open (output, "w") as outfile:
25 for line in infile:
26 if line[0] == "@":
27 continue
28 if line.split("\t")[1] != "4":
29 print_fastq_sequence (line, outfile)
30
31 if __name__ == "__main__":
32 args = Parser()
33 main (args.input, args.output)