#!/usr/bin/perl

# matchprofile.pl: compares and aligns two files containing 9-digit Krambeck and 
#                  Betenbaugh N-glycan identifiers
#
# Syntax: perl matchprofile.pl <superset> <subset>
#         the file <superset> contains a set of all structure codes
#         <subset> contains a subset of the codes listed in <superset>
#         It is assumed that both input files have been sorted similarly: 
#         for example, in increasing numerical order

$file1 = @ARGV[0];
$file2 = @ARGV[1];

open(INPUT1,"$file1") || die "Can't open file: $!";
open(INPUT2,"$file2") || die "Can't open file: $!";
$_ = <INPUT2>;
chomp();
$subcode = $_;
while (<INPUT1>) {      # read a line of input from the superset;
        chomp();
        $supercode = $_;
        if ( $supercode eq $subcode ) {
                print $supercode . "\n";
                $_ = <INPUT2>;  # read a line from the subset
                chomp();
                $subcode = $_;
        } else {
                if ( $supercode lt $subcode ) {
                        print "\n";
                }
        }
}
close(INPUT2);
close(INPUT1);

