@@ -1038,45 +1038,37 @@ def _flip(self, length):
1038
1038
strand = flip_strand ,
1039
1039
)
1040
1040
1041
+ """ Returns a shifted position given position, shift and N, where
1042
+ position is the given position, shift is the amount and N is the length of the sequence
1043
+ """
1041
1044
def _shift_position (self , position , shift , N ):
1042
- #Caso ExactPosition
1043
1045
if type (position )== ExactPosition :
1044
1046
position_new = (int (position ) + shift ) % N
1045
1047
return ExactPosition (position_new )
1046
1048
if type (position )== UncertainPosition :
1047
1049
position_new = (int (position ) + shift ) % N
1048
1050
return UncertainPosition (position_new )
1049
- #Caso UnknownPosition
1050
1051
if type (position )== UnknownPosition :
1051
1052
return position
1052
- #Caso WithinPosition
1053
1053
if type (position )== WithinPosition :
1054
1054
position_curr_default = int (position )
1055
- #Ricava il valore di left right usando la rappresentazione in stringa
1056
- #Elimina le parentesi e converte i valori separati da punto in interi
1055
+ #Get left and right values by using string representation
1056
+ #Delete parenthesis and converts values separated by dot into integers
1057
1057
position_curr_left_right = list (map (int , str (position )[1 :- 1 ].split ('.' )))
1058
-
1059
1058
position_new_default = (position_curr_default + shift ) % N
1060
1059
position_new_left = (position_curr_left_right [0 ] + shift ) % N
1061
1060
position_new_right = (position_curr_left_right [1 ] + shift ) % N
1062
-
1063
1061
return WithinPosition (position_new_default , position_new_left , position_new_right )
1064
- #Caso BeforePosition
1065
1062
if type (position )== BeforePosition :
1066
1063
position_new = (int (position ) + shift ) % N
1067
1064
return BeforePosition (position_new )
1068
- #Caso AfterPosition
1069
1065
if type (position )== AfterPosition :
1070
1066
position_new = (int (position ) + shift ) % N
1071
1067
return AfterPosition (position_new )
1072
- #Caso OneOfPosition
1073
1068
if type (position )== OneOfPosition :
1074
1069
position_curr_default = int (position )
1075
- #Ricava il valore di left right usando la rappresentazione in stringa
1076
- #Elimina le parentesi e converte i valori separati da virgola in interi
1077
1070
position_new_default = (position_curr_default + shift ) % N
1078
1071
new_choices = [self ._shift_position (pos , shift , N ) for pos in position .position_choices ]
1079
- #Riordino le posizioni in base alla posizione
1080
1072
new_choices .sort ()
1081
1073
return OneOfPosition (position_new_default , new_choices )
1082
1074
@@ -1138,25 +1130,23 @@ def nofuzzy_end(self):
1138
1130
return None
1139
1131
raise
1140
1132
1133
+ """Returns a rotated location given shift and N, where shift is the amount and N is the length of the sequence.
1134
+ Special case 1: if the shift is large enough the feature could be broken in two separated regions, so it becomes a
1135
+ CompoundLocation including the two regions.
1136
+ Special case 2: if the feature length is N, it doesn't get broken in two regions since they would be contigous.
1137
+ """
1141
1138
def rotate (self , shift , N ):
1142
1139
position_start = self ._shift_position (self ._start , shift , N )
1143
1140
position_end = self ._shift_position (self ._end , shift , N )
1144
1141
if (position_start > position_end ):
1145
1142
#Get middle location
1146
- position_middle_1 = self ._shift_position (self ._start , - self ._start , N ) #conserva il tipo di location
1143
+ position_middle_1 = self ._shift_position (self ._start , - self ._start , N ) #To preserve the type of position
1147
1144
position_middle_2 = self ._shift_position (position_end , N - int (position_end )- 1 , N )
1148
1145
f1 = FeatureLocation (position_start , position_middle_2 , self .strand , ref = self .ref , ref_db = self .ref_db )
1149
- f2 = FeatureLocation (position_middle_1 , position_end , self .strand , ref = self .ref , ref_db = self .ref_db )
1150
-
1151
- #location1 - location2 attaccate
1152
- #if f2.start - 1 == f1.end:
1153
- # return FeatureLocation(f1.start,f2.end, self.strand, ref=self.ref, ref_db=self.ref_db)
1154
-
1155
- #location2 - location1 attaccate
1146
+ f2 = FeatureLocation (position_middle_1 , position_end , self .strand , ref = self .ref , ref_db = self .ref_db )
1156
1147
if f1 .start - 1 == f2 .end :
1157
- return FeatureLocation (f2 .start ,f1 .end , self .strand , ref = self .ref , ref_db = self .ref_db )
1158
-
1159
- return CompoundLocation ([f2 , f1 ])
1148
+ return FeatureLocation (f2 .start ,f1 .end , self .strand , ref = self .ref , ref_db = self .ref_db ) #Special case 2
1149
+ return CompoundLocation ([f2 , f1 ]) #Special case 1
1160
1150
else :
1161
1151
return FeatureLocation (position_start , position_end , self .strand , ref = self .ref , ref_db = self .ref_db )
1162
1152
@@ -1578,6 +1568,10 @@ def ref_db(self):
1578
1568
"""Not present in CompoundLocation, dummy method for API compatibility."""
1579
1569
return None
1580
1570
1571
+ """Returns a rotated location given shift and N, where shift is the amount and N is the length of the sequence.
1572
+ Special Case: if the shift is large enough, separated regions could become contiguos, so must be joined into a single one.
1573
+ If all regions become contigous it returns a FeatureLocation.
1574
+ """
1581
1575
def rotate (self , shift , N ):
1582
1576
locations_tmp = [location .rotate (shift , N ).parts for location in self .parts ]
1583
1577
locations = []
@@ -1588,25 +1582,22 @@ def rotate(self, shift, N):
1588
1582
for location1 in locations :
1589
1583
for location2 in locations :
1590
1584
if location1 is not location2 :
1591
- #location1 - location2 attaccate
1585
+ #location1 - location2, in order
1592
1586
if location2 .start - 1 == location1 .end :
1593
1587
tmp_feature = FeatureLocation (location1 .start ,location2 .end ,location1 .strand , ref = location1 .ref , ref_db = location1 .ref_db )
1594
1588
if tmp_feature not in to_append :
1595
1589
to_append .append (tmp_feature )
1596
1590
to_delete .append (location1 )
1597
1591
to_delete .append (location2 )
1598
-
1599
- #location2 - location1 attaccate
1592
+ #location2 - location1, in order
1600
1593
if location1 .start - 1 == location2 .end :
1601
1594
tmp_feature = FeatureLocation (location2 .start ,location1 .end ,location2 .strand , ref = location1 .ref , ref_db = location1 .ref_db )
1602
1595
if tmp_feature not in to_append :
1603
1596
to_append .append (tmp_feature )
1604
1597
to_delete .append (location1 )
1605
1598
to_delete .append (location2 )
1606
-
1607
- locations = list (filter (lambda a : a not in to_delete , locations )) + to_append
1608
-
1609
- if len (locations ) == 1 : #tutte le feature della compound sono state contratte
1599
+ locations = list (filter (lambda a : a not in to_delete , locations )) + to_append #Updated locations
1600
+ if len (locations ) == 1 : #Special case
1610
1601
return locations [0 ]
1611
1602
else :
1612
1603
locations .sort (key = lambda loc : loc .start )
0 commit comments