CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
Need help with Regex

 



riya
New User

Oct 26, 2009, 4:48 PM

Post #1 of 6 (3161 views)
Need help with Regex Can't Post

I am a perl beginner and need some help with regex
Input for this code is :
aatgatgataaggtaaggtatgatgatgatgatgatagtagannnnnnnnnatgcatga'/atgca.atgactagca/atgactagcaaggtaaggtaaggtaaggtaaggtatgatgatgannnn./atgatgactagactgacaaggtaaggtaaggtatgatgatgatcgatgacgat... and so on

Here i am trying to assign input file as a scalar variable and trying to find a match of "aaggtaaggt" and then skip some 100 characters whether they are alphabets or symbols or any wildcard characters after skipping exact 100 characters, i am again asking code to start search for match again and every time it finds a match , i am counting and asking to print..

As of my knowledge i have tried using substr of match as pos1 and had set offset for 100 and then assigned that as initial pos for reading second match , but failed to get the correct output, then tried here post match as $' but doubt whether it is correct or not.

#!/usr/bin/perl
$count1 = 0;
open (FILE, "INPUT") || die "cannot open $!\n";
while ($line = <FILE>){

if(($line=~m/(aaggt){2}/ig)&&($'=~m/([atgcn]{100,})/i)) {
$count1 ++ ;
print " " ,$1, "\t";
print "count1 \t " ,$count1 , "\n" ;
}

}



Please, help me figuring out this task. Thanks


shawnhcorey
Enthusiast


Oct 27, 2009, 6:41 AM

Post #2 of 6 (3143 views)
Re: [riya] Need help with Regex [In reply to] Can't Post

What are the wildcards? Are they a single character or a sequence?

__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".


riya
New User

Oct 27, 2009, 7:43 AM

Post #3 of 6 (3138 views)
Re: [shawnhcorey] Need help with Regex [In reply to] Can't Post

They are single characters here in my input

Thanks


shawnhcorey
Enthusiast


Oct 27, 2009, 4:23 PM

Post #4 of 6 (3121 views)
Re: [riya] Need help with Regex [In reply to] Can't Post

Try:

Code
#!/usr/bin/env perl 

use strict;
use warnings;

while( <DATA> ){
chomp;
print "$1 $2\n" while m{ ( (?:aaggt){2} ) ( .{100} ) }gmsx;
}

__DATA__
aatgatgataaggtaaggtatgatgatgatgatgatagtagannnnnnnnnatgcatga'/atgca.atgactagca/atgactagcaaggtaaggtaaggtaaggtaaggtatgatgatgannnn./atgatgactagactgacaaggtaaggtaaggtatgatgatgatcgatgacgat


__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".


riya
New User

Oct 27, 2009, 8:12 PM

Post #5 of 6 (3112 views)
Re: [shawnhcorey] Need help with Regex [In reply to] Can't Post

Hi
Thanks for the reply
I have a question from ur reply
whats the use of usr/bin/env perl here instead of usr/bin/perl and i havent understood this regex..whats the use of gmsx here.i mean this looks like high level perl..cud u plz explain this regex..
onceagain..thank you.
while m{ ( (?:aaggt){2} ) ( .{100} ) }gmsx;


shawnhcorey
Enthusiast


Oct 27, 2009, 9:04 PM

Post #6 of 6 (3109 views)
Re: [riya] Need help with Regex [In reply to] Can't Post


In Reply To
Hi
Thanks for the reply
I have a question from ur reply
whats the use of usr/bin/env perl here instead of usr/bin/perl and i havent understood this regex..whats the use of gmsx here.i mean this looks like high level perl..cud u plz explain this regex..
onceagain..thank you.
while m{ ( (?:aaggt){2} ) ( .{100} ) }gmsx;


env(1) is a UNIX command that finds the program named in its argument and executes it. It is done this way because on some machines, perl is not stored in /usr/bin/

The /gmsx are modifiers for the match. See http://perldoc.perl.org/perlre.html#Modifiers

/g means repeat the match as often as possible.

/m means that ^ matches the start of a line not the start of the string and $ matches the end of a line not the end of the string.

/s means . matches \n too.

/x means ignore white space and comments in the pattern.

__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives