Entering edit mode
9.4 years ago
cabraham03
▴
30
Hi, I have a code to extract sequence from multiple fasta sequences and concatenate, and I want to add a new label; something like:
From
>seq1
ACAACCAGCTAGTCACCAAGTTACTGGCAGCACAAAAACAGTCGGCTGCGAATGACGATC
>seq2
CAACTGGCGTGTCATTCGCGGTTGCATCTCTGCTGATGAAAACGCAAACCTCGACAGAAG
to:
>new_label
ACAACCAGCTAGTCACCAAGTTACTGGCAGCACAAAAACAGTCGGCTGCGAATGACGATCCAACTGGCGTGTCATTCGCGGTTGCATCTCTGCTGATGAAAACGCAAACCTCGACAGAAG
My problem is in the print section, I want to add a new label just ones an all the sequences; I have try to use like
print 'New_label' . $seq; # but it don't work
#!/usr/bin/perl -w
use strict;
open FASTA, "file.fasta" or die;
while(my $seq= <FASTA>) {
chomp($seq);
if ($seq =~ m/^>/ ) {
next;
}
elsif ($seq =~ s/n|-//gi){
next;
}
else {
my $sequence =$seq;
print $sequence; #here is my problem
}
}
close FASTA;
print "\n";
Thanks so much
Thanks so much Jorge; it's works well : ))) !!!
If your problem got solved, please accept the answer by clicking on the green tick, which only you could see below the answer.
This form of open works for historical reasons, but this should never be used in practice. It's much better to write it as:
Specifying the mode and a lexical file handle will save you a lot of trouble!
now its not working
the
echo
andgrep
is an independentbash
solution, not to be used inside aperl
script. choose whatever you prefer:bash:
perl (the whole previous code can be rewritten to this):
you can remove the
chomp
if you don't need all the sequences to be in a single line. save it asscript.pl
, and call it asperl script.pl input.fasta