Hello Meetali16, and welcome to the Monastery!

I assume that the “Result” you give is the output you want to receive? If so, it’s difficult to see why some matches are included and others excluded. Looking at the rsid fields doesn’t help, since all lines in both input files have the same rsid. Matching base pairs between the two files would then result in 6 matches:

rs492602 CC GG Vitamin B12 deficiency FUT2 Higher levels of vita +min B12 rs492602 CC CC Vitamin B12 deficiency FUT2 Higher levels of vita +min B12 rs492602 CT GG Vitamin B12 deficiency FUT2 Normal levels of vita +min B12 rs492602 CT CC Vitamin B12 deficiency FUT2 Normal levels of vita +min B12 rs492602 TT GG Vitamin B12 deficiency FUT2 Normal levels of vita +min B12 rs492602 TT CC Vitamin B12 deficiency FUT2 Normal levels of vita +min B12

— unless the asterisks are significant? Please clarify.

In the meantime, I will propose a general strategy: Decide which of the two input files is likely to be shorter, and read the contents of that file into a hash. (The format for the hash will depend on the type of matching you require.) Then read the larger file, line by line, extracting its rsid and base pair fields and matching against the appropriate fields in the hash. Hash lookup is one of the areas where Perl really shines.

I notice you increment $i on each match, but never use it. I’m guessing you want to:

print "Found $i matches\n";

at the end of the script?

Please clarify what you are trying to achieve, to make it easier for the Monks to help you — and please remember that most of us are not biologists!

Cheers,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


In reply to Re: Matching complementary base pairs from 2 different files by Athanasius
in thread Matching complementary base pairs from 2 different files by Meetali16

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



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.