--- /dev/null
+#!/usr/bin/perl -w
+
+=head1 NAME
+
+Pathway Gene Swapper
+
+=head1 VERSION
+
+0.1
+
+=head1 DESCRIPTION
+
+Swap out one set of genes for another in an existing PathVisio GPML
+file.
+
+=head1 USAGE
+
+pathway_gene_swapper.pl -i INPUT_FILE -g GENE_FILE -c CONFIG_FILE -o OUTPUT_FILE -v -d
+
+=head1 OPTIONS
+
+ -i Name of input GPML file.
+ -g CSV file containing the genes to swap
+ -c config file containing color, label, and placement preferences
+ -o Name of output GPML file.
+ (NOTE: if no path supplied for input files,
+ current working directory is assumed)
+ -v View verbose information
+ -d View debugging information
+
+=head1 DEPENDENCIES and PREREQUISITES
+
+ - Non-standard Perl modules: Switch, XML::DOM
+ - The input file must be a valid GPML file
+ - The CSV file must have a single-line column header
+ If the second column contains
+ - The config file may have any or all of the following entries:
+ Title=
+ MaintainedBy=
+ Organism=
+ BoxBorder= (RRGGBB hex, default: black)
+ BoxColor= (RRGGBB hex, default: white)
+ BoxWidth= (integer, in px)
+ CommentPrefix= (will precede back-reference to prior source)
+ LabelPrefix= (precedes current gene label)
+ X-Offset= (integer, in px)
+ Y-Offset= (integer, in px)
+
+=head1 AUTHORS
+
+Justin Preece and Mamatha Hanumappa
+ Faculty Research Assistants
+ Jaiswal Lab, Botany & Plant Pathology
+ Oregon State University
+ L<mailto:preecej@science.oregonstate.edu>
+ L<mailto:hanumapm@science.oregonstate.edu>
+
+=cut
+
+# ---------------------------------------------------------------------------
+# modules
+# ---------------------------------------------------------------------------
+
+# general
+use strict;
+use Cwd;
+use Switch;
+use Getopt::Std;
+
+# specific
+use XML::DOM;
+
+# ---------------------------------------------------------------------------
+# declarations
+# ---------------------------------------------------------------------------
+
+my %opts; # arg options
+my $input_file;
+my $output_file;
+my $verbose = 0; # flag for verbose output
+my $debug = 0; # debugging switch
+
+my $gpml_doc;
+
+# ---------------------------------------------------------------------------
+# functions
+# ---------------------------------------------------------------------------
+
+
+# ---------------------------------------------------------------------------
+sub init
+{
+ # read and set options
+ getopts('i:o:vd', \%opts);
+
+ foreach my $key (keys %opts) {
+ my $value = $opts{$key};
+ switch ($key) {
+ case "i" {
+ if ($value =~ /\//) { # assume path
+ $input_file = $value;
+ } else {
+ $input_file = getcwd() . "\/$value";
+ }
+ }
+ case "o" {
+ if ($value =~ /\//) { # assume path
+ $output_file = $value;
+ } else {
+ $output_file = getcwd() . "\/$value";
+ }
+ }
+ case "v" { $verbose = 1; }
+
+ case "d" { $debug = 1; }
+ }
+ }
+
+ system "clear";
+ print "\n"
+ . "------------------------------------------------------------\n"
+ . "------------------ Pathway Gene Swapper --------------------\n"
+ . "------------------------------------------------------------\n"
+ . "\n"
+ . "Input File: $input_file\n"
+ . "Output File: $output_file\n"
+ . "Running in verbose mode? " . ($verbose ? "Yes" : "No") . "\n"
+ . "Running in debug mode? " . ($verbose ? "Yes" : "No") . "\n"
+ . "\n"
+ . "------------------------------------------------------------\n"
+ . "------------------------------------------------------------\n"
+ . "------------------------------------------------------------\n"
+ . "\n";
+}
+
+
+# read, parse, and store source GPML
+# ---------------------------------------------------------------------------
+sub import_data
+{
+ print "Opening input file and reading header info...\n\n";
+}
+
+
+# spit out the data to make sure you've read in the files correctly
+# ---------------------------------------------------------------------------
+sub show_input
+{
+ print "[Source GPML]\n";
+ print "\n";
+}
+
+# substitute gene data
+# ---------------------------------------------------------------------------
+sub swap_genes
+{
+ print "Swapping gene data...\n";
+
+ # -------------------------------------------------------------------------
+ # [PathVisio Perl Pseudo-Script]
+ # -------------------------------------------------------------------------
+ # .remove all <BiopaxRef> and <bp:PublicationXref> elements and children
+ # .identify mapped genes
+ # .if mapped gene did not belong to a group, create new group node
+ # .duplicate <DataNode> for each mapping
+ # .create new 5-digit hex code "GraphId"
+ # .if needed, add new group node (create new 5-digit hex code)
+ # .add "GroupRef" on each added node, including the orig.
+ # .rename TextLabel (prefix: Eu-, suffix: -#?)
+ # .add Comment back-referencing TAIR locus id (use "source" attribute)
+ # .edit <Xref Database="JGI" ID="Egrandis..." />
+ # .decrement the Z-order
+ # .decrement CenterX and CenterY by 10px each
+ # .change box Width if needed
+ # .color the box (<Graphics...Color="4488ff" />)
+ # .After PathVisio sanity check:
+ # .remove back-ref TAIR comments
+
+
+ # -------------------------------------------------------------------------
+ # [XML::DOM]
+ # -------------------------------------------------------------------------
+ # my $parser = new XML::DOM::Parser;
+ # my $doc = $parser->parsefile ("file.xml");
+
+ # # print all HREF attributes of all CODEBASE elements
+ # my $nodes = $doc->getElementsByTagName ("CODEBASE");
+ # my $n = $nodes->getLength;
+
+ # for (my $i = 0; $i < $n; $i++)
+ # {
+ # my $node = $nodes->item ($i);
+ # my $href = $node->getAttributeNode ("HREF");
+ # print $href->getValue . "\n";
+ # }
+
+ # # Print doc file
+ # $doc->printToFile ("out.xml");
+
+ # # Print to string
+ # print $doc->toString;
+
+ # # Avoid memory leaks - cleanup circular references for garbage collection
+ # $doc->dispose;
+
+}
+
+# display the transformed data
+# ---------------------------------------------------------------------------
+sub show_output
+{
+ print "Writing GPML to new output file...\n";
+ print "\n";
+}
+
+# ---------------------------------------------------------------------------
+# main
+# ---------------------------------------------------------------------------
+
+init;
+import_data;
+if ($verbose) { show_input; }
+swap_genes();
+if ($verbose) { show_output; }
+
+exit;
+