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 only print the lines that contained a
A
,T
,G
orC
. You want to print every line, so the print shouldn't be conditional.(
tr///
andprint
use$_
by default.)Note I didn't open the file. You can use the program as follows:
or
The latter modifies the file in place. (Be careful! Test it first. It does make a backup, though.)