microkorg has asked for the wisdom of the Perl Monks concerning the following question:
Greetings Monks,
A very new Perl programmer having a touch of trouble getting a small program to loop through an array.
The file I have read into the array is a .fasta DNA sequence file and has the format:
>Sequence_Header_A
DNAsequence
>Sequence_Header_B
DNAsequence
>Sequence_Header_C
DNAsequence
etc.
>Sequence_Header_A_1
DNAs
>Sequence_Header_A_2
equ
>Sequence_Header_A_3
enc
>Sequence_Header_A_4
e
>Sequence_Header_B_1
DNAs
>Sequence_Header_B_2
equ
>Sequence_Header_B_3
enc
>Sequence_Header_B_4
e
I have managed to get the separate elements working (in a fashion) but I don't seem to be able to get it to work as one element (at the moment the "header capture" section and the "insert newline" section are completely independent. My code is as follows:
#Capture header foreach $line (@array) { if ($line =~ /^>.+$/ ) { $header = $&; } }
...and the section which "cuts" the DNA sequence at the appropriate section is:
$number = 1 ; foreach (@array) { #cut at appropriate sites $_ =~ s/(e)/\n$header_$number\n$1/ ; $number++; #remove double ">>" $_ =~ s/\*/\*\n/g; #remove blank lines $_ =~ s/\n+/\n/g ; }
The last 2 steps are just to tidy up the formatting as the output must be exactly in the format of my 2 examples at the top of this post.
Help please!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl noob struggling to loop through an array
by aitap (Curate) on Oct 24, 2012 at 15:52 UTC | |
|
Re: Perl noob struggling to loop through an array
by jwkrahn (Abbot) on Oct 25, 2012 at 03:35 UTC | |
by microkorg (Initiate) on Oct 26, 2012 at 12:42 UTC | |
by Anonymous Monk on Oct 26, 2012 at 17:01 UTC |