[Bioperl-l] While running without stop
Chris Fields
cjfields at illinois.edu
Thu May 19 19:26:29 UTC 2011
The match needs to be made iterative so subsequent matches can be made, otherwise the match starts at the beginning of the string during each iteration of the while loop. To do that you need the /g modifier:
while ($sequence =~ m/(ATCGA)/g ){ ... }
You could also use pos() and the match length in the loop to get the match start and end position, it might be slightly faster.
Not sure whether $seq->seq would work in the place of $sequence above, but I think it would work fine.
chris
On May 19, 2011, at 1:48 PM, Kevin Brown wrote:
> This is a problem with accessing objects, IIRC.
>
> Try doing something like:
>
> my $in = Bio::SeqIO->new(-file => $file , '-format' => 'fasta');
> while ( my $seq = $in->next_seq() )
> {
> my $sequence = $seq->seq;
> while ($sequence =~ m/(ATCGA)/){
> print "ATCGA commence à la position $-[1]\nse termine juste avant la
> position $+[1]\n";
> }
> }
>
> Kevin Brown
> Center for Innovations in Medicine
> Biodesign Institute
> Arizona State University
>
>> -----Original Message-----
>> From: bioperl-l-bounces at lists.open-bio.org [mailto:bioperl-l-
>> bounces at lists.open-bio.org] On Behalf Of debutant.bioperl
>> Sent: Thursday, May 19, 2011 11:00 AM
>> To: Bioperl-l at lists.open-bio.org
>> Subject: [Bioperl-l] While running without stop
>>
>>
>> Hello all,
>> The following perl script looks for the pattern in each line (line of
>> the
>> fasta format that begins with">" : sequence).
>>
>> .......................................................................
>> .....................................................................
>> #!/usr/bin/perl
>> use strict;
>> use warnings;
>> use Bio::SeqIO;
>>
>> my $file = 'eee.txt';
>> my $in = Bio::SeqIO->new(-file => $file , '-format' => 'fasta');
>> while ( my $seq = $in->next_seq() )
>> {
>> while ($seq->seq =~ m/(ATCGA)/){
>> print "ATCGA commence à la position $-[1]\nse termine juste avant
>> la
>> position $+[1]\n";
>> }
>> }
>> .......................................................................
>> .....................................................................
>>
>> the problem that the while of:
>> .......................................................................
>> ...........................
>> while ($seq->seq =~ m/(ATCGA)/){
>> print "ATCGA commence à la position $-[1]\nse termine juste
>> avant la
>> position $+[1]\n";
>> }
>> .......................................................................
>> ...........................
>> Runs continuously and always gives the same result.
>>
>> ... ATCG commence Ó la position 172
>> se termine juste avant la position 176
>> ATCG commence Ó la position 172
>> se termine juste avant la position 176
>> ATCG commence Ó la position 172
>> se termine juste avant la position 176 ...
>>
>>
>> And if we use "if" instead of While he finds only the first pattern
>> (case),
>> otherwise, if more than one pattern in the same sequence, he finds only
>> the
>> first.
>> Please, have you any idea to fix this code so that:
>> While research patterns and ends.
>> Or
>> For If, when he finds a pattern he went to the next letter and not the
>> next
>> sequence and found many motifs per sequence.
>> Cordially
>>
>>
>> --
>> View this message in context: http://old.nabble.com/While-running-
>> without-stop-tp31658279p31658279.html
>> Sent from the Perl - Bioperl-L mailing list archive at Nabble.com.
>>
>>
>> _______________________________________________
>> Bioperl-l mailing list
>> Bioperl-l at lists.open-bio.org
>> http://lists.open-bio.org/mailman/listinfo/bioperl-l
>
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/bioperl-l
More information about the Bioperl-l
mailing list