I'm trying to extract a DNA sequence from a text file and store it. I can do it using the following code, but it's not the best way because I'm reading the text file line by line. I'm wondering if there's an easier way to find each of the DNA sequences in my text file without reading the text file line by line.
example.pl
#!/usr/local/bin/perl
open(MYFILE, 'data.txt');
@entire_file = <MYFILE>;
while (<MYFILE>) {
chomp;
print "$_\n";
}
$line1 = <MYFILE>;
chomp $line1;
$line2 = <MYFILE>;
chomp $line2;
$line3 = <MYFILE>;
chomp $line3;
$line4 = <MYFILE>;
chomp $line4;
$line5 = <MYFILE>;
chomp $line5;
#Prints DNA sequence 1
print "$line2";
#Prints DNA sequence 2
print "$line5";
close(MYFILE);
data.txt
gi|171361, Saccharomyces cerevisiae, (CYS3) gene, Lab 1, Joe Bloggs GCAGCGATCGACAGCTGTGCTATCCCGGCGAGCCCGTGGCAGAGGACCTCGCTTGCGAAAGCATCGAGTACC
gi|171362, Saccharomyces cerevisiae, (CYS4) gene, Lab 2, Paul McDonald GAAGCGCACGACAGCTGTGCTATCCCGGCGAGCCCGTGGCAGAGGACCTCGCTTGCGAAAGCATCGAGTACC