Mercurial > repos > devteam > cufflinks
annotate mass.py @ 12:d080005cffe1 draft
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
author | iuc |
---|---|
date | Tue, 16 Jun 2020 13:00:32 -0400 |
parents | |
children |
rev | line source |
---|---|
12
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
1 import shutil |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
2 import sys |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
3 import tempfile |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
4 |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
5 |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
6 def parse_gff_attributes(attr_str): |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
7 """ |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
8 Parses a GFF/GTF attribute string and returns a dictionary of name-value |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
9 pairs. The general format for a GFF3 attributes string is |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
10 |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
11 name1=value1;name2=value2 |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
12 |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
13 The general format for a GTF attribute string is |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
14 |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
15 name1 "value1" ; name2 "value2" |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
16 |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
17 The general format for a GFF attribute string is a single string that |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
18 denotes the interval's group; in this case, method returns a dictionary |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
19 with a single key-value pair, and key name is 'group' |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
20 """ |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
21 attributes_list = attr_str.split(";") |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
22 attributes = {} |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
23 for name_value_pair in attributes_list: |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
24 # Try splitting by '=' (GFF3) first because spaces are allowed in GFF3 |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
25 # attribute; next, try double quotes for GTF. |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
26 pair = name_value_pair.strip().split("=") |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
27 if len(pair) == 1: |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
28 pair = name_value_pair.strip().split("\"") |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
29 if len(pair) == 1: |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
30 # Could not split for some reason -- raise exception? |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
31 continue |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
32 if pair == '': |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
33 continue |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
34 name = pair[0].strip() |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
35 if name == '': |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
36 continue |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
37 # Need to strip double quote from values |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
38 value = pair[1].strip(" \"") |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
39 attributes[name] = value |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
40 |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
41 if len(attributes) == 0: |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
42 # Could not split attributes string, so entire string must be |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
43 # 'group' attribute. This is the case for strictly GFF files. |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
44 attributes['group'] = attr_str |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
45 return attributes |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
46 |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
47 |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
48 def gff_attributes_to_str(attrs, gff_format): |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
49 """ |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
50 Convert GFF attributes to string. Supported formats are GFF3, GTF. |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
51 """ |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
52 if gff_format == 'GTF': |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
53 format_string = '%s "%s"' |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
54 # Convert group (GFF) and ID, parent (GFF3) attributes to transcript_id, gene_id |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
55 id_attr = None |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
56 if 'group' in attrs: |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
57 id_attr = 'group' |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
58 elif 'ID' in attrs: |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
59 id_attr = 'ID' |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
60 elif 'Parent' in attrs: |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
61 id_attr = 'Parent' |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
62 if id_attr: |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
63 attrs['transcript_id'] = attrs['gene_id'] = attrs[id_attr] |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
64 elif gff_format == 'GFF3': |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
65 format_string = '%s=%s' |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
66 attrs_strs = [] |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
67 for name, value in attrs.items(): |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
68 attrs_strs.append(format_string % (name, value)) |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
69 return " ; ".join(attrs_strs) |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
70 |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
71 |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
72 stderr = sys.argv[1] |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
73 global_model_file_name = sys.argv[2] |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
74 transcripts = sys.argv[3] |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
75 |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
76 # Read standard error to get total map/upper quartile mass. |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
77 total_map_mass = -1 |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
78 with open(stderr, 'r') as tmp_stderr2: |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
79 for line in tmp_stderr2: |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
80 if line.lower().find("map mass") >= 0 or line.lower().find("upper quartile") >= 0: |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
81 total_map_mass = float(line.split(":")[1].strip()) |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
82 break |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
83 |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
84 if global_model_file_name != "None": |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
85 # Global model is simply total map mass from original run. |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
86 with open(global_model_file_name, 'r') as global_model_file: |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
87 global_model_total_map_mass = float(global_model_file.readline()) |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
88 |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
89 # Ratio of global model's total map mass to original run's map mass is |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
90 # factor used to adjust FPKM. |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
91 fpkm_map_mass_ratio = total_map_mass / global_model_total_map_mass |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
92 |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
93 # Update FPKM values in transcripts.gtf file. |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
94 with open(transcripts, 'r') as transcripts_file: |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
95 with tempfile.NamedTemporaryFile(dir=".", delete=False) as new_transcripts_file: |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
96 for line in transcripts_file: |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
97 fields = line.split('\t') |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
98 attrs = parse_gff_attributes(fields[8]) |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
99 attrs["FPKM"] = str(float(attrs["FPKM"]) * fpkm_map_mass_ratio) |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
100 attrs["conf_lo"] = str(float(attrs["conf_lo"]) * fpkm_map_mass_ratio) |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
101 attrs["conf_hi"] = str(float(attrs["conf_hi"]) * fpkm_map_mass_ratio) |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
102 fields[8] = gff_attributes_to_str(attrs, "GTF") |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
103 new_transcripts_file.write("%s\n" % '\t'.join(fields)) |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
104 shutil.move(new_transcripts_file.name, transcripts) |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
105 |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
106 if total_map_mass > -1: |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
107 with open("global_model.txt", 'w') as f: |
d080005cffe1
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff
changeset
|
108 f.write("%f\n" % total_map_mass) |