annotate tools/ngs_rna/cuffdiff_wrapper.py @ 1:cdcb0ce84a1b

Uploaded
author xuebing
date Fri, 09 Mar 2012 19:45:15 -0500
parents 9071e359b9a3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
1 #!/usr/bin/env python
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
2
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
3 import optparse, os, shutil, subprocess, sys, tempfile
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
4
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
5 def group_callback( option, op_str, value, parser ):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
6 groups = []
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
7 flist = []
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
8 for arg in parser.rargs:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
9 arg = arg.strip()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
10 if arg[0] is "-":
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
11 break
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
12 elif arg[0] is ",":
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
13 groups.append(flist)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
14 flist = []
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
15 else:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
16 flist.append(arg)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
17 groups.append(flist)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
18
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
19 setattr(parser.values, option.dest, groups)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
20
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
21 def label_callback( option, op_str, value, parser ):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
22 labels = []
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
23 for arg in parser.rargs:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
24 arg = arg.strip()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
25 if arg[0] is "-":
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
26 break
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
27 else:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
28 labels.append(arg)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
29
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
30 setattr(parser.values, option.dest, labels)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
31
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
32 def stop_err( msg ):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
33 sys.stderr.write( "%s\n" % msg )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
34 sys.exit()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
35
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
36 # Copied from sam_to_bam.py:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
37 def check_seq_file( dbkey, cached_seqs_pointer_file ):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
38 seq_path = ''
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
39 for line in open( cached_seqs_pointer_file ):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
40 line = line.rstrip( '\r\n' )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
41 if line and not line.startswith( '#' ) and line.startswith( 'index' ):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
42 fields = line.split( '\t' )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
43 if len( fields ) < 3:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
44 continue
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
45 if fields[1] == dbkey:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
46 seq_path = fields[2].strip()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
47 break
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
48 return seq_path
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
49
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
50 def __main__():
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
51 #Parse Command Line
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
52 parser = optparse.OptionParser()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
53
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
54 # Cuffdiff options.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
55 parser.add_option( '-s', '--inner-dist-std-dev', dest='inner_dist_std_dev', help='The standard deviation for the distribution on inner distances between mate pairs. The default is 20bp.' )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
56 parser.add_option( '-p', '--num-threads', dest='num_threads', help='Use this many threads to align reads. The default is 1.' )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
57 parser.add_option( '-m', '--inner-mean-dist', dest='inner_mean_dist', help='This is the expected (mean) inner distance between mate pairs. \
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
58 For, example, for paired end runs with fragments selected at 300bp, \
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
59 where each end is 50bp, you should set -r to be 200. The default is 45bp.')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
60 parser.add_option( '-c', '--min-alignment-count', dest='min_alignment_count', help='The minimum number of alignments in a locus for needed to conduct significance testing on changes in that locus observed between samples. If no testing is performed, changes in the locus are deemed not signficant, and the locus\' observed changes don\'t contribute to correction for multiple testing. The default is 1,000 fragment alignments (up to 2,000 paired reads).' )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
61 parser.add_option( '--FDR', dest='FDR', help='The allowed false discovery rate. The default is 0.05.' )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
62
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
63 # Advanced Options:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
64 parser.add_option( '--num-importance-samples', dest='num_importance_samples', help='Sets the number of importance samples generated for each locus during abundance estimation. Default: 1000' )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
65 parser.add_option( '--max-mle-iterations', dest='max_mle_iterations', help='Sets the number of iterations allowed during maximum likelihood estimation of abundances. Default: 5000' )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
66
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
67 # Wrapper / Galaxy options.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
68 parser.add_option( '-f', '--files', dest='groups', action="callback", callback=group_callback, help="Groups to be processed, groups are separated by spaces, replicates in a group comma separated. group1_rep1,group1_rep2 group2_rep1,group2_rep2, ..., groupN_rep1, groupN_rep2" )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
69 parser.add_option( '-A', '--inputA', dest='inputA', help='A transcript GTF file produced by cufflinks, cuffcompare, or other source.')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
70 parser.add_option( '-1', '--input1', dest='input1', help='File of RNA-Seq read alignments in the SAM format. SAM is a standard short read alignment, that allows aligners to attach custom tags to individual alignments, and Cufflinks requires that the alignments you supply have some of these tags. Please see Input formats for more details.' )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
71 parser.add_option( '-2', '--input2', dest='input2', help='File of RNA-Seq read alignments in the SAM format. SAM is a standard short read alignment, that allows aligners to attach custom tags to individual alignments, and Cufflinks requires that the alignments you supply have some of these tags. Please see Input formats for more details.' )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
72
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
73 # Label options
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
74 parser.add_option('-L', '--labels', dest='labels', action="callback", callback=label_callback, help="Labels for the groups the replicates are in.")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
75
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
76 # Normalization options.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
77 parser.add_option( "-N", "--quartile-normalization", dest="do_normalization", action="store_true" )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
78
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
79 # Bias correction options.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
80 parser.add_option( '-b', dest='do_bias_correction', action="store_true", help='Providing Cufflinks with a multifasta file via this option instructs it to run our new bias detection and correction algorithm which can significantly improve accuracy of transcript abundance estimates.')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
81 parser.add_option( '', '--dbkey', dest='dbkey', help='The build of the reference dataset' )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
82 parser.add_option( '', '--index_dir', dest='index_dir', help='GALAXY_DATA_INDEX_DIR' )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
83 parser.add_option( '', '--ref_file', dest='ref_file', help='The reference dataset from the history' )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
84
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
85 # Outputs.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
86 parser.add_option( "--isoforms_fpkm_tracking_output", dest="isoforms_fpkm_tracking_output" )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
87 parser.add_option( "--genes_fpkm_tracking_output", dest="genes_fpkm_tracking_output" )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
88 parser.add_option( "--cds_fpkm_tracking_output", dest="cds_fpkm_tracking_output" )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
89 parser.add_option( "--tss_groups_fpkm_tracking_output", dest="tss_groups_fpkm_tracking_output" )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
90 parser.add_option( "--isoforms_exp_output", dest="isoforms_exp_output" )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
91 parser.add_option( "--genes_exp_output", dest="genes_exp_output" )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
92 parser.add_option( "--tss_groups_exp_output", dest="tss_groups_exp_output" )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
93 parser.add_option( "--cds_exp_fpkm_tracking_output", dest="cds_exp_fpkm_tracking_output" )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
94 parser.add_option( "--splicing_diff_output", dest="splicing_diff_output" )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
95 parser.add_option( "--cds_diff_output", dest="cds_diff_output" )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
96 parser.add_option( "--promoters_diff_output", dest="promoters_diff_output" )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
97
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
98 (options, args) = parser.parse_args()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
99
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
100 # output version # of tool
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
101 try:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
102 tmp = tempfile.NamedTemporaryFile().name
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
103 tmp_stdout = open( tmp, 'wb' )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
104 proc = subprocess.Popen( args='cuffdiff --no-update-check 2>&1', shell=True, stdout=tmp_stdout )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
105 tmp_stdout.close()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
106 returncode = proc.wait()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
107 stdout = None
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
108 for line in open( tmp_stdout.name, 'rb' ):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
109 if line.lower().find( 'cuffdiff v' ) >= 0:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
110 stdout = line.strip()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
111 break
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
112 if stdout:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
113 sys.stdout.write( '%s\n' % stdout )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
114 else:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
115 raise Exception
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
116 except:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
117 sys.stdout.write( 'Could not determine Cuffdiff version\n' )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
118
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
119 # Make temp directory for output.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
120 tmp_output_dir = tempfile.mkdtemp()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
121
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
122 # If doing bias correction, set/link to sequence file.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
123 if options.do_bias_correction:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
124 cached_seqs_pointer_file = os.path.join( options.index_dir, 'sam_fa_indices.loc' )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
125 if not os.path.exists( cached_seqs_pointer_file ):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
126 stop_err( 'The required file (%s) does not exist.' % cached_seqs_pointer_file )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
127 # If found for the dbkey, seq_path will look something like /galaxy/data/equCab2/sam_index/equCab2.fa,
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
128 # and the equCab2.fa file will contain fasta sequences.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
129 seq_path = check_seq_file( options.dbkey, cached_seqs_pointer_file )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
130 if options.ref_file != 'None':
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
131 # Create symbolic link to ref_file so that index will be created in working directory.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
132 seq_path = os.path.join( tmp_output_dir, "ref.fa" )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
133 os.symlink( options.ref_file, seq_path )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
134
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
135 # Build command.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
136
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
137 # Base; always use quiet mode to avoid problems with storing log output.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
138 cmd = "cuffdiff --no-update-check -q"
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
139
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
140 # Add options.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
141 if options.inner_dist_std_dev:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
142 cmd += ( " -s %i" % int ( options.inner_dist_std_dev ) )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
143 if options.num_threads:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
144 cmd += ( " -p %i" % int ( options.num_threads ) )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
145 if options.inner_mean_dist:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
146 cmd += ( " -m %i" % int ( options.inner_mean_dist ) )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
147 if options.min_alignment_count:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
148 cmd += ( " -c %i" % int ( options.min_alignment_count ) )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
149 if options.FDR:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
150 cmd += ( " --FDR %f" % float( options.FDR ) )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
151 if options.num_importance_samples:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
152 cmd += ( " --num-importance-samples %i" % int ( options.num_importance_samples ) )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
153 if options.max_mle_iterations:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
154 cmd += ( " --max-mle-iterations %i" % int ( options.max_mle_iterations ) )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
155 if options.do_normalization:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
156 cmd += ( " -N" )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
157 if options.do_bias_correction:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
158 cmd += ( " -b %s" % seq_path )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
159
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
160 # Add inputs.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
161 # For replicate analysis: group1_rep1,group1_rep2 groupN_rep1,groupN_rep2
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
162 if options.groups:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
163 cmd += " --labels "
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
164 for label in options.labels:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
165 cmd += label + ","
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
166 cmd = cmd[:-1]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
167
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
168 cmd += " " + options.inputA + " "
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
169
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
170 for group in options.groups:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
171 for filename in group:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
172 cmd += filename + ","
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
173 cmd = cmd[:-1] + " "
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
174 else:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
175 cmd += " " + options.inputA + " " + options.input1 + " " + options.input2
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
176
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
177 # Debugging.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
178 print cmd
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
179
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
180 # Run command.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
181 try:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
182 tmp_name = tempfile.NamedTemporaryFile( dir=tmp_output_dir ).name
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
183 tmp_stderr = open( tmp_name, 'wb' )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
184 proc = subprocess.Popen( args=cmd, shell=True, cwd=tmp_output_dir, stderr=tmp_stderr.fileno() )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
185 returncode = proc.wait()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
186 tmp_stderr.close()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
187
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
188 # Get stderr, allowing for case where it's very large.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
189 tmp_stderr = open( tmp_name, 'rb' )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
190 stderr = ''
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
191 buffsize = 1048576
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
192 try:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
193 while True:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
194 stderr += tmp_stderr.read( buffsize )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
195 if not stderr or len( stderr ) % buffsize != 0:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
196 break
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
197 except OverflowError:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
198 pass
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
199 tmp_stderr.close()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
200
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
201 # Error checking.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
202 if returncode != 0:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
203 raise Exception, stderr
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
204
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
205 # check that there are results in the output file
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
206 if len( open( os.path.join( tmp_output_dir, "isoforms.fpkm_tracking" ), 'rb' ).read().strip() ) == 0:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
207 raise Exception, 'The main output file is empty, there may be an error with your input file or settings.'
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
208 except Exception, e:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
209 stop_err( 'Error running cuffdiff. ' + str( e ) )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
210
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
211
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
212 # Copy output files from tmp directory to specified files.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
213 try:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
214 try:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
215 shutil.copyfile( os.path.join( tmp_output_dir, "isoforms.fpkm_tracking" ), options.isoforms_fpkm_tracking_output )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
216 shutil.copyfile( os.path.join( tmp_output_dir, "genes.fpkm_tracking" ), options.genes_fpkm_tracking_output )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
217 shutil.copyfile( os.path.join( tmp_output_dir, "cds.fpkm_tracking" ), options.cds_fpkm_tracking_output )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
218 shutil.copyfile( os.path.join( tmp_output_dir, "tss_groups.fpkm_tracking" ), options.tss_groups_fpkm_tracking_output )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
219 shutil.copyfile( os.path.join( tmp_output_dir, "isoform_exp.diff" ), options.isoforms_exp_output )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
220 shutil.copyfile( os.path.join( tmp_output_dir, "gene_exp.diff" ), options.genes_exp_output )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
221 shutil.copyfile( os.path.join( tmp_output_dir, "tss_group_exp.diff" ), options.tss_groups_exp_output )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
222 shutil.copyfile( os.path.join( tmp_output_dir, "splicing.diff" ), options.splicing_diff_output )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
223 shutil.copyfile( os.path.join( tmp_output_dir, "cds.diff" ), options.cds_diff_output )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
224 shutil.copyfile( os.path.join( tmp_output_dir, "cds_exp.diff" ), options.cds_exp_fpkm_tracking_output )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
225 shutil.copyfile( os.path.join( tmp_output_dir, "promoters.diff" ), options.promoters_diff_output )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
226 except Exception, e:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
227 stop_err( 'Error in cuffdiff:\n' + str( e ) )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
228 finally:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
229 # Clean up temp dirs
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
230 if os.path.exists( tmp_output_dir ):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
231 shutil.rmtree( tmp_output_dir )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
232
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
233 if __name__=="__main__": __main__()