There's a problem while I'm processing sequences. My file content.
>seq1
ATGCCCTGACGTAAACGTAGGCTACG
>seq2
GCATGCCCTACGGGTACCCCAGTA
And I hope I can reverse the sequences to be this.
>seq1
GCATCGGATGCAAATGCAGTCCCGTA
>seq2
ATGACCCCATGGGCATCCCGTACG
I use "reverse" to do this, but it dose not work any more.
So could you tell me how to solve this problem?
Thank you very much~
Regards,
Amy Lee
You asked a self answering question: The reverse() function does exactly
that.
>I use "reverse" to do this, but it dose not work any more.
?????
Are you saying that coming back into the office after yesterday's Labour
Day the functionality of reverse() in Perl has changed?
jue
Well, I'd better paste my codes here. I'm still working :(
while (<$FILE_IN>)
{
unless (/^>.*$/)
{
reverse $_;
}
print $_;
}
Thank you very much~
Amy
reverse needs a list
$ perl -e '$x="GCAT";$y=join"",reverse(split "",$x);print"$y\n"'
TACG
doubtless there are better ways to do this.
--
RGB
Oh no it doesn't! How embarassing.
perl -e '$x="GCAT";$y=reverse($x);print"$y\n"'
TACG
--
RGB
> reverse $_;
"Useless use of reverse in void context at ./usenet-2May2008-2.pl line 8."
As A. Sinan Unur told you previously, you should always
use warnings;
use strict;
Had you used
use warnings; use strict;
as it strongly recommended then perl itself would have told you:
"Useless use of reverse in void context at [...] line [...]."
In other words: You reverse the content of $_ and then throw it away.
jue
You need to reverse the order of the reverse
operator, before reversing the text:
$_ =reverse;
Regards
M.
Also, the newline character will be reversed, so that should be removed
first:
while (<$FILE_IN>) {
chomp;
$_ = reverse unless /^>/;
print "$_\n";
}
--
Glenn Jackman
"If there is anything the nonconformist hates worse than a conformist,
it's another nonconformist who doesn't conform to the prevailing
standard of nonconformity." -- Bill Vaughan
> At 2008-05-02 11:04AM, "Mirco Wahab" wrote:
>> Amy Lee wrote:
>> > while (<$FILE_IN>)
>> > {
>> > unless (/^>.*$/)
>> > {
>> > reverse $_;
>>
>> You need to reverse the order of the reverse
>> operator, before reversing the text:
>>
>> $_ =reverse;
>
> Also, the newline character will be reversed, so that should be removed
> first:
>
> while (<$FILE_IN>) {
> chomp;
> $_ = reverse unless /^>/;
> print "$_\n";
> }
Thank you very much. However, I still have a problem which I can't
understand well. What if my file content is
>seq1
ACGGTC
ACTG
>seq2
CGATCC
ACCTC
In fact, the sequence is
>seq1
ACGGTCACTG
>seq2
CGATCCACCTC
So if I use the above codes to do that, I can't acquire the correct
sequences. I hope I can process the file that I mention.
Thank you very much~
Amy Lee
Then you have to extract the sequences between
some bounds marker according to your problem.
You coult read the file w/different record
separator (eg. "\nseq") or create a regular
expression to extractz the sequences from
the file slurped into a buffer, like:
...
use warnings;
use strict;
# read the file into a buffer ($seq)
open my $fh, '<', 'sequence.dat' or die $!;
my $seq; do { local $/; $seq = <$fh> };
close $fh;
# extract sequence records
my $match = qr{>[^\n\r]+([^>]+|$)}s;
while($seq =~ /$match/g) {
(my $sequence = $1) =~ tr/\n\r//d;
print "'$sequence'=>" . reverse($sequence) . "\n"
}
...
Regards
M.
You have a gift of stating requirements in a complex way that is
ambigious at best.
Are you saying that your data is split among many lines and should be
reversed across the whole file instead of line by line?
If that is the case then just slurp in the whole file into a single
string and reverse that string. Depending on if you want to preserve the
line breaks you may either have to chomp()/remove them or adjust the
leading/trailing line break of the whole file.
jue
Oh, or of course you could just slurp the whole file into an array and
run reverse() twice, once on the array and once on each element of the
array. Details see the man page for reverse().
jue
If you're processing FASTA files, why aren't you using BioPerl, as
others have already advised you to do? BioPerl would parse your file
for you, so that you could retrieve it as a scalar directly instead of
parsing the file yourself.
--keith
--
kkeller...@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
see X- headers for PGP signature information