So, you have a "locus" file containing lines with 6 tab-delimited
fields (and maybe some lines that don't fit that description),
and you have a "molecules" file with a list of target strings, and your
goal is to print the 6-field "locus" lines that contain any of the
"molecule" strings in the first or second field.
If I got that right, then I think something like the following
will do:
open( MOL, "molecules" );
@molecules = <MOL>;
close MOL;
map { chomp; $_ = quotemeta; } @molecules;
$bigRegex = join '|', @molecules;
open( LOCUS, "locus" );
@locus = <LOCUS>;
close LOCUS;
foreach (@locus) {
print if ( scalar( split /\t/ ) == 6 &&
/^([^\t]+\t)?($bigRegex)/ );
}
You may want to look at "qr" on the
perlop
manpage (under "Regexp Quote-like Operators), if you have a lot of molecule patterns to look for
and/or a lot of locus data to go through. The "print if"
condition says that there must be 6 fields on the line,
and the set of molecule strings in $bigRegex needs to match
either at the beginning of each line, or after the first
tab character.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.