Wednesday, November 7, 2012

Perl programming #3

You read the first two posts about perl? Missed? Don't worry, go and read here ( perl #1 #2 )

From today, we can learn few programs that would help biology students! Ya, as a biotechnology student I use perl programs for dealing with DNA , RNA and Proteins.

So, I know just something about perl (very limited) for processing sequences! Okay, let's learn some basic programs.

Program to convert DNA sequence to protein sequence:

print "enter a dna sequence file\n";
print "file not found\n";
print "DNA seq. is\n",$dna;
print "mRNA seq. is\n", $dna,"\n";
print "the protein sequence is\n",$protein,"\n";
open (PROTEIN, ">protein.txt");
print PROTEIN $protein;
close PROTEIN;

O/P of the above perl code
"Hashing" here we are using "Genetic code" where we specified the one letter aminoacid code for the codon

"length" this command is used in the perl for finding the number of letters in the pattern
"substr" is used for getting a substring from the given string. You can specify the string from which the substring must be taken and the number of letters of the string that must be taken as substring can also be selected.


Here, we are selecting the substring from the main string stored in "$dna" and as we are going to take as codon, so, we are taking 3 letters here as substring.

In the following line,

we are converting the three letter codon into one letter amino acid code and saving it in $protein. 
We are using ".= " which appends the value when each time the for loop is executed, so that, we get the complete aminoacid sequence, rather than a single amino acid - check with out giving the "dot", you could understand it better. 

In the following lines, we are saving the output sequence in a text file, we are creating the file protein.txt. In the next line, we are printing the output in the created file, in the next line, we  are closing the file.

open (PROTEIN, ">protein.txt");
print PROTEIN $protein;
close PROTEIN;

I explained in my own way, hope i explained in a better way.
Got the concept? Any doubts??? Then, comment.

No comments:

Post a Comment