Mercurial > repos > drosofff > sam_to_fastq
annotate 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 |
| 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") |
|
4c60ceadc414
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sam_to_fastq commit 8a467239b4e3aa42c448f5a088c399e53d50c3fd-dirty
drosofff
parents:
diff
changeset
|
18 print >> file, '@%s\n%s\n+\n%s' % (samfields[0], samfields[9], samfields[10]) |
|
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") |
|
4c60ceadc414
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sam_to_fastq commit 8a467239b4e3aa42c448f5a088c399e53d50c3fd-dirty
drosofff
parents:
diff
changeset
|
23 for line in infile: |
|
4c60ceadc414
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sam_to_fastq commit 8a467239b4e3aa42c448f5a088c399e53d50c3fd-dirty
drosofff
parents:
diff
changeset
|
24 if line[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
|
25 continue |
|
4c60ceadc414
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sam_to_fastq commit 8a467239b4e3aa42c448f5a088c399e53d50c3fd-dirty
drosofff
parents:
diff
changeset
|
26 if line.split("\t")[1] != "4": |
|
4c60ceadc414
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sam_to_fastq commit 8a467239b4e3aa42c448f5a088c399e53d50c3fd-dirty
drosofff
parents:
diff
changeset
|
27 print_fastq_sequence (line, outfile) |
|
4c60ceadc414
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sam_to_fastq commit 8a467239b4e3aa42c448f5a088c399e53d50c3fd-dirty
drosofff
parents:
diff
changeset
|
28 infile.close() |
|
4c60ceadc414
planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sam_to_fastq commit 8a467239b4e3aa42c448f5a088c399e53d50c3fd-dirty
drosofff
parents:
diff
changeset
|
29 outfile.close() |
|
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) |
