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.
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |