annotate novo_align.py @ 5:d51c5af7a8fe draft

planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
author sanbi-uwc
date Fri, 11 Mar 2016 02:02:09 -0500
parents
children 3938f90c9d91
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
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
3 from __future__ import print_function
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
4 import argparse
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
5 from subprocess import check_call, CalledProcessError, Popen
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
6 import shlex
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
7 import os
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
8 import logging
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
9 log = logging.getLogger( __name__ )
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
10
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 #novoalign -c 8 -k -d /cip0/research/ajayi/RNA-seq_Analysis_Project_Case_Study/reference/Homo_Sapiens/out/TB_H37Rv.nix
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
13 # -f X165_820L8_.R1_val_1.fq X165_820L8_.R2_val_2.fq -i PE 250,100
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
14 # -o SAM '@RG\tID:readgroup\tPU:platform unit\tLB:library' | samtools view -bS - > `pwd`/out/X165_820L8.bam
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
15 #output_filename = path.join(output_directory, fwd_file.split(".")[0] + ".bam")
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
16 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
17 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
18 index_filename,
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
19 fwd_file,
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
20 rev_file,
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
21 param,
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
22 output_filename)
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
23 #cmdline = newSplit(cmdline_str)
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
24
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
25 os.system(cmdline_str)
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
26 #try:
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
27 #check_call(cmdline)
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
28 #except CalledProcessError:
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
29 # print("Error running the nova-align", file=sys.stderr)
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
30
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
31 def newSplit(value):
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
32 lex = shlex.shlex(value)
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
33 lex.quotes = '"'
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
34 lex.whitespace_split = True
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
35 lex.commenters = ''
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
36 return list(lex)
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
37
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
38 def main():
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
39 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
40 parser.add_argument('output_filename')
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
41 parser.add_argument('--index_filename')
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
42 parser.add_argument('--forward_filename')
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
43 parser.add_argument('--reverse_filename')
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
44 args = parser.parse_args()
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
45
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
46 #a dirty way of referencing the file
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
47 index_file_path = args.index_filename + "/" + args.index_filename.split("/")[-1]
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
48
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
49 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
50
d51c5af7a8fe planemo upload for repository https://github.com/zipho/novo_align commit c3aee79679931e7a609fea1dade8973c97fb0d21
sanbi-uwc
parents:
diff changeset
51 if __name__ == "__main__": main()