in reply to Re: compare two files on the basis of Two IDs
in thread compare two files on the basis of Two IDs
#!/usr/bin/perl #use warnings; #use strict; #use Data::Dumper; my $file1 = $ARGV[0]; open($infile1,$file1); my $file2 = $ARGV[1]; open($infile2,$file2); my %file2_hash; while (my $line = <$infile2>) { next if $line =~ /^\s*$/; #skip blank lines (a common infile goof +) my ($key, $value1, $value2) = split /\s+/, $line; # use better "nam +es" I have # no idea of what a chr col + means $file2_hash{"$key:$value1:$value2"} = 1; } close $infile2; while (my $line = <$infile1>) { chomp $line; #so that output with E or M can be on same line next if $line =~ /^\s*$/; #skip blank lines (a common infile goof +) my ($chr, $value1) = split /\s+/,$line; if (exists $file2_hash{"$chr:$value1"} or exists $file2_hash{"$chr: +$value2"} ) { print "$line\tE\n"; # match exists with file 1 } else { print "$line\tM\n"; # match does NOT exist with file 1 } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: compare two files on the basis of Two IDs
by marinersk (Priest) on Sep 28, 2016 at 03:05 UTC | |
by genome (Novice) on Sep 28, 2016 at 13:39 UTC | |
by Marshall (Canon) on Sep 28, 2016 at 21:37 UTC | |
by genome (Novice) on Sep 29, 2016 at 20:08 UTC | |
by Marshall (Canon) on Sep 29, 2016 at 20:54 UTC | |
|