Mercurial > repos > sanbi-uwc > novo_sort
annotate novo_sort.py @ 5:6e11ef75c56c draft
planemo upload for repository https://github.com/zipho/novo_sort commit 91b08bec675d4e76b371b0f01bc0729cd6fbacdc
author | sanbi-uwc |
---|---|
date | Fri, 01 Apr 2016 10:16:18 -0400 |
parents | 146641fe5ff6 |
children | e35fbd921b6b |
rev | line source |
---|---|
0
9b131be2b326
planemo upload for repository https://github.com/zipho/novo_sort commit fbf62dc6b9a1794b07b5189279096b7d4c03ea3b
sanbi-uwc
parents:
diff
changeset
|
1 #!/usr/bin/env python |
9b131be2b326
planemo upload for repository https://github.com/zipho/novo_sort commit fbf62dc6b9a1794b07b5189279096b7d4c03ea3b
sanbi-uwc
parents:
diff
changeset
|
2 from __future__ import print_function |
9b131be2b326
planemo upload for repository https://github.com/zipho/novo_sort commit fbf62dc6b9a1794b07b5189279096b7d4c03ea3b
sanbi-uwc
parents:
diff
changeset
|
3 import argparse |
9b131be2b326
planemo upload for repository https://github.com/zipho/novo_sort commit fbf62dc6b9a1794b07b5189279096b7d4c03ea3b
sanbi-uwc
parents:
diff
changeset
|
4 from subprocess import check_call, CalledProcessError |
9b131be2b326
planemo upload for repository https://github.com/zipho/novo_sort commit fbf62dc6b9a1794b07b5189279096b7d4c03ea3b
sanbi-uwc
parents:
diff
changeset
|
5 import shlex |
9b131be2b326
planemo upload for repository https://github.com/zipho/novo_sort commit fbf62dc6b9a1794b07b5189279096b7d4c03ea3b
sanbi-uwc
parents:
diff
changeset
|
6 import sys |
9b131be2b326
planemo upload for repository https://github.com/zipho/novo_sort commit fbf62dc6b9a1794b07b5189279096b7d4c03ea3b
sanbi-uwc
parents:
diff
changeset
|
7 import logging |
9b131be2b326
planemo upload for repository https://github.com/zipho/novo_sort commit fbf62dc6b9a1794b07b5189279096b7d4c03ea3b
sanbi-uwc
parents:
diff
changeset
|
8 log = logging.getLogger( __name__ ) |
9b131be2b326
planemo upload for repository https://github.com/zipho/novo_sort commit fbf62dc6b9a1794b07b5189279096b7d4c03ea3b
sanbi-uwc
parents:
diff
changeset
|
9 |
4
146641fe5ff6
planemo upload for repository https://github.com/zipho/novo_sort commit 0bb684bfc6b3f1f07105117dfd71285ce4ff7f4e
sanbi-uwc
parents:
3
diff
changeset
|
10 def novo_sort( bam_filename, output_filename ): |
146641fe5ff6
planemo upload for repository https://github.com/zipho/novo_sort commit 0bb684bfc6b3f1f07105117dfd71285ce4ff7f4e
sanbi-uwc
parents:
3
diff
changeset
|
11 cmdline_str = "novosort -c 8 -m 8G -s -f {} > {}".format( bam_filename, output_filename ) |
0
9b131be2b326
planemo upload for repository https://github.com/zipho/novo_sort commit fbf62dc6b9a1794b07b5189279096b7d4c03ea3b
sanbi-uwc
parents:
diff
changeset
|
12 cmdline = newSplit(cmdline_str) |
9b131be2b326
planemo upload for repository https://github.com/zipho/novo_sort commit fbf62dc6b9a1794b07b5189279096b7d4c03ea3b
sanbi-uwc
parents:
diff
changeset
|
13 try: |
9b131be2b326
planemo upload for repository https://github.com/zipho/novo_sort commit fbf62dc6b9a1794b07b5189279096b7d4c03ea3b
sanbi-uwc
parents:
diff
changeset
|
14 check_call(cmdline) |
9b131be2b326
planemo upload for repository https://github.com/zipho/novo_sort commit fbf62dc6b9a1794b07b5189279096b7d4c03ea3b
sanbi-uwc
parents:
diff
changeset
|
15 except CalledProcessError: |
9b131be2b326
planemo upload for repository https://github.com/zipho/novo_sort commit fbf62dc6b9a1794b07b5189279096b7d4c03ea3b
sanbi-uwc
parents:
diff
changeset
|
16 print("Error running the nova-sort", file=sys.stderr) |
9b131be2b326
planemo upload for repository https://github.com/zipho/novo_sort commit fbf62dc6b9a1794b07b5189279096b7d4c03ea3b
sanbi-uwc
parents:
diff
changeset
|
17 |
9b131be2b326
planemo upload for repository https://github.com/zipho/novo_sort commit fbf62dc6b9a1794b07b5189279096b7d4c03ea3b
sanbi-uwc
parents:
diff
changeset
|
18 def newSplit(value): |
9b131be2b326
planemo upload for repository https://github.com/zipho/novo_sort commit fbf62dc6b9a1794b07b5189279096b7d4c03ea3b
sanbi-uwc
parents:
diff
changeset
|
19 lex = shlex.shlex(value) |
9b131be2b326
planemo upload for repository https://github.com/zipho/novo_sort commit fbf62dc6b9a1794b07b5189279096b7d4c03ea3b
sanbi-uwc
parents:
diff
changeset
|
20 lex.quotes = '"' |
9b131be2b326
planemo upload for repository https://github.com/zipho/novo_sort commit fbf62dc6b9a1794b07b5189279096b7d4c03ea3b
sanbi-uwc
parents:
diff
changeset
|
21 lex.whitespace_split = True |
9b131be2b326
planemo upload for repository https://github.com/zipho/novo_sort commit fbf62dc6b9a1794b07b5189279096b7d4c03ea3b
sanbi-uwc
parents:
diff
changeset
|
22 lex.commenters = '' |
9b131be2b326
planemo upload for repository https://github.com/zipho/novo_sort commit fbf62dc6b9a1794b07b5189279096b7d4c03ea3b
sanbi-uwc
parents:
diff
changeset
|
23 return list(lex) |
9b131be2b326
planemo upload for repository https://github.com/zipho/novo_sort commit fbf62dc6b9a1794b07b5189279096b7d4c03ea3b
sanbi-uwc
parents:
diff
changeset
|
24 |
9b131be2b326
planemo upload for repository https://github.com/zipho/novo_sort commit fbf62dc6b9a1794b07b5189279096b7d4c03ea3b
sanbi-uwc
parents:
diff
changeset
|
25 def main(): |
9b131be2b326
planemo upload for repository https://github.com/zipho/novo_sort commit fbf62dc6b9a1794b07b5189279096b7d4c03ea3b
sanbi-uwc
parents:
diff
changeset
|
26 parser = argparse.ArgumentParser(description="Re-sorting aligned files by read position") |
3
9c51aca51902
planemo upload for repository https://github.com/zipho/novo_sort commit c490d694fa0be39bcd5048981cf4f08cd0821a50
sanbi-uwc
parents:
0
diff
changeset
|
27 parser.add_argument('output_filename') |
0
9b131be2b326
planemo upload for repository https://github.com/zipho/novo_sort commit fbf62dc6b9a1794b07b5189279096b7d4c03ea3b
sanbi-uwc
parents:
diff
changeset
|
28 parser.add_argument('--bam_filename') |
9b131be2b326
planemo upload for repository https://github.com/zipho/novo_sort commit fbf62dc6b9a1794b07b5189279096b7d4c03ea3b
sanbi-uwc
parents:
diff
changeset
|
29 args = parser.parse_args() |
9b131be2b326
planemo upload for repository https://github.com/zipho/novo_sort commit fbf62dc6b9a1794b07b5189279096b7d4c03ea3b
sanbi-uwc
parents:
diff
changeset
|
30 |
5
6e11ef75c56c
planemo upload for repository https://github.com/zipho/novo_sort commit 91b08bec675d4e76b371b0f01bc0729cd6fbacdc
sanbi-uwc
parents:
4
diff
changeset
|
31 novo_sort(args.bam_filename, args.output_filename) |
0
9b131be2b326
planemo upload for repository https://github.com/zipho/novo_sort commit fbf62dc6b9a1794b07b5189279096b7d4c03ea3b
sanbi-uwc
parents:
diff
changeset
|
32 |
9b131be2b326
planemo upload for repository https://github.com/zipho/novo_sort commit fbf62dc6b9a1794b07b5189279096b7d4c03ea3b
sanbi-uwc
parents:
diff
changeset
|
33 if __name__ == "__main__": main() |