#!/usr/bin/perl -w
############################################################
#
# $Id: pathway-extractor,v 1.24 2011/12/02 22:03:19 jvanheld Exp $
#
############################################################

## use strict;

=pod

=head1 Extract Pathway from gene list

=head1 VERSION 1.0

=head1 DESCRIPTION

This tool is a Perl Wrapper around the stand-alone application
(PathwayInference) developed by Karoline Faust.

The PathwayInference tool can also be used via the Web interface
"Pathway Extraction" (http:// rsat.ulb.ac.be/neat).

The Perl wrapper performs several steps to enable the extraction of
pathways from sets of functionally related genes (e.g. co-expressed,
co-regulated, members of the same operon, …).

1. Gene to reaction mapping. Identify the set of reactions ("seed
reactions") catalyzed by the set of input genes ("seed genes"). The
mapping relies on a user-specified file describing the mapping of
genes to reactions (GPR, Gene-Protein-Reaction file).

2. Pathway extraction (=Pathway inference). PathwayInference takes as
input a network (typically a metabolic network made of compounds +
reactions) and a set of "seed" nodes. The program attempts to return a
subnetwork that interconnects the seed nodes at a minimal “cost",
where the cost is a weighted sum of the intermediate compounds and
reactions used to link the seed nodes (Faust, et al., 2011; Faust and
van Helden, 2011).

3. Annotation of the inferred pathway: identify the EC numbers,
enzymes and genes associated to each reaction (seed + inferred
reactions) of the inferred pathway. This documentation relies on the
same GPR file as the gene to reaction mapping.

This implementation requires no database or Internet connection and
works with local files only.  The PathwayInference tool wraps a number
of algorithms to infer pathways: k shortest paths (REA), kWalks and a
hybrid approach combining both (Faust, et al., 2010). In addition, two
Steiner tree algorithms are available (Takahashi-Matsuyama and
Klein-Ravi), each of them alone or in combination with kWalks.

=head1 AUTHORS

The java PathwInference tool was developed by Karoline Faust. This
Perl wrapper was developed by Didier Croes. The doc was written by
Didier Croes and Jacques van Helden.

=head1 REFERENCES

Faust, K., Croes, D. and van Helden, J. (2011). Prediction of
metabolic pathways from genome-scale metabolic networks. Biosystems.

Faust, K., Dupont, P., Callut, J. and van Helden, J. (2010). Pathway
discovery in metabolic networks by subgraph extraction. Bioinformatics
26, 1211-8.

Faust, K. and van Helden, J. (2011). Predicting metabolic pathways by
sub-network extraction.  Methods in Molecular Biology in press, 15.

=head1 CATEGORY

Graph tool

=head1 USAGE

pathway_extractor -h -hp [-i inputfile] [-o output_directory] [-v verbosity] \
    -g infile{graph} -a gene2ec2reactions [-d unique_descriptor] [-t temp_directory] [-show]

=head1 INPUT FORMAT

Warning: the same gene identifiers should be used in all input files.

=head2 1) List of seed genes (gene identifiers):

(Warning at least 2 gene ids must be present in the graph file see
below) in this example we use gene IDs. Beware, the gene IDs must be
compatible with the genome version installed on RSAT. Depending on the
organism source, the IDs can correspond to RefSeq, EnsEMBL, or other
references.

Example of seed gene file:
NP_414739
NP_414740
NP_414741
NP_416617
NP_417417
NP_417481
NP_418232
NP_418272
NP_418273
NP_418373
NP_418374
NP_418375
NP_418376
NP_418437
NP_418443

----------------------------------------------------------------

=head2 2)Graph file format:

see Pathwayinference tools helppathway_extractor

java graphtools.algorithms.Pathwayinference –h

The same result can be obtained by typing

pathway-extractor -hp

----------------------------------------------------------------



=head2 Seed mapping file

The seed mapping file makes the link between different types of seeds
(genes, EC numbers, proteins, compound names) and nodes of the network
(reactions or compounds depending on the seed type).

=head3 Gene-EC-reaction (GER) file (option I<-ger>)

Mandatory.

The GER file makes the link between genes and reactions, passing
through EC numbers.

This file is used for the reaction to gene mapping (backward).

The three first columns are mandatory (gene_id, ec_number,
reaction_id). Additional columns can be provided for convenience, but
are ignored.

=head3 Example of GERfile

 geneID	ec_number       reaction_id     species_name    taxonomy_id     gene_name
 O22340	4.2.3.-	 RXN-10482       Abies grandis   46611   (4S)-limonene synthase
 O22340	4.2.3.-	 RXN-10483       Abies grandis   46611   (4S)-limonene synthase
 O22340	4.2.3.-	 RXN-10566       Abies grandis   46611   (4S)-limonene synthase
 O22340	4.2.3.-	 RXN-10567       Abies grandis   46611   (4S)-limonene synthase
 O22340	4.2.3.-	 RXN-10568       Abies grandis   46611   (4S)-limonene synthase
 O22340	4.2.3.-	 RXN-10600       Abies grandis   46611   (4S)-limonene synthase
 ...

=head1 EXAMPLES

=head2 With an input file

=head3 Motivation

Get methionine-related genes in Escherichia coli genome. This
generates a file containing one line per gene and one column per
attribute (ID, start, end, name, ...).


=head3 Commands

Extract all E.coli genes whose name starts with met
 gene-info -org Escherichia_coli_K_12_substr__MG1655_uid57779 -feattype CDS -full -q '^met.*' -o met_genes.tab

Select the first column, containing gene Ids.
 grep -v "^;" met_genes.tab | cut -f 1 > met_genes_IDs.txt

Extract a pathway connecting at best the reactions catalyzed by these gene products
  pathway-extractor -i met_genes_IDs.txt \
     -g data/networks/MetaCyc/MetaCyc_directed_141.txt \
     -ger ${RSAT}/data/metabolic_networks/GER_files/GPR_Uniprot_112011_Escherichia_coli_K12.tab \
     -o result_dir \
     -t temp_dir

----------------------------------------------------------------

=head2 Using standard input

=head3 The script pathway-extractor can also use as input the STDIN. This allows to use it in aconcatenation of commands. For example, all the commands above could be combined in a single pipeline as follows.

 gene-info -org Escherichia_coli_K_12_substr__MG1655_uid57779 -feattype CDS -q 'met.*' \
   | grep -v "^;" met_genes.tab | cut -f 1 \
   | pathway-extractor -g data/networks/MetaCyc/MetaCyc_directed_141.txt \
       -ger data/networks/MetaCyc/METACYC_GPR_EC_20110620.txt \
       -o result_dir -t temp_dir

----------------------------------------------------------------

=head1 OUTPUT FILES:

*_converted_seeds.txt : pathway inference input file.

*_pred_pathways.txt : result graph file of the pathway inference

*_annot_pred_pathways.txt : : result file of the pathway inference with gene and EC annotation

*_annot_pred_pathways.dot : result file in dot format, which can be converted to a figure using the
automatic layout program dot (included in the software suite graphviz).

*._annot_pred_pathways.png : png image file of the inferred pathway
----------------------------------------------------------------

=cut


BEGIN {
    if ($0 =~ /([^(\/)]+)$/) {
	push (@INC, "$`lib/");
	push (@INC,"$ENV{RSAT}/perl-scripts/lib/");
    }
}
require "RSA.lib";


################################################################
## Main package
package main;
{

  ################################################################
  ## Initialise parameters
  #
  local $start_time = &RSAT::util::StartScript();
  $program_version = do { my @r = (q$Revision: 1.24 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
  #    $program_version = "0.00";

  ## Input/output files
  our %infile = ();	     # File name containing a list of genes ID
  our %outfile = ();

  ## Directories
  our %dir = ();
  $dir{output} = "."; # output directory
  $dir{temp}= "";     # temporary directory

  our $verbose = "";
  our $in = STDIN;
  our $out = STDOUT;

  $infile{gpr} ="METACYC_GPR_EC.tab"; # GPR Gene -> EC -> REACTION annotation file path. Default (METACYC_GPR_EC.tab)
  $graph = "";		# Graph Name
  $infile{graph}="";		# File containing the graph
  $show = 0;		# Open png image in gwenview
  $group_descriptor= ""; # Unique name to differenciate output files

  my $organism = "Unknown";
  my $organism_id;
  # my $working_dir = "";
  my $genes_id;
  my @genes_id_list;

  ################################################################
  ## Read argument values
  &ReadArguments();

  ################################################################
  ## Check argument values

  if (defined $infile{input}) {
    ($in) = &OpenInputFile($infile{input});
    if (!$group_descriptor) {
      $group_descriptor = $infile{input};
      $group_descriptor =~ s{.*/}{};     # removes path
      $group_descriptor=~ s{\.[^.]+$}{}; # removes extension
    }
  } else {
    if (!$group_descriptor) {
      $group_descriptor ="stdin";
    }
  }
  $group_descriptor=~s/(\s|\(|\))+/_/g;
  if (!$graph) {
    $graph = $infile{graph};
    $graph =~ s{.*/}{};	    # removes path
    $graph=~ s{\.[^.]+$}{};   # removes extension
  }
  $graph=~s/(\s|\(|\))+/_/g;


  ################################################################
  ## Print verbose
  &Verbose() if ($verbose);

  ################################################################
  ## Execute the command

  ## Check the existence of the output directory and create it if
  ## required
  unless ($dir{output} =~ /\/$/) {
    $dir{output} = $dir{output}."/";
  }
  $dir{output} =~s |//|/|g; ## Suppress double slashes
  &RSAT::util::CheckOutDir($dir{output});

  ## Check the existence of the temp directory and create it if
  ## required
  $dir{temp}=$dir{output} unless ($dir{temp});
  if (!($dir{temp}=~m/\/$/)) {
    $dir{temp} = $dir{temp}."/";
  }
  &RSAT::util::CheckOutDir($dir{temp});



  ################################################################
  ## GPR Mapping

  ## DIDIER: the GPR mapping should be redone with the new program match-names.

  &RSAT::message::TimeWarn("Mapping seeds to reactions") if ($verbose >= 1);
  @genes_id_list = <$in>;
  close $in if ($infile{input});
  chomp(@genes_id_list);
  $genes_id = (join "|^",@genes_id_list );	#
  &RSAT::message::Info("Gene IDs", join("; ", @genes_id_list)) if ($verbose >= 3);
  my @grconversiontable;
  my %genelist=();
  if ($outfile{gr}) {	    ## if annotated gene to reaction file (-b)
    my $seed_converter_cmd = "awk -F'\\t+' '\$1~\"^".$genes_id."\" {print \$2\"\\t\"\$1\"\\t\"\$3\"\\t\"\$4\"\\t\"\$5}' $outfile{gr}";
    @grconversiontable = qx ($seed_converter_cmd) ;
    chomp(@grconversiontable);
    @grconversiontable = sort(@grconversiontable);
    &RSAT::message::Debug("Gene IDs", join("; ", @grconversiontable)) if ($verbose >= 3);
  }
  my $seed_converter_cmd = "awk -F'\\t+' '\$1~\"^".$genes_id."\" {print \$2\"\\t\"\$1\"\\t\"\$3\"\\t\"\$4\"\\t\"\$5}' $infile{gpr}";

  &RSAT::message::TimeWarn("Seed conversion:", $seed_converter_cmd) if ($verbose >= 2);

  my @conversiontable = qx ($seed_converter_cmd) ;
  chomp(@conversiontable);
  @conversiontable =sort(@conversiontable);
  # getting organism information
  my @tempdata = split(/\t/,$conversiontable[0]);
  $organism = $tempdata[3];
  $organism_id = $tempdata[4];
  my $groupid=( join "-",$organism,$organism_id);
  $groupid=~s/(\s|\(|\))+/_/g;

  ##  merging GR and GPR in one array
  if (@grconversiontable) {
    foreach my $val (@conversiontable) {
      @tempdata = split(/\t/,$val);
      if (!grep(/^$tempdata[0]/, @grconversiontable)) {
	push(@grconversiontable, grep(/^$tempdata[0]/, @conversiontable))
      }
    }
    #   print join( "\n",@conversiontable) ."\n";
    @conversiontable=@grconversiontable;

  }
  #  End of merging GR and GPR in one array

  # End of GPR mapping
  ################################################################


  ################################################################
  ## Define output file names
  $outfile{gr} = "";		# GR Gene -> REACTION annotation
  $outfile{prefix} = $dir{output}."/";
  $outfile{prefix} .= join("_", $group_descriptor, $groupid, $graph, "pred_pathways");
  $outfile{prefix} =~ s|//|/|g; ## Suppress double slashes

  $outfile{predicted_pathway} = $outfile{prefix}.".txt";
  $outfile{graph_png} = $outfile{prefix}."_annot.png";
  $outfile{graph_dot} = $outfile{prefix}."_annot.dot";
  $outfile{graph_annot} = $outfile{prefix}."_annot.txt";
  $outfile{seeds_converted} = $outfile{prefix}."_seeds_converted.txt";
#  my $outfile{graph_png} = $dir{output}.(join "_",$group_descriptor, $groupid, $graph, "annot_pred_pathways.png");
#  my $outfile{graph_dot} = $dir{output}.(join "_",$group_descriptor, $groupid, $graph, "annot_pred_pathways.dot");
#  my $outfile{graph_annot} = $dir{output}.(join "_",$group_descriptor, $groupid, $graph, "annot_pred_pathways.txt");
#  my $outfile{seeds_converted} = $dir{output}.(join "_",$group_descriptor,$groupid,$graph, "_converted_seeds.txt");

  ################################################################
  # Creating reaction file fo pathway inference
  &RSAT::message::TimeWarn("Creating reaction file for pathway inference") if ($verbose >= 1);
#  my $outfile{seeds_converted} = $dir{output}.(join "_",$group_descriptor,$groupid,$graph, "_converted_seeds.txt");
  open (MYFILE, '>'.$outfile{seeds_converted});
  print MYFILE "# Batch file created", &RSAT::util::AlphaDate();
  print MYFILE "# GENE groups parsed from file:". "\n";
  print MYFILE "# Organism: ". $organism. "\n";
  print MYFILE "# EC number grouping: true". "\n";
  my $seednum= 0;
  my @previousarray;
  foreach my $val (@conversiontable) {

    @tempdata = split(/\t/,$val);
    if (@previousarray && !($tempdata[0] eq $previousarray[0])) {
      print MYFILE "$previousarray[0]\t$groupid\n";
      $seednum++;
    }
    # 	print "$tempdata[1] eq $previousarray[1]\n";
    print MYFILE $tempdata[2] .">\t".$tempdata[2]. "\n";
    print MYFILE $tempdata[2] ."<\t".$tempdata[2]. "\n";
    print MYFILE $tempdata[2] ."\t".$tempdata[0]. "\n";
    @previousarray = @tempdata;
  }

  if (@conversiontable) {
    print MYFILE "$previousarray[0]\t$groupid\n";
    $seednum++;
  }
  # END OF  Creating reaction file fo pathway inference
  ################################################################


  ## TO DO WITH DIDIER: CHECK SEED NUMBER AND SEND WARNING IF TOO BIG.
  ##
  ## Define a parameter max{seed_numbers}. By default, program dies
  ## with error if seeds exceed max{seed_number}, but the max can be
  ## increased by the user with the option -max seeds #.

  if ($seednum > 1) {
    ################################################################
    # Running PatywayInference
    &RSAT::message::TimeWarn("Running pathway inference with ", $seednum, "seeds") if ($verbose >= 1);
#    $outfile{predicted_pathway} = $dir{output}.(join "_",$group_descriptor, $groupid, $graph, "_pred_pathways.txt");
    my $pathway_infer_cmd = "java -Xmx1000M graphtools.algorithms.Pathwayinference";
    $pathway_infer_cmd .= " -i ".$outfile{seeds_converted};
    $pathway_infer_cmd .= " -m 5 -C -f flat -n";
    $pathway_infer_cmd .= " -p ".$dir{temp};
    $pathway_infer_cmd .= " -E ".$dir{output};
    $pathway_infer_cmd .= " -b -d -g";
    $pathway_infer_cmd .= " ".$infile{graph};
    $pathway_infer_cmd .= " -y con ".$verbose;
    $pathway_infer_cmd .= " -o $outfile{predicted_pathway}";
    &RSAT::message::TimeWarn("Pathway inference command", $pathway_infer_cmd) if ($verbose >= 2);
    &RSAT::message::Info("Predicted pathway file", $outfile{predicted_pathway}) if ($verbose >= 1);
    &doit($pathway_infer_cmd, $dry, $die_on_error, $verbose, $batch, $job_prefix);

    ## TO DO WITH DIDIER: redirect STDERR/STDOUD to log and err files in the output directory

    # END of Running patywayinference
    ################################################################

    ################################################################
    # Loading reactions from extracted  graph
    &RSAT::message::TimeWarn("Loading reactions from extracted graph") if ($verbose >= 1);
    open (INFILE, '<'.$outfile{predicted_pathway}) or die "couldn't open the file!";
    my $i = 0;
    my $stop = "";
    my $line;
    my $reactionquery="";
    my $cpdquery="";
    while ($line=<INFILE>) {
      #$line = $_;
      chomp  ($line );
      if (length($line)>0 && !($line=~m/^;/)) {
	my @tempdata = split(/\t/,$line);
	if ($tempdata[6] &&($tempdata[6] eq "Reaction")) {
	  #       print "|".$line."|"."\n";
	  $tempdata[0]=~s/<$|>$//;
	  $i++;
	  $reactionquery = $reactionquery."(\$3~\"^".$tempdata[0]."\"&&\$5~\"".$organism_id."\")||";
	} elsif ($tempdata[6] &&($tempdata[6] eq "Compound")) {
	  $cpdquery = $cpdquery."(\$1~\"^".$tempdata[0]."\"&&\$2~\"Compound\")||";
	}
      } elsif ($i>0) {
	last;
      }
    }
    close (INFILE);
    # End of Loading results graph reactions
    ################################################################

    ################################################################
    # Searching all reactions information for the reaction that are in  the inferred pathway graph
    &RSAT::message::TimeWarn("Searching information about extracted reactions") if ($verbose >= 1);
    $reactionquery =~s/\|+$//;
    $cpdquery =~s/\|+$//;

    my $command_ = "awk -F'\\t+' ' $reactionquery {print \$3\"\\t\"\$2\"\\t\"\$6}' $infile{gpr}|sort|uniq";
#    print "$command_\n";
    &RSAT::message::TimeWarn($command_) if ($verbose >= 3);
    @conversiontable = qx ($command_);


    $command_ = "awk -F'\\t+' '$cpdquery {print \$1\"\\t\"\$4\"\\t\"\$1}' $infile{graph}";
    &RSAT::message::TimeWarn($command_) if ($verbose >= 3);
    my @conversionreactiontable = qx ($command_);
    #     print "****************".join("\n", @conversionreactiontable)."\n";
    push (@conversiontable,@conversionreactiontable);

    chomp(@conversiontable);

    ## Storing reaction infos in a hash for faster search
    my %reactioninfos=();
    undef @previousarray;
    my @reacinfoarray=();
    foreach my $content (@conversiontable) {
      my @currentarray = split(/\t/,$content);
      if ( @previousarray && !($previousarray[0] eq $currentarray[0])) {
	# 	  print $previousarray[0]."\n";
	my @truc = @reacinfoarray;
	$reactioninfos{$previousarray[0]}=\@truc;
	undef @reacinfoarray;
      }
      push (@reacinfoarray,\@currentarray);
      @previousarray = @currentarray;
    }
    $reactioninfos{$previousarray[0]}=\@reacinfoarray;

    # End of Searching all reactions information for the reaction that are in  the infered pathway graph
    ################################################################

    ################################################################
    # Adding description to the pathway graph
    &RSAT::message::TimeWarn("Adding descriptions to pathway graph") if ($verbose >= 1);
    open (INFILE, '<'.$outfile{predicted_pathway}) or die "couldn't open the file!";
#    my $outfile{graph_annot} = $dir{output}.(join "_",$group_descriptor, $groupid, $graph, "annot_pred_pathways.txt");
    # my $outfilename = `mktemp $outfile{graph_annot}`;
    open (OUTFILE, '>'.$outfile{graph_annot});
    #     print $group_descriptor;
    while (<INFILE>) {
      my($line) = $_;
      chomp($line);
      my @tempdatab = split(/\t/,$line);
      if (length($line)==0 || $line=~ m/^;/) {
	print OUTFILE $line. "\n";
      } else {

	my $tempstring = $tempdatab[0];
	$tempstring=~s/<$|>$//;
	$tempdatab[0] = $tempstring; #remove directionality from reaction node id to merge the nodes
	# 	      print "TEMPSTRING = $tempstring\n";
	my $values_ref = $reactioninfos{$tempstring};
	if (defined $values_ref) {
	  my @values = @{$values_ref};
	  if ($tempdatab[6] && ($tempdatab[6] eq "Reaction")) {

	    my $label="";
	    my $labelb;
	    foreach my $info_ref (@values) {
	      my @info = @{$info_ref};

	      #  	      print "JOIN=".join("\t", $myarray[0][0])."\n";
	      my( $reacid,$ec,$genename) = @info;
	      # 		    print "ec: $ec\n";
	      if ($ec) {
		chomp($genename);
		$label=$label."$genename,";
		if (!defined $labelb) {
		  $labelb = "\\n$ec\\n($reacid)";
		}
	      }
	    }
	    $tempdatab[3] = $label.$labelb;
	  } elsif ($tempdatab[6] &&($tempdatab[6] eq "Compound")) {
	    $tempdatab[3] =  $values[0][1];
	  } else {
	    $tempdatab[1]=~s/<$|>$//;
	  }
	}
	print OUTFILE (join "\t",@tempdatab). "\n";
      }
    }
    close (MYFILE);
    # End of Adding description to the pathway graph
    ################################################################

    ################################################################
    # Converting graph to dot format
    &RSAT::message::TimeWarn("Converting graph to dot format") if ($verbose >= 1);
#    my $outfile{graph_dot} = $dir{output}.(join "_",$group_descriptor, $groupid, $graph, "annot_pred_pathways.dot");
    my $convert_graph_cmd = "convert-graph -from path_extract -to dot -i $outfile{graph_annot} -o $outfile{graph_dot}";
    system  $convert_graph_cmd;
    # End of Converting graph to dot graph format
    ################################################################

    ################################################################
    # Converting dot graph to image with graphviz dot
    &RSAT::message::TimeWarn("Creating graph image with graphviz dot") if ($verbose >= 1);
#    my $outfile{graph_png} = $dir{output}.(join "_",$group_descriptor, $groupid, $graph, "annot_pred_pathways.png");
    my $graph_image_cmd = "dot -Tpng -Kdot -o $outfile{graph_png} $outfile{graph_dot}";
    system $graph_image_cmd;
    #exit 0;
    if ($show) {
      system "gwenview $outfile{graph_png} &";
    }
  } else {
    print STDERR "NOT ENOUGH SEEDS. Min 2. I stop here!!\n";
    exit(1);
  }
  # End of Converting dot graph to image with graphviz dot
  ################################################################

  ################################################################
  ## Insert here output printing
  ## Report execution time and close output stream
  &RSAT::message::TimeWarn("Ending") if ($verbose >= 1);
  my $exec_time = &RSAT::util::ReportExecutionTime($start_time); ## This has to be exectuted by all scripts
  print $out $exec_time if ($verbose); ## only report exec time if verbosity is specified
  close $out if ($outfile{output});

  exit(0);
}

################################################################
################### SUBROUTINE DEFINITION ######################
################################################################



################################################################
## Display full help message
sub PrintHelp {
  system "pod2text -c $0";
  exit()
}

################################################################
## Display short help message
sub PrintOptions {
  &PrintHelp();
}

################################################################
## Read arguments
sub ReadArguments {
  my $arg;
  my @arguments = @ARGV; ## create a copy to shift, because we need ARGV to report command line in &Verbose()
  while (scalar(@arguments) >= 1) {
    $arg = shift (@arguments);
    ## Verbosity

=pod

=head1 OPTIONS

=over 4

=item B<-v>

Verbose mode

=cut
    if ($arg eq "-v") {
      if (&IsNatural($arguments[0])) {
	$verbose = shift(@arguments);
      } else {
	$verbose = 1;
      }


=pod

=item B<-h>

Display full help message

=cut
    } elsif ($arg eq "-h") {
      &PrintHelp();


=pod

=item B<-help>

Same as -h

=cut
    } elsif ($arg eq "-help") {
      &PrintOptions();

=pod

=item B<-hp>

Display full PathwayInference help message

=cut
    } elsif ($arg eq "-hp") {
      system("java graphtools.algorithms.Pathwayinference -h");
      print "\n";
      exit(0);

=pod

=item B<-show>

execute gwenview to display the pathway results in png format

=cut
    } elsif ($arg eq "-show") {
     $show = 1;

=pod

=item B<-i inputfile>

If no input file is specified, the standard input is used.  This
allows to use the command within a pipe.

=cut
    } elsif ($arg eq "-i") {
      $infile{input} = shift(@arguments);

=pod

=item	B<-ger GER Genes file>

Gene -> EC -> REACTION (GER) annotation file.

=cut
    } elsif ($arg eq "-ger") {
      $infile{gpr} = shift(@arguments);

# =item	B<-b GR Gene -> REACTION annotation>
#
# An gene annotation file with diredt link gene to reaction. Does not rely on the EC number annotation
#
#
# =pod
#
# =cut
#     } elsif ($arg eq "-b") {
#       $outfile{gr} = shift(@arguments);

# =pod

# =item	B<-n Graph name>
#
# Name of the Graph (default: Name of the graph file).
#
# =cut
#     } elsif ($arg eq "-n") {
#       $graph = shift(@arguments);
#

=pod

=item	B<-d group descriptor>

??? (Check with Didier)

=cut
    } elsif ($arg eq "-d") {
      $group_descriptor = shift(@arguments);


=pod

=item	B<-d Unique descriptor>

Unique name to differenciate output files. If not set With -i, the name of the input file will be used.

=cut
    } elsif ($arg eq "-g") {
      $infile{graph} = shift(@arguments);

=pod

=item	B<-o output Directory>

If no output file is specified, the current directory is used.

=cut
    } elsif ($arg eq "-o") {
      $dir{output} = shift(@arguments);

=pod

=item	B<-t temp Directory>

If no output file is specified, the current directory is used.

=cut
    } elsif ($arg eq "-t") {
      $dir{temp} = shift(@arguments);

    } else {
      &FatalError(join("\t", "Invalid pathway_extractor option", $arg));

    }
  }

=pod

=back

=cut

}
################################################################
## Verbose message
sub Verbose {
    print $out "; template ";
    &PrintArguments($out);
    printf $out "; %-22s\t%s\n", "Program version", $program_version;
    if (%infile) {
	print $out "; Input files\n";
	while (my ($key,$value) = each %infile) {
	  printf $out ";\t%-13s\t%s\n", $key, $value;
	}
    }
    if (%outfile) {
	print $out "; Output files\n";
	while (my ($key,$value) = each %outfile) {
	  printf $out ";\t%-13s\t%s\n", $key, $value;
	}
    }
}


__END__
