comparison methylation_analysis_bismark/methylation_analysis/bismark_wrapper.pl @ 9:5b208d4d89e5 draft

Uploaded
author fcaramia
date Tue, 04 Dec 2012 20:15:26 -0500
parents d15b4a2e3bdc
children
comparison
equal deleted inserted replaced
8:4c5c3994bfcb 9:5b208d4d89e5
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 = "--bowtie2 -p 4 ";
14 my $bam_output;
15 my $summary;
16 my $genome;
17 my $singles = "";
18 my $mates1 = "";
19 my $mates2 = "";
20 my $directional="";
21 my $format="";
22 my $log_file="";
23
24
25 foreach my $input (@ARGV)
26 {
27 my @tmp = split "::", $input;
28 if($tmp[0] eq "GENOME")
29 {
30 $genome=$tmp[1];
31 }
32 elsif($tmp[0] eq "MATES")
33 {
34 $mates1 = $tmp[1];
35 $mates2 = $tmp[2];
36 }
37 elsif($tmp[0] eq "SINGLES")
38 {
39 $singles = $tmp[1];
40 }
41 elsif($tmp[0] eq "FORMAT")
42 {
43 $format = $tmp[1];
44 }
45 elsif($tmp[0] eq "DIRECTIONAL")
46 {
47 $directional = $tmp[1];
48 }
49 elsif($tmp[0] eq "SUMMARY")
50 {
51 $summary = $tmp[1];
52 }
53 elsif($tmp[0] eq "OUTPUT")
54 {
55 $bam_output = $tmp[1];
56 }
57
58 else
59 {
60 die("Unknown Input: $input\n");
61 }
62 }
63
64
65 my $working_dir = cwd()."/BISMARK_OUTPUT";
66 make_path($working_dir);
67
68
69 #run bismark
70
71 if ($singles eq "")
72 {
73 system ("bismark $player_options $directional $format $genome -o $working_dir -1 $mates1 -2 $mates2 > $summary 2>&1 ");
74
75 }
76 else
77 {
78 system ("bismark $player_options $directional $format $genome -o $working_dir $singles > $summary 2>&1");
79
80 }
81
82
83 move_files($working_dir);
84
85
86 sub move_files
87 {
88 my $name;
89 my $suffix;
90 my $path;
91 my $local_dir = $_[0];
92 opendir(DIR, $local_dir);
93 #print ("Openning: $local_dir\n");
94 my @FILES= readdir(DIR);
95 closedir(DIR);
96 foreach my $file (@FILES)
97 {
98 if ($file eq "." || $file eq "..")
99 {
100 #print ("./ or ../ skipped\n");
101 }
102 elsif (-d "$local_dir/$file")
103 {
104 #print ("moving to: $local_dir/$file\n");
105 move_files("$local_dir/$file");
106 }
107 elsif (-f "$local_dir/$file")
108 {
109 ($name,$path,$suffix) = fileparse($file,qr"\.[^.]*$");
110 if ($suffix eq ".sam")
111 {
112 #converto to BAM and Delete SAM
113 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");
114 system ("rm -rf $local_dir/$file");
115
116 }
117 elsif($suffix eq ".txt")
118 {
119 system ("mv $local_dir/$file $summary");
120 }
121 }
122 else
123 {
124 die("Unrecognized file generated: $file\n");
125 }
126
127 }
128 }
129
130
131
132
133