Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re^3: unique sequences

by jwkrahn (Monsignor)
on Dec 11, 2017 at 19:26 UTC ( #1205300=note: print w/replies, xml ) Need Help??

in reply to Re^2: unique sequences
in thread unique sequences

Sorry, I didn't test the code well enough. I thought the capturing parenthesis would capture the look-behind pattern as well. This code will do what I originally intended:

Updated (thanks Cristoforo)

while ( $line =~ / (?<= .{9} [ATCG]{10} G ) G /gsx ) { my $match = substr $line, $+[ 0 ] - 21, 21; print $KMERS '>crispr_', ++$count, "\n$match\n" unless $unique_data{ $match }++; }

Replies are listed 'Best First'.
Re^4: unique sequences
by AnomalousMonk (Bishop) on Dec 11, 2017 at 21:25 UTC
    I thought the capturing parenthesis would capture the look-behind pattern as well.

    It does — except I wouldn't think of what was captured as "the look-behind pattern", but simply as "the pattern" or maybe "the match." Look-around doesn't really enter in to it, and I don't see any need to bring in substr either; you already seem to have everything you need in $1, e.g. (with one repeated sequence):

    c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my $line = 'AAAATTTTCCCCGGGGAAAGGxAAAACCCCTTTTGGGGAAAGGxAAAATTTTCCCCGGGGAAAGG' ; ;; my (%unique_data, $count); while ($line =~ m{ (.{9} [ATCG]{10} GG) }xmsg) { print qq{>crispr_@{[ ++$count ]} '$1'} unless $unique_data{$1}++; } ;; dd \%unique_data; " >crispr_1 'AAAATTTTCCCCGGGGAAAGG' >crispr_2 'AAAACCCCTTTTGGGGAAAGG' { "AAAACCCCTTTTGGGGAAAGG" => 1, "AAAATTTTCCCCGGGGAAAGG" => 2 }

    However, I think the line-by-line processing of your code here is problematic. In the OPed code, the function  loadSequence() (supposedly) concatenates all lines of  ATCG bases in a file together before trying to extract sub-sequences of interest. In line-by-line processing, a sub-sequence may be interrupted by a newline and thus be missed.

    (OTOH, the whole 21-base-versus-12-base aspect of the OPed code leaves me puzzled; I can't quite figure out what the OPer was going for there.)

    Give a man a fish:  <%-{-{-{-<

Re^4: unique sequences
by Cristoforo (Curate) on Dec 11, 2017 at 19:39 UTC
    $+ should be $+[0] :-)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1205300]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2020-10-21 04:48 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (212 votes). Check out past polls.