diff methylation_analysis/bismark_wrapper.pl @ 4:282edadee017 draft

Uploaded
author fcaramia
date Mon, 03 Dec 2012 18:26:25 -0500
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/methylation_analysis/bismark_wrapper.pl	Mon Dec 03 18:26:25 2012 -0500
@@ -0,0 +1,133 @@
+use strict;
+use warnings;
+use File::Basename; 
+use Cwd;
+use File::Path qw(make_path remove_tree);
+die qq(
+Bad numbr of inputs
+
+) if(!@ARGV);
+
+my @bam_list_entries;
+
+my $player_options = "--bowtie2 -p 4 ";
+my $bam_output;
+my $summary;
+my $genome;
+my $singles = "";
+my $mates1 = "";
+my $mates2 = "";
+my $directional="";
+my $format="";
+my $log_file="";
+
+
+foreach my $input (@ARGV) 
+{
+	my @tmp = split "::", $input;
+	if($tmp[0] eq "GENOME") 
+	{
+		$genome=$tmp[1];	
+	} 
+	elsif($tmp[0] eq "MATES") 
+	{
+		$mates1 = $tmp[1];
+		$mates2 = $tmp[2];
+	}
+	elsif($tmp[0] eq "SINGLES") 
+	{
+		$singles = $tmp[1];
+	} 
+	elsif($tmp[0] eq "FORMAT") 
+	{
+		$format = $tmp[1];
+	} 
+	elsif($tmp[0] eq "DIRECTIONAL") 
+	{
+		$directional = $tmp[1];
+	} 
+	elsif($tmp[0] eq "SUMMARY") 
+	{
+		$summary = $tmp[1];
+	} 
+        elsif($tmp[0] eq "OUTPUT") 
+	{
+		$bam_output = $tmp[1];
+	} 
+
+	else 
+	{
+		die("Unknown Input: $input\n");
+	}
+}
+
+
+my $working_dir = cwd()."/BISMARK_OUTPUT";
+make_path($working_dir);
+
+
+#run bismark 
+
+if ($singles eq "")
+{
+	system ("bismark $player_options $directional $format $genome -o $working_dir -1 $mates1 -2 $mates2 > $summary 2>&1 ");
+	
+}
+else
+{
+	system ("bismark $player_options $directional $format $genome -o $working_dir $singles > $summary 2>&1");
+	
+}
+
+
+move_files($working_dir);
+
+
+sub move_files
+{
+	my $name;
+	my $suffix;
+	my $path;
+	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")
+		{
+			($name,$path,$suffix) = fileparse($file,qr"\.[^.]*$");
+			if ($suffix eq ".sam")
+			{
+				#converto to BAM and Delete SAM
+				system ("MergeSamFiles.sh MAX_RECORDS_IN_RAM=2000000 I=$local_dir/$file O=$bam_output VALIDATION_STRINGENCY=LENIENT SO=coordinate USE_THREADING=true CREATE_INDEX=true > /dev/null 2>&1");
+				system ("rm -rf $local_dir/$file");
+				
+			}
+			elsif($suffix eq ".txt")
+			{
+				system ("mv $local_dir/$file $summary");
+			}
+		}
+		else
+		{
+			die("Unrecognized file generated: $file\n");
+		}
+		
+	}
+}
+
+
+
+
+