annotate mass.py @ 5:d83617f0305c draft default tip

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit 80b06e80066b32ad53ed418628992f056444256f
author iuc
date Sat, 05 Oct 2024 11:14:56 +0000
parents f842d03b75c2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
f842d03b75c2 "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
f842d03b75c2 "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
f842d03b75c2 "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
f842d03b75c2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff changeset
4
f842d03b75c2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff changeset
5
f842d03b75c2 "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):
f842d03b75c2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff changeset
7 """
f842d03b75c2 "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
f842d03b75c2 "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
f842d03b75c2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff changeset
10
f842d03b75c2 "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
f842d03b75c2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff changeset
12
f842d03b75c2 "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
f842d03b75c2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff changeset
14
f842d03b75c2 "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"
f842d03b75c2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff changeset
16
f842d03b75c2 "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
f842d03b75c2 "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
f842d03b75c2 "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'
f842d03b75c2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff changeset
20 """
f842d03b75c2 "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(";")
f842d03b75c2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff changeset
22 attributes = {}
f842d03b75c2 "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:
f842d03b75c2 "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
f842d03b75c2 "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.
f842d03b75c2 "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("=")
f842d03b75c2 "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:
f842d03b75c2 "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("\"")
f842d03b75c2 "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:
f842d03b75c2 "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?
f842d03b75c2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff changeset
31 continue
f842d03b75c2 "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 == '':
f842d03b75c2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff changeset
33 continue
f842d03b75c2 "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()
f842d03b75c2 "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 == '':
f842d03b75c2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff changeset
36 continue
f842d03b75c2 "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
f842d03b75c2 "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(" \"")
f842d03b75c2 "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
f842d03b75c2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff changeset
40
f842d03b75c2 "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:
f842d03b75c2 "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
f842d03b75c2 "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.
f842d03b75c2 "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
f842d03b75c2 "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
f842d03b75c2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff changeset
46
f842d03b75c2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff changeset
47
f842d03b75c2 "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):
f842d03b75c2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff changeset
49 """
f842d03b75c2 "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.
f842d03b75c2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff changeset
51 """
f842d03b75c2 "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':
f842d03b75c2 "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"'
f842d03b75c2 "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
f842d03b75c2 "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
f842d03b75c2 "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:
f842d03b75c2 "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'
f842d03b75c2 "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:
f842d03b75c2 "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'
f842d03b75c2 "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:
f842d03b75c2 "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'
f842d03b75c2 "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:
f842d03b75c2 "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]
f842d03b75c2 "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':
f842d03b75c2 "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'
f842d03b75c2 "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 = []
f842d03b75c2 "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():
f842d03b75c2 "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))
f842d03b75c2 "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)
f842d03b75c2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff changeset
70
f842d03b75c2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff changeset
71
f842d03b75c2 "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]
f842d03b75c2 "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]
f842d03b75c2 "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]
f842d03b75c2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff changeset
75
f842d03b75c2 "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.
f842d03b75c2 "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
f842d03b75c2 "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:
f842d03b75c2 "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:
f842d03b75c2 "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:
f842d03b75c2 "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())
f842d03b75c2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff changeset
82 break
f842d03b75c2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff changeset
83
f842d03b75c2 "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":
f842d03b75c2 "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.
f842d03b75c2 "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:
f842d03b75c2 "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())
f842d03b75c2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff changeset
88
f842d03b75c2 "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
f842d03b75c2 "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.
f842d03b75c2 "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
f842d03b75c2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff changeset
92
f842d03b75c2 "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.
f842d03b75c2 "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:
f842d03b75c2 "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:
f842d03b75c2 "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:
f842d03b75c2 "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')
f842d03b75c2 "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])
f842d03b75c2 "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)
f842d03b75c2 "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)
f842d03b75c2 "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)
f842d03b75c2 "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")
f842d03b75c2 "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))
f842d03b75c2 "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)
f842d03b75c2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tool_collections/cufflinks/cufflinks commit a0b0845a9d1b3e7ecdeacd1e606133617e3918bd"
iuc
parents:
diff changeset
105
f842d03b75c2 "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:
f842d03b75c2 "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:
f842d03b75c2 "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)