annotate gff3_rebase.py @ 5:ae9382cfb6ac draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 3bbca939ca8a3298a3a2d6450abb04a96851e1ed
author iuc
date Sat, 25 Jun 2016 15:06:43 -0400
parents 7342f467507b
children ad4b9d7eae6a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
1 #!/usr/bin/env python
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
2 import sys
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
3 import logging
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
4 logging.basicConfig(level=logging.INFO)
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
5 import argparse
3
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
6 import copy
1
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
7 from BCBio import GFF
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
8 from Bio.SeqFeature import FeatureLocation
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
9 log = logging.getLogger(__name__)
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
10
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
11 __author__ = "Eric Rasche"
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
12 __version__ = "0.4.0"
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
13 __maintainer__ = "Eric Rasche"
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
14 __email__ = "esr@tamu.edu"
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
15
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
16
3
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
17 def feature_lambda(feature_list, test, test_kwargs, subfeatures=True):
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
18 """Recursively search through features, testing each with a test function, yielding matches.
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
19
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
20 GFF3 is a hierachical data structure, so we need to be able to recursively
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
21 search through features. E.g. if you're looking for a feature with
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
22 ID='bob.42', you can't just do a simple list comprehension with a test
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
23 case. You don't know how deeply burried bob.42 will be in the feature tree. This is where feature_lambda steps in.
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
24
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
25 :type feature_list: list
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
26 :param feature_list: an iterable of features
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
27
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
28 :type test: function reference
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
29 :param test: a closure with the method signature (feature, **kwargs) where
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
30 the kwargs are those passed in the next argument. This
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
31 function should return True or False, True if the feature is
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
32 to be yielded as part of the main feature_lambda function, or
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
33 False if it is to be ignored. This function CAN mutate the
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
34 features passed to it (think "apply").
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
35
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
36 :type test_kwargs: dictionary
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
37 :param test_kwargs: kwargs to pass to your closure when it is called.
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
38
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
39 :type subfeatures: boolean
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
40 :param subfeatures: when a feature is matched, should just that feature be
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
41 yielded to the caller, or should the entire sub_feature
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
42 tree for that feature be included? subfeatures=True is
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
43 useful in cases such as searching for a gene feature,
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
44 and wanting to know what RBS/Shine_Dalgarno_sequences
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
45 are in the sub_feature tree (which can be accomplished
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
46 with two feature_lambda calls). subfeatures=False is
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
47 useful in cases when you want to process (and possibly
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
48 return) the entire feature tree, such as applying a
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
49 qualifier to every single feature.
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
50
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
51 :rtype: yielded list
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
52 :return: Yields a list of matching features.
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
53 """
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
54 # Either the top level set of [features] or the subfeature attribute
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
55 for feature in feature_list:
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
56 if test(feature, **test_kwargs):
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
57 if not subfeatures:
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
58 feature_copy = copy.deepcopy(feature)
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
59 feature_copy.sub_features = []
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
60 yield feature_copy
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
61 else:
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
62 yield feature
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
63
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
64 if hasattr(feature, 'sub_features'):
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
65 for x in feature_lambda(feature.sub_features, test, test_kwargs, subfeatures=subfeatures):
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
66 yield x
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
67
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
68
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
69 def feature_test_qual_value(feature, **kwargs):
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
70 """Test qualifier values.
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
71
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
72 For every feature, check that at least one value in
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
73 feature.quailfiers(kwargs['qualifier']) is in kwargs['attribute_list']
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
74 """
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
75 for attribute_value in feature.qualifiers.get(kwargs['qualifier'], []):
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
76 if attribute_value in kwargs['attribute_list']:
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
77 return True
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
78 return False
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
79
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
80
1
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
81 def __get_features(child, interpro=False):
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
82 child_features = {}
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
83 for rec in GFF.parse(child):
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
84 for feature in rec.features:
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
85 parent_feature_id = rec.id
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
86 if interpro:
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
87 if feature.type == 'polypeptide':
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
88 continue
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
89 if '_' in parent_feature_id:
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
90 parent_feature_id = parent_feature_id[parent_feature_id.index('_') + 1:]
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
91
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
92 try:
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
93 child_features[parent_feature_id].append(feature)
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
94 except KeyError:
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
95 child_features[parent_feature_id] = [feature]
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
96 return child_features
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
97
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
98
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
99 def __update_feature_location(feature, parent, protein2dna):
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
100 start = feature.location.start
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
101 end = feature.location.end
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
102 if protein2dna:
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
103 start *= 3
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
104 end *= 3
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
105
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
106 if parent.location.strand >= 0:
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
107 ns = parent.location.start + start
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
108 ne = parent.location.start + end
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
109 st = +1
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
110 else:
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
111 ns = parent.location.end - end
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
112 ne = parent.location.end - start
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
113 st = -1
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
114
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
115 # Don't let start/stops be less than zero. It's technically valid for them
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
116 # to be (at least in the model I'm working with) but it causes numerous
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
117 # issues.
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
118 #
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
119 # Instead, we'll replace with %3 to try and keep it in the same reading
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
120 # frame that it should be in.
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
121 if ns < 0:
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
122 ns %= 3
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
123 if ne < 0:
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
124 ne %= 3
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
125
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
126 feature.location = FeatureLocation(ns, ne, strand=st)
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
127
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
128 if hasattr(feature, 'sub_features'):
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
129 for subfeature in feature.sub_features:
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
130 __update_feature_location(subfeature, parent, protein2dna)
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
131
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
132
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
133 def rebase(parent, child, interpro=False, protein2dna=False):
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
134 child_features = __get_features(child, interpro=interpro)
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
135
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
136 for rec in GFF.parse(parent):
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
137 replacement_features = []
3
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
138 for feature in feature_lambda(
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
139 rec.features,
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
140 feature_test_qual_value,
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
141 {
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
142 'qualifier': 'ID',
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
143 'attribute_list': child_features.keys(),
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
144 },
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
145 subfeatures=False):
1
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
146
3
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
147 new_subfeatures = child_features[feature.id]
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
148 fixed_subfeatures = []
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
149 for x in new_subfeatures:
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
150 # Then update the location of the actual feature
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
151 __update_feature_location(x, feature, protein2dna)
1
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
152
3
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
153 if interpro:
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
154 for y in ('status', 'Target'):
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
155 try:
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
156 del x.qualifiers[y]
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
157 except:
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
158 pass
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
159
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
160 fixed_subfeatures.append(x)
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
161 replacement_features.extend(fixed_subfeatures)
1
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
162 # We do this so we don't include the original set of features that we
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
163 # were rebasing against in our result.
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
164 rec.features = replacement_features
3
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
165 rec.annotations = {}
1
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
166 GFF.write([rec], sys.stdout)
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
167
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
168
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
169 if __name__ == '__main__':
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
170 parser = argparse.ArgumentParser(description='rebase gff3 features against parent locations', epilog="")
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
171 parser.add_argument('parent', type=file, help='Parent GFF3 annotations')
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
172 parser.add_argument('child', help='Child GFF3 annotations to rebase against parent')
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
173 parser.add_argument('--interpro', action='store_true',
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
174 help='Interpro specific modifications')
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
175 parser.add_argument('--protein2dna', action='store_true',
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
176 help='Map protein translated results to original DNA data')
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
177 args = parser.parse_args()
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
178 rebase(**vars(args))