Commit 8a4be0e3 authored by rebelCoder's avatar rebelCoder
Browse files

Lesson 2: Transcription, Reverse Complement, Coloring, Dock Strings

parent 5eba0ed7
# DNA Toolkit file
import collections
Nucleotides = ["A", "C", "G", "T"]
from structures import *
# Check the sequence to make sure it is a DNA String
......@@ -19,3 +18,13 @@ def countNucFrequency(seq):
tmpFreqDict[nuc] += 1
return tmpFreqDict
# return dict(collections.Counter(seq))
def transcription(seq):
"""DNA -> RNA Transcription. Replacing Thymine with Uracil"""
return seq.replace("T", "U")
def reverse_complement(seq):
"""Swapping adenine with thymine and guanine with cytosine. Reversing newly generated string"""
return ''.join([DNA_ReverseComplement[nuc] for nuc in seq])[::-1]
# DNA Toolset/Code testing file
from DNAToolkit import *
from utilities import colored
import random
# Creating a random DNA sequence for testing:
......@@ -7,4 +8,13 @@ randDNAStr = ''.join([random.choice(Nucleotides)
for nuc in range(50)])
DNAStr = validateSeq(randDNAStr)
print(f'\nSequence: {colored(DNAStr)}\n')
print(f'[1] + Sequence Length: {len(DNAStr)}\n')
print(colored(f'[2] + Nucleotide Frequency: {countNucFrequency(DNAStr)}\n'))
print(f'[3] + DNA/RNA Transcription: {colored(transcription(DNAStr))}\n')
print(f"[4] + DNA String + Reverse Complement:\n5' {colored(DNAStr)} 3'")
print(f" {''.join(['|' for c in range(len(DNAStr))])}")
print(f"3' {colored(reverse_complement(DNAStr))} 5'\n")
Nucleotides = ["A", "C", "G", "T"]
DNA_ReverseComplement = {'A': 'T', 'T': 'A', 'G': 'C', 'C': 'G'}
def colored(seq):
bcolors = {
'A': '\033[92m',
'C': '\033[94m',
'G': '\033[93m',
'T': '\033[91m',
'U': '\033[91m',
'reset': '\033[0;0m'
tmpStr = ""
for nuc in seq:
if nuc in bcolors:
tmpStr += bcolors[nuc] + nuc
tmpStr += bcolors['reset'] + nuc
return tmpStr + '\033[0;0m'
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment