Hi
I could tell you the steps how to proceed.
Step 1. Use while loop to read file 1. and store your sample names and its corresponding features through hash. If your sample names are unique then use it as a key and corresponding features as its values. Something like
my %hash1;
open my $IN, "file1.txt" or die $!;
my $header = <$IN>; ## use if the file has a header otherwise leave it
while(<$IN>){
chomp $_;
my @line = split(',',$_); ## split the line to get the sample name a
+nd its values
$hash1{$line[0]} = 1; ## if your first column is a sample name or ch
+ange it accordingly
}
close($IN);
Step 2. Now open the file 2 and check for the sample names those are common to both the files using exists
my %CommonSampleNames
open my $IN1, "file2.txt" or die $!;
my $head = <$IN1> ;## again use it if it has a header
while(<$IN1>){
chomp $_;
my @line = split(',', $_);
if(exists $hash1{$line[0]} ){ ## $line[0] is the sample name column
$CommonSampleNames{$line[0]} = 1;
}
}
close($IN1);
3. Open the third file or reference file and again using exists extract the corresponding names.
my %supHash
open my $ref, "ref.txt" or die $!;
$head = <$ref>; ## if header is present
while(<$ref>){
chomp $_;
my @line = split(',', $_); ## if it is a csv file
if(exists $CommonSampleNames{$line[0]} ){
$supHash{$ine[0]} = $line[1]; ## if second column has reference names
}
}
close($ref);
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Outside of code tags, you may need to use entities for some characters:
| |
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.