annotate methylation_analysis/bismark_wrapper.pl @ 5:23fed0cf09f4 draft

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