Hello!

To see the file structure, click on "tree".

Note that updates take place every 10 minutes, commits may not be seen immediately.
Added commentary amd config file read-in
authorpreecej <preecej@localhost>
Thu, 28 Jul 2011 21:37:04 +0000 (21:37 +0000)
committerpreecej <preecej@localhost>
Thu, 28 Jul 2011 21:37:04 +0000 (21:37 +0000)
svn path=/; revision=128

preecej/perl_singletons/pathway_gene_swapper.pl

index ca17c35398d64f4ce7f63892d7dfd7a56616b41d..46aa49756dedade418e78d59acd467ff52cb3670 100644 (file)
@@ -32,9 +32,20 @@ pathway_gene_swapper.pl -i INPUT_FILE -g GENE_FILE -c CONFIG_FILE -o OUTPUT_FILE
 
     - 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 CSV file must have a single-line column header.
+        
+        The first column must have one and only one gene -- the 
+        "original" gene.
+        
+        The second column may have one or more genes or gene variants
+        -- the "replacement" gene(s).
+        
+        If the second column contains multiple genes or gene variants,
+        multiple PathVisio boxes will be drawn in place of the 
+        original.
+    
     - The config file may have any or all of the following entries:
+
         Title=
         MaintainedBy=
         Organism=
@@ -66,6 +77,7 @@ use strict;
 use Cwd;
 use Switch;
 use Getopt::Std;
+use Data::Dumper;
 
 # specific
 use XML::DOM;
@@ -74,6 +86,7 @@ use XML::DOM;
 # declarations
 # ---------------------------------------------------------------------------
 
+# command-line options
 my %opts; # arg options
 my $input_gpml_file;
 my $input_gene_file;
@@ -82,13 +95,55 @@ my $output_file;
 my $verbose = 0; # flag for verbose output
 my $debug = 0; # debugging switch
 
-my $gpml_doc;
+# global data containers
+my %configs; # holds global configuration settings
+my $gpml_doc; #holds imported GPML data for manipulation and output
+
+$Data::Dumper::Pad = "... "; 
+
+# ---------------------------------------------------------------------------
+=head1 FUNCTIONS
+
+=over
+
+=cut
+# ---------------------------------------------------------------------------
+
 
 # ---------------------------------------------------------------------------
-# functions
+=item B<hash config($file_path)>
+Reads a configuration file and sets config values.
+Returns a hash with config values set.
+=cut
 # ---------------------------------------------------------------------------
+sub config($)
+{
+    if ($debug) { print "...Config file path: $_[0]\n"; }
+
+    my %local_config_hash;
+
+    open(CONFIG_FILE, $_[0]) or die("Could not open $_[0]");
+    
+    while (<CONFIG_FILE>)
+    {
+       my $line = $_;
+       chomp $line;
+       my @line_ary = split('=',$line);
+       my $data_field = $line_ary[0];
+       my $data_val = $line_ary[1];
+
+       $local_config_hash{$data_field} = $data_val; 
+    }
+    
+    return %local_config_hash;
+}
 
 
+# ---------------------------------------------------------------------------
+=item B<void init()>
+Reads in command-line values, calls for config settings, and begins
+screen output.
+=cut
 # ---------------------------------------------------------------------------
 sub init
 {
@@ -112,14 +167,14 @@ sub init
                     $input_gene_file = getcwd() . "\/$value";
                 }
             }
-              case "c" { 
+            case "c" { 
                 if ($value =~ /\//) { # assume path
                     $input_config_file = $value;
                 } else {
                     $input_config_file = getcwd() . "\/$value";
                 }
             }
-              case "o" {
+            case "o" {
                 if ($value =~ /\//) { # assume path
                     $output_file = $value;
                 } else {
@@ -131,28 +186,40 @@ sub init
             case "d" { $debug = 1; }
         }
     }
-    
+
     system "clear";
     print "\n"
         . "------------------------------------------------------------\n"
         . "------------------ Pathway Gene Swapper --------------------\n"
         . "------------------------------------------------------------\n"
         . "\n"
-        . "Input File: $input_gpml_file\n"
-       . "            $input_gene_file\n"
-       . "            $input_config_file\n"
+        . "Input Files:\n"
+        . "    - PathVisio File (GPML):  $input_gpml_file\n"
+        . "    - Gene List (CSV):        $input_gene_file\n"
+        . "    - Configuration settings: $input_config_file\n"
+        . "\n"
         . "Output File: $output_file\n"
+        . "\n"
         . "Running in verbose mode? " . ($verbose ? "Yes" : "No") . "\n"
-        . "Running in debug mode? " . ($verbose ? "Yes" : "No") . "\n"
+        . "Running in debug mode? " . ($debug ? "Yes" : "No") . "\n"
         . "\n"
         . "------------------------------------------------------------\n"
         . "------------------------------------------------------------\n"
         . "------------------------------------------------------------\n"
         . "\n";
+
+    %configs = config($input_config_file);
+    
+    if ($debug) { print "...<DEBUG: \%configs>\n"
+        . Dumper(\%configs) . "\n\n"; }
 }
 
 
-# read, parse, and store source GPML
+
+# ---------------------------------------------------------------------------
+=item B<void import_data()>
+Reads, parses, and stores source GPML.
+=cut
 # ---------------------------------------------------------------------------
 sub import_data
 {
@@ -160,7 +227,11 @@ sub import_data
 }
 
 
-# spit out the data to make sure you've read in the files correctly
+# ---------------------------------------------------------------------------
+=item B<void show_input()>
+Spits out the data to make sure you've read in the files correctly.
+Verbose only.
+=cut
 # ---------------------------------------------------------------------------
 sub show_input
 {
@@ -168,11 +239,14 @@ sub show_input
     print "\n";
 }
 
-# substitute gene data
+# ---------------------------------------------------------------------------
+=item B<void swap_genes()>
+Substitutes gene data.
+=cut
 # ---------------------------------------------------------------------------
 sub swap_genes
 {
-    print "Swapping gene data...\n";
+    print "Swapping gene data...\n\n";
         
     # -------------------------------------------------------------------------
     # [PathVisio Perl Pseudo-Script]
@@ -223,14 +297,31 @@ sub swap_genes
 
 }
 
-# display the transformed data
+# ---------------------------------------------------------------------------
+=item B<void show_output()>
+Displays the transformed data. Verbose only.
+=cut
 # ---------------------------------------------------------------------------
 sub show_output
+{
+    print "[Modified GPML]\n";
+    print "\n";
+}
+
+# ---------------------------------------------------------------------------
+=item B<void export_data()>
+Writes the transformed GPML doc out to the specified output file.
+=cut
+# ---------------------------------------------------------------------------
+sub export_data
 {
     print "Writing GPML to new output file...\n";
     print "\n";
 }
 
+=back
+=cut
+
 # ---------------------------------------------------------------------------
 # main
 # ---------------------------------------------------------------------------
@@ -240,6 +331,6 @@ import_data;
 if ($verbose) { show_input; }
 swap_genes();
 if ($verbose) { show_output; }
-
+export_data;
 exit;