annotate gff3_rebase.py @ 16:b5c5470d7c09 draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit c306d242caf7e0447517c9749ca7656823f315e5
author iuc
date Wed, 13 Sep 2017 13:07:20 -0400
parents 18be2d72fdee
children ff11d442feed
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 argparse
3
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
3 import copy
8
ad4b9d7eae6a planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 9a243c616a4a3156347e38fdb5f35863ae5133f9
iuc
parents: 3
diff changeset
4 import logging
ad4b9d7eae6a planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 9a243c616a4a3156347e38fdb5f35863ae5133f9
iuc
parents: 3
diff changeset
5 import sys
ad4b9d7eae6a planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 9a243c616a4a3156347e38fdb5f35863ae5133f9
iuc
parents: 3
diff changeset
6
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
8
ad4b9d7eae6a planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 9a243c616a4a3156347e38fdb5f35863ae5133f9
iuc
parents: 3
diff changeset
9
ad4b9d7eae6a planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 9a243c616a4a3156347e38fdb5f35863ae5133f9
iuc
parents: 3
diff changeset
10 logging.basicConfig(level=logging.INFO)
1
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
11 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
12
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
13 __author__ = "Eric Rasche"
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
14 __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
15 __maintainer__ = "Eric Rasche"
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
16 __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
17
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
18
3
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
19 def feature_lambda(feature_list, test, test_kwargs, subfeatures=True):
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
20 """Recursively search through features, testing each with a test function, yielding matches.
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
21
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
22 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
23 search through features. E.g. if you're looking for a feature with
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
24 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
25 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
26
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
27 :type feature_list: list
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
28 :param feature_list: an iterable of features
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
29
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
30 :type test: function reference
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
31 :param test: a closure with the method signature (feature, **kwargs) where
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
32 the kwargs are those passed in the next argument. This
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
33 function should return True or False, True if the feature is
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
34 to be yielded as part of the main feature_lambda function, or
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
35 False if it is to be ignored. This function CAN mutate the
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
36 features passed to it (think "apply").
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
37
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
38 :type test_kwargs: dictionary
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
39 :param test_kwargs: kwargs to pass to your closure when it is called.
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
40
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
41 :type subfeatures: boolean
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
42 :param subfeatures: when a feature is matched, should just that feature be
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
43 yielded to the caller, or should the entire sub_feature
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
44 tree for that feature be included? subfeatures=True is
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
45 useful in cases such as searching for a gene feature,
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
46 and wanting to know what RBS/Shine_Dalgarno_sequences
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
47 are in the sub_feature tree (which can be accomplished
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
48 with two feature_lambda calls). subfeatures=False is
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
49 useful in cases when you want to process (and possibly
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
50 return) the entire feature tree, such as applying a
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
51 qualifier to every single feature.
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
52
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
53 :rtype: yielded list
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
54 :return: Yields a list of matching features.
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
55 """
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
56 # Either the top level set of [features] or the subfeature attribute
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
57 for feature in feature_list:
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
58 if test(feature, **test_kwargs):
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
59 if not subfeatures:
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
60 feature_copy = copy.deepcopy(feature)
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
61 feature_copy.sub_features = []
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
62 yield feature_copy
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
63 else:
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
64 yield feature
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
65
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
66 if hasattr(feature, 'sub_features'):
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
67 for x in feature_lambda(feature.sub_features, test, test_kwargs, subfeatures=subfeatures):
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
68 yield x
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
69
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
70
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
71 def feature_test_qual_value(feature, **kwargs):
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
72 """Test qualifier values.
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
73
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
74 For every feature, check that at least one value in
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
75 feature.quailfiers(kwargs['qualifier']) is in kwargs['attribute_list']
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
76 """
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
77 for attribute_value in feature.qualifiers.get(kwargs['qualifier'], []):
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
78 if attribute_value in kwargs['attribute_list']:
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
79 return True
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
80 return False
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
81
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
82
1
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
83 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
84 child_features = {}
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
85 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
86 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
87 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
88 if interpro:
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
89 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
90 continue
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
91 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
92 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
93
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
94 try:
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].append(feature)
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
96 except KeyError:
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
97 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
98 return child_features
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
99
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
100
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
101 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
102 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
103 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
104 if protein2dna:
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
105 start *= 3
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
106 end *= 3
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
107
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
108 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
109 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
110 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
111 st = +1
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
112 else:
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
113 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
114 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
115 st = -1
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
116
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
117 # 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
118 # 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
119 # issues.
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
120 #
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
121 # 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
122 # 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
123 if ns < 0:
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
124 ns %= 3
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
125 if ne < 0:
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
126 ne %= 3
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 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
129
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
130 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
131 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
132 __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
133
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
134
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
135 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
136 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
137
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
138 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
139 replacement_features = []
3
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
140 for feature in feature_lambda(
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
141 rec.features,
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
142 feature_test_qual_value,
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
143 {
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
144 'qualifier': 'ID',
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
145 'attribute_list': child_features.keys(),
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
146 },
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
147 subfeatures=False):
1
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
148
3
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
149 new_subfeatures = child_features[feature.id]
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
150 fixed_subfeatures = []
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
151 for x in new_subfeatures:
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
152 # Then update the location of the actual feature
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
153 __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
154
3
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
155 if interpro:
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
156 for y in ('status', 'Target'):
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
157 try:
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
158 del x.qualifiers[y]
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
159 except:
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
160 pass
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
161
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
162 fixed_subfeatures.append(x)
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
163 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
164 # 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
165 # 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
166 rec.features = replacement_features
3
7342f467507b Uploaded v0.4 of JBrowse
iuc
parents: 1
diff changeset
167 rec.annotations = {}
1
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
168 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
169
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
170
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
171 if __name__ == '__main__':
497c6bb3b717 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0887009a23d176b21536c9fd8a18c4fecc417d4f
iuc
parents:
diff changeset
172 parser = argparse.ArgumentParser(description='rebase gff3 features against parent locations', epilog="")
14
18be2d72fdee planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0bfb0de98c918860c21808e8832caad9f0535975
iuc
parents: 8
diff changeset
173 parser.add_argument('parent', type=argparse.FileType('r'), help='Parent GFF3 annotations')
18be2d72fdee planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/jbrowse commit 0bfb0de98c918860c21808e8832caad9f0535975
iuc
parents: 8
diff changeset
174 parser.add_argument('child', type=argparse.FileType('r'), help='Child GFF3 annotations to rebase against parent')
1
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('--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
176 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
177 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
178 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
179 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
180 rebase(**vars(args))