I have been using "Perl for biologists with little computer coding knowledge" from site called Scriptome (Harvard). It gives great Perl one-liners to achieve desired functions which runs on Unix line command. One very useful script that I use is titled: "Join two tables based on columns sharing a value (merge_lines_based_on_shared_column)" This works great, but sometimes I want the exact opposite. IE: the generation of tables where given values from two columns do not match. For the former, I copy/paste the code they provide below. I would be most grateful if someone can help me.


while (<F2>) {
    @F=split /\t/, $_;
    $line2{$F[$col2]} .= "$_\n"
$count2 = $.;
while (<F1>) {
    @F=split /\t/, $_;
    $x = $line2{$F[$col1]};
    if ($x) {
        $num_changes = ($x =~ s/^/$_\t/gm);
        print $x;
        $merged += $num_changes
} warn "\nJoining $f1 column $col1 with $f2 column $col2\n"
    . "$f1: $. lines\n"
    . "$f2: $count2 lines\n"
    . "Merged file: $merged lines\n";

Then I run it like,

myScript.pl Input-file1.txt Input-file2.txt > Merge-file.txt

This script is pretty poor you should specify exactly where you found it so it can be fixed. In this example

$x = $line2{$F[$col1]};

Is writing to a global undeclared hash called %line2. Then it later checks to see if that value is present here,

if ($x) {

You probably want to change that block to

if (!$x) {
    print $F[$col1];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.