Using python in bioinformatics for making programs is simple and easy. I am sharing few programs to solve problems related to bioinformatics and i hope these programs will help you.
Program to introduce spaces and printing in new line
S = ‘a\nb\tc’
Print(S)
Output
a
b c
Here \n is used for printing in new line and \t is used for introducing space by using tab.
**************************************************************
code to remove whitespace characters and ambiguous characters (not
belonging to DNA) from the string, where whitespace could be one of these ’\t\n\r ’
dna = """
aaattcctga gccctgggtg caaagtctca gttctctgaa atcctgacct aattcacaag
ggttactgaa gatttttctt xtttccagga cctctacagt ggattaattg gccccctgat
tgtotgtcga agaccttact tgaaagtatt caatcccaga aggaagctgg aatttgccct
tctgtttcta gtttttgatg agaatgaatc ttggtactta watgacaaca tcaaaacata
ctctgatcac cccgagaaag taaacaaag3 tgatgaggaa ttcatagaaa gcaataaaat
gcatggtatg tcacattatt ctaaaacaa """
e=dna.replace("
", "") # removes empty spaces
print(e)
f=e.replace('\n', "")
print(f)
t=f.replace('\r', "")
print(t)
#replacing ambiguous characters
h=t.replace('x',"").replace('3',"").replace('w',"")
print(h)
i=h.replace('o', "")
print(i)
output:
aaattcctgagccctgggtgcaaagtctcagttctctgaaatcctgacctaattcacaagggttactgaagatttttctttttccaggacctctacagtggattaattggccccctgattgttgtcgaagaccttacttgaaagtattcaatcccagaaggaagctggaatttgcccttctgtttctagtttttgatgagaatgaatcttggtacttaatgacaacatcaaaacatactctgatcaccccgagaaagtaaacaaagtgatgaggaattcatagaaagcaataaaatgcatggtatgtcacattattctaaaacaa
*********************************************************************
Program that returns
the reverse of the DNA sequence
S = "a\nb\tc"
# removing spaces then removing ambigous characters that are not part of DNA
p=S.replace('\n',
"").replace('\t', "").replace('b', "")
def rep(): # defining a function
t=p[::-1]
print(t)
print(p)
rep()
output:
ac
ca
*******************************************************************
Extract
Exons start and end positions from the following string. Print information as
total number of exons and length of each exon
"CDS
join(100..221,345..600,771..908,4787..5452)"
DNA = "CDS join(100..221,345..600,771..908,4787..5452)"
print(DNA)
abc=DNA.replace('CDS', "").replace(" ", "").replace('join', "").replace('(', "").replace(')', "")
print(abc)
exon=abc.split(",")
exon11=len(exon)
msg="****Total number of Exons is given below******"
print(msg)
print(exon11)
DNA3 = DNA.split("(")[1].split(',')[0].split('.')[0]
DNA4=int(DNA3)
DNA5 = DNA.split("(")[1].split(',')[0].split('.')[2]
DNA6=int(DNA5)
print("length of 1st exon found in sequence is")
lenexon1=DNA6-DNA4
print(lenexon1)
DNA7 = DNA.split("(")[1].split(',')[1].split('.')[0]
DNA8=int(DNA7)
DNA9 = DNA.split("(")[1].split(',')[1].split('.')[2]
DNA10=int(DNA9)
print("length of 2nd exon is in sequence is")
lenexon2=DNA10-DNA8
print(lenexon2)
DNA11 = DNA.split("(")[1].split(',')[2].split('.')[0]
DNA12=int(DNA11)
DNA13 = DNA.split("(")[1].split(',')[2].split('.')[2]
DNA14=int(DNA13)
print("length of 3rd exon present in sequence is")
lenexon3=DNA14-DNA12
print(lenexon3)
DNA15 = DNA.split("(")[1].split(',')[3].split('.')[0]
DNA16=int(DNA15)
DNA17 = DNA.split("(")[1].split(',')[3].split('.')[2].split(')')[0]
DNA18=int(DNA17)
print("length of 4th exon is present in sequence is")
lenexon4=DNA18-DNA16
print(lenexon4)
print(DNA)
abc=DNA.replace('CDS', "").replace(" ", "").replace('join', "").replace('(', "").replace(')', "")
print(abc)
exon=abc.split(",")
exon11=len(exon)
msg="****Total number of Exons is given below******"
print(msg)
print(exon11)
DNA3 = DNA.split("(")[1].split(',')[0].split('.')[0]
DNA4=int(DNA3)
DNA5 = DNA.split("(")[1].split(',')[0].split('.')[2]
DNA6=int(DNA5)
print("length of 1st exon found in sequence is")
lenexon1=DNA6-DNA4
print(lenexon1)
DNA7 = DNA.split("(")[1].split(',')[1].split('.')[0]
DNA8=int(DNA7)
DNA9 = DNA.split("(")[1].split(',')[1].split('.')[2]
DNA10=int(DNA9)
print("length of 2nd exon is in sequence is")
lenexon2=DNA10-DNA8
print(lenexon2)
DNA11 = DNA.split("(")[1].split(',')[2].split('.')[0]
DNA12=int(DNA11)
DNA13 = DNA.split("(")[1].split(',')[2].split('.')[2]
DNA14=int(DNA13)
print("length of 3rd exon present in sequence is")
lenexon3=DNA14-DNA12
print(lenexon3)
DNA15 = DNA.split("(")[1].split(',')[3].split('.')[0]
DNA16=int(DNA15)
DNA17 = DNA.split("(")[1].split(',')[3].split('.')[2].split(')')[0]
DNA18=int(DNA17)
print("length of 4th exon is present in sequence is")
lenexon4=DNA18-DNA16
print(lenexon4)
No comments:
Post a Comment