Mercurial > repos > drosofff > sam_to_fastq
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c60ceadc414 |
---|---|
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 print >> file, '@%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 for line in infile: | |
24 if line[0] == "@": | |
25 continue | |
26 if line.split("\t")[1] != "4": | |
27 print_fastq_sequence (line, outfile) | |
28 infile.close() | |
29 outfile.close() | |
30 | |
31 if __name__ == "__main__": | |
32 args = Parser() | |
33 main (args.input, args.output) |