comparison cufflinks_wrapper.py @ 9:a1ea9af8d5f4 draft

planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
author devteam
date Wed, 11 Nov 2015 12:34:49 -0500
parents 64698e16f4a6
children 83bec71c5c9f
comparison
equal deleted inserted replaced
8:64698e16f4a6 9:a1ea9af8d5f4
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 import optparse, os, shutil, subprocess, sys, tempfile 3 import optparse
4 from galaxy import eggs 4 import os
5 import shutil
6 import subprocess
7 import sys
8 import tempfile
5 from galaxy.datatypes.util.gff_util import parse_gff_attributes, gff_attributes_to_str 9 from galaxy.datatypes.util.gff_util import parse_gff_attributes, gff_attributes_to_str
6 10
11
7 def stop_err( msg ): 12 def stop_err( msg ):
8 sys.stderr.write( "%s\n" % msg ) 13 sys.exit( "%s\n" % msg )
9 sys.exit() 14
10 15
11 def __main__(): 16 def __main__():
12 #Parse Command Line 17 #Parse Command Line
13 parser = optparse.OptionParser() 18 parser = optparse.OptionParser()
14 parser.add_option( '-1', '--input', dest='input', 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.' ) 19 parser.add_option( '-1', '--input', dest='input', 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.' )
15 parser.add_option( '-I', '--max-intron-length', dest='max_intron_len', help='The minimum intron length. Cufflinks will not report transcripts with introns longer than this, and will ignore SAM alignments with REF_SKIP CIGAR operations longer than this. The default is 300,000.' ) 20 parser.add_option( '-I', '--max-intron-length', dest='max_intron_len', help='The minimum intron length. Cufflinks will not report transcripts with introns longer than this, and will ignore SAM alignments with REF_SKIP CIGAR operations longer than this. The default is 300,000.' )
17 parser.add_option( '-j', '--pre-mrna-fraction', dest='pre_mrna_fraction', help='Some RNA-Seq protocols produce a significant amount of reads that originate from incompletely spliced transcripts, and these reads can confound the assembly of fully spliced mRNAs. Cufflinks uses this parameter to filter out alignments that lie within the intronic intervals implied by the spliced alignments. The minimum depth of coverage in the intronic region covered by the alignment is divided by the number of spliced reads, and if the result is lower than this parameter value, the intronic alignments are ignored. The default is 5%.' ) 22 parser.add_option( '-j', '--pre-mrna-fraction', dest='pre_mrna_fraction', help='Some RNA-Seq protocols produce a significant amount of reads that originate from incompletely spliced transcripts, and these reads can confound the assembly of fully spliced mRNAs. Cufflinks uses this parameter to filter out alignments that lie within the intronic intervals implied by the spliced alignments. The minimum depth of coverage in the intronic region covered by the alignment is divided by the number of spliced reads, and if the result is lower than this parameter value, the intronic alignments are ignored. The default is 5%.' )
18 parser.add_option( '-p', '--num-threads', dest='num_threads', help='Use this many threads to align reads. The default is 1.' ) 23 parser.add_option( '-p', '--num-threads', dest='num_threads', help='Use this many threads to align reads. The default is 1.' )
19 parser.add_option( '-G', '--GTF', dest='GTF', help='Tells Cufflinks to use the supplied reference annotation to estimate isoform expression. It will not assemble novel transcripts, and the program will ignore alignments not structurally compatible with any reference transcript.' ) 24 parser.add_option( '-G', '--GTF', dest='GTF', help='Tells Cufflinks to use the supplied reference annotation to estimate isoform expression. It will not assemble novel transcripts, and the program will ignore alignments not structurally compatible with any reference transcript.' )
20 parser.add_option("--compatible-hits-norm", dest='compatible_hits_norm', action="store_true", help='Count hits compatible with reference RNAs only') 25 parser.add_option("--compatible-hits-norm", dest='compatible_hits_norm', action="store_true", help='Count hits compatible with reference RNAs only')
21 parser.add_option( '-g', '--GTF-guide', dest='GTFguide', help='use reference transcript annotation to guide assembly' ) 26 parser.add_option( '-g', '--GTF-guide', dest='GTFguide', help='use reference transcript annotation to guide assembly' )
22 parser.add_option("--3-overhang-tolerance",dest='three_overhang_tolerance', help='The number of bp allowed to overhang the 3prime end of a reference transcript when determining if an assembled transcript should be merged with it (ie, the assembled transcript is not novel). The default is 600 bp.') 27 parser.add_option("--3-overhang-tolerance", dest='three_overhang_tolerance', help='The number of bp allowed to overhang the 3prime end of a reference transcript when determining if an assembled transcript should be merged with it (ie, the assembled transcript is not novel). The default is 600 bp.')
23 parser.add_option("--intron-overhang-tolerance",dest='intron_overhang_tolerance',help='The number of bp allowed to enter the intron of a reference transcript when determining if an assembled transcript should be merged with it (ie, the assembled transcript is not novel). The default is 50 bp.') 28 parser.add_option("--intron-overhang-tolerance", dest='intron_overhang_tolerance', help='The number of bp allowed to enter the intron of a reference transcript when determining if an assembled transcript should be merged with it (ie, the assembled transcript is not novel). The default is 50 bp.')
24 parser.add_option("--no-faux-reads", dest='no_faux_reads',help='This option disables tiling of the reference transcripts with faux reads. Use this if you only want to use sequencing reads in assembly but do not want to output assembled transcripts that lay within reference transcripts. All reference transcripts in the input annotation will also be included in the output.') 29 parser.add_option("--no-faux-reads", dest='no_faux_reads', help='This option disables tiling of the reference transcripts with faux reads. Use this if you only want to use sequencing reads in assembly but do not want to output assembled transcripts that lay within reference transcripts. All reference transcripts in the input annotation will also be included in the output.')
25 parser.add_option( '-u', '--multi-read-correct', dest='multi_read_correct', action="store_true", help='Tells Cufflinks to do an initial estimation procedure to more accurately weight reads mapping to multiple locations in the genome') 30 parser.add_option( '-u', '--multi-read-correct', dest='multi_read_correct', action="store_true", help='Tells Cufflinks to do an initial estimation procedure to more accurately weight reads mapping to multiple locations in the genome')
26 31
27 # Normalization options. 32 # Normalization options.
28 parser.add_option( "--no-effective-length-correction", dest="no_effective_length_correction", action="store_true" ) 33 parser.add_option( "--no-effective-length-correction", dest="no_effective_length_correction", action="store_true" )
29 parser.add_option( "--no-length-correction", dest="no_length_correction", action="store_true" ) 34 parser.add_option( "--no-length-correction", dest="no_length_correction", action="store_true" )
30 35
31 # Wrapper / Galaxy options. 36 # Wrapper / Galaxy options.
32 parser.add_option( '-A', '--assembled-isoforms-output', dest='assembled_isoforms_output_file', help='Assembled isoforms output file; formate is GTF.' ) 37 parser.add_option( '-A', '--assembled-isoforms-output', dest='assembled_isoforms_output_file', help='Assembled isoforms output file; formate is GTF.' )
33 38
34 # Advanced Options: 39 # Advanced Options:
35 parser.add_option( "--library-type",dest="library_type",help=' library prep used for input reads, default fr-unstranded') 40 parser.add_option( "--library-type", dest="library_type", help=' library prep used for input reads, default fr-unstranded')
36 parser.add_option( '-M','--mask-file', dest='mask_file', help='Tells Cufflinks to ignore all reads that could have come from transcripts in this GTF file. \ 41 parser.add_option( '-M', '--mask-file', dest='mask_file', help='Tells Cufflinks to ignore all reads that could have come from transcripts in this GTF file. \
37 We recommend including any annotated rRNA, mitochondrial transcripts other abundant transcripts \ 42 We recommend including any annotated rRNA, mitochondrial transcripts other abundant transcripts \
38 you wish to ignore in your analysis in this file. Due to variable efficiency of mRNA enrichment \ 43 you wish to ignore in your analysis in this file. Due to variable efficiency of mRNA enrichment \
39 methods and rRNA depletion kits, masking these transcripts often improves the overall robustness \ 44 methods and rRNA depletion kits, masking these transcripts often improves the overall robustness \
40 of transcript abundance estimates.') 45 of transcript abundance estimates.')
41 parser.add_option( '-m', '--inner-mean-dist', dest='inner_mean_dist', help='This is the expected (mean) inner distance between mate pairs. \ 46 parser.add_option( '-m', '--inner-mean-dist', dest='inner_mean_dist', help='This is the expected (mean) inner distance between mate pairs. \
42 For, example, for paired end runs with fragments selected at 300bp, \ 47 For, example, for paired end runs with fragments selected at 300bp, \
43 where each end is 50bp, you should set -r to be 200. The default is 45bp.') # cufflinks: --frag-len-mean 48 where each end is 50bp, you should set -r to be 200. The default is 45bp.') # cufflinks: --frag-len-mean
44 49
45 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.' ) # cufflinks: --frag-len-std-dev 50 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.' ) # cufflinks: --frag-len-std-dev
46 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' ) 51 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' )
47 parser.add_option( '--junc-alpha', dest='junc_alpha', help='Alpha value for the binomial test used during false positive spliced alignment filtration. Default: 0.001' ) 52 parser.add_option( '--junc-alpha', dest='junc_alpha', help='Alpha value for the binomial test used during false positive spliced alignment filtration. Default: 0.001' )
48 parser.add_option( '--small-anchor-fraction', dest='small_anchor_fraction', help='Spliced reads with less than this percent of their length on each side of\ 53 parser.add_option( '--small-anchor-fraction', dest='small_anchor_fraction', help='Spliced reads with less than this percent of their length on each side of\
53 parser.add_option( '--max-bundle-frags', dest='max_bundle_frags', help='Sets the maximum number of fragments a locus may have before being skipped. Skipped loci are listed in skipped.gtf. Default: 1,000,000' ) 58 parser.add_option( '--max-bundle-frags', dest='max_bundle_frags', help='Sets the maximum number of fragments a locus may have before being skipped. Skipped loci are listed in skipped.gtf. Default: 1,000,000' )
54 parser.add_option( '--min-intron-length', dest='min_intron_length', help='Minimal allowed intron size. Default: 50' ) 59 parser.add_option( '--min-intron-length', dest='min_intron_length', help='Minimal allowed intron size. Default: 50' )
55 parser.add_option( '--trim-3-avgcov-thresh', dest='trim_three_avgcov_thresh', help='Minimum average coverage required to attempt 3prime trimming. Default: 10' ) 60 parser.add_option( '--trim-3-avgcov-thresh', dest='trim_three_avgcov_thresh', help='Minimum average coverage required to attempt 3prime trimming. Default: 10' )
56 parser.add_option( '--trim-3-dropoff-frac', dest='trim_three_dropoff_frac', help='The fraction of average coverage below which to trim the 3prime end of an assembled transcript. Default: 0.1' ) 61 parser.add_option( '--trim-3-dropoff-frac', dest='trim_three_dropoff_frac', help='The fraction of average coverage below which to trim the 3prime end of an assembled transcript. Default: 0.1' )
57 62
58
59 # Bias correction options. 63 # Bias correction options.
60 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.') 64 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.')
61 parser.add_option( '', '--index', dest='index', help='The path of the reference genome' ) 65 parser.add_option( '', '--index', dest='index', help='The path of the reference genome' )
62 parser.add_option( '', '--ref_file', dest='ref_file', help='The reference dataset from the history' ) 66 parser.add_option( '', '--ref_file', dest='ref_file', help='The reference dataset from the history' )
63 67
64 # Global model (for trackster). 68 # Global model (for trackster).
65 parser.add_option( '', '--global_model', dest='global_model_file', help='Global model used for computing on local data' ) 69 parser.add_option( '', '--global_model', dest='global_model_file', help='Global model used for computing on local data' )
66 70
67 (options, args) = parser.parse_args() 71 (options, args) = parser.parse_args()
68 72
69 # output version # of tool 73 # output version # of tool
70 try: 74 try:
71 tmp = tempfile.NamedTemporaryFile().name 75 tmp = tempfile.NamedTemporaryFile().name
72 tmp_stdout = open( tmp, 'wb' ) 76 tmp_stdout = open( tmp, 'wb' )
73 proc = subprocess.Popen( args='cufflinks --no-update-check 2>&1', shell=True, stdout=tmp_stdout ) 77 proc = subprocess.Popen( args='cufflinks --no-update-check 2>&1', shell=True, stdout=tmp_stdout )
82 sys.stdout.write( '%s\n' % stdout ) 86 sys.stdout.write( '%s\n' % stdout )
83 else: 87 else:
84 raise Exception 88 raise Exception
85 except: 89 except:
86 sys.stdout.write( 'Could not determine Cufflinks version\n' ) 90 sys.stdout.write( 'Could not determine Cufflinks version\n' )
87 91
88 # If doing bias correction, set/link to sequence file. 92 # If doing bias correction, set/link to sequence file.
89 if options.do_bias_correction: 93 if options.do_bias_correction:
90 if options.ref_file: 94 if options.ref_file:
91 # Sequence data from history. 95 # Sequence data from history.
92 # Create symbolic link to ref_file so that index will be created in working directory. 96 # Create symbolic link to ref_file so that index will be created in working directory.
96 if not os.path.exists( options.index ): 100 if not os.path.exists( options.index ):
97 stop_err( 'Reference genome %s not present, request it by reporting this error.' % options.index ) 101 stop_err( 'Reference genome %s not present, request it by reporting this error.' % options.index )
98 seq_path = options.index 102 seq_path = options.index
99 103
100 # Build command. 104 # Build command.
101 105
102 # Base; always use quiet mode to avoid problems with storing log output. 106 # Base; always use quiet mode to avoid problems with storing log output.
103 cmd = "cufflinks -q --no-update-check" 107 cmd = "cufflinks -q --no-update-check"
104 108
105 # Add options. 109 # Add options.
106 if options.max_intron_len: 110 if options.max_intron_len:
107 cmd += ( " -I %i" % int ( options.max_intron_len ) ) 111 cmd += ( " -I %i" % int( options.max_intron_len ) )
108 if options.min_isoform_fraction: 112 if options.min_isoform_fraction:
109 cmd += ( " -F %f" % float ( options.min_isoform_fraction ) ) 113 cmd += ( " -F %f" % float( options.min_isoform_fraction ) )
110 if options.pre_mrna_fraction: 114 if options.pre_mrna_fraction:
111 cmd += ( " -j %f" % float ( options.pre_mrna_fraction ) ) 115 cmd += ( " -j %f" % float( options.pre_mrna_fraction ) )
112 if options.num_threads: 116 if options.num_threads:
113 cmd += ( " -p %i" % int ( options.num_threads ) ) 117 cmd += ( " -p %i" % int( options.num_threads ) )
114 if options.GTF: 118 if options.GTF:
115 cmd += ( " -G %s" % options.GTF ) 119 cmd += ( " -G %s" % options.GTF )
116 if options.compatible_hits_norm: 120 if options.compatible_hits_norm:
117 cmd += ( " --compatible-hits-norm" ) 121 cmd += ( " --compatible-hits-norm" )
118 if options.GTFguide: 122 if options.GTFguide:
119 cmd += ( " -g %s" % options.GTFguide ) 123 cmd += ( " -g %s" % options.GTFguide )
120 cmd += ( " --3-overhang-tolerance %i" % int ( options.three_overhang_tolerance ) ) 124 cmd += ( " --3-overhang-tolerance %i" % int( options.three_overhang_tolerance ) )
121 cmd += ( " --intron-overhang-tolerance %i" % int ( options.intron_overhang_tolerance ) ) 125 cmd += ( " --intron-overhang-tolerance %i" % int( options.intron_overhang_tolerance ) )
122 if options.no_faux_reads: 126 if options.no_faux_reads:
123 cmd += ( " --no-faux-reads" ) 127 cmd += ( " --no-faux-reads" )
124 if options.multi_read_correct: 128 if options.multi_read_correct:
125 cmd += ( " -u" ) 129 cmd += ( " -u" )
126 130
127 if options.library_type and options.library_type != 'auto': 131 if options.library_type and options.library_type != 'auto':
128 cmd += ( " --library-type %s" % options.library_type) 132 cmd += ( " --library-type %s" % options.library_type)
129 if options.mask_file: 133 if options.mask_file:
130 cmd += ( " --mask-file %s" % options.mask_file ) 134 cmd += ( " --mask-file %s" % options.mask_file )
131 if options.inner_mean_dist: 135 if options.inner_mean_dist:
132 cmd += ( " -m %i" % int ( options.inner_mean_dist ) ) 136 cmd += ( " -m %i" % int( options.inner_mean_dist ) )
133 if options.inner_dist_std_dev: 137 if options.inner_dist_std_dev:
134 cmd += ( " -s %i" % int ( options.inner_dist_std_dev ) ) 138 cmd += ( " -s %i" % int( options.inner_dist_std_dev ) )
135 if options.max_mle_iterations: 139 if options.max_mle_iterations:
136 cmd += ( " --max-mle-iterations %i" % int ( options.max_mle_iterations ) ) 140 cmd += ( " --max-mle-iterations %i" % int( options.max_mle_iterations ) )
137 if options.junc_alpha: 141 if options.junc_alpha:
138 cmd += ( " --junc-alpha %f" % float ( options.junc_alpha) ) 142 cmd += ( " --junc-alpha %f" % float( options.junc_alpha) )
139 if options.small_anchor_fraction: 143 if options.small_anchor_fraction:
140 cmd += ( " --small-anchor-fraction %f" % float (options.small_anchor_fraction ) ) 144 cmd += ( " --small-anchor-fraction %f" % float(options.small_anchor_fraction ) )
141 if options.overhang_tolerance: 145 if options.overhang_tolerance:
142 cmd += ( " --overhang-tolerance %i" % int ( options.overhang_tolerance ) ) 146 cmd += ( " --overhang-tolerance %i" % int( options.overhang_tolerance ) )
143 if options.max_bundle_length: 147 if options.max_bundle_length:
144 cmd += ( " --max-bundle-length %i" % int ( options.max_bundle_length ) ) 148 cmd += ( " --max-bundle-length %i" % int( options.max_bundle_length ) )
145 if options.max_bundle_frags: 149 if options.max_bundle_frags:
146 cmd += ( " --max-bundle-frags %i" % int ( options.max_bundle_frags ) ) 150 cmd += ( " --max-bundle-frags %i" % int( options.max_bundle_frags ) )
147 if options.min_intron_length: 151 if options.min_intron_length:
148 cmd += ( " --min-intron-length %i" % int ( options.min_intron_length ) ) 152 cmd += ( " --min-intron-length %i" % int( options.min_intron_length ) )
149 if options.trim_three_avgcov_thresh: 153 if options.trim_three_avgcov_thresh:
150 cmd += ( " --trim-3-avgcov-thresh %i" % int ( options.trim_three_avgcov_thresh ) ) 154 cmd += ( " --trim-3-avgcov-thresh %i" % int( options.trim_three_avgcov_thresh ) )
151 if options.trim_three_dropoff_frac: 155 if options.trim_three_dropoff_frac:
152 cmd += ( " --trim-3-dropoff-frac %f" % float ( options.trim_three_dropoff_frac ) ) 156 cmd += ( " --trim-3-dropoff-frac %f" % float( options.trim_three_dropoff_frac ) )
153 157
154 if options.do_bias_correction: 158 if options.do_bias_correction:
155 cmd += ( " -b %s" % seq_path ) 159 cmd += ( " -b %s" % seq_path )
156 if options.no_effective_length_correction: 160 if options.no_effective_length_correction:
157 cmd += ( " --no-effective-length-correction" ) 161 cmd += ( " --no-effective-length-correction" )
158 if options.no_length_correction: 162 if options.no_length_correction:
159 cmd += ( " --no-length-correction" ) 163 cmd += ( " --no-length-correction" )
160 164
161 # Add input files. 165 # Add input files.
162 cmd += " " + options.input 166 cmd += " " + options.input
163 167
164 # Debugging. 168 # Debugging.
165 print cmd 169 print cmd
166 170
167 # 171 #
168 # Run command and handle output. 172 # Run command and handle output.
169 # 173 #
170 try: 174 try:
171 # 175 #
174 tmp_name = tempfile.NamedTemporaryFile( dir="." ).name 178 tmp_name = tempfile.NamedTemporaryFile( dir="." ).name
175 tmp_stderr = open( tmp_name, 'wb' ) 179 tmp_stderr = open( tmp_name, 'wb' )
176 proc = subprocess.Popen( args=cmd, shell=True, stderr=tmp_stderr.fileno() ) 180 proc = subprocess.Popen( args=cmd, shell=True, stderr=tmp_stderr.fileno() )
177 returncode = proc.wait() 181 returncode = proc.wait()
178 tmp_stderr.close() 182 tmp_stderr.close()
179 183
180 # Error checking. 184 # Error checking.
181 if returncode != 0: 185 if returncode != 0:
182 raise Exception, "return code = %i" % returncode 186 raise Exception("return code = %i" % returncode)
183 187
184 # 188 #
185 # Handle output. 189 # Handle output.
186 # 190 #
187 191
188 # Read standard error to get total map/upper quartile mass. 192 # Read standard error to get total map/upper quartile mass.
189 total_map_mass = -1 193 total_map_mass = -1
190 tmp_stderr = open( tmp_name, 'r' ) 194 tmp_stderr = open( tmp_name, 'r' )
191 for line in tmp_stderr: 195 for line in tmp_stderr:
192 if line.lower().find( "map mass" ) >= 0 or line.lower().find( "upper quartile" ) >= 0: 196 if line.lower().find( "map mass" ) >= 0 or line.lower().find( "upper quartile" ) >= 0:
193 total_map_mass = float( line.split(":")[1].strip() ) 197 total_map_mass = float( line.split(":")[1].strip() )
194 break 198 break
195 tmp_stderr.close() 199 tmp_stderr.close()
196 200
197 # 201 #
198 # If there's a global model provided, use model's total map mass 202 # If there's a global model provided, use model's total map mass
199 # to adjust FPKM + confidence intervals. 203 # to adjust FPKM + confidence intervals.
200 # 204 #
201 if options.global_model_file: 205 if options.global_model_file:
202 # Global model is simply total map mass from original run. 206 # Global model is simply total map mass from original run.
203 global_model_file = open( options.global_model_file, 'r' ) 207 global_model_file = open( options.global_model_file, 'r' )
204 global_model_total_map_mass = float( global_model_file.readline() ) 208 global_model_total_map_mass = float( global_model_file.readline() )
205 global_model_file.close() 209 global_model_file.close()
206 210
207 # Ratio of global model's total map mass to original run's map mass is 211 # Ratio of global model's total map mass to original run's map mass is
208 # factor used to adjust FPKM. 212 # factor used to adjust FPKM.
209 fpkm_map_mass_ratio = total_map_mass / global_model_total_map_mass 213 fpkm_map_mass_ratio = total_map_mass / global_model_total_map_mass
210 214
211 # Update FPKM values in transcripts.gtf file. 215 # Update FPKM values in transcripts.gtf file.
212 transcripts_file = open( "transcripts.gtf", 'r' ) 216 transcripts_file = open( "transcripts.gtf", 'r' )
213 tmp_transcripts = tempfile.NamedTemporaryFile( dir="." ).name 217 tmp_transcripts = tempfile.NamedTemporaryFile( dir="." ).name
214 new_transcripts_file = open( tmp_transcripts, 'w' ) 218 new_transcripts_file = open( tmp_transcripts, 'w' )
215 for line in transcripts_file: 219 for line in transcripts_file:
221 fields[8] = gff_attributes_to_str( attrs, "GTF" ) 225 fields[8] = gff_attributes_to_str( attrs, "GTF" )
222 new_transcripts_file.write( "%s\n" % '\t'.join( fields ) ) 226 new_transcripts_file.write( "%s\n" % '\t'.join( fields ) )
223 transcripts_file.close() 227 transcripts_file.close()
224 new_transcripts_file.close() 228 new_transcripts_file.close()
225 shutil.copyfile( tmp_transcripts, "transcripts.gtf" ) 229 shutil.copyfile( tmp_transcripts, "transcripts.gtf" )
226 230
227 # TODO: update expression files as well. 231 # TODO: update expression files as well.
228 232
229 # Set outputs. Transcript and gene expression handled by wrapper directives. 233 # Set outputs. Transcript and gene expression handled by wrapper directives.
230 shutil.copyfile( "transcripts.gtf" , options.assembled_isoforms_output_file ) 234 shutil.copyfile( "transcripts.gtf", options.assembled_isoforms_output_file )
231 if total_map_mass > -1: 235 if total_map_mass > -1:
232 f = open( "global_model.txt", 'w' ) 236 f = open( "global_model.txt", 'w' )
233 f.write( "%f\n" % total_map_mass ) 237 f.write( "%f\n" % total_map_mass )
234 f.close() 238 f.close()
235 except Exception, e: 239 except Exception, e:
243 if not stderr or len( stderr ) % buffsize != 0: 247 if not stderr or len( stderr ) % buffsize != 0:
244 break 248 break
245 except OverflowError: 249 except OverflowError:
246 pass 250 pass
247 tmp_stderr.close() 251 tmp_stderr.close()
248
249 stop_err( 'Error running cufflinks.\n%s\n%s' % ( str( e ), stderr ) ) 252 stop_err( 'Error running cufflinks.\n%s\n%s' % ( str( e ), stderr ) )
250 253
251 if __name__=="__main__": __main__() 254 if __name__ == "__main__":
255 __main__()