def insertion(n1, n2, i): if i == 0: return linked_code.concatenate(n2, n1) elif n1 is None or i < 0: raise IndexError("index out of bounds in insertion") else: return LinkNode(n1.value, insertion(n1.rest, n2, i - 1))
def insertion(dna_seq1, dna_seq2, index): """ This function takes the input of 2 DNA sequences and an index and insert the second DNA sequence in the first sequence at the specified index """ if index == 0: return linked_code.concatenate(dna_seq2, dna_seq1) elif dna_seq1 == None: raise IndexError("Invalid Insertion Index") else: return (Node(dna_seq1.value, insertion(dna_seq1.rest, dna_seq2, index - 1)))
def insertion(DNA_1, DNA_2, idx): """ Insert dna sequence 2 at specific index of dna sequence 1 :param DNA_1: dna sequence 1 :param DNA_2: dna sequence 2 :param idx: index where dna sequence 2 is being inserted at :return: new linked node with dna sequence 2 being inserted at specific index of dna sequence 1 """ if idx == 0: return concatenate(DNA_2, DNA_1) elif DNA_1 is None: raise IndexError("Out of Bounds") else: return LinkNode(DNA_1.value, insertion(DNA_1.rest, DNA_2, idx - 1))
def substitution(dna_seq, idx, base): """ Takes a DNA sequence and substitutes a new base in at a certain index. :param dna_seq: The sequence in which the substitution mutation occurs. :param idx: Index where the substitution occurs. :param base: The new base to be substituted at a specific index. :return: A new linked sequence that represents the DNA strand after the substitution mutation has occurred. """ if dna_seq is None or idx < 0: raise IndexError("index out of bounds in substitution") elif idx == 0: return lc.concatenate(LinkNode(base, None), dna_seq.rest) else: return LinkNode(dna_seq.value, substitution(dna_seq.rest, idx - 1, base))
def substitution(dna_seq1, idx, base): """ :param dna_seq1: :param idx: :param base: :return: """ if dna_seq1 is None or idx < 0: raise IndexError("index out of bounds in substitution") elif idx == 0: x = LinkNode(base, None) return linked_code.concatenate(x, dna_seq1.rest) else: return LinkNode(dna_seq1.value, substitution(dna_seq1.rest, idx - 1, base))
def insertion(dna_seq1, dna_seq2, idx): """ Inserts a new sequence at a given index of an original sequence. :param dna_seq1: The first sequence into which the second sequence is inserted. :param dna_seq2: The second sequence, which is inserted into the first. :param idx: The index before which the insertion occurs. :return: A new linked sequence that represents the resulting DNA strand after dna_seq2 has been inserted in its entirety just before idx in dna_seq1. """ if idx == 0: return lc.concatenate(dna_seq2, dna_seq1) elif dna_seq1 is None: raise IndexError("Error: Index out of range.") elif idx < 0: raise IndexError("Error: Index out of range.") else: return LinkNode(dna_seq1.value, insertion(dna_seq1.rest, dna_seq2, idx - 1))
def insertion(dna_seq1, dna_seq2, idx): """ This function inserts a linked list into another linked list at a chosen index. Pre: takes three parameters, idx must be integer, dna_seq1 and dna_seq2 must be linked lists. :param dna_seq1: a linked list :param dna_seq2: a link list that will be inserted into dna_seq1 :param idx: the index of dna_seq1 where dna_seq2 will be inserted :return: """ if idx == 0: return linked_code.concatenate(dna_seq2, dna_seq1) if dna_seq1 == None: raise IndexError('Invalid insertion error') if dna_seq2 == None: return dna_seq1 else: return LinkNode(dna_seq1.value, insertion(dna_seq1.rest, dna_seq2, idx - 1))
def duplication(dna_seq, idx, segment_size): """ This function duplicates a segemnt of length segment_size at a chosen index in a linked list. Pre: dna_seq must be a valid linked list, idx must be an integer, and segment_size should be an integer. Post: a linked list with duplicated segment in place is returned :param dna_seq: linked list :param idx: index at which duplicated segment begins :param segment_size: length of duplicated segment :return: a linked list with correctly duplicated segment in place """ if segment_size == 0: return dna_seq elif linked_code.length_rec(dna_seq) < idx + segment_size: raise IndexError('Index out of range') else: if idx > 0: return LinkNode(dna_seq.value, duplication(dna_seq.rest, idx - 1, segment_size)) if idx == 0: dna_seq2 = find_values_sequence(dna_seq, segment_size) dna_seq3 = linked_code.concatenate(dna_seq2, dna_seq) return dna_seq3
def insertion(list1, list2, idx): if idx > 0: return insertion(list1.rest, list2, idx - 1) elif idx == 0: return linked_code.concatenate(list2, list1)