annotate novo_align.py @ 16:a2bc4041241c draft

planemo upload for repository https://github.com/zipho/novo_align commit 5f66b8469dedd0905e0d9fd8d37194575f77ed26-dirty
author sanbi-uwc
date Mon, 09 Jan 2017 08:34:13 -0500
parents 8553432eb6d8
children 94ae1dd64bca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
1 #!/usr/bin/env python
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
2 from __future__ import print_function
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
3 import argparse
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
4 import shlex
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
5 import os
12
bfe39c503a40 planemo upload for repository https://github.com/zipho/novo_align commit 896a5a73f2a5f71a7b38dc0403f54afba1f27643
sanbi-uwc
parents: 10
diff changeset
6 import sys
5
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
7 import logging
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
8 log = logging.getLogger( __name__ )
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
9
12
bfe39c503a40 planemo upload for repository https://github.com/zipho/novo_align commit 896a5a73f2a5f71a7b38dc0403f54afba1f27643
sanbi-uwc
parents: 10
diff changeset
10
5
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
11 def novo_align(output_filename, index_filename, fwd_file, rev_file ):
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
12 param = r'@RG\tID:RG\tSM:$i\tPL:ILLUMINA'
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
13 cmdline_str = "novoalign -c 8 -k -d {} -f {} {} -i PE 250, 100 -o SAM '{}' | samtools view -bS - > {}".format(
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
14 index_filename,
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
15 fwd_file,
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
16 rev_file,
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
17 param,
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
18 output_filename)
6
3938f90c9d91 planemo upload for repository https://github.com/zipho/novo_align commit 4a89d4d866533a93706ceb29077d2e9bda69aa9f
sanbi-uwc
parents: 5
diff changeset
19 try:
3938f90c9d91 planemo upload for repository https://github.com/zipho/novo_align commit 4a89d4d866533a93706ceb29077d2e9bda69aa9f
sanbi-uwc
parents: 5
diff changeset
20 os.system(cmdline_str)
3938f90c9d91 planemo upload for repository https://github.com/zipho/novo_align commit 4a89d4d866533a93706ceb29077d2e9bda69aa9f
sanbi-uwc
parents: 5
diff changeset
21 except:
3938f90c9d91 planemo upload for repository https://github.com/zipho/novo_align commit 4a89d4d866533a93706ceb29077d2e9bda69aa9f
sanbi-uwc
parents: 5
diff changeset
22 print("Error running the nova-align", file=sys.stderr)
5
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
23
12
bfe39c503a40 planemo upload for repository https://github.com/zipho/novo_align commit 896a5a73f2a5f71a7b38dc0403f54afba1f27643
sanbi-uwc
parents: 10
diff changeset
24
5
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
25 def newSplit(value):
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
26 lex = shlex.shlex(value)
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
27 lex.quotes = '"'
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
28 lex.whitespace_split = True
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
29 lex.commenters = ''
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
30 return list(lex)
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
31
12
bfe39c503a40 planemo upload for repository https://github.com/zipho/novo_align commit 896a5a73f2a5f71a7b38dc0403f54afba1f27643
sanbi-uwc
parents: 10
diff changeset
32
5
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
33 def main():
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
34 parser = argparse.ArgumentParser(description="Generate a BAM file from the Novo Align tool")
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
35 parser.add_argument('output_filename')
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
36 parser.add_argument('--index_filename')
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
37 parser.add_argument('--forward_filename')
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
38 parser.add_argument('--reverse_filename')
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
39 args = parser.parse_args()
12
bfe39c503a40 planemo upload for repository https://github.com/zipho/novo_align commit 896a5a73f2a5f71a7b38dc0403f54afba1f27643
sanbi-uwc
parents: 10
diff changeset
40
10
9a6f14e2c8fd planemo upload for repository https://github.com/zipho/novo_align commit 41c644b735d3140ec0b383deb23491f0fdf4dcfe
sanbi-uwc
parents: 6
diff changeset
41 # a dirty way of referencing the file
15
8553432eb6d8 planemo upload for repository https://github.com/zipho/novo_align commit 4db125fcd73327813d7bd511852bbe9ffc68a25c
sanbi-uwc
parents: 12
diff changeset
42 index_file_path = args.index_filename # not sure of the logic here: + "/" + args.index_filename.split("/")[-1]
5
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
43 novo_align(args.output_filename, index_file_path, args.forward_filename, args.reverse_filename)
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
44
15
8553432eb6d8 planemo upload for repository https://github.com/zipho/novo_align commit 4db125fcd73327813d7bd511852bbe9ffc68a25c
sanbi-uwc
parents: 12
diff changeset
45
12
bfe39c503a40 planemo upload for repository https://github.com/zipho/novo_align commit 896a5a73f2a5f71a7b38dc0403f54afba1f27643
sanbi-uwc
parents: 10
diff changeset
46 if __name__ == "__main__":
bfe39c503a40 planemo upload for repository https://github.com/zipho/novo_align commit 896a5a73f2a5f71a7b38dc0403f54afba1f27643
sanbi-uwc
parents: 10
diff changeset
47 main()