Hello all, I want some help. I have two files. One file contains the ID's (some alpha numeric text) as below. File named is "BreastCnAPmiRNAsID.txt"

hsa-miR-4700-5p hsa-miR-300 hsa-miR-381 hsa-miR-4803

I want to read this file line by line and then see if the same ID is present in the second file and extract the related information which is in a single row too separated by space. Second file is named "tarbaseData.txt" looks like this:

ENSG00000005175 RPAP3 hsa-miR-3199 Homo sapiens 293S Ki +dney NA HITS-CLIP POSITIVE DIRECT DOWN treatment:em +etine ENSG00000005175 RPAP3 hsa-miR-342-3p Homo sapiens HELA +Cervix Cancer/Malignant HITS-CLIP POSITIVE DIRECT DOWN + Hela cells were treated with control shRNA. ENSG00000005175 RPAP3 hsa-miR-381-3p Homo sapiens HS5 B +one Marrow Normal/Primary HITS-CLIP POSITIVE DIRECT DO +WN NA ENSG00000005187 ACSM3 hsa-miR-196a-5p Homo sapiens EF3DAGO +2 NA Normal/Primary PAR-CLIP POSITIVE DIRECT DOWN + NA

The new lines in the second file starts with the ID as well which is somehwhat like ENS.....What I actually want is that the program takes ID from the 1st file (BreastCnAPmiRNAsID.txt) and whenever it finds the same ID in the second file, it copies the complete line and write it in another file. For the time being I am printing the result in the terminal. My code is not working properly which is as follows.

#!/usr/bin/perl open(FILEID, "BreastCnAPmiRNAsID.txt") || die "cannot open file"; { open(FILECOMPARE, "tarbaseData.txt") || die "cannot open file"; { while(<FILEID>) { chomp; $rnaid = $_; while(<FILECOMPARE>) { chomp; print "$rnaid\n"; if (/$rnaid/) { print "$_\n"; } } close(FILECOMPARE); } close(FILEID); } }

If I replace "/$rnaid/" in the second while loop with specific ID, it searches the second file and gives the output. But I am not able to compare the both files correctly. Any kind help will be appreciated. As I am new to programing any simple understandable approach/help would be highly highly appreciated.


In reply to comparing an ID fom one file to the records in the second file by ag88

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.