Mercurial > repos > fcaramia > methylation_analysis_bismark
diff methylation_analysis/methylation_extractor_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/methylation_extractor_wrapper.pl Mon Dec 03 18:26:25 2012 -0500 @@ -0,0 +1,106 @@ +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 = ""; +my $bam_file; +my $ending; +my $genome; +my $summary ; +my $output; + +foreach my $input (@ARGV) +{ + my @tmp = split "::", $input; + if($tmp[0] eq "GENOME") + { + $genome=$tmp[1]; + } + elsif($tmp[0] eq "OPTION") + { + $player_options = "$player_options ${tmp[1]}"; + } + elsif($tmp[0] eq "ENDING") + { + $ending = $tmp[1]; + } + elsif($tmp[0] eq "BAMFILE") + { + $bam_file = $tmp[1]; + } + elsif($tmp[0] eq "SUMMARY") + { + $summary = $tmp[1]; + } + elsif($tmp[0] eq "OUTPUT") + { + $output = $tmp[1]; + } + else + { + die("Unknown Input: $input\n"); + } +} + + +my $working_dir = cwd(); + +#convert bam to sam +my $sam_file = "$working_dir/coverted.sam"; +system("samtools view -h $bam_file > $sam_file"); + +#run bismark + +system ("bismark_methylation_extractor $ending $player_options --genome_folder $genome $sam_file > $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 ".bedGraph") + { + system ("mv $local_dir/$file $output"); + } + } + else + { + die("Unrecognized file generated: $file\n"); + } + + } +} + + + + +