#!/usr/bin/perl

use strict;
use warnings;

use Data::Dumper;

use Getopt::Euclid;
use Network;

my ($network_file, $network);


$network_file = $ARGV{'-n'};
$network = Network::new();
print("network is a reference to a ", ref($network), "\n");
$network->read($network_file);
print("Read a network with ", $network->get_num_nodes(), " nodes and ",
	 $network->get_num_edges(), " edges.\n");

# print("Neighbours of YFL039C are ", join(" ", @{$network->get_neighbours("YFL039C")}), "\n");

if (exists($ARGV{'-add-interaction'}))
  # the user has provided an interaction to be added on the command line.
  {
    my ($gene1, $gene2) = values %{$ARGV{'-add-interaction'}};
    $network->add_edge($gene1, $gene2);
    print("After adding an interaction between $gene1 and $gene2, network has ", 
		$network->get_num_nodes(), " nodes and ",
		$network->get_num_edges(), " edges.\n");
  }

if (exists($ARGV{'-delete-gene'}))
  {
    my ($gene) = $ARGV{'-delete-gene'};
    my $num_deleted_edges = $network->delete_node($gene);
    print("After deleting node $gene and $num_deleted_edges interactions, network has ", 
		$network->get_num_nodes(), " nodes and ",
		$network->get_num_edges(), " edges.\n");
  }


my (@genes) = ("YFL039C", "YOL133W", "YFL039C", "YER112W");
my $subgraph = $network->compute_subgraph(\@genes);
print("Subgraph contains ", $subgraph->get_num_nodes(), " nodes and ", $subgraph->get_num_edges(), " edges.\n");

__END__

=head1 NAME

lecture-10.pl: read and manipulate molecular interaction networks.

=head1 SYNOPSIS

lecture-10.pl -n <network-file>

Read <network-file> and print some basic information about the
data. 

=head1 REQUIRED ARGUMENTS

=over

=item -n <network-file>

=for Euclid:

network-file.type: readable

=back

=head1 OPTIONS

=over

=item -a[dd-]i[nteraction] <gene1>,<gene2>

Add an interaction between two genes to the network.

=item -d[elete-]g[ene] <gene>

Delete a gene and all its interactions from the network.

=back

=cut
