annotate kisspliceGWrapper.py @ 1:496a2e67e5f7 default tip

change package repository
author cmonjeau
date Mon, 06 Jul 2015 15:51:44 +0000
parents 131c36a303ee
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
1 import subprocess, os, sys, shutil, tempfile, os.path
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
2 from os.path import basename, splitext
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
3
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
4 ## inputs
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
5 kmer_value = sys.argv[7]
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
6 smallc_value = sys.argv[8]
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
7 bigc_value = sys.argv[9]
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
8 output_contex_value = sys.argv[10]
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
9 counts_value = sys.argv[11]
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
10 input_dat = sys.argv[12:len(sys.argv):2] # contains filename1... filenameq
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
11 input_ext = sys.argv[13:len(sys.argv):2] # contains extension1... extensionq
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
12
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
13 ## tmp directory
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
14 tmp_dir = tempfile.mkdtemp(prefix='kissplice-galaxy.')
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
15
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
16 ## command line (init)
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
17 command_line = []
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
18 command_line.append("kissplice")
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
19
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
20 ## symlink for .fasta/q (extension required)
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
21 ## command line built with -r option
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
22 identifier = ""
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
23 for i in range(0,len(input_dat)):
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
24 tmp_input_fasta = os.path.join(tmp_dir, 'input'+str(i)+'.'+input_ext[i])
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
25 identifier += 'input'+str(i)+'_'
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
26 os.symlink(input_dat[i], tmp_input_fasta)
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
27 command_line.append("-r")
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
28 command_line.append(tmp_input_fasta)
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
29
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
30 ## command line (end)
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
31 opath=tmp_dir+"/results"
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
32 nocontext = ""
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
33 nosnp = ""
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
34 if output_contex_value == "yes":
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
35 command_line.extend(["-k", kmer_value,
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
36 "-c", smallc_value, "-C", bigc_value,
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
37 "--counts", counts_value, "--output-context",
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
38 "-o", opath, "-s"])
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
39 else:
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
40 command_line.extend(["-k", kmer_value,
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
41 "-c", smallc_value, "-C", bigc_value,
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
42 "--counts", counts_value,
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
43 "-o", opath, "-s"])
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
44
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
45 ## running kissplice
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
46 p=subprocess.Popen(command_line,
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
47 stdout=subprocess.PIPE,stderr=subprocess.PIPE)
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
48 stdoutput = p.communicate()
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
49
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
50 ## outputs
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
51 output_f1=sys.argv[1]
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
52 out1=open(output_f1, 'w' )
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
53 out1.write(stdoutput[0])
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
54 out1.close()
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
55
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
56 output_type0=sys.argv[2]
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
57 output_type1=sys.argv[3]
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
58 output_type2=sys.argv[4]
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
59 output_type3=sys.argv[5]
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
60 output_type4=sys.argv[6]
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
61
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
62 result_type0 = opath+"/"+"results_"+identifier+"k"+kmer_value+"_coherents_type_0.fa"
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
63 result_type1 = opath+"/"+"results_"+identifier+"k"+kmer_value+"_coherents_type_1.fa"
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
64 result_type2 = opath+"/"+"results_"+identifier+"k"+kmer_value+"_coherents_type_2.fa"
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
65 result_type3 = opath+"/"+"results_"+identifier+"k"+kmer_value+"_coherents_type_3.fa"
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
66 result_type4 = opath+"/"+"results_"+identifier+"k"+kmer_value+"_coherents_type_4.fa"
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
67
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
68 shutil.move(result_type0, output_type0)
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
69 shutil.move(result_type1, output_type1)
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
70 shutil.move(result_type2, output_type2)
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
71 shutil.move(result_type3, output_type3)
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
72 shutil.move(result_type4, output_type4)
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
73
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
74 ## cleaning
131c36a303ee Imported from capsule None
cmonjeau
parents:
diff changeset
75 shutil.rmtree(tmp_dir)