Thursday 5 March 2015

python programming to deal with DNA and RNA sequence( finding complimentary strand, Conversion of DNA into RNA sequence etc.)

Start codon always starts with the sequence "ATG" that codes for methionine. Stop codon sequence in DNA is
  • TAG 
  • TAA 
  • TGA 
similarly for RNA Start codon is "AUG" and stop codons are
  • UAG 
  • UAA 
  • UGA 
This program consists of a menu , by choosing suitable value you will be able to perform following functions !

  1. Printing the DNA in reverse order
  2. Converting DNA sequence into RNA sequence
  3. Finding the complimentary strand of NDA
  4. Finding the reverse compliment of DNA
  5. Finding the GC content of DNA
  6. Finding the GC percentage of DNA
  7. Finding the location of start and stop codon if present in the DNA sequence
Program
#Nadia Baig
value=input("Enter the dna strand\n")
value=value.lower()
print(value)


def reverse(value): # function to return value
    
 DNAr=value[::-1]
 return DNAr
xyz=reverse(value)
#print("complement of DNA")
def complement(value): # function to find complement
   strand=""
   for q in value:
     if q=="a":
       strand +="t"
     if q=="t":
       strand +="a"
     if q=="c":
       strand +="g"
     if q=="g":
       strand +="c"
 #print(value,q)
   return strand
z=complement(value)
def GCper(value): # function to gind GC percentage
   Gcontent=value.count('g')
   Ccontent=value.count('c')
  #print(Ccontent)
  length=len(value)
  
  result=((Gcontent+Ccontent)/length)*100
  return result
c=GCper(value)

def content(value):#function to find GC content
    Gcontent=value.count('g')
    Ccontent=value.count('c')
    length=len(value)
    
    return("G content",Gcontent,"CContent",Ccontent)
r= content(value)


def rcomplement(value):#function to find reverse complemnt
    reverse=value[::-1]
    rstrand= ""
    
    for base in reverse:
            if base=="a":
              rstrand +="t"

            elif base == "t":
               rstrand +="a"

            elif base == "g":
               rstrand += "c"

            elif base == "c":
               rstrand += "g"
    return rstrand

m=rcomplement(value)


#print("reverse complement of sequence is",n)
def stopstartcodon(value):
    start = 'atg'
    start=value.find('atg')
    stop1 =('tag')
    stop1=value.find('tag')
    stop2=('taa')
    stop2=value.find('taa')
    stop3=('tga')
    stop3=value.find('tga')
                    
    return(start,"start codons position",stop1,stop2,stop3,"stop codon position")
codons=stopstartcodon(value)                          
    
def rna(value):
 rev=""
 for base in value:
  if base=="t":
   rev +="u"
  if base=="a":
    rev +="a"
  if base=="c":
    rev +="c"
  if base=="g":
   rev +="g"
 return rev
n=rna(value)
#NOW CREATING MENU TO CALL ALL THE FUNCTIONS
userchoice="Please choose from the following options to perform operations\n To print the DNA strand in reverse print 1\n To get the complementary strand of DNA press 2\n To get the reverse complement of DNA strand press 3\n To get the GC% press 4\n To get the value of G and C content press 5\n To get the location of start and stop codon press 6\n To convert DNA into RNA press 7\n"
val=input(userchoice)
num=int(val)
for userchoice in val:
    if (num==1):
        print (xyz)
        reverse(value)
    elif (num==2):
         print(z)
         complement(value)  
    elif (num==3):
        print (m)
        rcomplement(value)
    elif (num==4):
        print (c)
        GCper(value)
    elif (num==5):
        print (r)
        content(value)
    elif (num==6):
        print (codons)
        stopstartcodon(value)
    elif (num==7):
        print(n)
        rna(value)
    else:
        print("the option you have choosen is incorrect")
Sample output
  Enter the dna strand
atggtggttgacccctatcgat
atggtggttgacccctatcgat
Please choose from the following options to perform operations
 To print the DNA strand in reverse print 1
 To get the complementary strand of DNA press 2
 To get the reverse complement of DNA strand press 3
 To get the GC% press 4
 To get the value of G and C content press 5
 To get the location of start and stop codon press 6
 To convert DNA into RNA press 7
2
taccaccaactggggatagcta
**********************************************************************
        


     
    







No comments:

Post a Comment