I am workning on a projekt based on DNA sequences in Perl. I wanna make a program that reverse complements the DNA sequence and writes it into a file fx. revdna.fsa (Which I have done ) but the problem is that I want to keep the first unaltered because it's just a description line and therefore has to stay that way even though I change the lines after it.
Also If I wanna keep the first line AND add some more text to the first line-how do I do that???
This is a DNA seqeunce taken from the GenBank database. (the first line is not part of the sequence and is the line I wanna keep as it is)
>AB000410 1559 bp mRNA Homo sapiens
I have done this so far:
open(IN, '<',"dna.dat") or die "Can't read file\n $!";
$dna = "";
$dna .= $line;
Say your data is in a variable called $page. You can use the split function to split on the first line break only and then only apply your data processing code to the text that appears after that. Take a look at this:
@stuff = split(/\\n/, $page, 2);
You can find out how the split function works here:
In the example I have given above, the data in the variable $page after the first line break is put into $stuff. Remember, some characters (including \ ) have special meanings when used inside a regular expression (//) and therefore need to be escaped with a \ . It would be useful to give this page about regular expressions a good read if you haven't yet:
Thanxs alot for ur big help!
Kevin I have tried the following but when I want to write the data into a file I get problems with displaying the first line without repeating itself for every new data line (because of loop):
How do I display the first line only once and followed by the dataset
I have tried this:
open(IN, '<',"dna.fsa") or die "Can't read file\n $!";
my $first_line = <IN>;
my $dna = '';
$dna .= $line;