diff contra_wrapper.pl @ 25:c361b3fb806e

added Nicola Path 2.0
author Franco Caramia <franco.caramia@petermac.org>
date Tue, 03 Jun 2014 17:31:28 +1000
parents 2770f49cb0dc
children 00278c5fe014
line wrap: on
line diff
--- a/contra_wrapper.pl	Mon May 19 20:00:44 2014 -0400
+++ b/contra_wrapper.pl	Tue Jun 03 17:31:28 2014 +1000
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use FindBin;
+use Find;
 use File::Path qw(make_path);
 use File::Spec;
 
@@ -22,7 +22,7 @@
 	{
 		my $variable = $tmp[1];
 		$variable =~ s/=/ /g;
-		print "$variable\n";
+		
 		$player_options = "$player_options $variable";
 	}
 	elsif($tmp[0] eq "CONTRAOUTPUT") 
@@ -40,52 +40,28 @@
 }
 
 
-my $working_dir = "CONTRA_OUTPUT";
+
+my $working_dir = File::Spec->catfile($contra_dir, 'CONTRA_OUTPUT');
 make_path($contra_dir);
 #remove extension
 
-#run contra 
-system(File::Spec->catfile($FindBin::Bin, 'contra.py') . " -o $working_dir $player_options > /dev/null 2>&1");
+my $cmd = "contra.py -o $working_dir $player_options";
+print "Command to be executed: $cmd\n";
+system($cmd);
 
 #set html
 #print "$contra_output - $working_dir\n";
 open(HTML, ">$contra_output");
 print HTML "<html><head><title>Contra: Copy Number Analysis for Targeted Resequencing</title></head><body><h3>Contra Output Files:</h3><p><ul>\n";
-move_files($working_dir);
+find({wanted => \&add_file, preprocess => sub {sort @_}}, $working_dir);
 print HTML "</ul></p>\n";
 close(HTML);
 
-sub move_files
-{
-	my $local_dir = $_[0];
-	opendir(DIR, $local_dir);
-	#print ("Openning: $local_dir\n");
-	my @FILES= readdir(DIR); 
-	closedir(DIR);
-	foreach my $file (@FILES) 
-	{
-		if ($file eq "." || $file eq "..")
-		{
-			#print ("./ or ../ skipped\n");
-		}
-		elsif (-d "$local_dir/$file")
-		{
-			#print ("moving to: $local_dir/$file\n");
-			move_files("$local_dir/$file");
-		}
-		elsif (-f "$local_dir/$file")
-		{
-			#print ("mv $local_dir/$file $contra_dir\n");
-			print HTML "<li><a href=$file>$file</a></li>\n";
-			system ("mv $local_dir/$file $contra_dir");
-		}
-		else
-		{
-			die("Unrecognized file generated: $file\n");
-		}
-		
-		
-	}
-	
+sub add_file {
+	if (-f $File::Find::name) {
+		my $rel_path = File::Spec->abs2rel($File::Find::name, $working_dir);
+		print ("adding $rel_path\n");
+		print HTML "<li><a href=\"CONTRA_OUTPUT/$rel_path\">$rel_path</a></li>\n";
+ 	}
 }