CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [Chris Charley] Merges 2 text files under few conditions : Edit Log



Thalakos
Novice

Apr 5, 2013, 1:25 PM


Views: 851
Re: [Chris Charley] Merges 2 text files under few conditions

Thank you guys! Unfortunately the output is like incomplete.
The file_a.txt has 2026 lines in the output I got only 926 lines.
I need to have all the 2026 lines (with respective associated genes or a blank line if no association is reported).
So that way probably does not work; may be another simple chainge in the script could do the job?


Code
#!/usr/bin/perl  

use strict;
use warnings;

my %ID;

open my $a_fh, '<', 'file_A.txt' or die "failed to open file_A.txt $!";
open my $b_fh, '<', 'file_B.txt' or die "failed to open file_B.txt $!";

while ( my $id = <$a_fh> ) {
chomp $id;
$ID{$id}++;
}
close $a_fh;

while ( my $line = <$b_fh> ) {
my($id, $genes) = split /\t/, $line;

if (exists $ID{$id}) {
print $line x delete $ID{$id};
}
else {
print $line;
}
}
close $b_fh;
print "$_\n" for keys %ID;



(This post was edited by Thalakos on Apr 5, 2013, 1:27 PM)


Edit Log:
Post edited by Thalakos (Novice) on Apr 5, 2013, 1:26 PM
Post edited by Thalakos (Novice) on Apr 5, 2013, 1:27 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives