Mercurial > repos > fcaramia > methylation_analysis_bismark
comparison methylation_analysis/methylation_extractor_wrapper.pl @ 4:282edadee017 draft
Uploaded
author | fcaramia |
---|---|
date | Mon, 03 Dec 2012 18:26:25 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
3:d0fc260f6dc9 | 4:282edadee017 |
---|---|
1 use strict; | |
2 use warnings; | |
3 use File::Basename; | |
4 use Cwd; | |
5 use File::Path qw(make_path remove_tree); | |
6 die qq( | |
7 Bad numbr of inputs | |
8 | |
9 ) if(!@ARGV); | |
10 | |
11 my @bam_list_entries; | |
12 | |
13 my $player_options = ""; | |
14 my $bam_file; | |
15 my $ending; | |
16 my $genome; | |
17 my $summary ; | |
18 my $output; | |
19 | |
20 foreach my $input (@ARGV) | |
21 { | |
22 my @tmp = split "::", $input; | |
23 if($tmp[0] eq "GENOME") | |
24 { | |
25 $genome=$tmp[1]; | |
26 } | |
27 elsif($tmp[0] eq "OPTION") | |
28 { | |
29 $player_options = "$player_options ${tmp[1]}"; | |
30 } | |
31 elsif($tmp[0] eq "ENDING") | |
32 { | |
33 $ending = $tmp[1]; | |
34 } | |
35 elsif($tmp[0] eq "BAMFILE") | |
36 { | |
37 $bam_file = $tmp[1]; | |
38 } | |
39 elsif($tmp[0] eq "SUMMARY") | |
40 { | |
41 $summary = $tmp[1]; | |
42 } | |
43 elsif($tmp[0] eq "OUTPUT") | |
44 { | |
45 $output = $tmp[1]; | |
46 } | |
47 else | |
48 { | |
49 die("Unknown Input: $input\n"); | |
50 } | |
51 } | |
52 | |
53 | |
54 my $working_dir = cwd(); | |
55 | |
56 #convert bam to sam | |
57 my $sam_file = "$working_dir/coverted.sam"; | |
58 system("samtools view -h $bam_file > $sam_file"); | |
59 | |
60 #run bismark | |
61 | |
62 system ("bismark_methylation_extractor $ending $player_options --genome_folder $genome $sam_file > $summary 2>&1"); | |
63 | |
64 move_files($working_dir); | |
65 | |
66 sub move_files | |
67 { | |
68 my $name; | |
69 my $suffix; | |
70 my $path; | |
71 my $local_dir = $_[0]; | |
72 opendir(DIR, $local_dir); | |
73 #print ("Openning: $local_dir\n"); | |
74 my @FILES= readdir(DIR); | |
75 closedir(DIR); | |
76 foreach my $file (@FILES) | |
77 { | |
78 if ($file eq "." || $file eq "..") | |
79 { | |
80 #print ("./ or ../ skipped\n"); | |
81 } | |
82 elsif (-d "$local_dir/$file") | |
83 { | |
84 #print ("moving to: $local_dir/$file\n"); | |
85 move_files("$local_dir/$file"); | |
86 } | |
87 elsif (-f "$local_dir/$file") | |
88 { | |
89 ($name,$path,$suffix) = fileparse($file,qr"\.[^.]*$"); | |
90 if ($suffix eq ".bedGraph") | |
91 { | |
92 system ("mv $local_dir/$file $output"); | |
93 } | |
94 } | |
95 else | |
96 { | |
97 die("Unrecognized file generated: $file\n"); | |
98 } | |
99 | |
100 } | |
101 } | |
102 | |
103 | |
104 | |
105 | |
106 |