Mercurial > repos > sanbi-uwc > novo_align
annotate novo_align.py @ 27:df170f4d2eea draft
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc/tree/master/tools/novo_align commit 018e4e2f405e9e55f3b7c3ba92b29f957e468f2b
author | sanbi-uwc |
---|---|
date | Mon, 07 May 2018 09:42:08 -0400 |
parents | 482aef16b6f5 |
children | 395aac51afa6 |
rev | line source |
---|---|
22
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
1 #!/usr/bin/env python |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
2 from __future__ import print_function |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
3 import argparse |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
4 import shlex |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
5 import os |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
6 import sys |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
7 import logging |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
8 log = logging.getLogger( __name__ ) |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
9 |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
10 |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
11 def novo_align(output_filename, index_filename, fwd_file, rev_file ): |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
12 param = r'@RG\tID:RG\tSM:$i\tPL:ILLUMINA' |
27
df170f4d2eea
planemo upload for repository https://github.com/SANBI-SA/tools-sanbi-uwc/tree/master/tools/novo_align commit 018e4e2f405e9e55f3b7c3ba92b29f957e468f2b
sanbi-uwc
parents:
22
diff
changeset
|
13 cmdline_str = "novoalign -c 8 -k -d {} -f {} {} -i PE 250, 100 -o SAM '{}' | samtools sort - | samtools view -b - > {}".format( |
22
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
14 index_filename, |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
15 fwd_file, |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
16 rev_file, |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
17 param, |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
18 output_filename) |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
19 try: |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
20 os.system(cmdline_str) |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
21 except: |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
22 print("Error running the nova-align", file=sys.stderr) |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
23 |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
24 |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
25 def newSplit(value): |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
26 lex = shlex.shlex(value) |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
27 lex.quotes = '"' |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
28 lex.whitespace_split = True |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
29 lex.commenters = '' |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
30 return list(lex) |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
31 |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
32 |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
33 def main(): |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
34 parser = argparse.ArgumentParser(description="Generate a BAM file from the Novo Align tool") |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
35 parser.add_argument('output_filename') |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
36 parser.add_argument('--index_filename') |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
37 parser.add_argument('--forward_filename') |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
38 parser.add_argument('--reverse_filename') |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
39 args = parser.parse_args() |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
40 |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
41 # a dirty way of referencing the file |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
42 index_file_path = args.index_filename # removed old logic here: + "/" + args.index_filename.split("/")[-1] |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
43 novo_align(args.output_filename, index_file_path, args.forward_filename, args.reverse_filename) |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
44 |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
45 |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
46 if __name__ == "__main__": |
482aef16b6f5
planemo upload for repository https://github.com/zipho/novo_align commit 3aa343058f631ac4117c9bc86989dc449f84135f
sanbi-uwc
parents:
diff
changeset
|
47 main() |