HuggyMonkey/Chat-To-Sequence
1
1class Sequence:2 def __init__(self, sequence):3 self.sequence = sequence.lower()4 5 def get_seq_length(self):6 return len(self.sequence)7 # Total length of sequence8 9 def get_unit_count(self, unit):10 unit = unit.lower()11 return self.sequence.count(unit)12 # Unit count of specified unit in sequence13 14 def get_unit_percentage(self, unit):15 total_units = self.get_seq_length()16 unit_count = self.get_unit_count(unit)17 unit_percentage = (unit_count / total_units) * 10018 return unit_percentage19 # unit percentage for specified unit in sequence20 21 def get_unit_at_position(self, position):22 pos = position - 123 24 if 0 <= pos < len(self.sequence):25 base_at_pos = self.sequence[pos]26 return base_at_pos27 else:28 return "Position is out of range. Positions should be 1 - {}".format(len(self.sequence))29 # Returns the unit at a specified position in the sequence30 31 def get_unit_at_positions(self, position_list):32 if self.check_positions(position_list):33 pos_dict = {i: self.sequence[i - 1] for i in position_list if 0 <= i < len(self.sequence)}34 return pos_dict35 else:36 return "Position is out of range.Positions should be 1 - {}".format(len(self.sequence))37 # Returns unit for each position in list38 39 def check_positions(self, position_list):40 # Check if the positions are within the range of the sequence length41 # Value = 0 -> position out of sequence range42 # Value = 1 -> position within sequence range43 44 checked = {}45 for pos in position_list:46 if pos <= 0 or pos > len(self.sequence):47 checked[pos] = 048 else:49 checked[pos] = 150 51 # Check if all values are equal to 1 / All positions in the list are within the range of the sequence length52 all_values_equal_to_1 = all(value == 1 for value in checked.values())53 54 if all_values_equal_to_1:55 valid = True56 else:57 valid = False58 59 return valid60 61 def get_subsequence(self, start_position, end_position):62 # Ensure the start and end positions are within the bounds of the sequence63 if start_position > 0 and end_position <= len(self.sequence):64 return self.sequence[start_position - 1:end_position]65 else:66 return "Position is out of range. Positions should be 1 - {}".format(len(self.sequence))67 # Returns the subsequence based on given positions68 69 def subsequence_total_units(self, start_position, end_position):70 return len(self.get_subsequence(start_position, end_position))71 # Returns the total number of units in the subsequence72 73 