Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- from termcolor import colored
- def makeDNA(countAT, countCG):
- countA = int(countAT / 2)
- countT = int(countAT / 2)
- countC = int(countCG / 2)
- countG = int(countCG / 2)
- strA = ''.join(random.choice("A") for _ in range(countA))
- strT = ''.join(random.choice("T") for _ in range(countT))
- strC = ''.join(random.choice("C") for _ in range(countC))
- strG = ''.join(random.choice("G") for _ in range(countG))
- listDNA = list(strA + strT + strC + strG)
- random.shuffle(listDNA)
- DNA = ''.join(listDNA)
- return DNA
- def reverseDNA(strDNA):
- rDNA = ""
- for i in strDNA:
- if i == "A":
- rDNA = rDNA + "T"
- elif i == "T":
- rDNA = rDNA + "A"
- if i == "G":
- rDNA = rDNA + "C"
- elif i == "C":
- rDNA = rDNA + "G"
- return rDNA[::-1]
- def orf_it_up(strDNA, k):
- listORF = []
- listAmino = []
- start_codon = "ATG"
- stop_codons = ["TAA", "TAG", "TGA"]
- gencode = {
- 'ATA': 'I', 'ATC': 'I', 'ATT': 'I', 'ATG': 'M',
- 'ACA': 'T', 'ACC': 'T', 'ACG': 'T', 'ACT': 'T',
- 'AAC': 'N', 'AAT': 'N', 'AAA': 'K', 'AAG': 'K',
- 'AGC': 'S', 'AGT': 'S', 'AGA': 'R', 'AGG': 'R',
- 'CTA': 'L', 'CTC': 'L', 'CTG': 'L', 'CTT': 'L',
- 'CCA': 'P', 'CCC': 'P', 'CCG': 'P', 'CCT': 'P',
- 'CAC': 'H', 'CAT': 'H', 'CAA': 'Q', 'CAG': 'Q',
- 'CGA': 'R', 'CGC': 'R', 'CGG': 'R', 'CGT': 'R',
- 'GTA': 'V', 'GTC': 'V', 'GTG': 'V', 'GTT': 'V',
- 'GCA': 'A', 'GCC': 'A', 'GCG': 'A', 'GCT': 'A',
- 'GAC': 'D', 'GAT': 'D', 'GAA': 'E', 'GAG': 'E',
- 'GGA': 'G', 'GGC': 'G', 'GGG': 'G', 'GGT': 'G',
- 'TCA': 'S', 'TCC': 'S', 'TCG': 'S', 'TCT': 'S',
- 'TTC': 'F', 'TTT': 'F', 'TTA': 'L', 'TTG': 'L',
- 'TAC': 'Y', 'TAT': 'Y', 'TAA': '*', 'TAG': '*',
- 'TGC': 'C', 'TGT': 'C', 'TGA': '*', 'TGG': 'W'}
- position = 0
- orf = ""
- aas = ""
- while position < len(strDNA) - 2:
- current_codon = strDNA[position:position + 3]
- if current_codon == start_codon:
- while not (current_codon in stop_codons) and (current_codon in gencode):
- orf += current_codon
- aas += gencode[current_codon]
- position += 3
- current_codon = strDNA[position:position + 3]
- orf += current_codon
- if current_codon in stop_codons:
- aas += '*'
- if len(orf) >= 30 and len(orf) % 3 == 0:
- listORF.append(orf)
- listAmino.append(aas)
- orf = ""
- aas = ""
- position += 3
- if listORF:
- strDNA1 = strDNA
- maxL = max(listORF, key=len)
- print(maxL)
- print(strDNA1.rindex(maxL)+k, '-', strDNA1.index(maxL)+len(maxL)+k-1)
- print(max(listAmino, key=len))
- else:
- print(colored('Nothing', 'red'))
- if __name__ == '__main__':
- print("Enter length of DNA dnaSize=")
- dnaSize = int(input())
- print("Enter content percentage of CG percentCG= ")
- percentGC = int(input())
- percentAT = 100 - percentGC
- countGC = int((dnaSize * percentGC) / 100)
- countAT = int((dnaSize * percentAT) / 100)
- strDNA = makeDNA(countAT, countGC)
- print('DNA=', strDNA)
- rDNA = reverseDNA(strDNA)
- print('rDNA=', rDNA)
- phi_genome = strDNA
- phi_genome_plus1 = strDNA[1:]
- phi_genome_plus2 = strDNA[2:]
- phi_genome_reversed = rDNA # reversed string
- phi_genome_reversed_plus1 = rDNA[1:]
- phi_genome_reversed_plus2 = rDNA[2:]
- all_genomes = [phi_genome, phi_genome_plus1, phi_genome_plus2, phi_genome_reversed, phi_genome_reversed_plus1,
- phi_genome_reversed_plus2]
- print(colored('On direct stand', 'blue'))
- print(colored('On 1st frame', 'green'))
- orf_it_up(all_genomes[0], 1 )
- print(colored('On 2nd frame', 'green'))
- orf_it_up(all_genomes[1], 2)
- print(colored('On 3rd frame', 'green'))
- orf_it_up(all_genomes[2], 3)
- print(colored('On reverse stand', 'blue'))
- print(colored('On 1st frame', 'green'))
- orf_it_up(all_genomes[3], 1)
- print(colored('On 2nd frame', 'green'))
- orf_it_up(all_genomes[4], 2)
- print(colored('On 3rd frame', 'green'))
- orf_it_up(all_genomes[5], 3)
Add Comment
Please, Sign In to add comment