# HG changeset patch # User cpt # Date 1723437620 0 # Node ID 00aab5199327085ddc6d64a8757d422dfce6b7ab # Parent 3e3b5ba626b9f91908a65503bc79cbeb25f1a518 planemo upload commit 6b68423e1d9bbced95ecfb92e26329a7e8d7df47 diff -r 3e3b5ba626b9 -r 00aab5199327 intersect_and_adjacent.py --- a/intersect_and_adjacent.py Mon Aug 12 04:33:20 2024 +0000 +++ b/intersect_and_adjacent.py Mon Aug 12 04:40:20 2024 +0000 @@ -130,8 +130,8 @@ rec_a_map = {f.id: f for f in rec_a_i.features} rec_b_map = {f.id: f for f in rec_b_i.features} - rec_a_hits_in_b = [] - rec_b_hits_in_a = [] + rec_a_hits_in_b = {} + rec_b_hits_in_a = {} for feature in rec_a_i.features: if feature.type == "remark" or feature.type == "annotation": @@ -142,7 +142,7 @@ int(feature.location.start) : int(feature.location.end) ] for hit in hits: - rec_a_hits_in_b.append(rec_b_map[hit.data]) + rec_a_hits_in_b[hit.data] = rec_b_map[hit.data] else: if feature.strand > 0: hits = tree_b_pos[ @@ -153,7 +153,7 @@ int(feature.location.start) : int(feature.location.end) ] for hit in hits: - rec_a_hits_in_b.append(rec_b_map[hit.data]) + rec_a_hits_in_b[hit.data] = rec_b_map[hit.data] for feature in rec_b_i.features: if feature.type == "remark" or feature.type == "annotation": @@ -164,7 +164,7 @@ int(feature.location.start) : int(feature.location.end) ] for hit in hits: - rec_b_hits_in_a.append(rec_a_map[hit.data]) + rec_b_hits_in_a[hit.data] = rec_a_map[hit.data] else: if feature.strand > 0: hits = tree_a_pos[ @@ -175,9 +175,9 @@ int(feature.location.start) : int(feature.location.end) ] for hit in hits: - rec_b_hits_in_a.append(rec_a_map[hit.data]) + rec_b_hits_in_a[hit.data] = rec_a_map[hit.data] - # Remove duplicate features using sets + # Sort features by start position rec_a_out.append( SeqRecord( rec_a[iterate].seq, @@ -185,7 +185,9 @@ rec_a[iterate].name, rec_a[iterate].description, rec_a[iterate].dbxrefs, - sorted(set(rec_a_hits_in_b), key=lambda feat: feat.location.start), + sorted( + rec_a_hits_in_b.values(), key=lambda feat: feat.location.start + ), rec_a[iterate].annotations, ) ) @@ -196,7 +198,9 @@ rec_b[iterate].name, rec_b[iterate].description, rec_b[iterate].dbxrefs, - sorted(set(rec_b_hits_in_a), key=lambda feat: feat.location.start), + sorted( + rec_b_hits_in_a.values(), key=lambda feat: feat.location.start + ), rec_b[iterate].annotations, ) )