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