I was trying to make a perl code to get the reverse complement of fasta sequences of DNA in a .fna file format. the sequence02C.fna file contains 100s of DNA sequences :
>adbca3e
TGCTCCCCACGCTTGCCTCTCCAGTACTCAACCAAAGCAGTCTCTAGAAAAACAGTTTCCAACGCAATACGATGGAATTCCACTTCCCAAATATCTC
>4c2a958
TCCCCACGCTTTCGCGCTTCAGCGTCAGTATCTGTCCAGTGAGCTGACTTCTCCATCGGCATTCCTACACAGTACTCTAGAAAAACAGTTTCTGCTC
>0639b5b
TCGCGCCTCAGTGTCCAACGCAATACGAGTTGCAGACCAGGACACATGGAATTCCACTTCCCTCTCCAGTACTCAACCAAAGCAGTCTCTAGAAAAG
I have used the following command which can open the file and make reverse but does not show the sequence ID (eg: >adbca3e) in the output.
The code is:
#!/usr/local/perl
open (NS, "sequence02C.fna");
while (<NS>) {
if ($_ =~ tr/ATGC/TACG/) {print $_;}
}
output file is only the complementary of the sequence but not reverse. Additionally, it does not contain the sequence IDs ">adbca3e"
Could anyone please suggest the appropriate code to do this reverse complementary of this sequence at once and getting the result into an output file?
You say you have a program to "make reverse", but it only gives complementary. Maybe that is a very obvious description for you, but it is not very clear to me.
If by "reverse" you mean to print the string backwards, just use the
reversefunction. Complementary I assume is taking the corresponding nucleobases, which is what your transliteration is meant to dotr/ATGC/TACG/.To fix not printing ids, just remove the
ifcondition on the print-statement.What I would do is just use the diamond operator for a small program like this:
Then you can use this program like this: