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