#!/usr/bin/perl

use strict;
use warnings;

use Getopt::Euclid;
use Condition;

my ($condition1_file, $condition2_file, $mapping_file); # = @ARGV;
# remember that Getopt::Euclid stuffs arguments into %ARGV.
$condition1_file = $ARGV{'-1'};
$condition2_file = $ARGV{'-2'};
$mapping_file = $ARGV{'-m'};

my ($file, $condition1, $condition2, $mapping);
# read the genes from $condition1_file.
$condition1 = Condition::read_condition_genes($condition1_file);
# read the genes from $condition2_file.
$condition2 = Condition::read_condition_genes($condition2_file);

# read the mapping from $mapping_file (if it exists).
if (defined($mapping_file))
  {
    $mapping = Condition::read_mapping($mapping_file);
    $condition1 = Condition::map_gene_names($condition1, $mapping);
    $condition2 = Condition::map_gene_names($condition2, $mapping);
  }


# perform the comparison.
my ($both, $only_condition1) = 
  # pass the references to the two arrays.
  #
  # use the fully qualified name of the subroutine.
  Condition::condition_compare($condition1, $condition2);
print("There are ", scalar(@$both), " genes in both arrays.\n");
print("There are ", scalar(@$only_condition1), " genes only in condition 1.\n");
print("both contains ", join(" ", @$both), "\n");
print("only_condition1 contains ", join(" ", @$only_condition1, "\n"));


__END__

=head1 NAME

lecture-04.pl

=head1 SYNOPSIS

Read genes up-regulated in two different conditions and compare the
two lists. Optionally, read a mapping file and compare the two lists,
after mapping the genes into a new namespace.

=head1 USAGE

lecture-04.pl -1 condition1.txt -2 condition2.txt -m mapping.txt

=head1 REQUIRED ARGUMENTS

=over

=item -1 <file1>

A file containing a list of genes up-regulated in condition 1. Each
line should contain the name of one gene.

=for Euclid: 
file1.type: readable

=item -2 <file2>

A file containing a list of genes up-regulated in condition 2. Each
line should contain the name of one gene.

=for Euclid:
file2.type: readable


=back

=head1 OPTIONS

=over

=item -m <mapping>

A file containing a list of (gene, name) pairs. Each
line should contain one gene and one name, separated by a tab.

=for Euclid:
mapping.type: readable



=back

=cut

 


