Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hello perl monks and wisefolks,

I need some help with a regular expression I have a file that has the following strings that I need to match (Query strings)

file1: GCGAT, CACGT

The target strings are in file2, against which the query strings need to be matched GNGATNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN GCGANBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB CNCGTNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN

The condition for match is that: 1. Each of the query strings should be matched only in the beginning of the string 2. The query strings can have an N at any position which means for each query string eg. GCGAT we can have NCGAT,GNGAT,GCNAT,GCGNT,GCGAN. So any of these strings should be matched with the target strings. How do I make a regular expression that can contain all the 6 possibilities(includes the original string, GCGAT). I have the following code so far:

# reading in each query string (file1) into an array while($line1= <INP1>){ chomp($line1); push (@barcode,$line1); } foreach $code(@barcode){ my $filename = $code; open(OUT, ">$filename") || die "$!\n"; for my $data(keys %idhash){ # I have stored each of the query stri +ngs in a hash. The value of the hash contains the target strings. The + keys are 1,2,3... my $value = $idhash{$data}; chomp($code); if($value =~ m/^$code/) # HOW DO I WRITE A REGULAR EXPRESSION HERE TO +ALLOW ALL THE 6 COMBINATIONS TO BE MATCHED PER QUERY STRING. { print "$idhash{data}\n"; # where the query string matches the +target string print value of the hash } } }
Thanks in advance, biobee

In reply to string match using with an N in any position by biobee07

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2024-04-19 16:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found