Mercurial > repos > devteam > cufflinks
annotate 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 |
rev | line source |
---|---|
0 | 1 #!/usr/bin/env python |
2 | |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
3 import optparse |
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
4 import os |
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
5 import shutil |
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
6 import subprocess |
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
7 import sys |
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
8 import tempfile |
0 | 9 from galaxy.datatypes.util.gff_util import parse_gff_attributes, gff_attributes_to_str |
10 | |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
11 |
0 | 12 def stop_err( msg ): |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
13 sys.exit( "%s\n" % msg ) |
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
14 |
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
15 |
0 | 16 def __main__(): |
17 #Parse Command Line | |
18 parser = optparse.OptionParser() | |
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.' ) | |
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.' ) | |
21 parser.add_option( '-F', '--min-isoform-fraction', dest='min_isoform_fraction', help='After calculating isoform abundance for a gene, Cufflinks filters out transcripts that it believes are very low abundance, because isoforms expressed at extremely low levels often cannot reliably be assembled, and may even be artifacts of incompletely spliced precursors of processed transcripts. This parameter is also used to filter out introns that have far fewer spliced alignments supporting them. The default is 0.05, or 5% of the most abundant isoform (the major isoform) of the gene.' ) | |
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%.' ) | |
23 parser.add_option( '-p', '--num-threads', dest='num_threads', help='Use this many threads to align reads. The default is 1.' ) | |
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.' ) | |
8 | 25 parser.add_option("--compatible-hits-norm", dest='compatible_hits_norm', action="store_true", help='Count hits compatible with reference RNAs only') |
0 | 26 parser.add_option( '-g', '--GTF-guide', dest='GTFguide', help='use reference transcript annotation to guide assembly' ) |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
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.') |
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
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.') |
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
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.') |
0 | 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') |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
31 |
0 | 32 # Normalization options. |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
33 parser.add_option( "--no-effective-length-correction", dest="no_effective_length_correction", action="store_true" ) |
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
34 parser.add_option( "--no-length-correction", dest="no_length_correction", action="store_true" ) |
0 | 35 |
36 # Wrapper / Galaxy options. | |
37 parser.add_option( '-A', '--assembled-isoforms-output', dest='assembled_isoforms_output_file', help='Assembled isoforms output file; formate is GTF.' ) | |
38 | |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
39 # Advanced Options: |
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
40 parser.add_option( "--library-type", dest="library_type", help=' library prep used for input reads, default fr-unstranded') |
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
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. \ |
7 | 42 We recommend including any annotated rRNA, mitochondrial transcripts other abundant transcripts \ |
43 you wish to ignore in your analysis in this file. Due to variable efficiency of mRNA enrichment \ | |
44 methods and rRNA depletion kits, masking these transcripts often improves the overall robustness \ | |
45 of transcript abundance estimates.') | |
46 parser.add_option( '-m', '--inner-mean-dist', dest='inner_mean_dist', help='This is the expected (mean) inner distance between mate pairs. \ | |
47 For, example, for paired end runs with fragments selected at 300bp, \ | |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
48 where each end is 50bp, you should set -r to be 200. The default is 45bp.') # cufflinks: --frag-len-mean |
7 | 49 |
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 | |
0 | 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' ) |
7 | 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' ) |
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\ | |
54 the junction are considered suspicious and are candidates for filtering prior to assembly. Default: 0.09.' ) | |
55 parser.add_option( '--overhang-tolerance', dest='overhang_tolerance', help='The number of bp allowed to enter the intron of a transcript when determining if a \ | |
56 read or another transcript is mappable to/compatible with it. The default is 8 bp based on the default bowtie/TopHat parameters.' ) | |
57 parser.add_option( '--max-bundle-length', dest='max_bundle_length', help='Maximum genomic length of a given bundle" help="Default: 3,500,000bp' ) | |
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' ) | |
59 parser.add_option( '--min-intron-length', dest='min_intron_length', help='Minimal allowed intron size. Default: 50' ) | |
60 parser.add_option( '--trim-3-avgcov-thresh', dest='trim_three_avgcov_thresh', help='Minimum average coverage required to attempt 3prime trimming. Default: 10' ) | |
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' ) | |
62 | |
0 | 63 # Bias correction options. |
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.') | |
2
da11bfc10e81
Update to the new data table specification.
Dave Bouvier <dave@bx.psu.edu>
parents:
0
diff
changeset
|
65 parser.add_option( '', '--index', dest='index', help='The path of the reference genome' ) |
0 | 66 parser.add_option( '', '--ref_file', dest='ref_file', help='The reference dataset from the history' ) |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
67 |
7 | 68 # Global model (for trackster). |
0 | 69 parser.add_option( '', '--global_model', dest='global_model_file', help='Global model used for computing on local data' ) |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
70 |
0 | 71 (options, args) = parser.parse_args() |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
72 |
0 | 73 # output version # of tool |
74 try: | |
75 tmp = tempfile.NamedTemporaryFile().name | |
76 tmp_stdout = open( tmp, 'wb' ) | |
77 proc = subprocess.Popen( args='cufflinks --no-update-check 2>&1', shell=True, stdout=tmp_stdout ) | |
78 tmp_stdout.close() | |
79 returncode = proc.wait() | |
80 stdout = None | |
81 for line in open( tmp_stdout.name, 'rb' ): | |
82 if line.lower().find( 'cufflinks v' ) >= 0: | |
83 stdout = line.strip() | |
84 break | |
85 if stdout: | |
86 sys.stdout.write( '%s\n' % stdout ) | |
87 else: | |
88 raise Exception | |
89 except: | |
90 sys.stdout.write( 'Could not determine Cufflinks version\n' ) | |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
91 |
0 | 92 # If doing bias correction, set/link to sequence file. |
93 if options.do_bias_correction: | |
2
da11bfc10e81
Update to the new data table specification.
Dave Bouvier <dave@bx.psu.edu>
parents:
0
diff
changeset
|
94 if options.ref_file: |
0 | 95 # Sequence data from history. |
96 # Create symbolic link to ref_file so that index will be created in working directory. | |
97 seq_path = "ref.fa" | |
98 os.symlink( options.ref_file, seq_path ) | |
99 else: | |
2
da11bfc10e81
Update to the new data table specification.
Dave Bouvier <dave@bx.psu.edu>
parents:
0
diff
changeset
|
100 if not os.path.exists( options.index ): |
da11bfc10e81
Update to the new data table specification.
Dave Bouvier <dave@bx.psu.edu>
parents:
0
diff
changeset
|
101 stop_err( 'Reference genome %s not present, request it by reporting this error.' % options.index ) |
da11bfc10e81
Update to the new data table specification.
Dave Bouvier <dave@bx.psu.edu>
parents:
0
diff
changeset
|
102 seq_path = options.index |
da11bfc10e81
Update to the new data table specification.
Dave Bouvier <dave@bx.psu.edu>
parents:
0
diff
changeset
|
103 |
0 | 104 # Build command. |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
105 |
0 | 106 # Base; always use quiet mode to avoid problems with storing log output. |
107 cmd = "cufflinks -q --no-update-check" | |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
108 |
0 | 109 # Add options. |
110 if options.max_intron_len: | |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
111 cmd += ( " -I %i" % int( options.max_intron_len ) ) |
0 | 112 if options.min_isoform_fraction: |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
113 cmd += ( " -F %f" % float( options.min_isoform_fraction ) ) |
0 | 114 if options.pre_mrna_fraction: |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
115 cmd += ( " -j %f" % float( options.pre_mrna_fraction ) ) |
0 | 116 if options.num_threads: |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
117 cmd += ( " -p %i" % int( options.num_threads ) ) |
0 | 118 if options.GTF: |
119 cmd += ( " -G %s" % options.GTF ) | |
7 | 120 if options.compatible_hits_norm: |
121 cmd += ( " --compatible-hits-norm" ) | |
0 | 122 if options.GTFguide: |
123 cmd += ( " -g %s" % options.GTFguide ) | |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
124 cmd += ( " --3-overhang-tolerance %i" % int( options.three_overhang_tolerance ) ) |
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
125 cmd += ( " --intron-overhang-tolerance %i" % int( options.intron_overhang_tolerance ) ) |
7 | 126 if options.no_faux_reads: |
127 cmd += ( " --no-faux-reads" ) | |
0 | 128 if options.multi_read_correct: |
129 cmd += ( " -u" ) | |
7 | 130 |
131 if options.library_type and options.library_type != 'auto': | |
132 cmd += ( " --library-type %s" % options.library_type) | |
133 if options.mask_file: | |
134 cmd += ( " --mask-file %s" % options.mask_file ) | |
135 if options.inner_mean_dist: | |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
136 cmd += ( " -m %i" % int( options.inner_mean_dist ) ) |
7 | 137 if options.inner_dist_std_dev: |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
138 cmd += ( " -s %i" % int( options.inner_dist_std_dev ) ) |
0 | 139 if options.max_mle_iterations: |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
140 cmd += ( " --max-mle-iterations %i" % int( options.max_mle_iterations ) ) |
7 | 141 if options.junc_alpha: |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
142 cmd += ( " --junc-alpha %f" % float( options.junc_alpha) ) |
7 | 143 if options.small_anchor_fraction: |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
144 cmd += ( " --small-anchor-fraction %f" % float(options.small_anchor_fraction ) ) |
7 | 145 if options.overhang_tolerance: |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
146 cmd += ( " --overhang-tolerance %i" % int( options.overhang_tolerance ) ) |
7 | 147 if options.max_bundle_length: |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
148 cmd += ( " --max-bundle-length %i" % int( options.max_bundle_length ) ) |
7 | 149 if options.max_bundle_frags: |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
150 cmd += ( " --max-bundle-frags %i" % int( options.max_bundle_frags ) ) |
7 | 151 if options.min_intron_length: |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
152 cmd += ( " --min-intron-length %i" % int( options.min_intron_length ) ) |
7 | 153 if options.trim_three_avgcov_thresh: |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
154 cmd += ( " --trim-3-avgcov-thresh %i" % int( options.trim_three_avgcov_thresh ) ) |
7 | 155 if options.trim_three_dropoff_frac: |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
156 cmd += ( " --trim-3-dropoff-frac %f" % float( options.trim_three_dropoff_frac ) ) |
7 | 157 |
0 | 158 if options.do_bias_correction: |
159 cmd += ( " -b %s" % seq_path ) | |
160 if options.no_effective_length_correction: | |
161 cmd += ( " --no-effective-length-correction" ) | |
7 | 162 if options.no_length_correction: |
163 cmd += ( " --no-length-correction" ) | |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
164 |
0 | 165 # Add input files. |
166 cmd += " " + options.input | |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
167 |
7 | 168 # Debugging. |
169 print cmd | |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
170 |
0 | 171 # |
172 # Run command and handle output. | |
173 # | |
174 try: | |
175 # | |
176 # Run command. | |
177 # | |
178 tmp_name = tempfile.NamedTemporaryFile( dir="." ).name | |
179 tmp_stderr = open( tmp_name, 'wb' ) | |
180 proc = subprocess.Popen( args=cmd, shell=True, stderr=tmp_stderr.fileno() ) | |
181 returncode = proc.wait() | |
182 tmp_stderr.close() | |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
183 |
0 | 184 # Error checking. |
185 if returncode != 0: | |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
186 raise Exception("return code = %i" % returncode) |
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
187 |
0 | 188 # |
189 # Handle output. | |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
190 # |
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
191 |
0 | 192 # Read standard error to get total map/upper quartile mass. |
193 total_map_mass = -1 | |
194 tmp_stderr = open( tmp_name, 'r' ) | |
195 for line in tmp_stderr: | |
196 if line.lower().find( "map mass" ) >= 0 or line.lower().find( "upper quartile" ) >= 0: | |
197 total_map_mass = float( line.split(":")[1].strip() ) | |
198 break | |
199 tmp_stderr.close() | |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
200 |
0 | 201 # |
202 # If there's a global model provided, use model's total map mass | |
203 # to adjust FPKM + confidence intervals. | |
204 # | |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
205 if options.global_model_file: |
0 | 206 # Global model is simply total map mass from original run. |
207 global_model_file = open( options.global_model_file, 'r' ) | |
208 global_model_total_map_mass = float( global_model_file.readline() ) | |
209 global_model_file.close() | |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
210 |
0 | 211 # Ratio of global model's total map mass to original run's map mass is |
212 # factor used to adjust FPKM. | |
213 fpkm_map_mass_ratio = total_map_mass / global_model_total_map_mass | |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
214 |
0 | 215 # Update FPKM values in transcripts.gtf file. |
216 transcripts_file = open( "transcripts.gtf", 'r' ) | |
217 tmp_transcripts = tempfile.NamedTemporaryFile( dir="." ).name | |
218 new_transcripts_file = open( tmp_transcripts, 'w' ) | |
219 for line in transcripts_file: | |
220 fields = line.split( '\t' ) | |
221 attrs = parse_gff_attributes( fields[8] ) | |
222 attrs[ "FPKM" ] = str( float( attrs[ "FPKM" ] ) * fpkm_map_mass_ratio ) | |
223 attrs[ "conf_lo" ] = str( float( attrs[ "conf_lo" ] ) * fpkm_map_mass_ratio ) | |
224 attrs[ "conf_hi" ] = str( float( attrs[ "conf_hi" ] ) * fpkm_map_mass_ratio ) | |
225 fields[8] = gff_attributes_to_str( attrs, "GTF" ) | |
226 new_transcripts_file.write( "%s\n" % '\t'.join( fields ) ) | |
227 transcripts_file.close() | |
228 new_transcripts_file.close() | |
229 shutil.copyfile( tmp_transcripts, "transcripts.gtf" ) | |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
230 |
0 | 231 # TODO: update expression files as well. |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
232 |
0 | 233 # Set outputs. Transcript and gene expression handled by wrapper directives. |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
234 shutil.copyfile( "transcripts.gtf", options.assembled_isoforms_output_file ) |
0 | 235 if total_map_mass > -1: |
236 f = open( "global_model.txt", 'w' ) | |
237 f.write( "%f\n" % total_map_mass ) | |
238 f.close() | |
239 except Exception, e: | |
240 # Read stderr so that it can be reported: | |
241 tmp_stderr = open( tmp_name, 'rb' ) | |
242 stderr = '' | |
243 buffsize = 1048576 | |
244 try: | |
245 while True: | |
246 stderr += tmp_stderr.read( buffsize ) | |
247 if not stderr or len( stderr ) % buffsize != 0: | |
248 break | |
249 except OverflowError: | |
250 pass | |
251 tmp_stderr.close() | |
252 stop_err( 'Error running cufflinks.\n%s\n%s' % ( str( e ), stderr ) ) | |
253 | |
9
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
254 if __name__ == "__main__": |
a1ea9af8d5f4
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents:
8
diff
changeset
|
255 __main__() |