@@ -170,8 +170,8 @@ def local_to_global_index(self, local_pair, base):
170
170
"""
171
171
Converts a pair of local indices (relative to the region of interest) to global indices
172
172
"""
173
- start = local_pair [0 ] + self .get_global_coords (base )[0 ] - 1
174
- end = self .get_global_coords (base )[0 ] + local_pair [1 ] - 1
173
+ start = local_pair [0 ] + self .get_local_coords (base )[0 ] - 1
174
+ end = self .get_local_coords (base )[0 ] + local_pair [1 ] - 1
175
175
global_pair = [start , end ]
176
176
return global_pair
177
177
@@ -511,12 +511,12 @@ def set_nucleotide_equivalents(query_reg, ref_regions):
511
511
nt_equiv = None
512
512
for ref_reg in ref_regions :
513
513
if ref_reg .region_name == query_reg .region_name and ref_reg .codon_aln is not None :
514
- if query_reg .nt_coords is not None :
514
+ if query_reg .global_ncoords is not None :
515
515
query_reg .make_codon_aln ()
516
516
regex = re .compile (query_reg .codon_aln )
517
517
coords = regex .search (ref_reg .codon_aln ).span ()
518
518
nt_equiv = ref_reg .nt_seq [coords [0 ]: coords [1 ]]
519
- query_reg .set_nt_seq ( nt_equiv )
519
+ query_reg .set_sequence ( 'nucl' , nt_equiv )
520
520
521
521
return nt_equiv
522
522
@@ -602,44 +602,43 @@ def output(query_regions, outfile=None):
602
602
.format (reg .rel_pos ['rstart' ][0 ], reg .rel_pos ['rstart' ][1 ]))
603
603
604
604
605
- def retrieve (virus , base , ref_regions , region , outfile = None , local_start = 1 , local_end = 'end' ):
605
+ def retrieve (virus , base , ref_regions , region , outfile = None , qstart = 1 , qend = 'end' ):
606
606
"""
607
607
Retrieves a sequence given its coordinates
608
608
:param virus: The organism (HIV or SIV)
609
609
:param base: The base of the sequence (nucleotide or protein)
610
610
:param ref_regions: A list of GenomeRegion objects
611
611
:param region: The genomic region
612
612
:param outfile: The file stream of the output file
613
- :param local_start : <option> The start coordinate of the query region (given as local coordinate)
614
- :param local_end : <option> The end coordinate of the query region (given as local coordinate)
613
+ :param qstart : <option> The start coordinate of the query region (given as local coordinate)
614
+ :param qend : <option> The end coordinate of the query region (given as local coordinate)
615
615
:return: The genomic region defined by the starting and ending coordinates
616
616
"""
617
617
618
618
query_region = None
619
619
for ref_region in ref_regions :
620
- sequence_range = ref_region .get_local_coords (base )
621
- region_start , region_end = sequence_range [0 ], sequence_range [1 ]
622
- length = region_end - region_start
623
-
624
- if local_end == 'end' :
625
- local_end = length
626
620
627
621
if ref_region .region_name == region :
622
+ sequence_range = ref_region .get_local_coords (base )
623
+ region_start , region_end = sequence_range [0 ], sequence_range [1 ]
624
+
625
+ if qend == 'end' :
626
+ qend = region_end - region_start
628
627
629
- if local_start != region_start or local_end > region_end :
628
+ if qstart < region_start or qend > region_end :
630
629
print ("Invalid {} coordinates: {} to {}.\n Valid range: {} to {}"
631
- .format (region , local_start , local_end , region_start , region_end ))
630
+ .format (region , qstart , qend , region_start , region_end ))
632
631
sys .exit (0 )
633
632
634
633
query_region = GenomeRegion (region )
635
634
636
635
# Set local and global coordinates
637
- query_region .set_local_coords ([local_start , local_end ], base )
638
- global_coords = query_region .local_to_global_index ([local_start , local_end ], base )
636
+ query_region .set_local_coords ([qstart , qend ], base )
637
+ global_coords = query_region .local_to_global_index ([qstart , qend ], base )
639
638
query_region .set_global_coords (global_coords , base )
640
639
641
640
# Set sequences protein and nucleotide sequences
642
- seq = ref_region .get_sequence (base )[local_start : local_end + 1 ]
641
+ seq = ref_region .get_sequence (base )[qstart : qend + 1 ]
643
642
query_region .set_sequence (seq , base )
644
643
645
644
# Set equivalent sequence
0 commit comments