def find_min_vdel(v_nt, cdr3_aa): # find the minimum number of V nucleotides need to be deleted to # result in the CDR3aa v_aa = lcommon.nt2aa(v_nt) matchseq = left_max_match(v_aa, cdr3_aa) # max matched aa seq len_ntmatch = len(matchseq) * 3 min_vdel = len(v_nt) - len_ntmatch # see if 1 or 2 of the next v nts can result in the next cdr3 aa if min_vdel > 0 and len(cdr3_aa) > len(matchseq): if min_vdel >= 2: v_nts = v_nt[len_ntmatch: len_ntmatch + 2] else: v_nts = v_nt[len_ntmatch] got2nts = False firstaa = cdr3_aa[len(matchseq)] codons = lcommon.aa2codons(firstaa) for codon in codons: if re.match(v_nts, codon): min_vdel -= len(v_nts) got2nts = True break if len(v_nts) == 2 and not got2nts: for codon in codons: if re.match(v_nts[0], codon): min_vdel -= 1 break return min_vdel
def find_min_jdel(j_nt, cdr3_aa): # find the minimum number of J nucleotides need to be deleted to # result in the CDR3aa hang_j = len(j_nt) % 3 hang_j_nts = j_nt[: hang_j] # the 5' of j nt seq that not part of a codon j_aa = lcommon.nt2aa(j_nt[hang_j:]) matchseq = right_max_match(j_aa, cdr3_aa) len_ntmatch = len(matchseq) * 3 min_jdel = len(j_nt) - len_ntmatch if min_jdel > 0 and len(cdr3_aa) > len(matchseq): if min_jdel >= 2: j_nts = j_nt[min_jdel - 2: min_jdel] else: j_nts = j_nt[min_jdel - 1] got2nts = False firstaa = cdr3_aa[len(cdr3_aa) - len(matchseq) - 1] codons = lcommon.aa2codons(firstaa) for codon in codons: if codon[-1 * len(j_nts): ] == j_nts: min_jdel -= len(j_nts) got2nts = True break if len(j_nts) == 2 and not got2nts: for codon in codons: if codon[2] == j_nts[1]: min_jdel -= 1 break return min_jdel
def get_all_codons(aaseq): codon_lists = [] for aa in aaseq: codon_lists.append(lcommon.aa2codons(aa)) return codon_lists