comparison cufflinks_wrapper.py @ 11:e04dbae2abe0 draft

planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/cufflinks/cufflinks commit 82ee6fc860c52c531b7a57bbb346ab1a67a434a5
author devteam
date Sun, 19 Feb 2017 12:12:28 -0500
parents 83bec71c5c9f
children
comparison
equal deleted inserted replaced
10:83bec71c5c9f 11:e04dbae2abe0
5 import shutil 5 import shutil
6 import subprocess 6 import subprocess
7 import sys 7 import sys
8 import tempfile 8 import tempfile
9 9
10 from galaxy.datatypes.util.gff_util import gff_attributes_to_str, parse_gff_attributes 10
11 def parse_gff_attributes( attr_str ):
12 """
13 Parses a GFF/GTF attribute string and returns a dictionary of name-value
14 pairs. The general format for a GFF3 attributes string is
15
16 name1=value1;name2=value2
17
18 The general format for a GTF attribute string is
19
20 name1 "value1" ; name2 "value2"
21
22 The general format for a GFF attribute string is a single string that
23 denotes the interval's group; in this case, method returns a dictionary
24 with a single key-value pair, and key name is 'group'
25 """
26 attributes_list = attr_str.split(";")
27 attributes = {}
28 for name_value_pair in attributes_list:
29 # Try splitting by '=' (GFF3) first because spaces are allowed in GFF3
30 # attribute; next, try double quotes for GTF.
31 pair = name_value_pair.strip().split("=")
32 if len( pair ) == 1:
33 pair = name_value_pair.strip().split("\"")
34 if len( pair ) == 1:
35 # Could not split for some reason -- raise exception?
36 continue
37 if pair == '':
38 continue
39 name = pair[0].strip()
40 if name == '':
41 continue
42 # Need to strip double quote from values
43 value = pair[1].strip(" \"")
44 attributes[ name ] = value
45
46 if len( attributes ) == 0:
47 # Could not split attributes string, so entire string must be
48 # 'group' attribute. This is the case for strictly GFF files.
49 attributes['group'] = attr_str
50 return attributes
51
52
53 def gff_attributes_to_str( attrs, gff_format ):
54 """
55 Convert GFF attributes to string. Supported formats are GFF3, GTF.
56 """
57 if gff_format == 'GTF':
58 format_string = '%s "%s"'
59 # Convert group (GFF) and ID, parent (GFF3) attributes to transcript_id, gene_id
60 id_attr = None
61 if 'group' in attrs:
62 id_attr = 'group'
63 elif 'ID' in attrs:
64 id_attr = 'ID'
65 elif 'Parent' in attrs:
66 id_attr = 'Parent'
67 if id_attr:
68 attrs['transcript_id'] = attrs['gene_id'] = attrs[id_attr]
69 elif gff_format == 'GFF3':
70 format_string = '%s=%s'
71 attrs_strs = []
72 for name, value in attrs.items():
73 attrs_strs.append( format_string % ( name, value ) )
74 return " ; ".join( attrs_strs )
11 75
12 76
13 def stop_err(msg): 77 def stop_err(msg):
14 sys.exit("%s\n" % msg) 78 sys.exit("%s\n" % msg)
15 79
67 131
68 # Global model (for trackster). 132 # Global model (for trackster).
69 parser.add_option('', '--global_model', dest='global_model_file', help='Global model used for computing on local data') 133 parser.add_option('', '--global_model', dest='global_model_file', help='Global model used for computing on local data')
70 134
71 (options, args) = parser.parse_args() 135 (options, args) = parser.parse_args()
72
73 # output version # of tool
74 try:
75 with tempfile.NamedTemporaryFile() as tmp_stdout:
76 returncode = subprocess.call(args='cufflinks --no-update-check 2>&1', stdout=tmp_stdout, shell=True)
77 stdout = None
78 with open(tmp_stdout.name) as tmp_stdout2:
79 for line in tmp_stdout2:
80 if line.lower().find('cufflinks v') >= 0:
81 stdout = line.strip()
82 break
83 if stdout:
84 sys.stdout.write('%s\n' % stdout)
85 else:
86 raise Exception
87 except:
88 sys.stdout.write('Could not determine Cufflinks version\n')
89 136
90 # If doing bias correction, set/link to sequence file. 137 # If doing bias correction, set/link to sequence file.
91 if options.do_bias_correction: 138 if options.do_bias_correction:
92 if options.ref_file: 139 if options.ref_file:
93 # Sequence data from history. 140 # Sequence data from history.