in reply to Re^5: compare two files on the basis of Two IDs
in thread compare two files on the basis of Two IDs
File 2chr7 151046672 chr7 151047369 chr3 127680920 chr3 127680920
Code for now.chr1 66953622 66953654 chr1 67200451 67200472 chr1 67200475 67200478 chr1 67058869 67058880 chr1 67058881 67058885 chr7 151046672 127680920 chr7 151047369 127680920 chr3 127680920 151046672 chr3 127680920 151047369
Its not working, Since I want to print the output with respect to my file 1. If you can help with. I Know there is some error in 'If' statement. I could note understand that..#!/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 = <$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, $val1, $val2) = split /\s+/,$line; } close $infile1; while (my $line = <$infile2>) { chomp $line; 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 $file2_hash{"$key:$value1:$value2"} = 1; # file handle closure is optional, but I'd do it. ### process each line in file2: ### If a line "matches" with any line in file1, then "E", else "M" ### I don't know that these numbers mean, come up with better comment close $infile2; if (exists $file2_hash{"$chr:$val1:$val2"}) { 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^7: compare two files on the basis of Two IDs
by Marshall (Canon) on Sep 29, 2016 at 20:54 UTC | |
by genome (Novice) on Sep 30, 2016 at 02:21 UTC | |
by Marshall (Canon) on Sep 30, 2016 at 02:45 UTC | |
by genome (Novice) on Sep 30, 2016 at 14:29 UTC | |
by genome (Novice) on Oct 07, 2016 at 19:14 UTC | |
by Marshall (Canon) on Oct 09, 2016 at 05:24 UTC |