annotate bismark_methylation_extractor @ 0:62c6da72dd4a draft

Uploaded
author bgruening
date Sat, 06 Jul 2013 09:57:36 -0400
parents
children 91f07ff056ca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1 #!/usr/bin/perl
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2 use warnings;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3 use strict;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
4 $|++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
5 use Getopt::Long;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
6 use Cwd;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
7 use Carp;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
8 use FindBin qw($Bin);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
9 use lib "$Bin/../lib";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
10
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
11 ## This program is Copyright (C) 2010-13, Felix Krueger (felix.krueger@babraham.ac.uk)
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
12
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
13 ## This program is free software: you can redistribute it and/or modify
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
14 ## it under the terms of the GNU General Public License as published by
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
15 ## the Free Software Foundation, either version 3 of the License, or
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
16 ## (at your option) any later version.
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
17
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
18 ## This program is distributed in the hope that it will be useful,
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
19 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
20 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
21 ## GNU General Public License for more details.
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
22
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
23 ## You should have received a copy of the GNU General Public License
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
24 ## along with this program. If not, see <http://www.gnu.org/licenses/>.
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
25
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
26 my @filenames; # input files
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
27 my %counting;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
28 my $parent_dir = getcwd();
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
29
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
30 my %fhs;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
31
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
32 my $version = 'v0.7.11';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
33 my ($ignore,$genomic_fasta,$single,$paired,$full,$report,$no_overlap,$merge_non_CpG,$vanilla,$output_dir,$no_header,$bedGraph,$remove,$coverage_threshold,$counts,$cytosine_report,$genome_folder,$zero,$CpG_only,$CX_context,$split_by_chromosome,$sort_size,$samtools_path,$gzip) = process_commandline();
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
34
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
35
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
36 ### only needed for bedGraph output
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
37 my @sorting_files; # if files are to be written to bedGraph format, these are the methylation extractor output files
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
38 my @methylcalls = qw (0 0 0); # [0] = methylated, [1] = unmethylated, [2] = total
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
39 my @bedfiles;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
40
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
41 ### only needed for genome-wide cytosine methylation report
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
42 my %chromosomes;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
43
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
44 ##############################################################################################
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
45 ### Summarising Run Parameters
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
46 ##############################################################################################
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
47
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
48 ### METHYLATION EXTRACTOR
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
49
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
50 warn "Summarising Bismark methylation extractor parameters:\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
51 warn '='x63,"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
52
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
53 if ($single){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
54 if ($vanilla){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
55 warn "Bismark single-end vanilla format specified\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
56 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
57 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
58 warn "Bismark single-end SAM format specified (default)\n"; # default
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
59 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
60 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
61 elsif ($paired){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
62 if ($vanilla){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
63 warn "Bismark paired-end vanilla format specified\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
64 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
65 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
66 warn "Bismark paired-end SAM format specified (default)\n"; # default
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
67 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
68 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
69
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
70 if ($ignore){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
71 warn "First $ignore bases will be disregarded when processing the methylation call string\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
72 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
73
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
74 if ($full){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
75 warn "Strand-specific outputs will be skipped. Separate output files for cytosines in CpG, CHG and CHH context will be generated\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
76 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
77 if ($merge_non_CpG){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
78 warn "Merge CHG and CHH context to non-CpG context specified\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
79 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
80 ### output directory
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
81 if ($output_dir eq ''){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
82 warn "Output will be written to the current directory ('$parent_dir')\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
83 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
84 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
85 warn "Output path specified as: $output_dir\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
86 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
87
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
88
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
89 sleep (1);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
90
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
91 ### BEDGRAPH
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
92
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
93 if ($bedGraph){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
94 warn "\n\nSummarising bedGraph parameters:\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
95 warn '='x63,"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
96
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
97 if ($counts){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
98 warn "Generating additional output in bedGraph format including methylating counts (output format: <Chromosome> <Start Position> <End Position> <Methylation Percentage> <count methylated> <count non-methylated>)\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
99 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
100 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
101 warn "Generating additional sorted output in bedGraph format (output format: <Chromosome> <Start Position> <End Position> <Methylation Percentage>)\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
102 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
103
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
104 warn "Using a cutoff of $coverage_threshold read(s) to report cytosine positions\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
105
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
106 if ($CX_context){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
107 warn "Reporting and sorting methylation information for all cytosine context (sorting may take a long time, you have been warned ...)\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
108 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
109 else{ # default
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
110 $CpG_only = 1;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
111 warn "Reporting and sorting cytosine methylation information in CpG context only (default)\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
112 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
113
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
114 if ($remove){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
115 warn "White spaces in read ID names will be removed prior to sorting\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
116 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
117
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
118 if (defined $sort_size){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
119 warn "The bedGraph UNIX sort command will use the following memory setting:\t'$sort_size'. Temporary directory used for sorting is the output directory\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
120 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
121 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
122 warn "Setting a default memory usage for the bedGraph UNIX sort command to 2GB\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
123 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
124
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
125
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
126
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
127 sleep (1);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
128
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
129 if ($cytosine_report){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
130 warn "\n\nSummarising genome-wide cytosine methylation report parameters:\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
131 warn '='x63,"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
132 warn "Generating comprehensive genome-wide cytosine report\n(output format: <Chromosome> <Position> <Strand> <count methylated> <count non-methylated> <C-context> <trinucleotide context> )\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
133
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
134
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
135 if ($CX_context){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
136 warn "Reporting methylation for all cytosine contexts. Be aware that this will generate enormous files\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
137 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
138 else{ # default
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
139 $CpG_only = 1;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
140 warn "Reporting cytosine methylation in CpG context only (default)\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
141 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
142
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
143 if ($split_by_chromosome){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
144 warn "Splitting the cytosine report output up into individual files for each chromosome\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
145 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
146
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
147 ### Zero-based coordinates
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
148 if ($zero){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
149 warn "Using zero-based genomic coordinates (user-defined)\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
150 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
151 else{ # default, 1-based coords
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
152 warn "Using 1-based genomic coordinates (default)\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
153 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
154
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
155 ### GENOME folder
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
156 if ($genome_folder){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
157 unless ($genome_folder =~/\/$/){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
158 $genome_folder =~ s/$/\//;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
159 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
160 warn "Genome folder was specified as $genome_folder\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
161 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
162 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
163 $genome_folder = '/data/public/Genomes/Mouse/NCBIM37/';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
164 warn "Using the default genome folder /data/public/Genomes/Mouse/NCBIM37/\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
165 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
166 sleep (1);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
167 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
168 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
169
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
170 warn "\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
171 sleep (5);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
172
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
173 ######################################################
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
174 ### PROCESSING FILES
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
175 ######################################################
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
176
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
177 foreach my $filename (@filenames){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
178 # resetting counters and filehandles
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
179 %fhs = ();
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
180 %counting =(
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
181 total_meCHG_count => 0,
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
182 total_meCHH_count => 0,
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
183 total_meCpG_count => 0,
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
184 total_unmethylated_CHG_count => 0,
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
185 total_unmethylated_CHH_count => 0,
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
186 total_unmethylated_CpG_count => 0,
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
187 sequences_count => 0,
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
188 );
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
189 @sorting_files = ();
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
190 @bedfiles = ();
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
191
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
192 process_Bismark_results_file($filename);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
193
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
194 ### Closing all filehandles so that the Bismark methylation extractor output doesn't get truncated due to buffering issues
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
195 foreach my $fh (keys %fhs) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
196 if ($fh =~ /^[1230]$/) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
197 foreach my $context (keys %{$fhs{$fh}}) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
198 close $fhs{$fh}->{$context} or die $!;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
199
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
200 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
201 } else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
202 close $fhs{$fh} or die $!;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
203 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
204 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
205
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
206 if ($bedGraph){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
207
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
208 my $out = (split (/\//,$filename))[-1]; # extracting the filename if a full path was specified
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
209 $out =~ s/gz$//;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
210 $out =~ s/sam$//;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
211 $out =~ s/bam$//;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
212 $out =~ s/txt$//;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
213 $out =~ s/$/bedGraph/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
214
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
215
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
216
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
217 my $bedGraph_output = $out;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
218 my @args;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
219
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
220 if ($remove){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
221 push @args, '--remove';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
222 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
223 if ($CX_context){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
224 push @args, '--CX_context';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
225 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
226 if ($no_header){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
227 push @args, '--no_header';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
228 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
229 if ($counts){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
230 push @args, "--counts";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
231 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
232
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
233 push @args, "--buffer_size $sort_size";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
234 push @args, "--cutoff $coverage_threshold";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
235 push @args, "--output $bedGraph_output";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
236 push @args, "--dir '$output_dir'";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
237
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
238 ### adding all files to be sorted to @args
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
239 foreach my $f (@sorting_files){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
240 push @args, $f;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
241 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
242
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
243 # print join "\t",@args,"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
244
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
245 system ("$Bin/bismark2bedGraph @args");
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
246
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
247 warn "Finished BedGraph conversion ...\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
248 sleep(3);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
249
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
250 # open (OUT,'>',$output_dir.$bedGraph_output) or die "Problems with the bedGraph output filename detected: file path: '$output_dir'\tfile name: '$bedGraph_output' $!";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
251 # warn "Writing bedGraph to file: $bedGraph_output\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
252 # process_bedGraph_output();
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
253 # close OUT or die $!;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
254
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
255 ### genome-wide cytosine methylation report requires bedGraph processing anyway
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
256 if ($cytosine_report){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
257 @args = (); # resetting @args
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
258 my $cytosine_out = $out;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
259 $cytosine_out =~ s/bedGraph$//;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
260
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
261 if ($CX_context){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
262 $cytosine_out =~ s/$/CX_report.txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
263 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
264 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
265 $cytosine_out =~ s/$/CpG_report.txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
266 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
267
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
268 push @args, "--output $cytosine_out";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
269 push @args, "--dir '$output_dir'";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
270 push @args, "--genome '$genome_folder'";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
271 push @args, "--parent_dir '$parent_dir'";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
272
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
273 if ($zero){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
274 push @args, "--zero";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
275 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
276 if ($CX_context){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
277 push @args, '--CX_context';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
278 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
279 if ($split_by_chromosome){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
280 push @args, '--split_by_chromosome';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
281 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
282
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
283 push @args, $bedGraph_output; # this will be the infile
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
284
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
285 system ("$Bin/bedGraph2cytosine @args");
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
286 # generate_genome_wide_cytosine_report($bedGraph_output,$cytosine_out);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
287 warn "\n\nFinished generating genome-wide cytosine report\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
288 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
289 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
290 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
291
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
292
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
293 sub process_commandline{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
294 my $help;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
295 my $single_end;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
296 my $paired_end;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
297 my $ignore;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
298 my $genomic_fasta;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
299 my $full;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
300 my $report;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
301 my $extractor_version;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
302 my $no_overlap;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
303 my $merge_non_CpG;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
304 my $vanilla;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
305 my $output_dir;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
306 my $no_header;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
307 my $bedGraph;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
308 my $coverage_threshold = 1; # Minimum number of reads covering before calling methylation status
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
309 my $remove;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
310 my $counts;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
311 my $cytosine_report;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
312 my $genome_folder;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
313 my $zero;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
314 my $CpG_only;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
315 my $CX_context;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
316 my $split_by_chromosome;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
317 my $sort_size;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
318 my $samtools_path;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
319 my $gzip;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
320
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
321 my $command_line = GetOptions ('help|man' => \$help,
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
322 'p|paired-end' => \$paired_end,
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
323 's|single-end' => \$single_end,
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
324 'fasta' => \$genomic_fasta,
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
325 'ignore=i' => \$ignore,
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
326 'comprehensive' => \$full,
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
327 'report' => \$report,
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
328 'version' => \$extractor_version,
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
329 'no_overlap' => \$no_overlap,
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
330 'merge_non_CpG' => \$merge_non_CpG,
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
331 'vanilla' => \$vanilla,
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
332 'o|output=s' => \$output_dir,
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
333 'no_header' => \$no_header,
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
334 'bedGraph' => \$bedGraph,
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
335 "cutoff=i" => \$coverage_threshold,
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
336 "remove_spaces" => \$remove,
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
337 "counts" => \$counts,
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
338 "cytosine_report" => \$cytosine_report,
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
339 'g|genome_folder=s' => \$genome_folder,
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
340 "zero_based" => \$zero,
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
341 "CX|CX_context" => \$CX_context,
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
342 "split_by_chromosome" => \$split_by_chromosome,
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
343 "buffer_size=s" => \$sort_size,
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
344 'samtools_path=s' => \$samtools_path,
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
345 "gzip" => \$gzip,
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
346 );
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
347
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
348 ### EXIT ON ERROR if there were errors with any of the supplied options
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
349 unless ($command_line){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
350 die "Please respecify command line options\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
351 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
352
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
353 ### HELPFILE
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
354 if ($help){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
355 print_helpfile();
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
356 exit;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
357 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
358
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
359 if ($extractor_version){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
360 print << "VERSION";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
361
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
362
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
363 Bismark Methylation Extractor
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
364
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
365 Bismark Extractor Version: $version
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
366 Copyright 2010-13 Felix Krueger, Babraham Bioinformatics
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
367 www.bioinformatics.babraham.ac.uk/projects/bismark/
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
368
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
369
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
370 VERSION
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
371 exit;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
372 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
373
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
374
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
375 ### no files provided
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
376 unless (@ARGV){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
377 die "You need to provide one or more Bismark files to create an individual C methylation output. Please respecify!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
378 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
379 @filenames = @ARGV;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
380
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
381 warn "\n *** Bismark methylation extractor version $version ***\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
382
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
383 ### IGNORING <INT> bases at the start of the read when processing the methylation call string
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
384 unless ($ignore){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
385 $ignore = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
386 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
387 ### PRINT A REPORT
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
388 unless ($report){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
389 $report = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
390 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
391
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
392 ### OUTPUT DIR PATH
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
393 if ($output_dir){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
394 unless ($output_dir =~ /\/$/){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
395 $output_dir =~ s/$/\//;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
396 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
397 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
398 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
399 $output_dir = '';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
400 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
401
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
402 ### NO HEADER
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
403 unless ($no_header){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
404 $no_header = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
405 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
406
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
407 ### OLD (VANILLA) OUTPUT FORMAT
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
408 unless ($vanilla){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
409 $vanilla = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
410 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
411
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
412 if ($single_end){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
413 $paired_end = 0; ### SINGLE END ALIGNMENTS
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
414 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
415 elsif ($paired_end){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
416 $single_end = 0; ### PAIRED-END ALIGNMENTS
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
417 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
418 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
419 die "Please specify whether the supplied file(s) are in Bismark single-end or paired-end format\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
420 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
421
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
422 ### NO OVERLAP
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
423 if ($no_overlap){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
424 die "The option '--no_overlap' can only be specified for paired-end input!\n" unless ($paired_end);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
425 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
426 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
427 $no_overlap = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
428 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
429
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
430 ### COMPREHENSIVE OUTPUT
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
431 unless ($full){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
432 $full = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
433 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
434
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
435 ### MERGE NON-CpG context
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
436 unless ($merge_non_CpG){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
437 $merge_non_CpG = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
438 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
439
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
440 ### remove white spaces in read ID (needed for sorting using the sort command
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
441 unless ($remove){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
442 $remove = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
443 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
444
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
445 ### COVERAGE THRESHOLD FOR bedGraph OUTPUT
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
446 if (defined $coverage_threshold){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
447 unless ($coverage_threshold > 0){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
448 die "Please select a coverage greater than 0 (positive integers only)\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
449 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
450 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
451 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
452 $coverage_threshold = 1;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
453 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
454
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
455 ### SORT buffer size
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
456 if (defined $sort_size){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
457 unless ($sort_size =~ /^\d+\%$/ or $sort_size =~ /^\d+(K|M|G|T)$/){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
458 die "Please select a buffer size as percentage (e.g. --buffer_size 20%) or a number to be multiplied with K, M, G, T etc. (e.g. --buffer_size 20G). For more information on sort type 'info sort' on a command line\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
459 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
460 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
461 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
462 $sort_size = '2G';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
463 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
464
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
465 if ($zero){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
466 die "Option '--zero' is only available if '--cytosine_report' is specified as well. Please respecify\n" unless ($cytosine_report);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
467 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
468
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
469 if ($CX_context){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
470 die "Option '--CX_context' is only available if '--cytosine_report' or '--bedGraph' is specified as well. Please respecify\n" unless ($cytosine_report or $bedGraph);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
471 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
472 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
473 $CX_context = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
474 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
475
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
476 unless ($counts){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
477 $counts = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
478 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
479
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
480 if ($cytosine_report){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
481
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
482 ### GENOME folder
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
483 if ($genome_folder){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
484 unless ($genome_folder =~/\/$/){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
485 $genome_folder =~ s/$/\//;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
486 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
487 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
488 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
489 die "Please specify a genome folder to proceed (full path only)\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
490 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
491
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
492 unless ($bedGraph){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
493 warn "Setting the option '--bedGraph' since this is required for the genome-wide cytosine report\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
494 $bedGraph = 1;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
495 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
496 unless ($counts){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
497 warn "Setting the option '--counts' since this is required for the genome-wide cytosine report\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
498 $counts = 1;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
499 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
500 warn "\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
501 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
502
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
503 ### PATH TO SAMTOOLS
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
504 if (defined $samtools_path){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
505 # if Samtools was specified as full command
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
506 if ($samtools_path =~ /samtools$/){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
507 if (-e $samtools_path){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
508 # Samtools executable found
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
509 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
510 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
511 die "Could not find an installation of Samtools at the location $samtools_path. Please respecify\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
512 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
513 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
514 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
515 unless ($samtools_path =~ /\/$/){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
516 $samtools_path =~ s/$/\//;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
517 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
518 $samtools_path .= 'samtools';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
519 if (-e $samtools_path){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
520 # Samtools executable found
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
521 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
522 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
523 die "Could not find an installation of Samtools at the location $samtools_path. Please respecify\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
524 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
525 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
526 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
527 # Check whether Samtools is in the PATH if no path was supplied by the user
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
528 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
529 if (!system "which samtools >/dev/null 2>&1"){ # STDOUT is binned, STDERR is redirected to STDOUT. Returns 0 if Samtools is in the PATH
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
530 $samtools_path = `which samtools`;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
531 chomp $samtools_path;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
532 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
533 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
534
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
535 unless (defined $samtools_path){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
536 $samtools_path = '';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
537 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
538
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
539 return ($ignore,$genomic_fasta,$single_end,$paired_end,$full,$report,$no_overlap,$merge_non_CpG,$vanilla,$output_dir,$no_header,$bedGraph,$remove,$coverage_threshold,$counts,$cytosine_report,$genome_folder,$zero,$CpG_only,$CX_context,$split_by_chromosome,$sort_size,$samtools_path,$gzip);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
540 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
541
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
542
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
543 sub process_Bismark_results_file{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
544 my $filename = shift;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
545
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
546 warn "\nNow reading in Bismark result file $filename\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
547
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
548 if ($filename =~ /\.gz$/) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
549 open (IN,"zcat $filename |") or die "Can't open gzipped file $filename: $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
550 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
551 elsif ($filename =~ /bam$/) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
552 if ($samtools_path){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
553 open (IN,"$samtools_path view -h $filename |") or die "Can't open BAM file $filename: $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
554 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
555 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
556 die "Sorry couldn't find an installation of Samtools. Either specifiy an alternative path using the option '--samtools_path /your/path/', or use a SAM file instead\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
557 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
558 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
559 else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
560 open (IN,$filename) or die "Can't open file $filename: $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
561 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
562
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
563 ### Vanilla and SAM output need to read different numbers of header lines
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
564 if ($vanilla) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
565 my $bismark_version = <IN>; ## discarding the Bismark version info
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
566 chomp $bismark_version;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
567 $bismark_version =~ s/\r//; # replaces \r line feed
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
568 $bismark_version =~ s/Bismark version: //;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
569 if ($bismark_version =~ /^\@/) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
570 warn "Detected \@ as the first character of the version information. Is it possible that the file is in SAM format?\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
571 sleep (2);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
572 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
573
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
574 unless ($version eq $bismark_version){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
575 die "The methylation extractor and Bismark itself need to be of the same version!\n\nVersions used:\nmethylation extractor: '$version'\nBismark: '$bismark_version'\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
576 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
577 } else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
578 # If the read is in SAM format (default) it can either start with @ header lines or start with alignments directly.
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
579 # We are reading from it further down
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
580 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
581
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
582 my $output_filename = (split (/\//,$filename))[-1];
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
583
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
584 ### OPENING OUTPUT-FILEHANDLES
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
585 if ($report) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
586 my $report_filename = $output_filename;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
587 $report_filename =~ s/\.sam$//;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
588 $report_filename =~ s/\.txt$//;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
589 $report_filename =~ s/$/_splitting_report.txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
590 $report_filename = $output_dir . $report_filename;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
591 open (REPORT,'>',$report_filename) or die "Failed to write to file $report_filename $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
592 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
593
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
594 if ($report) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
595 print REPORT "$output_filename\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
596 print REPORT "Parameters used to extract methylation information:\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
597 if ($paired) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
598 if ($vanilla) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
599 print REPORT "Bismark result file: paired-end (vanilla Bismark format)\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
600 } else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
601 print REPORT "Bismark result file: paired-end (SAM format)\n"; # default
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
602 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
603 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
604
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
605 if ($single) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
606 if ($vanilla) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
607 print REPORT "Bismark result file: single-end (vanilla Bismark format)\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
608 } else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
609 print REPORT "Bismark result file: single-end (SAM format)\n"; # default
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
610 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
611 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
612
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
613 if ($ignore) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
614 print REPORT "Ignoring first $ignore bases\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
615 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
616
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
617 if ($full) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
618 print REPORT "Output specified: comprehensive\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
619 } else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
620 print REPORT "Output specified: strand-specific (default)\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
621 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
622
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
623 if ($no_overlap) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
624 print REPORT "No overlapping methylation calls specified\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
625 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
626 if ($genomic_fasta) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
627 print REPORT "Genomic equivalent sequences will be printed out in FastA format\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
628 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
629 if ($merge_non_CpG) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
630 print REPORT "Methylation in CHG and CHH context will be merged into \"non-CpG context\" output\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
631 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
632
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
633 print REPORT "\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
634 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
635
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
636 ##### open (OUT,"| gzip -c - > $output_dir$outfile") or die "Failed to write to $outfile: $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
637
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
638 ### CpG-context and non-CpG context. THIS SECTION IS OPTIONAL
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
639 ### if --comprehensive AND --merge_non_CpG was specified we are only writing out one CpG-context and one Any-Other-context result file
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
640 if ($full and $merge_non_CpG) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
641 my $cpg_output = my $other_c_output = $output_filename;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
642 ### C in CpG context
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
643 $cpg_output =~ s/^/CpG_context_/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
644 $cpg_output =~ s/sam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
645 $cpg_output =~ s/bam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
646 $cpg_output =~ s/$/.txt/ unless ($cpg_output =~ /\.txt$/);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
647 $cpg_output = $output_dir . $cpg_output;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
648
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
649 if ($gzip){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
650 $cpg_output .= '.gz';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
651 open ($fhs{CpG_context},"| gzip -c - > $cpg_output") or die "Failed to write to $cpg_output $! \n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
652 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
653 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
654 open ($fhs{CpG_context},'>',$cpg_output) or die "Failed to write to $cpg_output $! \n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
655 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
656
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
657 warn "Writing result file containing methylation information for C in CpG context to $cpg_output\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
658 push @sorting_files,$cpg_output;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
659
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
660 unless ($no_header) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
661 print {$fhs{CpG_context}} "Bismark methylation extractor version $version\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
662 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
663
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
664 ### C in any other context than CpG
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
665 $other_c_output =~ s/^/Non_CpG_context_/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
666 $other_c_output =~ s/sam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
667 $other_c_output =~ s/bam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
668 $other_c_output =~ s/$/.txt/ unless ($other_c_output =~ /\.txt$/);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
669 $other_c_output = $output_dir . $other_c_output;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
670
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
671 if ($gzip){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
672 $other_c_output .= '.gz';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
673 open ($fhs{other_context},"| gzip -c - > $other_c_output") or die "Failed to write to $other_c_output $! \n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
674 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
675 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
676 open ($fhs{other_context},'>',$other_c_output) or die "Failed to write to $other_c_output $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
677 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
678
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
679 warn "Writing result file containing methylation information for C in any other context to $other_c_output\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
680 push @sorting_files,$other_c_output;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
681
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
682
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
683 unless ($no_header) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
684 print {$fhs{other_context}} "Bismark methylation extractor version $version\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
685 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
686 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
687
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
688 ### if only --merge_non_CpG was specified we will write out 8 different output files, depending on where the (first) unique best alignment has been found
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
689 elsif ($merge_non_CpG) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
690
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
691 my $cpg_ot = my $cpg_ctot = my $cpg_ctob = my $cpg_ob = $output_filename;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
692
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
693 ### For cytosines in CpG context
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
694 $cpg_ot =~ s/^/CpG_OT_/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
695 $cpg_ot =~ s/sam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
696 $cpg_ot =~ s/bam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
697 $cpg_ot =~ s/$/.txt/ unless ($cpg_ot =~ /\.txt$/);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
698 $cpg_ot = $output_dir . $cpg_ot;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
699
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
700 if ($gzip){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
701 $cpg_ot .= '.gz';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
702 open ($fhs{0}->{CpG},"| gzip -c - > $cpg_ot") or die "Failed to write to $cpg_ot $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
703 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
704 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
705 open ($fhs{0}->{CpG},'>',$cpg_ot) or die "Failed to write to $cpg_ot $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
706 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
707
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
708 warn "Writing result file containing methylation information for C in CpG context from the original top strand to $cpg_ot\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
709 push @sorting_files,$cpg_ot;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
710
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
711 unless($no_header){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
712 print {$fhs{0}->{CpG}} "Bismark methylation extractor version $version\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
713 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
714
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
715 $cpg_ctot =~ s/^/CpG_CTOT_/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
716 $cpg_ctot =~ s/sam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
717 $cpg_ctot =~ s/bam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
718 $cpg_ctot =~ s/$/.txt/ unless ($cpg_ctot =~ /\.txt$/);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
719 $cpg_ctot = $output_dir . $cpg_ctot;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
720
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
721 if ($gzip){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
722 $cpg_ctot .= '.gz';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
723 open ($fhs{1}->{CpG},"| gzip -c - > $cpg_ctot") or die "Failed to write to $cpg_ctot $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
724 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
725 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
726 open ($fhs{1}->{CpG},'>',$cpg_ctot) or die "Failed to write to $cpg_ctot $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
727 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
728
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
729 warn "Writing result file containing methylation information for C in CpG context from the complementary to original top strand to $cpg_ctot\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
730 push @sorting_files,$cpg_ctot;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
731
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
732 unless($no_header){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
733 print {$fhs{1}->{CpG}} "Bismark methylation extractor version $version\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
734 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
735
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
736 $cpg_ctob =~ s/^/CpG_CTOB_/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
737 $cpg_ctob =~ s/sam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
738 $cpg_ctob =~ s/bam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
739 $cpg_ctob =~ s/$/.txt/ unless ($cpg_ctob =~ /\.txt$/);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
740 $cpg_ctob = $output_dir . $cpg_ctob;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
741
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
742 if ($gzip){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
743 $cpg_ctob .= '.gz';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
744 open ($fhs{2}->{CpG},"| gzip -c - > $cpg_ctob") or die "Failed to write to $cpg_ctob $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
745 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
746 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
747 open ($fhs{2}->{CpG},'>',$cpg_ctob) or die "Failed to write to $cpg_ctob $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
748 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
749
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
750 warn "Writing result file containing methylation information for C in CpG context from the complementary to original bottom strand to $cpg_ctob\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
751 push @sorting_files,$cpg_ctob;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
752
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
753 unless($no_header){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
754 print {$fhs{2}->{CpG}} "Bismark methylation extractor version $version\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
755 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
756
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
757 $cpg_ob =~ s/^/CpG_OB_/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
758 $cpg_ob =~ s/sam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
759 $cpg_ob =~ s/bam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
760 $cpg_ob =~ s/$/.txt/ unless ($cpg_ob =~ /\.txt$/);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
761 $cpg_ob = $output_dir . $cpg_ob;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
762
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
763 if ($gzip){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
764 $cpg_ob .= '.gz';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
765 open ($fhs{3}->{CpG},"| gzip -c - > $cpg_ob") or die "Failed to write to $cpg_ob $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
766 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
767 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
768 open ($fhs{3}->{CpG},'>',$cpg_ob) or die "Failed to write to $cpg_ob $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
769 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
770
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
771 warn "Writing result file containing methylation information for C in CpG context from the original bottom strand to $cpg_ob\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
772 push @sorting_files,$cpg_ob;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
773
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
774 unless($no_header){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
775 print {$fhs{3}->{CpG}} "Bismark methylation extractor version $version\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
776 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
777
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
778 ### For cytosines in Non-CpG (CC, CT or CA) context
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
779 my $other_c_ot = my $other_c_ctot = my $other_c_ctob = my $other_c_ob = $output_filename;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
780
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
781 $other_c_ot =~ s/^/Non_CpG_OT_/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
782 $other_c_ot =~ s/sam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
783 $other_c_ot =~ s/bam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
784 $other_c_ot =~ s/$/.txt/ unless ($other_c_ot =~ /\.txt$/);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
785 $other_c_ot = $output_dir . $other_c_ot;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
786
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
787 if ($gzip){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
788 $other_c_ot .= '.gz';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
789 open ($fhs{0}->{other_c},"| gzip -c - > $other_c_ot") or die "Failed to write to $other_c_ot $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
790 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
791 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
792 open ($fhs{0}->{other_c},'>',$other_c_ot) or die "Failed to write to $other_c_ot $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
793 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
794
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
795 warn "Writing result file containing methylation information for C in any other context from the original top strand to $other_c_ot\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
796 push @sorting_files,$other_c_ot;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
797
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
798 unless($no_header){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
799 print {$fhs{0}->{other_c}} "Bismark methylation extractor version $version\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
800 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
801
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
802 $other_c_ctot =~ s/^/Non_CpG_CTOT_/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
803 $other_c_ctot =~ s/sam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
804 $other_c_ctot =~ s/bam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
805 $other_c_ctot =~ s/$/.txt/ unless ($other_c_ctot =~ /\.txt$/);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
806 $other_c_ctot = $output_dir . $other_c_ctot;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
807
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
808 if ($gzip){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
809 $other_c_ctot .= '.gz';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
810 open ($fhs{1}->{other_c},"| gzip -c - > $other_c_ctot") or die "Failed to write to $other_c_ctot $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
811 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
812 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
813 open ($fhs{1}->{other_c},'>',$other_c_ctot) or die "Failed to write to $other_c_ctot $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
814 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
815
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
816 warn "Writing result file containing methylation information for C in any other context from the complementary to original top strand to $other_c_ctot\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
817 push @sorting_files,$other_c_ctot;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
818
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
819 unless($no_header){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
820 print {$fhs{1}->{other_c}} "Bismark methylation extractor version $version\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
821 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
822
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
823 $other_c_ctob =~ s/^/Non_CpG_CTOB_/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
824 $other_c_ctob =~ s/sam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
825 $other_c_ctob =~ s/bam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
826 $other_c_ctob =~ s/$/.txt/ unless ($other_c_ctob =~ /\.txt$/);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
827 $other_c_ctob = $output_dir . $other_c_ctob;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
828
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
829 if ($gzip){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
830 $other_c_ctob .= '.gz';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
831 open ($fhs{2}->{other_c},"| gzip -c - > $other_c_ctob") or die "Failed to write to $other_c_ctob $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
832 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
833 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
834 open ($fhs{2}->{other_c},'>',$other_c_ctob) or die "Failed to write to $other_c_ctob $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
835 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
836
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
837 warn "Writing result file containing methylation information for C in any other context from the complementary to original bottom strand to $other_c_ctob\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
838 push @sorting_files,$other_c_ctob;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
839
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
840 unless($no_header){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
841 print {$fhs{2}->{other_c}} "Bismark methylation extractor version $version\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
842 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
843
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
844 $other_c_ob =~ s/^/Non_CpG_OB_/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
845 $other_c_ob =~ s/sam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
846 $other_c_ob =~ s/sam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
847 $other_c_ob =~ s/$/.txt/ unless ($other_c_ob =~ /\.txt$/);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
848 $other_c_ob = $output_dir . $other_c_ob;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
849
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
850 if ($gzip){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
851 $other_c_ob .= '.gz';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
852 open ($fhs{3}->{other_c},"| gzip -c - > $other_c_ob") or die "Failed to write to $other_c_ob $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
853 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
854 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
855 open ($fhs{3}->{other_c},'>',$other_c_ob) or die "Failed to write to $other_c_ob $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
856 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
857
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
858 warn "Writing result file containing methylation information for C in any other context from the original bottom strand to $other_c_ob\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
859 push @sorting_files,$other_c_ob;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
860
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
861 unless($no_header){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
862 print {$fhs{3}->{other_c}} "Bismark methylation extractor version $version\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
863 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
864 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
865 ### THIS SECTION IS THE DEFAULT (CpG, CHG and CHH context)
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
866
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
867 ### if --comprehensive was specified we are only writing one file per context
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
868 elsif ($full) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
869 my $cpg_output = my $chg_output = my $chh_output = $output_filename;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
870 ### C in CpG context
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
871 $cpg_output =~ s/^/CpG_context_/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
872 $cpg_output =~ s/sam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
873 $cpg_output =~ s/bam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
874 $cpg_output =~ s/$/.txt/ unless ($cpg_output =~ /\.txt$/);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
875 $cpg_output = $output_dir . $cpg_output;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
876
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
877 if ($gzip){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
878 $cpg_output .= '.gz';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
879 open ($fhs{CpG_context},"| gzip -c - > $cpg_output") or die "Failed to write to $cpg_output $! \n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
880 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
881 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
882 open ($fhs{CpG_context},'>',$cpg_output) or die "Failed to write to $cpg_output $! \n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
883 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
884
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
885 warn "Writing result file containing methylation information for C in CpG context to $cpg_output\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
886 push @sorting_files,$cpg_output;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
887
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
888 unless($no_header){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
889 print {$fhs{CpG_context}} "Bismark methylation extractor version $version\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
890 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
891
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
892 ### C in CHG context
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
893 $chg_output =~ s/^/CHG_context_/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
894 $chg_output =~ s/sam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
895 $chg_output =~ s/bam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
896 $chg_output =~ s/$/.txt/ unless ($chg_output =~ /\.txt$/);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
897 $chg_output = $output_dir . $chg_output;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
898
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
899 if ($gzip){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
900 $chg_output .= '.gz';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
901 open ($fhs{CHG_context},"| gzip -c - > $chg_output") or die "Failed to write to $chg_output $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
902 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
903 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
904 open ($fhs{CHG_context},'>',$chg_output) or die "Failed to write to $chg_output $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
905 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
906
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
907 warn "Writing result file containing methylation information for C in CHG context to $chg_output\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
908 push @sorting_files,$chg_output;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
909
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
910 unless($no_header){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
911 print {$fhs{CHG_context}} "Bismark methylation extractor version $version\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
912 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
913
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
914 ### C in CHH context
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
915 $chh_output =~ s/^/CHH_context_/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
916 $chh_output =~ s/sam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
917 $chh_output =~ s/bam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
918 $chh_output =~ s/$/.txt/ unless ($chh_output =~ /\.txt$/);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
919 $chh_output = $output_dir . $chh_output;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
920
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
921 if ($gzip){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
922 $chh_output .= '.gz';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
923 open ($fhs{CHH_context},"| gzip -c - > $chh_output") or die "Failed to write to $chh_output $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
924 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
925 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
926 open ($fhs{CHH_context},'>',$chh_output) or die "Failed to write to $chh_output $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
927 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
928
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
929 warn "Writing result file containing methylation information for C in CHH context to $chh_output\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
930 push @sorting_files, $chh_output;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
931
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
932 unless($no_header){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
933 print {$fhs{CHH_context}} "Bismark methylation extractor version $version\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
934 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
935 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
936 ### else we will write out 12 different output files, depending on where the (first) unique best alignment was found
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
937 else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
938 my $cpg_ot = my $cpg_ctot = my $cpg_ctob = my $cpg_ob = $output_filename;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
939
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
940 ### For cytosines in CpG context
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
941 $cpg_ot =~ s/^/CpG_OT_/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
942 $cpg_ot =~ s/sam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
943 $cpg_ot =~ s/bam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
944 $cpg_ot =~ s/$/.txt/ unless ($cpg_ot =~ /\.txt$/);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
945 $cpg_ot = $output_dir . $cpg_ot;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
946
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
947 if ($gzip){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
948 $cpg_ot .= '.gz';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
949 open ($fhs{0}->{CpG},"| gzip -c - > $cpg_ot") or die "Failed to write to $cpg_ot $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
950 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
951 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
952 open ($fhs{0}->{CpG},'>',$cpg_ot) or die "Failed to write to $cpg_ot $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
953 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
954
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
955 warn "Writing result file containing methylation information for C in CpG context from the original top strand to $cpg_ot\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
956 push @sorting_files,$cpg_ot;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
957
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
958 unless($no_header){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
959 print {$fhs{0}->{CpG}} "Bismark methylation extractor version $version\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
960 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
961
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
962 $cpg_ctot =~ s/^/CpG_CTOT_/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
963 $cpg_ctot =~ s/sam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
964 $cpg_ctot =~ s/bam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
965 $cpg_ctot =~ s/$/.txt/ unless ($cpg_ctot =~ /\.txt$/);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
966 $cpg_ctot = $output_dir . $cpg_ctot;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
967
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
968 if ($gzip){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
969 $cpg_ctot .= '.gz';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
970 open ($fhs{1}->{CpG},"| gzip -c - > $cpg_ctot") or die "Failed to write to $cpg_ctot $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
971 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
972 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
973 open ($fhs{1}->{CpG},'>',$cpg_ctot) or die "Failed to write to $cpg_ctot $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
974 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
975
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
976 warn "Writing result file containing methylation information for C in CpG context from the complementary to original top strand to $cpg_ctot\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
977 push @sorting_files,$cpg_ctot;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
978
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
979 unless($no_header){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
980 print {$fhs{1}->{CpG}} "Bismark methylation extractor version $version\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
981 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
982
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
983 $cpg_ctob =~ s/^/CpG_CTOB_/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
984 $cpg_ctob =~ s/sam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
985 $cpg_ctob =~ s/bam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
986 $cpg_ctob =~ s/$/.txt/ unless ($cpg_ctob =~ /\.txt$/);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
987 $cpg_ctob = $output_dir . $cpg_ctob;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
988
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
989 if ($gzip){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
990 $cpg_ctob .= '.gz';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
991 open ($fhs{2}->{CpG},"| gzip -c - > $cpg_ctob") or die "Failed to write to $cpg_ctob $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
992 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
993 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
994 open ($fhs{2}->{CpG},'>',$cpg_ctob) or die "Failed to write to $cpg_ctob $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
995 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
996
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
997 warn "Writing result file containing methylation information for C in CpG context from the complementary to original bottom strand to $cpg_ctob\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
998 push @sorting_files,$cpg_ctob;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
999
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1000 unless($no_header){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1001 print {$fhs{2}->{CpG}} "Bismark methylation extractor version $version\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1002 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1003
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1004 $cpg_ob =~ s/^/CpG_OB_/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1005 $cpg_ob =~ s/sam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1006 $cpg_ob =~ s/bam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1007 $cpg_ob =~ s/$/.txt/ unless ($cpg_ob =~ /\.txt$/);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1008 $cpg_ob = $output_dir . $cpg_ob;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1009
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1010 if ($gzip){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1011 $cpg_ob .= '.gz';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1012 open ($fhs{3}->{CpG},"| gzip -c - > $cpg_ob") or die "Failed to write to $cpg_ob $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1013 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1014 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1015 open ($fhs{3}->{CpG},'>',$cpg_ob) or die "Failed to write to $cpg_ob $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1016 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1017
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1018 warn "Writing result file containing methylation information for C in CpG context from the original bottom strand to $cpg_ob\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1019 push @sorting_files,$cpg_ob;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1020
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1021 unless($no_header){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1022 print {$fhs{3}->{CpG}} "Bismark methylation extractor version $version\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1023 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1024
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1025 ### For cytosines in CHG context
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1026 my $chg_ot = my $chg_ctot = my $chg_ctob = my $chg_ob = $output_filename;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1027
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1028 $chg_ot =~ s/^/CHG_OT_/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1029 $chg_ot =~ s/sam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1030 $chg_ot =~ s/bam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1031 $chg_ot =~ s/$/.txt/ unless ($chg_ot =~ /\.txt$/);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1032 $chg_ot = $output_dir . $chg_ot;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1033
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1034 if ($gzip){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1035 $chg_ot .= '.gz';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1036 open ($fhs{0}->{CHG},"| gzip -c - > $chg_ot") or die "Failed to write to $chg_ot $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1037 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1038 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1039 open ($fhs{0}->{CHG},'>',$chg_ot) or die "Failed to write to $chg_ot $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1040 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1041
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1042 warn "Writing result file containing methylation information for C in CHG context from the original top strand to $chg_ot\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1043 push @sorting_files,$chg_ot;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1044
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1045 unless($no_header){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1046 print {$fhs{0}->{CHG}} "Bismark methylation extractor version $version\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1047 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1048
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1049 $chg_ctot =~ s/^/CHG_CTOT_/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1050 $chg_ctot =~ s/sam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1051 $chg_ctot =~ s/bam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1052 $chg_ctot =~ s/$/.txt/ unless ($chg_ctot =~ /\.txt$/);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1053 $chg_ctot = $output_dir . $chg_ctot;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1054
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1055 if ($gzip){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1056 $chg_ctot .= '.gz';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1057 open ($fhs{1}->{CHG},"| gzip -c - > $chg_ctot") or die "Failed to write to $chg_ctot $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1058 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1059 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1060 open ($fhs{1}->{CHG},'>',$chg_ctot) or die "Failed to write to $chg_ctot $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1061 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1062
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1063 warn "Writing result file containing methylation information for C in CHG context from the complementary to original top strand to $chg_ctot\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1064 push @sorting_files,$chg_ctot;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1065
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1066 unless($no_header){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1067 print {$fhs{1}->{CHG}} "Bismark methylation extractor version $version\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1068 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1069
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1070 $chg_ctob =~ s/^/CHG_CTOB_/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1071 $chg_ctob =~ s/sam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1072 $chg_ctob =~ s/bam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1073 $chg_ctob =~ s/$/.txt/ unless ($chg_ctob =~ /\.txt$/);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1074 $chg_ctob = $output_dir . $chg_ctob;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1075
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1076 if ($gzip){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1077 $chg_ctob .= '.gz';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1078 open ($fhs{2}->{CHG},"| gzip -c - > $chg_ctob") or die "Failed to write to $chg_ctob $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1079 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1080 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1081 open ($fhs{2}->{CHG},'>',$chg_ctob) or die "Failed to write to $chg_ctob $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1082 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1083
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1084 warn "Writing result file containing methylation information for C in CHG context from the complementary to original bottom strand to $chg_ctob\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1085 push @sorting_files,$chg_ctob;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1086
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1087 unless($no_header){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1088 print {$fhs{2}->{CHG}} "Bismark methylation extractor version $version\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1089 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1090
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1091 $chg_ob =~ s/^/CHG_OB_/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1092 $chg_ob =~ s/sam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1093 $chg_ob =~ s/bam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1094 $chg_ob =~ s/$/.txt/ unless ($chg_ob =~ /\.txt$/);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1095 $chg_ob = $output_dir . $chg_ob;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1096
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1097 if ($gzip){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1098 $chg_ob .= '.gz';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1099 open ($fhs{3}->{CHG},"| gzip -c - > $chg_ob") or die "Failed to write to $chg_ob $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1100 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1101 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1102 open ($fhs{3}->{CHG},'>',$chg_ob) or die "Failed to write to $chg_ob $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1103 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1104
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1105 warn "Writing result file containing methylation information for C in CHG context from the original bottom strand to $chg_ob\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1106 push @sorting_files,$chg_ob;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1107
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1108 unless($no_header){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1109 print {$fhs{3}->{CHG}} "Bismark methylation extractor version $version\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1110 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1111
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1112 ### For cytosines in CHH context
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1113 my $chh_ot = my $chh_ctot = my $chh_ctob = my $chh_ob = $output_filename;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1114
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1115 $chh_ot =~ s/^/CHH_OT_/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1116 $chh_ot =~ s/sam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1117 $chh_ot =~ s/bam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1118 $chh_ot =~ s/$/.txt/ unless ($chh_ot =~ /\.txt$/);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1119 $chh_ot = $output_dir . $chh_ot;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1120
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1121 if ($gzip){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1122 $chh_ot .= '.gz';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1123 open ($fhs{0}->{CHH},"| gzip -c - > $chh_ot") or die "Failed to write to $chh_ot $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1124 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1125 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1126 open ($fhs{0}->{CHH},'>',$chh_ot) or die "Failed to write to $chh_ot $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1127 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1128
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1129 warn "Writing result file containing methylation information for C in CHH context from the original top strand to $chh_ot\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1130 push @sorting_files,$chh_ot;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1131
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1132 unless($no_header){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1133 print {$fhs{0}->{CHH}} "Bismark methylation extractor version $version\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1134 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1135
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1136 $chh_ctot =~ s/^/CHH_CTOT_/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1137 $chh_ctot =~ s/sam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1138 $chh_ctot =~ s/bam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1139 $chh_ctot =~ s/$/.txt/ unless ($chh_ctot =~ /\.txt$/);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1140 $chh_ctot = $output_dir . $chh_ctot;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1141
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1142 if ($gzip){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1143 $chh_ctot .= '.gz';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1144 open ($fhs{1}->{CHH},"| gzip -c - > $chh_ctot") or die "Failed to write to $chh_ctot $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1145 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1146 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1147 open ($fhs{1}->{CHH},'>',$chh_ctot) or die "Failed to write to $chh_ctot $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1148 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1149
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1150 warn "Writing result file containing methylation information for C in CHH context from the complementary to original top strand to $chh_ctot\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1151 push @sorting_files,$chh_ctot;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1152
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1153 unless($no_header){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1154 print {$fhs{1}->{CHH}} "Bismark methylation extractor version $version\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1155 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1156
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1157 $chh_ctob =~ s/^/CHH_CTOB_/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1158 $chh_ctob =~ s/sam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1159 $chh_ctob =~ s/bam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1160 $chh_ctob =~ s/$/.txt/ unless ($chh_ctob =~ /\.txt$/);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1161 $chh_ctob = $output_dir . $chh_ctob;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1162
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1163 if ($gzip){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1164 $chh_ctob .= '.gz';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1165 open ($fhs{2}->{CHH},"| gzip -c - > $chh_ctob") or die "Failed to write to $chh_ctob $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1166 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1167 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1168 open ($fhs{2}->{CHH},'>',$chh_ctob) or die "Failed to write to $chh_ctob $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1169 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1170
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1171 warn "Writing result file containing methylation information for C in CHH context from the complementary to original bottom strand to $chh_ctob\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1172 push @sorting_files,$chh_ctob;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1173
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1174 unless($no_header){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1175 print {$fhs{2}->{CHH}} "Bismark methylation extractor version $version\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1176 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1177
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1178 $chh_ob =~ s/^/CHH_OB_/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1179 $chh_ob =~ s/sam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1180 $chh_ob =~ s/bam$/txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1181 $chh_ob =~ s/$/.txt/ unless ($chh_ob =~ /\.txt$/);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1182 $chh_ob = $output_dir . $chh_ob;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1183
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1184 if ($gzip){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1185 $chh_ob .= '.gz';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1186 open ($fhs{3}->{CHH},"| gzip -c - > $chh_ob") or die "Failed to write to $chh_ob $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1187 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1188 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1189 open ($fhs{3}->{CHH},'>',$chh_ob) or die "Failed to write to $chh_ob $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1190 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1191
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1192 warn "Writing result file containing methylation information for C in CHH context from the original bottom strand to $chh_ob\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1193 push @sorting_files,$chh_ob;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1194
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1195 unless($no_header){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1196 print {$fhs{3}->{CHH}} "Bismark methylation extractor version $version\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1197 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1198 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1199
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1200 my $methylation_call_strings_processed = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1201 my $line_count = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1202
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1203 ### proceeding differently now for single-end or paired-end Bismark files
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1204
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1205 ### PROCESSING SINGLE-END RESULT FILES
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1206 if ($single) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1207
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1208 ### also proceeding differently now for SAM format or vanilla Bismark format files
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1209 if ($vanilla) { # old vanilla Bismark output format
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1210 while (<IN>) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1211 ++$line_count;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1212 warn "Processed lines: $line_count\n" if ($line_count%500000==0);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1213
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1214 ### $seq here is the chromosomal sequence (to use for the repeat analysis for example)
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1215 my ($id,$strand,$chrom,$start,$seq,$meth_call,$read_conversion,$genome_conversion) = (split("\t"))[0,1,2,3,6,7,8,9];
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1216
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1217 ### we need to remove 2 bp of the genomic sequence as we were extracting read + 2bp long fragments to make a methylation call at the first or
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1218 ### last position
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1219 chomp $genome_conversion;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1220
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1221 my $index;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1222 if ($meth_call) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1223
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1224 if ($read_conversion eq 'CT' and $genome_conversion eq 'CT') { ## original top strand
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1225 $index = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1226 } elsif ($read_conversion eq 'GA' and $genome_conversion eq 'CT') { ## complementary to original top strand
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1227 $index = 1;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1228 } elsif ($read_conversion eq 'CT' and $genome_conversion eq 'GA') { ## original bottom strand
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1229 $index = 3;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1230 } elsif ($read_conversion eq 'GA' and $genome_conversion eq 'GA') { ## complementary to original bottom strand
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1231 $index = 2;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1232 } else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1233 die "Unexpected combination of read and genome conversion: '$read_conversion' / '$genome_conversion'\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1234 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1235
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1236 ### Clipping off the first <int> number of bases from the methylation call string as specified with --ignore <int>
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1237 if ($ignore) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1238 $meth_call = substr($meth_call,$ignore,length($meth_call)-$ignore);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1239
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1240 ### If we are clipping off some bases at the start we need to adjust the start position of the alignments accordingly!
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1241 if ($strand eq '+') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1242 $start += $ignore;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1243 } elsif ($strand eq '-') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1244 $start += length($meth_call)-1; ## $meth_call is already shortened!
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1245 } else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1246 die "Alignment did not have proper strand information: $strand\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1247 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1248 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1249 ### printing out the methylation state of every C in the read
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1250 print_individual_C_methylation_states_single_end($meth_call,$chrom,$start,$id,$strand,$index);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1251
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1252 ++$methylation_call_strings_processed; # 1 per single-end result
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1253 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1254 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1255 } else { # processing single-end SAM format (default)
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1256 while (<IN>) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1257 ### SAM format can either start with header lines (starting with @) or start with alignments directly
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1258 if (/^\@/) { # skipping header lines (starting with @)
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1259 warn "skipping SAM header line:\t$_";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1260 next;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1261 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1262
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1263 ++$line_count;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1264 warn "Processed lines: $line_count\n" if ($line_count%500000==0);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1265
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1266 # example read in SAM format
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1267 # 1_R1/1 67 5 103172224 255 40M = 103172417 233 AATATTTTTTTTATTTTAAAATGTGTATTGATTTAAATTT IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII NM:i:4 XX:Z:4T1T24TT7 XM:Z:....h.h........................hh....... XR:Z:CT XG:Z:CT
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1268 ###
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1269
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1270 # < 0.7.6 my ($id,$chrom,$start,$meth_call,$read_conversion,$genome_conversion) = (split("\t"))[0,2,3,13,14,15];
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1271 # < 0.7.6 $meth_call =~ s/^XM:Z://;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1272 # < 0.7.6 $read_conversion =~ s/^XR:Z://;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1273 # < 0.7.6 $genome_conversion =~ s/^XG:Z://;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1274
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1275 my ($id,$chrom,$start,$cigar) = (split("\t"))[0,2,3,5];
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1276
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1277 ### detecting the following SAM flags in case the SAM entry was shuffled by CRAM or Goby compression/decompression
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1278 my $meth_call; ### Thanks to Zachary Zeno for this solution
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1279 my $read_conversion;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1280 my $genome_conversion;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1281
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1282 while ( /(XM|XR|XG):Z:([^\t]+)/g ) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1283 my $tag = $1;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1284 my $value = $2;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1285
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1286 if ($tag eq "XM") {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1287 $meth_call = $value;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1288 $meth_call =~ s/\r//;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1289 } elsif ($tag eq "XR") {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1290 $read_conversion = $value;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1291 $read_conversion =~ s/\r//;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1292 } elsif ($tag eq "XG") {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1293 $genome_conversion = $value;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1294 $genome_conversion =~ s/\r//;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1295 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1296 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1297
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1298 my $strand;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1299 chomp $genome_conversion;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1300 # print "$meth_call\n$read_conversion\n$genome_conversion\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1301
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1302 my $index;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1303 if ($meth_call) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1304 if ($read_conversion eq 'CT' and $genome_conversion eq 'CT') { ## original top strand
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1305 $index = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1306 $strand = '+';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1307 } elsif ($read_conversion eq 'GA' and $genome_conversion eq 'CT') { ## complementary to original top strand
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1308 $index = 1;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1309 $strand = '-';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1310 } elsif ($read_conversion eq 'GA' and $genome_conversion eq 'GA') { ## complementary to original bottom strand
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1311 $index = 2;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1312 $strand = '+';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1313 } elsif ($read_conversion eq 'CT' and $genome_conversion eq 'GA') { ## original bottom strand
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1314 $index = 3;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1315 $strand = '-';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1316 } else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1317 die "Unexpected combination of read and genome conversion: '$read_conversion' / '$genome_conversion'\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1318 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1319
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1320 ### If the read is in SAM format we need to reverse the methylation call if the read has been reverse-complemented for the output
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1321 if ($strand eq '-') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1322 $meth_call = reverse $meth_call;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1323 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1324
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1325 ### Clipping off the first <int> number of bases from the methylation call string as specified with --ignore <int>
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1326 if ($ignore) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1327 # print "\n\n$meth_call\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1328 $meth_call = substr($meth_call,$ignore,length($meth_call)-$ignore);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1329 # print "$meth_call\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1330 ### If we are ignoring a part of the sequence we also need to adjust the cigar string accordingly
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1331
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1332 my @len = split (/\D+/,$cigar); # storing the length per operation
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1333 my @ops = split (/\d+/,$cigar); # storing the operation
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1334 shift @ops; # remove the empty first element
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1335 die "CIGAR string contained a non-matching number of lengths and operations\n" unless (scalar @len == scalar @ops);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1336
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1337 my @comp_cigar; # building an array with all CIGAR operations
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1338 foreach my $index (0..$#len) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1339 foreach (1..$len[$index]) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1340 # print "$ops[$index]";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1341 push @comp_cigar, $ops[$index];
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1342 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1343 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1344 # print "original CIGAR: $cigar\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1345 # print "original CIGAR: @comp_cigar\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1346
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1347 ### If we are clipping off some bases at the start we need to adjust the start position of the alignments accordingly!
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1348 if ($strand eq '+') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1349
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1350 my $D_count = 0; # counting all deletions that affect the ignored genomic position, i.e. Deletions and insertions
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1351 my $I_count = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1352
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1353 for (1..$ignore) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1354 my $op = shift @comp_cigar; # adjusting composite CIGAR string by removing $ignore operations from the start
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1355 # print "$_ deleted $op\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1356
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1357 while ($op eq 'D') { # repeating this for deletions (D)
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1358 $D_count++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1359 $op = shift @comp_cigar;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1360 # print "$_ deleted $op\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1361 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1362 if ($op eq 'I') { # adjusting the genomic position for insertions (I)
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1363 $I_count++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1364 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1365 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1366 $start += $ignore + $D_count - $I_count;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1367 # print "start $start\t ignore: $ignore\t D count: $D_count I_count: $I_count\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1368 } elsif ($strand eq '-') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1369
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1370 for (1..$ignore) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1371 my $op = pop @comp_cigar; # adjusting composite CIGAR string by removing $ignore operations, here the last value of the array
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1372 while ($op eq 'D') { # repeating this for deletions (D)
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1373 $op = pop @comp_cigar;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1374 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1375 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1376
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1377 ### For reverse strand alignments we need to determine the number of matching bases (M) or deletions (D) in the read from the CIGAR
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1378 ### string to be able to work out the starting position of the read which is on the 3' end of the sequence
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1379 my $MD_count = 0; # counting all operations that affect the genomic position, i.e. M and D. Insertions do not affect the start position
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1380 foreach (@comp_cigar) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1381 ++$MD_count if ($_ eq 'M' or $_ eq 'D');
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1382 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1383 $start += $MD_count - 1;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1384 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1385
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1386 ### reconstituting shortened CIGAR string
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1387 my $new_cigar;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1388 my $count = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1389 my $last_op;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1390 # print "ignore adjusted: @comp_cigar\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1391 foreach my $op (@comp_cigar) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1392 unless (defined $last_op){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1393 $last_op = $op;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1394 ++$count;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1395 next;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1396 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1397 if ($last_op eq $op) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1398 ++$count;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1399 } else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1400 $new_cigar .= "$count$last_op";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1401 $last_op = $op;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1402 $count = 1;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1403 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1404 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1405 $new_cigar .= "$count$last_op"; # appending the last operation and count
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1406 $cigar = $new_cigar;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1407 # print "ignore adjusted scalar: $cigar\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1408 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1409 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1410 ### printing out the methylation state of every C in the read
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1411 print_individual_C_methylation_states_single_end($meth_call,$chrom,$start,$id,$strand,$index,$cigar);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1412
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1413 ++$methylation_call_strings_processed; # 1 per single-end result
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1414 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1415 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1416 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1417
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1418 ### PROCESSING PAIRED-END RESULT FILES
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1419 elsif ($paired) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1420
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1421 ### proceeding differently now for SAM format or vanilla Bismark format files
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1422 if ($vanilla) { # old vanilla Bismark paired-end output format
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1423 while (<IN>) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1424 ++$line_count;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1425 warn "processed line: $line_count\n" if ($line_count%500000==0);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1426
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1427 ### $seq here is the chromosomal sequence (to use for the repeat analysis for example)
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1428 my ($id,$strand,$chrom,$start_read_1,$end_read_2,$seq_1,$meth_call_1,$seq_2,$meth_call_2,$first_read_conversion,$genome_conversion) = (split("\t"))[0,1,2,3,4,6,7,9,10,11,12,13];
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1429
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1430 my $index;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1431 chomp $genome_conversion;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1432
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1433 if ($first_read_conversion eq 'CT' and $genome_conversion eq 'CT') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1434 $index = 0; ## this is OT
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1435 } elsif ($first_read_conversion eq 'GA' and $genome_conversion eq 'GA') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1436 $index = 2; ## this is CTOB!!!
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1437 } elsif ($first_read_conversion eq 'GA' and $genome_conversion eq 'CT') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1438 $index = 1; ## this is CTOT!!!
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1439 } elsif ($first_read_conversion eq 'CT' and $genome_conversion eq 'GA') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1440 $index = 3; ## this is OB
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1441 } else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1442 die "Unexpected combination of read and genome conversion: $first_read_conversion / $genome_conversion\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1443 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1444
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1445 if ($meth_call_1 and $meth_call_2) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1446 ### Clipping off the first <int> number of bases from the methylation call strings as specified with '--ignore <int>'
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1447 if ($ignore) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1448 $meth_call_1 = substr($meth_call_1,$ignore,length($meth_call_1)-$ignore);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1449 $meth_call_2 = substr($meth_call_2,$ignore,length($meth_call_2)-$ignore);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1450
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1451 ### we also need to adjust the start and end positions of the alignments accordingly if '--ignore' was specified
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1452 $start_read_1 += $ignore;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1453 $end_read_2 -= $ignore;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1454 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1455 my $end_read_1;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1456 my $start_read_2;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1457
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1458 if ($strand eq '+') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1459
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1460 $end_read_1 = $start_read_1+length($meth_call_1)-1;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1461 $start_read_2 = $end_read_2-length($meth_call_2)+1;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1462
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1463 ## we first pass the first read which is in + orientation on the forward strand
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1464 print_individual_C_methylation_states_paired_end_files($meth_call_1,$chrom,$start_read_1,$id,'+',$index,0,0);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1465
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1466 # we next pass the second read which is in - orientation on the reverse strand
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1467 ### if --no_overlap was specified we also pass the end of read 1. If read 2 starts to overlap with read 1 we can stop extracting methylation calls from read 2
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1468 print_individual_C_methylation_states_paired_end_files($meth_call_2,$chrom,$end_read_2,$id,'-',$index,$no_overlap,$end_read_1);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1469 } else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1470
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1471 $end_read_1 = $start_read_1+length($meth_call_2)-1; # read 1 is the second reported read!
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1472 $start_read_2 = $end_read_2-length($meth_call_1)+1; # read 2 is the first reported read!
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1473
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1474 ## we first pass the first read which is in - orientation on the reverse strand
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1475 print_individual_C_methylation_states_paired_end_files($meth_call_1,$chrom,$end_read_2,$id,'-',$index,0,0);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1476
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1477 # we next pass the second read which is in + orientation on the forward strand
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1478 ### if --no_overlap was specified we also pass the end of read 2. If read 2 starts to overlap with read 1 we will stop extracting methylation calls from read 2
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1479 print_individual_C_methylation_states_paired_end_files($meth_call_2,$chrom,$start_read_1,$id,'+',$index,$no_overlap,$start_read_2);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1480 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1481
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1482 $methylation_call_strings_processed += 2; # paired-end = 2 methylation calls
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1483 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1484 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1485 } else { # Bismark paired-end SAM output format (default)
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1486 while (<IN>) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1487 ### SAM format can either start with header lines (starting with @) or start with alignments directly
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1488 if (/^\@/) { # skipping header lines (starting with @)
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1489 warn "skipping SAM header line:\t$_";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1490 next;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1491 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1492
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1493 ++$line_count;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1494 warn "Processed lines: $line_count\n" if ($line_count%500000==0);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1495
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1496 # example paired-end reads in SAM format (2 consecutive lines)
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1497 # 1_R1/1 67 5 103172224 255 40M = 103172417 233 AATATTTTTTTTATTTTAAAATGTGTATTGATTTAAATTT IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII NM:i:4 XX:Z:4T1T24TT7 XM:Z:....h.h........................hh....... XR:Z:CT XG:Z:CT
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1498 # 1_R1/2 131 5 103172417 255 40M = 103172224 -233 TATTTTTTTTTAGAGTATTTTTTAATGGTTATTAGATTTT IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII NM:i:6 XX:Z:T5T1T9T9T7T3 XM:Z:h.....h.h.........h.........h.......h... XR:Z:GA XG:Z:CT
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1499
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1500 # < version 0.7.6 my ($id_1,$chrom,$start_read_1,$meth_call_1,$first_read_conversion,$genome_conversion) = (split("\t"))[0,2,3,13,14,15];
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1501
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1502 my ($id_1,$chrom,$start_read_1,$cigar_1) = (split("\t"))[0,2,3,5]; ### detecting the following SAM flags in case the SAM entry was shuffled by CRAM or Goby compression/decompression
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1503 my $meth_call_1;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1504 my $first_read_conversion;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1505 my $genome_conversion;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1506
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1507 while ( /(XM|XR|XG):Z:([^\t]+)/g ) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1508 my $tag = $1;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1509 my $value = $2;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1510
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1511 if ($tag eq "XM") {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1512 $meth_call_1 = $value;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1513 $meth_call_1 =~ s/\r//;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1514 } elsif ($tag eq "XR") {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1515 $first_read_conversion = $value;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1516 $first_read_conversion =~ s/\r//;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1517 } elsif ($tag eq "XG") {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1518 $genome_conversion = $value;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1519 $genome_conversion =~ s/\r//;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1520 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1521 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1522
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1523 $_ = <IN>; # reading in the paired read
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1524
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1525 # < version 0.7.6 my ($id_2,$start_read_2,$meth_call_2,$second_read_conversion) = (split("\t"))[0,3,13,14];
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1526 # < version 0.7.6 $meth_call_1 =~ s/^XM:Z://;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1527 # < version 0.7.6 $meth_call_2 =~ s/^XM:Z://;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1528 # < version 0.7.6 $first_read_conversion =~ s/^XR:Z://;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1529 # < version 0.7.6 $second_read_conversion =~ s/^XR:Z://;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1530
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1531 my ($id_2,$start_read_2,$cigar_2) = (split("\t"))[0,3,5]; ### detecting the following SAM flags in case the SAM entry was shuffled by CRAM or Goby compression/decompression
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1532
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1533 my $meth_call_2;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1534 my $second_read_conversion;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1535
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1536 while ( /(XM|XR):Z:([^\t]+)/g ) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1537 my $tag = $1;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1538 my $value = $2;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1539
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1540 if ($tag eq "XM") {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1541 $meth_call_2 = $value;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1542 $meth_call_2 =~ s/\r//;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1543 } elsif ($tag eq "XR") {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1544 $second_read_conversion = $value;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1545 $second_read_conversion = s/\r//;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1546 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1547 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1548
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1549 # < version 0.7.6 $genome_conversion =~ s/^XG:Z://;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1550 chomp $genome_conversion; # in case it captured a new line character
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1551
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1552 # print join ("\t",$meth_call_1,$meth_call_2,$first_read_conversion,$second_read_conversion,$genome_conversion),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1553
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1554 my $index;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1555 my $strand;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1556
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1557 if ($first_read_conversion eq 'CT' and $genome_conversion eq 'CT') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1558 $index = 0; ## this is OT
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1559 $strand = '+';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1560 } elsif ($first_read_conversion eq 'GA' and $genome_conversion eq 'CT') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1561 $index = 1; ## this is CTOT
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1562 $strand = '-';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1563 } elsif ($first_read_conversion eq 'GA' and $genome_conversion eq 'GA') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1564 $index = 2; ## this is CTOB
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1565 $strand = '+';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1566 } elsif ($first_read_conversion eq 'CT' and $genome_conversion eq 'GA') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1567 $index = 3; ## this is OB
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1568 $strand = '-';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1569 } else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1570 die "Unexpected combination of read and genome conversion: $first_read_conversion / $genome_conversion\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1571 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1572
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1573 ### reversing the methylation call of the read that was reverse-complemented
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1574 if ($strand eq '+') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1575 $meth_call_2 = reverse $meth_call_2;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1576 } else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1577 $meth_call_1 = reverse $meth_call_1;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1578 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1579
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1580 if ($meth_call_1 and $meth_call_2) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1581
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1582 my $end_read_1;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1583
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1584 ### READ 1
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1585 my @len_1 = split (/\D+/,$cigar_1); # storing the length per operation
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1586 my @ops_1 = split (/\d+/,$cigar_1); # storing the operation
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1587 shift @ops_1; # remove the empty first element
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1588 die "CIGAR string contained a non-matching number of lengths and operations\n" unless (scalar @len_1 == scalar @ops_1);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1589
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1590 my @comp_cigar_1; # building an array with all CIGAR operations
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1591 foreach my $index (0..$#len_1) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1592 foreach (1..$len_1[$index]) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1593 # print "$ops_1[$index]";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1594 push @comp_cigar_1, $ops_1[$index];
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1595 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1596 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1597 # print "original CIGAR read 1: $cigar_1\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1598 # print "original CIGAR read 1: @comp_cigar_1\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1599
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1600 ### READ 2
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1601 my @len_2 = split (/\D+/,$cigar_2); # storing the length per operation
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1602 my @ops_2 = split (/\d+/,$cigar_2); # storing the operation
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1603 shift @ops_2; # remove the empty first element
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1604 die "CIGAR string contained a non-matching number of lengths and operations\n" unless (scalar @len_2 == scalar @ops_2);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1605 my @comp_cigar_2; # building an array with all CIGAR operations for read 2
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1606 foreach my $index (0..$#len_2) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1607 foreach (1..$len_2[$index]) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1608 # print "$ops_2[$index]";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1609 push @comp_cigar_2, $ops_2[$index];
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1610 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1611 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1612 # print "original CIGAR read 2: $cigar_2\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1613 # print "original CIGAR read 2: @comp_cigar_2\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1614
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1615 if ($ignore) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1616 ### Clipping off the first <int> number of bases from the methylation call strings as specified with '--ignore <int>'
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1617 ### the methylation calls have already been reversed where necessary
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1618 $meth_call_1 = substr($meth_call_1,$ignore,length($meth_call_1)-$ignore);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1619 $meth_call_2 = substr($meth_call_2,$ignore,length($meth_call_2)-$ignore);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1620
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1621 ### If we are ignoring a part of the sequence we also need to adjust the cigar string accordingly
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1622
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1623 if ($strand eq '+') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1624
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1625 ### if the (read 1) strand information is '+', read 1 needs to be trimmed from the start
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1626 my $D_count_1 = 0; # counting all deletions that affect the ignored genomic position for read 1, i.e. Deletions and insertions
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1627 my $I_count_1 = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1628
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1629 for (1..$ignore) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1630 my $op = shift @comp_cigar_1; # adjusting composite CIGAR string of read 1 by removing $ignore operations from the start
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1631 # print "$_ deleted $op\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1632
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1633 while ($op eq 'D') { # repeating this for deletions (D)
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1634 $D_count_1++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1635 $op = shift @comp_cigar_1;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1636 # print "$_ deleted $op\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1637 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1638 if ($op eq 'I') { # adjusting the genomic position for insertions (I)
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1639 $I_count_1++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1640 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1641 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1642
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1643 $start_read_1 += $ignore + $D_count_1 - $I_count_1;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1644 # print "start read 1 $start_read_1\t ignore: $ignore\t D count 1: $D_count_1\tI_count 1: $I_count_1\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1645
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1646 ### if the (read 1) strand information is '+', read 2 needs to be trimmed from the back
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1647
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1648 for (1..$ignore) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1649 my $op = pop @comp_cigar_2; # adjusting composite CIGAR string by removing $ignore operations, here the last value of the array
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1650 while ($op eq 'D') { # repeating this for deletions (D)
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1651 $op = pop @comp_cigar_2;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1652 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1653 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1654 # the start position of reads mapping to the reverse strand is being adjusted further below
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1655 } elsif ($strand eq '-') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1656
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1657 ### if the (read 1) strand information is '-', read 1 needs to be trimmed from the back
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1658 for (1..$ignore) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1659 my $op = pop @comp_cigar_1; # adjusting composite CIGAR string by removing $ignore operations, here the last value of the array
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1660 while ($op eq 'D') { # repeating this for deletions (D)
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1661 $op = pop @comp_cigar_1;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1662 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1663 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1664 # the start position of reads mapping to the reverse strand is being adjusted further below
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1665
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1666 ### if the (read 1) strand information is '-', read 2 needs to be trimmed from the start
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1667 my $D_count_2 = 0; # counting all deletions that affect the ignored genomic position for read 2, i.e. Deletions and insertions
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1668 my $I_count_2 = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1669
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1670 for (1..$ignore) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1671 my $op = shift @comp_cigar_2; # adjusting composite CIGAR string of read 2 by removing $ignore operations from the start
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1672 # print "$_ deleted $op\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1673
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1674 while ($op eq 'D') { # repeating this for deletions (D)
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1675 $D_count_2++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1676 $op = shift @comp_cigar_2;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1677 # print "$_ deleted $op\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1678 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1679 if ($op eq 'I') { # adjusting the genomic position for insertions (I)
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1680 $I_count_2++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1681 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1682 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1683
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1684 $start_read_2 += $ignore + $D_count_2 - $I_count_2;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1685 # print "start read 2 $start_read_2\t ignore: $ignore\t D count 2: $D_count_2\tI_count 2: $I_count_2\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1686
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1687 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1688
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1689 ### reconstituting shortened CIGAR string 1
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1690 my $new_cigar_1;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1691 my $count_1 = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1692 my $last_op_1;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1693 # print "ignore adjusted CIGAR 1: @comp_cigar_1\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1694 foreach my $op (@comp_cigar_1) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1695 unless (defined $last_op_1){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1696 $last_op_1 = $op;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1697 ++$count_1;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1698 next;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1699 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1700 if ($last_op_1 eq $op) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1701 ++$count_1;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1702 } else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1703 $new_cigar_1 .= "$count_1$last_op_1";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1704 $last_op_1 = $op;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1705 $count_1 = 1;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1706 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1707 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1708 $new_cigar_1 .= "$count_1$last_op_1"; # appending the last operation and count
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1709 $cigar_1 = $new_cigar_1;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1710 # print "ignore adjusted CIGAR 1 scalar: $cigar_1\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1711
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1712 ### reconstituting shortened CIGAR string 2
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1713 my $new_cigar_2;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1714 my $count_2 = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1715 my $last_op_2;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1716 # print "ignore adjusted CIGAR 2: @comp_cigar_2\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1717 foreach my $op (@comp_cigar_2) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1718 unless (defined $last_op_2){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1719 $last_op_2 = $op;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1720 ++$count_2;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1721 next;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1722 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1723 if ($last_op_2 eq $op) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1724 ++$count_2;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1725 } else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1726 $new_cigar_2 .= "$count_2$last_op_2";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1727 $last_op_2 = $op;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1728 $count_2 = 1;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1729 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1730 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1731 $new_cigar_2 .= "$count_2$last_op_2"; # appending the last operation and count
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1732 $cigar_2 = $new_cigar_2;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1733 # print "ignore adjusted CIGAR 2 scalar: $cigar_2\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1734
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1735 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1736
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1737 if ($strand eq '+') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1738 ### adjusting the start position for all reads mapping to the reverse strand, in this case read 2
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1739 @comp_cigar_2 = reverse@comp_cigar_2; # the CIGAR string needs to be reversed for all reads aligning to the reverse strand, too
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1740 # print "reverse: @comp_cigar_2\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1741
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1742 my $MD_count_1 = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1743 foreach (@comp_cigar_1) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1744 ++$MD_count_1 if ($_ eq 'M' or $_ eq 'D'); # Matching bases or deletions affect the genomic position of the 3' ends of reads, insertions don't
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1745 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1746
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1747 my $MD_count_2 = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1748 foreach (@comp_cigar_2) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1749 ++$MD_count_2 if ($_ eq 'M' or $_ eq 'D'); # Matching bases or deletions affect the genomic position of the 3' ends of reads, insertions don't
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1750 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1751
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1752 $end_read_1 = $start_read_1 + $MD_count_1 - 1;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1753 $start_read_2 += $MD_count_2 - 1; ## Passing on the start position on the reverse strand
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1754 } else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1755 ### adjusting the start position for all reads mapping to the reverse strand, in this case read 1
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1756
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1757 @comp_cigar_1 = reverse@comp_cigar_1; # the CIGAR string needs to be reversed for all reads aligning to the reverse strand, too
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1758 # print "reverse: @comp_cigar_1\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1759
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1760 my $MD_count_1 = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1761 foreach (@comp_cigar_1) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1762 ++$MD_count_1 if ($_ eq 'M' or $_ eq 'D'); # Matching bases or deletions affect the genomic position of the 3' ends of reads, insertions don't
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1763 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1764
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1765 $end_read_1 = $start_read_1;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1766 $start_read_1 += $MD_count_1 - 1; ### Passing on the start position on the reverse strand
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1767
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1768 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1769
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1770 if ($strand eq '+') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1771 ## we first pass the first read which is in + orientation on the forward strand
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1772 print_individual_C_methylation_states_paired_end_files($meth_call_1,$chrom,$start_read_1,$id_1,'+',$index,0,0,$cigar_1);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1773
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1774 # we next pass the second read which is in - orientation on the reverse strand
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1775 ### if --no_overlap was specified we also pass the end of read 1. If read 2 starts to overlap with read 1 we can stop extracting methylation calls from read 2
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1776 print_individual_C_methylation_states_paired_end_files($meth_call_2,$chrom,$start_read_2,$id_2,'-',$index,$no_overlap,$end_read_1,$cigar_2);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1777 } else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1778 ## we first pass the first read which is in - orientation on the reverse strand
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1779 print_individual_C_methylation_states_paired_end_files($meth_call_1,$chrom,$start_read_1,$id_1,'-',$index,0,0,$cigar_1);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1780
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1781 # we next pass the second read which is in + orientation on the forward strand
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1782 ### if --no_overlap was specified we also pass the end of read 1. If read 2 starts to overlap with read 1 we will stop extracting methylation calls from read 2
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1783 print_individual_C_methylation_states_paired_end_files($meth_call_2,$chrom,$start_read_2,$id_2,'+',$index,$no_overlap,$end_read_1,$cigar_2);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1784 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1785
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1786 $methylation_call_strings_processed += 2; # paired-end = 2 methylation calls
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1787 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1788 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1789 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1790 } else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1791 die "Single-end or paired-end reads not specified properly\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1792 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1793
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1794 print "\n\nProcessed $line_count lines from $filename in total\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1795 print "Total number of methylation call strings processed: $methylation_call_strings_processed\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1796 if ($report) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1797 print REPORT "Total number of methylation call strings processed: $methylation_call_strings_processed\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1798 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1799 print_splitting_report ();
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1800 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1801
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1802
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1803
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1804 sub print_splitting_report{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1805
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1806 ### Calculating methylation percentages if applicable
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1807
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1808 my $percent_meCpG;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1809 if (($counting{total_meCpG_count}+$counting{total_unmethylated_CpG_count}) > 0){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1810 $percent_meCpG = sprintf("%.1f",100*$counting{total_meCpG_count}/($counting{total_meCpG_count}+$counting{total_unmethylated_CpG_count}));
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1811 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1812
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1813 my $percent_meCHG;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1814 if (($counting{total_meCHG_count}+$counting{total_unmethylated_CHG_count}) > 0){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1815 $percent_meCHG = sprintf("%.1f",100*$counting{total_meCHG_count}/($counting{total_meCHG_count}+$counting{total_unmethylated_CHG_count}));
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1816 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1817
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1818 my $percent_meCHH;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1819 if (($counting{total_meCHH_count}+$counting{total_unmethylated_CHH_count}) > 0){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1820 $percent_meCHH = sprintf("%.1f",100*$counting{total_meCHH_count}/($counting{total_meCHH_count}+$counting{total_unmethylated_CHH_count}));
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1821 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1822
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1823 my $percent_non_CpG_methylation;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1824 if ($merge_non_CpG){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1825 if ( ($counting{total_meCHH_count}+$counting{total_unmethylated_CHH_count}+$counting{total_meCHG_count}+$counting{total_unmethylated_CHG_count}) > 0){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1826 $percent_non_CpG_methylation = sprintf("%.1f",100* ( $counting{total_meCHH_count}+$counting{total_meCHG_count} ) / ( $counting{total_meCHH_count}+$counting{total_unmethylated_CHH_count}+$counting{total_meCHG_count}+$counting{total_unmethylated_CHG_count} ) );
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1827 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1828 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1829
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1830 if ($report){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1831 ### detailed information about Cs analysed
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1832 print REPORT "Final Cytosine Methylation Report\n",'='x33,"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1833
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1834 my $total_number_of_C = $counting{total_meCHG_count}+$counting{total_meCHH_count}+$counting{total_meCpG_count}+$counting{total_unmethylated_CHG_count}+$counting{total_unmethylated_CHH_count}+$counting{total_unmethylated_CpG_count};
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1835 print REPORT "Total number of C's analysed:\t$total_number_of_C\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1836
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1837 print REPORT "Total methylated C's in CpG context:\t$counting{total_meCpG_count}\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1838 print REPORT "Total methylated C's in CHG context:\t$counting{total_meCHG_count}\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1839 print REPORT "Total methylated C's in CHH context:\t$counting{total_meCHH_count}\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1840
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1841 print REPORT "Total C to T conversions in CpG context:\t$counting{total_unmethylated_CpG_count}\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1842 print REPORT "Total C to T conversions in CHG context:\t$counting{total_unmethylated_CHG_count}\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1843 print REPORT "Total C to T conversions in CHH context:\t$counting{total_unmethylated_CHH_count}\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1844
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1845 ### calculating methylated CpG percentage if applicable
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1846 if ($percent_meCpG){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1847 print REPORT "C methylated in CpG context:\t${percent_meCpG}%\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1848 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1849 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1850 print REPORT "Can't determine percentage of methylated Cs in CpG context if value was 0\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1851 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1852
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1853 ### 2-Context Output
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1854 if ($merge_non_CpG){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1855 if ($percent_non_CpG_methylation){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1856 print REPORT "C methylated in non-CpG context:\t${percent_non_CpG_methylation}%\n\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1857 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1858 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1859 print REPORT "Can't determine percentage of methylated Cs in non-CpG context if value was 0\n\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1860 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1861 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1862
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1863 ### 3 Context Output
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1864 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1865 ### calculating methylated CHG percentage if applicable
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1866 if ($percent_meCHG){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1867 print REPORT "C methylated in CHG context:\t${percent_meCHG}%\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1868 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1869 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1870 print REPORT "Can't determine percentage of methylated Cs in CHG context if value was 0\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1871 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1872
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1873 ### calculating methylated CHH percentage if applicable
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1874 if ($percent_meCHH){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1875 print REPORT "C methylated in CHH context:\t${percent_meCHH}%\n\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1876 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1877 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1878 print REPORT "Can't determine percentage of methylated Cs in CHH context if value was 0\n\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1879 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1880 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1881 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1882
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1883 ### detailed information about Cs analysed for on-screen report
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1884 print "Final Cytosine Methylation Report\n",'='x33,"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1885
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1886 my $total_number_of_C = $counting{total_meCHG_count}+$counting{total_meCHH_count}+$counting{total_meCpG_count}+$counting{total_unmethylated_CHG_count}+$counting{total_unmethylated_CHH_count}+$counting{total_unmethylated_CpG_count};
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1887 print "Total number of C's analysed:\t$total_number_of_C\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1888
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1889 print "Total methylated C's in CpG context:\t$counting{total_meCpG_count}\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1890 print "Total methylated C's in CHG context:\t$counting{total_meCHG_count}\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1891 print "Total methylated C's in CHH context:\t$counting{total_meCHH_count}\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1892
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1893 print "Total C to T conversions in CpG context:\t$counting{total_unmethylated_CpG_count}\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1894 print "Total C to T conversions in CHG context:\t$counting{total_unmethylated_CHG_count}\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1895 print "Total C to T conversions in CHH context:\t$counting{total_unmethylated_CHH_count}\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1896
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1897 ### printing methylated CpG percentage if applicable
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1898 if ($percent_meCpG){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1899 print "C methylated in CpG context:\t${percent_meCpG}%\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1900 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1901 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1902 print "Can't determine percentage of methylated Cs in CpG context if value was 0\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1903 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1904
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1905 ### 2-Context Output
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1906 if ($merge_non_CpG){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1907 if ($percent_non_CpG_methylation){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1908 print "C methylated in non-CpG context:\t${percent_non_CpG_methylation}%\n\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1909 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1910 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1911 print "Can't determine percentage of methylated Cs in non-CpG context if value was 0\n\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1912 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1913 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1914
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1915 ### 3-Context Output
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1916 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1917 ### printing methylated CHG percentage if applicable
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1918 if ($percent_meCHG){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1919 print "C methylated in CHG context:\t${percent_meCHG}%\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1920 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1921 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1922 print "Can't determine percentage of methylated Cs in CHG context if value was 0\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1923 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1924
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1925 ### printing methylated CHH percentage if applicable
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1926 if ($percent_meCHH){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1927 print "C methylated in CHH context:\t${percent_meCHH}%\n\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1928 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1929 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1930 print "Can't determine percentage of methylated Cs in CHH context if value was 0\n\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1931 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1932 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1933 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1934
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1935
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1936
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1937
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1938
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1939 sub print_individual_C_methylation_states_paired_end_files{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1940
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1941 my ($meth_call,$chrom,$start,$id,$strand,$filehandle_index,$no_overlap,$end_read_1,$cigar) = @_;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1942 my @methylation_calls = split(//,$meth_call);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1943
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1944 #################################################################
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1945 ### . for bases not involving cytosines ###
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1946 ### X for methylated C in CHG context (was protected) ###
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1947 ### x for not methylated C in CHG context (was converted) ###
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1948 ### H for methylated C in CHH context (was protected) ###
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1949 ### h for not methylated C in CHH context (was converted) ###
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1950 ### Z for methylated C in CpG context (was protected) ###
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1951 ### z for not methylated C in CpG context (was converted) ###
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1952 #################################################################
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1953
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1954 my $methyl_CHG_count = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1955 my $methyl_CHH_count = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1956 my $methyl_CpG_count = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1957 my $unmethylated_CHG_count = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1958 my $unmethylated_CHH_count = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1959 my $unmethylated_CpG_count = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1960
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1961
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1962 my $pos_offset = 0; # this is only relevant for SAM reads with insertions or deletions
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1963 my $cigar_offset = 0; # again, this is only relevant for SAM reads containing indels
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1964 my @comp_cigar;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1965
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1966 ### Checking whether the CIGAR string is a linear genomic match or whether if requires indel processing
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1967 if ($cigar =~ /^\d+M$/){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1968 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1969 else{ # parsing CIGAR string
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1970 my @len;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1971 my @ops;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1972 @len = split (/\D+/,$cigar); # storing the length per operation
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1973 @ops = split (/\d+/,$cigar); # storing the operation
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1974 shift @ops; # remove the empty first element
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1975 die "CIGAR string contained a non-matching number of lengths and operations\n" unless (scalar @len == scalar @ops);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1976
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1977 foreach my $index (0..$#len){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1978 foreach (1..$len[$index]){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1979 # print "$ops[$index]";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1980 push @comp_cigar, $ops[$index];
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1981 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1982 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1983 # warn "\nDetected CIGAR string: $cigar\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1984 # warn "Length of methylation call: ",length $meth_call,"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1985 # warn "number of operations: ",scalar @ops,"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1986 # warn "number of length digits: ",scalar @len,"\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1987 # print @comp_cigar,"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1988 # print "$meth_call\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1989 # sleep (1);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1990 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1991
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1992 if ($strand eq '-') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1993
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1994 ### the CIGAR string needs to be reversed, the methylation call has already been reversed above
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1995 if (@comp_cigar){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1996 @comp_cigar = reverse@comp_cigar; # the CIGAR string needs to be reversed for all reads aligning to the reverse strand, too
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1997 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1998 # print "reverse CIGAR string: @comp_cigar\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
1999
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2000 ### the start position of paired-end files has already been corrected, see above
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2001 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2002
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2003 ### THIS IS AN OPTIONAL 2-CONTEXT (CpG and non-CpG) SECTION IF --merge_non_CpG was specified
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2004
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2005 if ($merge_non_CpG) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2006
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2007 if ($no_overlap) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2008
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2009 ### single-file CpG and non-CpG context output
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2010 if ($full) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2011 if ($strand eq '+') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2012 for my $index (0..$#methylation_calls) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2013
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2014 if ($cigar and @comp_cigar){ # only needed for SAM reads with InDels
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2015 my ($cigar_mod,$pos_mod) = check_cigar_string($index,$cigar_offset,$pos_offset,$strand,\@comp_cigar);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2016 # print "index: $index\tmethylation_call: $methylation_calls[$index]\tposition+index: ",$start+$index,"\t";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2017 $cigar_offset += $cigar_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2018 $pos_offset += $pos_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2019 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2020
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2021 ### Returning as soon as the methylation calls start overlapping
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2022 if ($start+$index+$pos_offset >= $end_read_1) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2023 return;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2024 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2025
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2026 if ($methylation_calls[$index] eq 'X') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2027 $counting{total_meCHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2028 print {$fhs{other_context}} join ("\t",$id,'+',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2029 } elsif ($methylation_calls[$index] eq 'x') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2030 $counting{total_unmethylated_CHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2031 print {$fhs{other_context}} join ("\t",$id,'-',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2032 } elsif ($methylation_calls[$index] eq 'Z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2033 $counting{total_meCpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2034 print {$fhs{CpG_context}} join ("\t",$id,'+',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2035 } elsif ($methylation_calls[$index] eq 'z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2036 $counting{total_unmethylated_CpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2037 print {$fhs{CpG_context}} join ("\t",$id,'-',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2038 } elsif ($methylation_calls[$index] eq 'H') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2039 $counting{total_meCHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2040 print {$fhs{other_context}} join ("\t",$id,'+',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2041 } elsif ($methylation_calls[$index] eq 'h') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2042 $counting{total_unmethylated_CHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2043 print {$fhs{other_context}} join ("\t",$id,'-',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2044 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2045 elsif ($methylation_calls[$index] eq '.'){}
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2046 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2047 die "The methylation call string contained the following unrecognised character: $methylation_calls[$index]\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2048 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2049 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2050 } elsif ($strand eq '-') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2051 for my $index (0..$#methylation_calls) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2052
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2053 if ($cigar and @comp_cigar){ # only needed for SAM reads with InDels
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2054 # print "index: $index\tmethylation_call: $methylation_calls[$index]\tposition-index: ",$start-$index,"\t";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2055 my ($cigar_mod,$pos_mod) = check_cigar_string($index,$cigar_offset,$pos_offset,$strand,\@comp_cigar);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2056 $cigar_offset += $cigar_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2057 $pos_offset += $pos_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2058 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2059
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2060 ### Returning as soon as the methylation calls start overlapping
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2061 if ($start-$index+$pos_offset <= $end_read_1) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2062 return;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2063 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2064
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2065 if ($methylation_calls[$index] eq 'X') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2066 $counting{total_meCHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2067 print {$fhs{other_context}} join ("\t",$id,'+',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2068 } elsif ($methylation_calls[$index] eq 'x') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2069 $counting{total_unmethylated_CHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2070 print {$fhs{other_context}} join ("\t",$id,'-',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2071 } elsif ($methylation_calls[$index] eq 'Z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2072 $counting{total_meCpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2073 print {$fhs{CpG_context}} join ("\t",$id,'+',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2074 } elsif ($methylation_calls[$index] eq 'z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2075 $counting{total_unmethylated_CpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2076 print {$fhs{CpG_context}} join ("\t",$id,'-',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2077 } elsif ($methylation_calls[$index] eq 'H') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2078 $counting{total_meCHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2079 print {$fhs{other_context}} join ("\t",$id,'+',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2080 } elsif ($methylation_calls[$index] eq 'h') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2081 $counting{total_unmethylated_CHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2082 print {$fhs{other_context}} join ("\t",$id,'-',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2083 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2084 elsif ($methylation_calls[$index] eq '.') {}
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2085 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2086 die "The methylation call string contained the following unrecognised character: $methylation_calls[$index]\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2087 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2088 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2089 } else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2090 die "The read orientation was neither + nor -: '$strand'\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2091 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2092 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2093
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2094 ### strand-specific methylation output
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2095 else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2096 if ($strand eq '+') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2097 for my $index (0..$#methylation_calls) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2098
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2099 if ($cigar and @comp_cigar){ # only needed for SAM reads with InDels
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2100 my ($cigar_mod,$pos_mod) = check_cigar_string($index,$cigar_offset,$pos_offset,$strand,\@comp_cigar);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2101 # print "index: $index\tmethylation_call: $methylation_calls[$index]\tposition+index: ",$start+$index,"\t";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2102 $cigar_offset += $cigar_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2103 $pos_offset += $pos_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2104 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2105
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2106 ### Returning as soon as the methylation calls start overlapping
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2107 if ($start+$index+$pos_offset >= $end_read_1) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2108 return;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2109 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2110
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2111 if ($methylation_calls[$index] eq 'X') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2112 $counting{total_meCHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2113 print {$fhs{$filehandle_index}->{other_c}} join ("\t",$id,'+',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2114 } elsif ($methylation_calls[$index] eq 'x') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2115 $counting{total_unmethylated_CHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2116 print {$fhs{$filehandle_index}->{other_c}} join ("\t",$id,'-',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2117 } elsif ($methylation_calls[$index] eq 'Z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2118 $counting{total_meCpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2119 print {$fhs{$filehandle_index}->{CpG}} join ("\t",$id,'+',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2120 } elsif ($methylation_calls[$index] eq 'z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2121 $counting{total_unmethylated_CpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2122 print {$fhs{$filehandle_index}->{CpG}} join ("\t",$id,'-',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2123 } elsif ($methylation_calls[$index] eq 'H') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2124 $counting{total_meCHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2125 print {$fhs{$filehandle_index}->{other_c}} join ("\t",$id,'+',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2126 } elsif ($methylation_calls[$index] eq 'h') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2127 $counting{total_unmethylated_CHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2128 print {$fhs{$filehandle_index}->{other_c}} join ("\t",$id,'-',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2129 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2130 elsif ($methylation_calls[$index] eq '.') {}
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2131 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2132 die "The methylation call string contained the following unrecognised character: $methylation_calls[$index]\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2133 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2134 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2135 } elsif ($strand eq '-') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2136 for my $index (0..$#methylation_calls) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2137
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2138 if ($cigar and @comp_cigar){ # only needed for SAM reads with InDels
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2139 # print "index: $index\tmethylation_call: $methylation_calls[$index]\tposition-index: ",$start-$index,"\t";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2140 my ($cigar_mod,$pos_mod) = check_cigar_string($index,$cigar_offset,$pos_offset,$strand,\@comp_cigar);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2141 $cigar_offset += $cigar_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2142 $pos_offset += $pos_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2143 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2144
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2145 ### Returning as soon as the methylation calls start overlapping
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2146 if ($start-$index+$pos_offset <= $end_read_1) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2147 return;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2148 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2149
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2150 if ($methylation_calls[$index] eq 'X') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2151 $counting{total_meCHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2152 print {$fhs{$filehandle_index}->{other_c}} join ("\t",$id,'+',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2153 } elsif ($methylation_calls[$index] eq 'x') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2154 $counting{total_unmethylated_CHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2155 print {$fhs{$filehandle_index}->{other_c}} join ("\t",$id,'-',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2156 } elsif ($methylation_calls[$index] eq 'Z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2157 $counting{total_meCpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2158 print {$fhs{$filehandle_index}->{CpG}} join ("\t",$id,'+',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2159 } elsif ($methylation_calls[$index] eq 'z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2160 $counting{total_unmethylated_CpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2161 print {$fhs{$filehandle_index}->{CpG}} join ("\t",$id,'-',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2162 } elsif ($methylation_calls[$index] eq 'H') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2163 $counting{total_meCHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2164 print {$fhs{$filehandle_index}->{other_c}} join ("\t",$id,'+',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2165 } elsif ($methylation_calls[$index] eq 'h') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2166 $counting{total_unmethylated_CHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2167 print {$fhs{$filehandle_index}->{other_c}} join ("\t",$id,'-',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2168 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2169 elsif ($methylation_calls[$index] eq '.') {}
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2170 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2171 die "The methylation call string contained the following unrecognised character: $methylation_calls[$index]\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2172 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2173 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2174 } else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2175 die "The strand orientation was neither + nor -: '$strand'/n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2176 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2177 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2178 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2179
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2180 ### this is the default paired-end procedure allowing overlaps and using every single C position
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2181 ### Still within the 2-CONTEXT ONLY optional section
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2182 else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2183 ### single-file CpG and non-CpG context output
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2184 if ($full) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2185 if ($strand eq '+') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2186 for my $index (0..$#methylation_calls) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2187
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2188 if ($cigar and @comp_cigar){ # only needed for SAM reads with InDels
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2189 my ($cigar_mod,$pos_mod) = check_cigar_string($index,$cigar_offset,$pos_offset,$strand,\@comp_cigar);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2190 # print "index: $index\tmethylation_call: $methylation_calls[$index]\tposition+index: ",$start+$index,"\t";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2191 $cigar_offset += $cigar_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2192 $pos_offset += $pos_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2193 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2194
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2195 if ($methylation_calls[$index] eq 'X') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2196 $counting{total_meCHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2197 print {$fhs{other_context}} join ("\t",$id,'+',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2198 } elsif ($methylation_calls[$index] eq 'x') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2199 $counting{total_unmethylated_CHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2200 print {$fhs{other_context}} join ("\t",$id,'-',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2201 } elsif ($methylation_calls[$index] eq 'Z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2202 $counting{total_meCpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2203 print {$fhs{CpG_context}} join ("\t",$id,'+',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2204 } elsif ($methylation_calls[$index] eq 'z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2205 $counting{total_unmethylated_CpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2206 print {$fhs{CpG_context}} join ("\t",$id,'-',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2207 } elsif ($methylation_calls[$index] eq 'H') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2208 $counting{total_meCHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2209 print {$fhs{other_context}} join ("\t",$id,'+',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2210 } elsif ($methylation_calls[$index] eq 'h') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2211 $counting{total_unmethylated_CHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2212 print {$fhs{other_context}} join ("\t",$id,'-',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2213 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2214 elsif ($methylation_calls[$index] eq '.') {}
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2215 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2216 die "The methylation call string contained the following unrecognised character: $methylation_calls[$index]\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2217 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2218 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2219 } elsif ($strand eq '-') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2220 for my $index (0..$#methylation_calls) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2221
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2222 if ($cigar and @comp_cigar){ # only needed for SAM reads with InDels
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2223 # print "index: $index\tmethylation_call: $methylation_calls[$index]\tposition-index: ",$start-$index,"\t";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2224 my ($cigar_mod,$pos_mod) = check_cigar_string($index,$cigar_offset,$pos_offset,$strand,\@comp_cigar);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2225 $cigar_offset += $cigar_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2226 $pos_offset += $pos_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2227 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2228
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2229 if ($methylation_calls[$index] eq 'X') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2230 $counting{total_meCHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2231 print {$fhs{other_context}} join ("\t",$id,'+',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2232 } elsif ($methylation_calls[$index] eq 'x') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2233 $counting{total_unmethylated_CHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2234 print {$fhs{other_context}} join ("\t",$id,'-',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2235 } elsif ($methylation_calls[$index] eq 'Z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2236 $counting{total_meCpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2237 print {$fhs{CpG_context}} join ("\t",$id,'+',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2238 } elsif ($methylation_calls[$index] eq 'z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2239 $counting{total_unmethylated_CpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2240 print {$fhs{CpG_context}} join ("\t",$id,'-',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2241 } elsif ($methylation_calls[$index] eq 'H') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2242 $counting{total_meCHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2243 print {$fhs{other_context}} join ("\t",$id,'+',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2244 } elsif ($methylation_calls[$index] eq 'h') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2245 $counting{total_unmethylated_CHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2246 print {$fhs{other_context}} join ("\t",$id,'-',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2247 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2248 elsif ($methylation_calls[$index] eq '.') {}
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2249 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2250 die "The methylation call string contained the following unrecognised character: $methylation_calls[$index]\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2251 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2252 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2253 } else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2254 die "The strand orientation as neither + nor -: '$strand'\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2255 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2256 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2257
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2258 ### strand-specific methylation output
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2259 ### still within the 2-CONTEXT optional section
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2260 else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2261 if ($strand eq '+') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2262 for my $index (0..$#methylation_calls) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2263
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2264 if ($cigar and @comp_cigar){ # only needed for SAM reads with InDels
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2265 my ($cigar_mod,$pos_mod) = check_cigar_string($index,$cigar_offset,$pos_offset,$strand,\@comp_cigar);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2266 # print "index: $index\tmethylation_call: $methylation_calls[$index]\tposition+index: ",$start+$index,"\t";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2267 $cigar_offset += $cigar_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2268 $pos_offset += $pos_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2269 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2270
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2271 if ($methylation_calls[$index] eq 'X') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2272 $counting{total_meCHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2273 print {$fhs{$filehandle_index}->{other_c}} join ("\t",$id,'+',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2274 } elsif ($methylation_calls[$index] eq 'x') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2275 $counting{total_unmethylated_CHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2276 print {$fhs{$filehandle_index}->{other_c}} join ("\t",$id,'-',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2277 } elsif ($methylation_calls[$index] eq 'Z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2278 $counting{total_meCpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2279 print {$fhs{$filehandle_index}->{CpG}} join ("\t",$id,'+',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2280 } elsif ($methylation_calls[$index] eq 'z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2281 $counting{total_unmethylated_CpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2282 print {$fhs{$filehandle_index}->{CpG}} join ("\t",$id,'-',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2283 } elsif ($methylation_calls[$index] eq 'H') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2284 $counting{total_meCHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2285 print {$fhs{$filehandle_index}->{other_c}} join ("\t",$id,'+',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2286 } elsif ($methylation_calls[$index] eq 'h') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2287 $counting{total_unmethylated_CHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2288 print {$fhs{$filehandle_index}->{other_c}} join ("\t",$id,'-',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2289 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2290 elsif ($methylation_calls[$index] eq '.') {}
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2291 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2292 die "The methylation call string contained the following unrecognised character: $methylation_calls[$index]\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2293 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2294 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2295 } elsif ($strand eq '-') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2296 for my $index (0..$#methylation_calls) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2297
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2298 if ($cigar and @comp_cigar){ # only needed for SAM reads with InDels
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2299 # print "index: $index\tmethylation_call: $methylation_calls[$index]\tposition-index: ",$start-$index,"\t";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2300 my ($cigar_mod,$pos_mod) = check_cigar_string($index,$cigar_offset,$pos_offset,$strand,\@comp_cigar);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2301 $cigar_offset += $cigar_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2302 $pos_offset += $pos_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2303 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2304
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2305 if ($methylation_calls[$index] eq 'X') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2306 $counting{total_meCHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2307 print {$fhs{$filehandle_index}->{other_c}} join ("\t",$id,'+',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2308 } elsif ($methylation_calls[$index] eq 'x') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2309 $counting{total_unmethylated_CHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2310 print {$fhs{$filehandle_index}->{other_c}} join ("\t",$id,'-',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2311 } elsif ($methylation_calls[$index] eq 'Z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2312 $counting{total_meCpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2313 print {$fhs{$filehandle_index}->{CpG}} join ("\t",$id,'+',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2314 } elsif ($methylation_calls[$index] eq 'z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2315 $counting{total_unmethylated_CpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2316 print {$fhs{$filehandle_index}->{CpG}} join ("\t",$id,'-',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2317 } elsif ($methylation_calls[$index] eq 'H') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2318 $counting{total_meCHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2319 print {$fhs{$filehandle_index}->{other_c}} join ("\t",$id,'+',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2320 } elsif ($methylation_calls[$index] eq 'h') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2321 $counting{total_unmethylated_CHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2322 print {$fhs{$filehandle_index}->{other_c}} join ("\t",$id,'-',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2323 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2324 elsif ($methylation_calls[$index] eq '.') {}
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2325 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2326 die "The methylation call string contained the following unrecognised character: $methylation_calls[$index]\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2327 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2328 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2329 } else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2330 die "The strand orientation as neither + nor -: '$strand'\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2331 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2332 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2333 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2334 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2335
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2336 ############################################
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2337 ### THIS IS THE DEFAULT 3-CONTEXT OUTPUT ###
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2338 ############################################
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2339
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2340 elsif ($no_overlap) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2341 ### single-file CpG, CHG and CHH context output
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2342 if ($full) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2343 if ($strand eq '+') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2344 for my $index (0..$#methylation_calls) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2345
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2346 if ($cigar and @comp_cigar){ # only needed for SAM reads with InDels
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2347 my ($cigar_mod,$pos_mod) = check_cigar_string($index,$cigar_offset,$pos_offset,$strand,\@comp_cigar);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2348 # print "index: $index\tmethylation_call: $methylation_calls[$index]\tposition+index: ",$start+$index,"\t";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2349 $cigar_offset += $cigar_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2350 $pos_offset += $pos_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2351 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2352
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2353 ### Returning as soon as the methylation calls start overlapping
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2354 if ($start+$index+$pos_offset >= $end_read_1) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2355 return;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2356 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2357
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2358 if ($methylation_calls[$index] eq 'X') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2359 $counting{total_meCHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2360 print {$fhs{CHG_context}} join ("\t",$id,'+',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2361 } elsif ($methylation_calls[$index] eq 'x') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2362 $counting{total_unmethylated_CHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2363 print {$fhs{CHG_context}} join ("\t",$id,'-',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2364 } elsif ($methylation_calls[$index] eq 'Z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2365 $counting{total_meCpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2366 print {$fhs{CpG_context}} join ("\t",$id,'+',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2367 } elsif ($methylation_calls[$index] eq 'z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2368 $counting{total_unmethylated_CpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2369 print {$fhs{CpG_context}} join ("\t",$id,'-',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2370 } elsif ($methylation_calls[$index] eq 'H') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2371 $counting{total_meCHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2372 print {$fhs{CHH_context}} join ("\t",$id,'+',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2373 } elsif ($methylation_calls[$index] eq 'h') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2374 $counting{total_unmethylated_CHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2375 print {$fhs{CHH_context}} join ("\t",$id,'-',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2376 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2377 elsif ($methylation_calls[$index] eq '.') {}
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2378 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2379 die "The methylation call string contained the following unrecognised character: $methylation_calls[$index]\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2380 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2381 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2382 } elsif ($strand eq '-') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2383 for my $index (0..$#methylation_calls) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2384
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2385 if ($cigar and @comp_cigar){ # only needed for SAM reads with InDels
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2386 # print "index: $index\tmethylation_call: $methylation_calls[$index]\tposition-index: ",$start-$index,"\t";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2387 my ($cigar_mod,$pos_mod) = check_cigar_string($index,$cigar_offset,$pos_offset,$strand,\@comp_cigar);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2388 $cigar_offset += $cigar_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2389 $pos_offset += $pos_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2390 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2391
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2392 ### Returning as soon as the methylation calls start overlapping
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2393 if ($start-$index+$pos_offset <= $end_read_1) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2394 return;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2395 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2396
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2397 if ($methylation_calls[$index] eq 'X') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2398 $counting{total_meCHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2399 print {$fhs{CHG_context}} join ("\t",$id,'+',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2400 } elsif ($methylation_calls[$index] eq 'x') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2401 $counting{total_unmethylated_CHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2402 print {$fhs{CHG_context}} join ("\t",$id,'-',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2403 } elsif ($methylation_calls[$index] eq 'Z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2404 $counting{total_meCpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2405 print {$fhs{CpG_context}} join ("\t",$id,'+',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2406 } elsif ($methylation_calls[$index] eq 'z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2407 $counting{total_unmethylated_CpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2408 print {$fhs{CpG_context}} join ("\t",$id,'-',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2409 } elsif ($methylation_calls[$index] eq 'H') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2410 $counting{total_meCHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2411 print {$fhs{CHH_context}} join ("\t",$id,'+',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2412 } elsif ($methylation_calls[$index] eq 'h') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2413 $counting{total_unmethylated_CHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2414 print {$fhs{CHH_context}} join ("\t",$id,'-',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2415 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2416 elsif ($methylation_calls[$index] eq '.') {}
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2417 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2418 die "The methylation call string contained the following unrecognised character: $methylation_calls[$index]\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2419 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2420 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2421 } else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2422 die "The strand orientation as neither + nor -: '$strand'\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2423 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2424 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2425
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2426 ### strand-specific methylation output
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2427 else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2428 if ($strand eq '+') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2429 for my $index (0..$#methylation_calls) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2430
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2431 if ($cigar and @comp_cigar){ # only needed for SAM reads with InDels
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2432 my ($cigar_mod,$pos_mod) = check_cigar_string($index,$cigar_offset,$pos_offset,$strand,\@comp_cigar);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2433 # print "index: $index\tmethylation_call: $methylation_calls[$index]\tposition+index: ",$start+$index,"\t";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2434 $cigar_offset += $cigar_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2435 $pos_offset += $pos_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2436 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2437
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2438 ### Returning as soon as the methylation calls start overlapping
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2439 if ($start+$index+$pos_offset >= $end_read_1) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2440 return;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2441 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2442
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2443 if ($methylation_calls[$index] eq 'X') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2444 $counting{total_meCHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2445 print {$fhs{$filehandle_index}->{CHG}} join ("\t",$id,'+',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2446 } elsif ($methylation_calls[$index] eq 'x') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2447 $counting{total_unmethylated_CHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2448 print {$fhs{$filehandle_index}->{CHG}} join ("\t",$id,'-',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2449 } elsif ($methylation_calls[$index] eq 'Z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2450 $counting{total_meCpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2451 print {$fhs{$filehandle_index}->{CpG}} join ("\t",$id,'+',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2452 } elsif ($methylation_calls[$index] eq 'z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2453 $counting{total_unmethylated_CpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2454 print {$fhs{$filehandle_index}->{CpG}} join ("\t",$id,'-',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2455 } elsif ($methylation_calls[$index] eq 'H') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2456 $counting{total_meCHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2457 print {$fhs{$filehandle_index}->{CHH}} join ("\t",$id,'+',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2458 } elsif ($methylation_calls[$index] eq 'h') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2459 $counting{total_unmethylated_CHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2460 print {$fhs{$filehandle_index}->{CHH}} join ("\t",$id,'-',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2461 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2462 elsif ($methylation_calls[$index] eq '.') {}
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2463 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2464 die "The methylation call string contained the following unrecognised character: $methylation_calls[$index]\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2465 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2466 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2467 } elsif ($strand eq '-') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2468 for my $index (0..$#methylation_calls) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2469
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2470 if ($cigar and @comp_cigar){ # only needed for SAM reads with InDels
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2471 # print "index: $index\tmethylation_call: $methylation_calls[$index]\tposition-index: ",$start-$index,"\t";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2472 my ($cigar_mod,$pos_mod) = check_cigar_string($index,$cigar_offset,$pos_offset,$strand,\@comp_cigar);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2473 $cigar_offset += $cigar_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2474 $pos_offset += $pos_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2475 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2476
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2477 ### Returning as soon as the methylation calls start overlapping
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2478 if ($start-$index+$pos_offset <= $end_read_1) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2479 return;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2480 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2481
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2482 if ($methylation_calls[$index] eq 'X') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2483 $counting{total_meCHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2484 print {$fhs{$filehandle_index}->{CHG}} join ("\t",$id,'+',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2485 } elsif ($methylation_calls[$index] eq 'x') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2486 $counting{total_unmethylated_CHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2487 print {$fhs{$filehandle_index}->{CHG}} join ("\t",$id,'-',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2488 } elsif ($methylation_calls[$index] eq 'Z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2489 $counting{total_meCpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2490 print {$fhs{$filehandle_index}->{CpG}} join ("\t",$id,'+',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2491 } elsif ($methylation_calls[$index] eq 'z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2492 $counting{total_unmethylated_CpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2493 print {$fhs{$filehandle_index}->{CpG}} join ("\t",$id,'-',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2494 } elsif ($methylation_calls[$index] eq 'H') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2495 $counting{total_meCHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2496 print {$fhs{$filehandle_index}->{CHH}} join ("\t",$id,'+',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2497 } elsif ($methylation_calls[$index] eq 'h') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2498 $counting{total_unmethylated_CHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2499 print {$fhs{$filehandle_index}->{CHH}} join ("\t",$id,'-',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2500 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2501 elsif ($methylation_calls[$index] eq '.') {}
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2502 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2503 die "The methylation call string contained the following unrecognised character: $methylation_calls[$index]\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2504 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2505 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2506 } else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2507 die "The strand orientation as neither + nor -: '$strand'\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2508 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2509 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2510 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2511
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2512 ### this is the default paired-end procedure allowing overlaps and using every single C position
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2513 else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2514 ### single-file CpG, CHG and CHH context output
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2515 if ($full) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2516 if ($strand eq '+') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2517 for my $index (0..$#methylation_calls) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2518
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2519 if ($cigar and @comp_cigar){ # only needed for SAM reads with InDels
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2520 my ($cigar_mod,$pos_mod) = check_cigar_string($index,$cigar_offset,$pos_offset,$strand,\@comp_cigar);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2521 # print "index: $index\tmethylation_call: $methylation_calls[$index]\tposition+index: ",$start+$index,"\t";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2522 $cigar_offset += $cigar_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2523 $pos_offset += $pos_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2524 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2525
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2526 if ($methylation_calls[$index] eq 'X') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2527 $counting{total_meCHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2528 print {$fhs{CHG_context}} join ("\t",$id,'+',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2529 } elsif ($methylation_calls[$index] eq 'x') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2530 $counting{total_unmethylated_CHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2531 print {$fhs{CHG_context}} join ("\t",$id,'-',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2532 } elsif ($methylation_calls[$index] eq 'Z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2533 $counting{total_meCpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2534 print {$fhs{CpG_context}} join ("\t",$id,'+',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2535 } elsif ($methylation_calls[$index] eq 'z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2536 $counting{total_unmethylated_CpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2537 print {$fhs{CpG_context}} join ("\t",$id,'-',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2538 } elsif ($methylation_calls[$index] eq 'H') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2539 $counting{total_meCHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2540 print {$fhs{CHH_context}} join ("\t",$id,'+',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2541 } elsif ($methylation_calls[$index] eq 'h') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2542 $counting{total_unmethylated_CHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2543 print {$fhs{CHH_context}} join ("\t",$id,'-',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2544 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2545 elsif ($methylation_calls[$index] eq '.') {}
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2546 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2547 die "The methylation call string contained the following unrecognised character: $methylation_calls[$index]\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2548 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2549 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2550 } elsif ($strand eq '-') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2551 for my $index (0..$#methylation_calls) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2552
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2553 if ($cigar and @comp_cigar){ # only needed for SAM reads with InDels
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2554 # print "index: $index\tmethylation_call: $methylation_calls[$index]\tposition-index: ",$start-$index,"\t";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2555 my ($cigar_mod,$pos_mod) = check_cigar_string($index,$cigar_offset,$pos_offset,$strand,\@comp_cigar);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2556 $cigar_offset += $cigar_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2557 $pos_offset += $pos_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2558 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2559
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2560 if ($methylation_calls[$index] eq 'X') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2561 $counting{total_meCHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2562 print {$fhs{CHG_context}} join ("\t",$id,'+',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2563 } elsif ($methylation_calls[$index] eq 'x') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2564 $counting{total_unmethylated_CHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2565 print {$fhs{CHG_context}} join ("\t",$id,'-',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2566 } elsif ($methylation_calls[$index] eq 'Z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2567 $counting{total_meCpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2568 print {$fhs{CpG_context}} join ("\t",$id,'+',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2569 } elsif ($methylation_calls[$index] eq 'z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2570 $counting{total_unmethylated_CpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2571 print {$fhs{CpG_context}} join ("\t",$id,'-',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2572 } elsif ($methylation_calls[$index] eq 'H') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2573 $counting{total_meCHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2574 print {$fhs{CHH_context}} join ("\t",$id,'+',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2575 } elsif ($methylation_calls[$index] eq 'h') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2576 $counting{total_unmethylated_CHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2577 print {$fhs{CHH_context}} join ("\t",$id,'-',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2578 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2579 elsif ($methylation_calls[$index] eq '.') {}
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2580 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2581 die "The methylation call string contained the following unrecognised character: $methylation_calls[$index]\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2582 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2583 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2584 } else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2585 die "The strand orientation as neither + nor -: '$strand'\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2586 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2587 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2588
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2589 ### strand-specific methylation output
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2590 else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2591 if ($strand eq '+') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2592 for my $index (0..$#methylation_calls) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2593
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2594 if ($cigar and @comp_cigar){ # only needed for SAM reads with InDels
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2595 my ($cigar_mod,$pos_mod) = check_cigar_string($index,$cigar_offset,$pos_offset,$strand,\@comp_cigar);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2596 # print "index: $index\tmethylation_call: $methylation_calls[$index]\tposition+index: ",$start+$index,"\t";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2597 $cigar_offset += $cigar_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2598 $pos_offset += $pos_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2599 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2600
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2601 if ($methylation_calls[$index] eq 'X') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2602 $counting{total_meCHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2603 print {$fhs{$filehandle_index}->{CHG}} join ("\t",$id,'+',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2604 } elsif ($methylation_calls[$index] eq 'x') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2605 $counting{total_unmethylated_CHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2606 print {$fhs{$filehandle_index}->{CHG}} join ("\t",$id,'-',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2607 } elsif ($methylation_calls[$index] eq 'Z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2608 $counting{total_meCpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2609 print {$fhs{$filehandle_index}->{CpG}} join ("\t",$id,'+',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2610 } elsif ($methylation_calls[$index] eq 'z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2611 $counting{total_unmethylated_CpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2612 print {$fhs{$filehandle_index}->{CpG}} join ("\t",$id,'-',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2613 } elsif ($methylation_calls[$index] eq 'H') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2614 $counting{total_meCHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2615 print {$fhs{$filehandle_index}->{CHH}} join ("\t",$id,'+',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2616 } elsif ($methylation_calls[$index] eq 'h') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2617 $counting{total_unmethylated_CHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2618 print {$fhs{$filehandle_index}->{CHH}} join ("\t",$id,'-',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2619 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2620 elsif ($methylation_calls[$index] eq '.') {}
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2621 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2622 die "The methylation call string contained the following unrecognised character: $methylation_calls[$index]\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2623 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2624 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2625 } elsif ($strand eq '-') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2626 for my $index (0..$#methylation_calls) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2627
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2628 if ($cigar and @comp_cigar){ # only needed for SAM reads with InDels
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2629 # print "index: $index\tmethylation_call: $methylation_calls[$index]\tposition-index: ",$start-$index,"\t";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2630 my ($cigar_mod,$pos_mod) = check_cigar_string($index,$cigar_offset,$pos_offset,$strand,\@comp_cigar);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2631 $cigar_offset += $cigar_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2632 $pos_offset += $pos_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2633 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2634
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2635 if ($methylation_calls[$index] eq 'X') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2636 $counting{total_meCHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2637 print {$fhs{$filehandle_index}->{CHG}} join ("\t",$id,'+',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2638 } elsif ($methylation_calls[$index] eq 'x') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2639 $counting{total_unmethylated_CHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2640 print {$fhs{$filehandle_index}->{CHG}} join ("\t",$id,'-',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2641 } elsif ($methylation_calls[$index] eq 'Z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2642 $counting{total_meCpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2643 print {$fhs{$filehandle_index}->{CpG}} join ("\t",$id,'+',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2644 } elsif ($methylation_calls[$index] eq 'z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2645 $counting{total_unmethylated_CpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2646 print {$fhs{$filehandle_index}->{CpG}} join ("\t",$id,'-',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2647 } elsif ($methylation_calls[$index] eq 'H') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2648 $counting{total_meCHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2649 print {$fhs{$filehandle_index}->{CHH}} join ("\t",$id,'+',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2650 } elsif ($methylation_calls[$index] eq 'h') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2651 $counting{total_unmethylated_CHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2652 print {$fhs{$filehandle_index}->{CHH}} join ("\t",$id,'-',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2653 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2654 elsif ($methylation_calls[$index] eq '.') {}
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2655 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2656 die "The methylation call string contained the following unrecognised character: $methylation_calls[$index]\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2657 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2658 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2659 } else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2660 die "The strand orientation as neither + nor -: '$strand'\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2661 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2662 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2663 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2664 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2665
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2666 sub check_cigar_string {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2667 my ($index,$cigar_offset,$pos_offset,$strand,$comp_cigar) = @_;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2668 # print "$index\t$cigar_offset\t$pos_offset\t$strand\t";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2669 my ($new_cigar_offset,$new_pos_offset) = (0,0);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2670
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2671 if ($strand eq '+') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2672 # print "### $strand strand @$comp_cigar[$index + $cigar_offset]\t";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2673
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2674 if (@$comp_cigar[$index + $cigar_offset + $new_cigar_offset] eq 'M'){ # sequence position matches the genomic position
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2675 # warn "position needs no adjustment\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2676 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2677
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2678 elsif (@$comp_cigar[$index + $cigar_offset + $new_cigar_offset] eq 'I'){ # insertion in the read sequence
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2679 $new_pos_offset -= 1; # we need to subtract the length of inserted bases from the genomic position
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2680 # warn "adjusted genomic position by -1 bp (insertion)\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2681 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2682
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2683 elsif (@$comp_cigar[$index + $cigar_offset + $new_cigar_offset] eq 'D'){ # deletion in the read sequence
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2684 $new_cigar_offset += 1; # the composite cigar string does no longer match the methylation call index
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2685 $new_pos_offset += 1; # we need to add the length of deleted bases to get the genomic position
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2686 # warn "adjusted genomic position by +1 bp (deletion). Now looping through the CIGAR string until we hit another M or I\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2687
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2688 while ( ($index + $cigar_offset + $new_cigar_offset) < (scalar @$comp_cigar) ){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2689 if (@$comp_cigar[$index + $cigar_offset + $new_cigar_offset] eq 'M'){ # sequence position matches the genomic position
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2690 # warn "position needs no adjustment\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2691 last;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2692 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2693 elsif (@$comp_cigar[$index + $cigar_offset + $new_cigar_offset] eq 'I'){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2694 $new_pos_offset -= 1; # we need to subtract the length of inserted bases from the genomic position
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2695 # warn "adjusted genomic position by another -1 bp (insertion)\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2696 last;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2697 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2698 elsif (@$comp_cigar[$index + $cigar_offset + $new_cigar_offset] eq 'D'){ # deletion in the read sequence
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2699 $new_cigar_offset += 1; # the composite cigar string does no longer match the methylation call index
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2700 $new_pos_offset += 1; # we need to add the length of deleted bases to get the genomic position
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2701 # warn "adjusted genomic position by another +1 bp (deletion)\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2702 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2703 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2704 die "The CIGAR string contained undefined operations in addition to 'M', 'I' and 'D': '@$comp_cigar[$index + $cigar_offset + $new_cigar_offset]'\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2705 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2706 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2707 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2708 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2709 die "The CIGAR string contained undefined operations in addition to 'M', 'I' and 'D': '@$comp_cigar[$index + $cigar_offset + $new_cigar_offset]'\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2710 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2711 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2712
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2713 elsif ($strand eq '-') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2714 # print "### $strand strand @$comp_cigar[$index + $cigar_offset]\t";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2715
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2716 if (@$comp_cigar[$index + $cigar_offset + $new_cigar_offset] eq 'M'){ # sequence position matches the genomic position
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2717 # warn "position needs no adjustment\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2718 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2719
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2720 elsif (@$comp_cigar[$index + $cigar_offset + $new_cigar_offset] eq 'I'){ # insertion in the read sequence
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2721 $new_pos_offset += 1; # we need to add the length of inserted bases to the genomic position
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2722 # warn "adjusted genomic position by +1 bp (insertion)\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2723 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2724
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2725 elsif (@$comp_cigar[$index + $cigar_offset + $new_cigar_offset] eq 'D'){ # deletion in the read sequence
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2726 $new_cigar_offset += 1; # the composite cigar string does no longer match the methylation call index
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2727 $new_pos_offset -= 1; # we need to subtract the length of deleted bases to get the genomic position
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2728 # warn "adjusted genomic position by -1 bp (deletion). Now looping through the CIGAR string until we hit another M or I\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2729
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2730 while ( ($index + $cigar_offset + $new_cigar_offset) < (scalar @$comp_cigar) ){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2731 if (@$comp_cigar[$index + $cigar_offset + $new_cigar_offset] eq 'M'){ # sequence position matches the genomic position
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2732 # warn "Found new 'M' operation; position needs no adjustment\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2733 last;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2734 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2735 elsif (@$comp_cigar[$index + $cigar_offset + $new_cigar_offset] eq 'I'){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2736 $new_pos_offset += 1; # we need to subtract the length of inserted bases from the genomic position
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2737 # warn "Found new 'I' operation; adjusted genomic position by another +1 bp (insertion)\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2738 last;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2739 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2740 elsif (@$comp_cigar[$index + $cigar_offset + $new_cigar_offset] eq 'D'){ # deletion in the read sequence
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2741 $new_cigar_offset += 1; # the composite cigar string does no longer match the methylation call index
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2742 $new_pos_offset -= 1; # we need to subtract the length of deleted bases to get the genomic position
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2743 # warn "adjusted genomic position by another -1 bp (deletion)\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2744 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2745 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2746 die "The CIGAR string contained undefined operations in addition to 'M', 'I' and 'D': '@$comp_cigar[$index + $cigar_offset + $new_cigar_offset]'\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2747 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2748 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2749 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2750 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2751 die "The CIGAR string contained undefined operations in addition to 'M', 'I' and 'D': '@$comp_cigar[$index + $cigar_offset + $new_cigar_offset]'\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2752 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2753 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2754 # print "new cigar offset: $new_cigar_offset\tnew pos offset: $new_pos_offset\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2755 return ($new_cigar_offset,$new_pos_offset);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2756 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2757
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2758 sub print_individual_C_methylation_states_single_end{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2759
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2760 my ($meth_call,$chrom,$start,$id,$strand,$filehandle_index,$cigar) = @_;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2761 my @methylation_calls = split(//,$meth_call);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2762
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2763 #################################################################
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2764 ### . for bases not involving cytosines ###
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2765 ### X for methylated C in CHG context (was protected) ###
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2766 ### x for not methylated C in CHG context (was converted) ###
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2767 ### H for methylated C in CHH context (was protected) ###
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2768 ### h for not methylated C in CHH context (was converted) ###
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2769 ### Z for methylated C in CpG context (was protected) ###
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2770 ### z for not methylated C in CpG context (was converted) ###
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2771 #################################################################
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2772
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2773 my $methyl_CHG_count = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2774 my $methyl_CHH_count = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2775 my $methyl_CpG_count = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2776 my $unmethylated_CHG_count = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2777 my $unmethylated_CHH_count = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2778 my $unmethylated_CpG_count = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2779
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2780 my $pos_offset = 0; # this is only relevant for SAM reads with insertions or deletions
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2781 my $cigar_offset = 0; # again, this is only relevant for SAM reads containing indels
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2782
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2783 my @comp_cigar;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2784
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2785 if ($cigar){ # parsing CIGAR string
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2786
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2787 ### Checking whether the CIGAR string is a linear genomic match or whether if requires indel processing
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2788 if ($cigar =~ /^\d+M$/){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2789 # warn "See!? I told you so! $cigar\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2790 # sleep(1);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2791 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2792 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2793
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2794 my @len;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2795 my @ops;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2796
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2797 @len = split (/\D+/,$cigar); # storing the length per operation
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2798 @ops = split (/\d+/,$cigar); # storing the operation
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2799 shift @ops; # remove the empty first element
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2800 die "CIGAR string contained a non-matching number of lengths and operations\n" unless (scalar @len == scalar @ops);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2801
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2802 foreach my $index (0..$#len){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2803 foreach (1..$len[$index]){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2804 # print "$ops[$index]";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2805 push @comp_cigar, $ops[$index];
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2806 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2807 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2808 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2809 # warn "\nDetected CIGAR string: $cigar\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2810 # warn "Length of methylation call: ",length $meth_call,"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2811 # warn "number of operations: ",scalar @ops,"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2812 # warn "number of length digits: ",scalar @len,"\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2813 # print @comp_cigar,"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2814 # print "$meth_call\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2815 # sleep (1);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2816 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2817
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2818 ### adjusting the start position for all reads mapping to the reverse strand
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2819 if ($strand eq '-') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2820
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2821 if (@comp_cigar){ # only needed for SAM reads with InDels
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2822 @comp_cigar = reverse@comp_cigar; # the CIGAR string needs to be reversed for all reads aligning to the reverse strand, too
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2823 # print @comp_cigar,"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2824 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2825
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2826 unless ($ignore){ ### if --ignore was specified the start position has already been corrected
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2827
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2828 if ($cigar){ ### SAM format
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2829 if ($cigar =~ /^(\d+)M$/){ # linear match
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2830 $start += $1 - 1;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2831 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2832 else{ # InDel read
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2833 my $MD_count = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2834 foreach (@comp_cigar){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2835 ++$MD_count if ($_ eq 'M' or $_ eq 'D'); # Matching bases or deletions affect the genomic position of the 3' ends of reads, insertions don't
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2836 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2837 $start += $MD_count - 1;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2838 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2839 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2840 else{ ### vanilla format
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2841 $start += length($meth_call)-1;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2842 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2843 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2844 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2845
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2846 ### THIS IS THE CpG and Non-CpG SECTION (OPTIONAL)
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2847
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2848 ### single-file CpG and other-context output
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2849 if ($full and $merge_non_CpG) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2850 if ($strand eq '+') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2851 for my $index (0..$#methylation_calls) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2852
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2853 if ($cigar and @comp_cigar){ # only needed for SAM alignments with InDels
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2854 my ($cigar_mod,$pos_mod) = check_cigar_string($index,$cigar_offset,$pos_offset,$strand,\@comp_cigar);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2855 # print "index: $index\tmethylation_call: $methylation_calls[$index]\tposition+index: ",$start+$index,"\t";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2856 $cigar_offset += $cigar_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2857 $pos_offset += $pos_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2858 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2859
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2860 ### methylated Cs (any context) will receive a forward (+) orientation
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2861 ### not methylated Cs (any context) will receive a reverse (-) orientation
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2862 if ($methylation_calls[$index] eq 'X') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2863 $counting{total_meCHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2864 print {$fhs{other_context}} join ("\t",$id,'+',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2865 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2866 elsif ($methylation_calls[$index] eq 'x') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2867 $counting{total_unmethylated_CHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2868 print {$fhs{other_context}} join ("\t",$id,'-',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2869 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2870 elsif ($methylation_calls[$index] eq 'Z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2871 $counting{total_meCpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2872 print {$fhs{CpG_context}} join ("\t",$id,'+',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2873 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2874 elsif ($methylation_calls[$index] eq 'z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2875 $counting{total_unmethylated_CpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2876 print {$fhs{CpG_context}} join ("\t",$id,'-',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2877 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2878 elsif ($methylation_calls[$index] eq 'H') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2879 $counting{total_meCHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2880 print {$fhs{other_context}} join ("\t",$id,'+',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2881 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2882 elsif ($methylation_calls[$index] eq 'h') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2883 $counting{total_unmethylated_CHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2884 print {$fhs{other_context}} join ("\t",$id,'-',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2885 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2886 elsif ($methylation_calls[$index] eq '.') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2887 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2888 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2889 die "The methylation call string contained the following unrecognised character: $methylation_calls[$index]\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2890 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2891 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2892 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2893 elsif ($strand eq '-') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2894
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2895 for my $index (0..$#methylation_calls) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2896 ### methylated Cs (any context) will receive a forward (+) orientation
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2897 ### not methylated Cs (any context) will receive a reverse (-) orientation
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2898
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2899 if ($cigar and @comp_cigar){ # only needed for SAM entries with InDels
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2900 # print "index: $index\tmethylation_call: $methylation_calls[$index]\tposition-index: ",$start-$index,"\t";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2901 my ($cigar_mod,$pos_mod) = check_cigar_string($index,$cigar_offset,$pos_offset,$strand,\@comp_cigar);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2902 $cigar_offset += $cigar_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2903 $pos_offset += $pos_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2904 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2905
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2906 if ($methylation_calls[$index] eq 'X') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2907 $counting{total_meCHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2908 print {$fhs{other_context}} join ("\t",$id,'+',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2909 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2910 elsif ($methylation_calls[$index] eq 'x') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2911 $counting{total_unmethylated_CHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2912 print {$fhs{other_context}} join ("\t",$id,'-',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2913 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2914 elsif ($methylation_calls[$index] eq 'Z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2915 $counting{total_meCpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2916 print {$fhs{CpG_context}} join ("\t",$id,'+',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2917 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2918 elsif ($methylation_calls[$index] eq 'z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2919 $counting{total_unmethylated_CpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2920 print {$fhs{CpG_context}} join ("\t",$id,'-',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2921 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2922 elsif ($methylation_calls[$index] eq 'H') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2923 $counting{total_meCHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2924 print {$fhs{other_context}} join ("\t",$id,'+',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2925 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2926 elsif ($methylation_calls[$index] eq 'h') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2927 $counting{total_unmethylated_CHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2928 print {$fhs{other_context}} join ("\t",$id,'-',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2929 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2930 elsif ($methylation_calls[$index] eq '.'){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2931 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2932 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2933 die "The methylation call string contained the following unrecognised character: $methylation_calls[$index]\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2934 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2935 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2936 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2937 else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2938 die "The strand information was neither + nor -: $strand\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2939 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2940 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2941
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2942 ### strand-specific methylation output
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2943 elsif ($merge_non_CpG) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2944 if ($strand eq '+') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2945 for my $index (0..$#methylation_calls) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2946 ### methylated Cs (any context) will receive a forward (+) orientation
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2947 ### not methylated Cs (any context) will receive a reverse (-) orientation
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2948
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2949 if ($cigar and @comp_cigar){ # only needed for SAM reads with Indels
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2950 my ($cigar_mod,$pos_mod) = check_cigar_string($index,$cigar_offset,$pos_offset,$strand,\@comp_cigar);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2951 $cigar_offset += $cigar_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2952 $pos_offset += $pos_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2953 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2954
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2955 if ($methylation_calls[$index] eq 'X') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2956 $counting{total_meCHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2957 print {$fhs{$filehandle_index}->{other_c}} join ("\t",$id,'+',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2958 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2959 elsif ($methylation_calls[$index] eq 'x') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2960 $counting{total_unmethylated_CHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2961 print {$fhs{$filehandle_index}->{other_c}} join ("\t",$id,'-',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2962 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2963 elsif ($methylation_calls[$index] eq 'Z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2964 $counting{total_meCpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2965 print {$fhs{$filehandle_index}->{CpG}} join ("\t",$id,'+',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2966 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2967 elsif ($methylation_calls[$index] eq 'z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2968 $counting{total_unmethylated_CpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2969 print {$fhs{$filehandle_index}->{CpG}} join ("\t",$id,'-',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2970 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2971 elsif ($methylation_calls[$index] eq 'H') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2972 $counting{total_meCHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2973 print {$fhs{$filehandle_index}->{other_c}} join ("\t",$id,'+',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2974 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2975 elsif ($methylation_calls[$index] eq 'h') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2976 $counting{total_unmethylated_CHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2977 print {$fhs{$filehandle_index}->{other_c}} join ("\t",$id,'-',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2978 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2979 elsif ($methylation_calls[$index] eq '.') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2980 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2981 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2982 die "The methylation call string contained the following unrecognised character: $methylation_calls[$index]\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2983 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2984 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2985 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2986 elsif ($strand eq '-') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2987
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2988 for my $index (0..$#methylation_calls) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2989 ### methylated Cs (any context) will receive a forward (+) orientation
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2990 ### not methylated Cs (any context) will receive a reverse (-) orientation
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2991
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2992 if ($cigar and @comp_cigar){ # only needed for SAM reads with Indels
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2993 my ($cigar_mod,$pos_mod) = check_cigar_string($index,$cigar_offset,$pos_offset,$strand,\@comp_cigar);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2994 $cigar_offset += $cigar_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2995 $pos_offset += $pos_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2996 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2997
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2998 if ($methylation_calls[$index] eq 'X') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
2999 $counting{total_meCHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3000 print {$fhs{$filehandle_index}->{other_c}} join ("\t",$id,'+',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3001 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3002 elsif ($methylation_calls[$index] eq 'x') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3003 $counting{total_unmethylated_CHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3004 print {$fhs{$filehandle_index}->{other_c}} join ("\t",$id,'-',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3005 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3006 elsif ($methylation_calls[$index] eq 'Z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3007 $counting{total_meCpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3008 print {$fhs{$filehandle_index}->{CpG}} join ("\t",$id,'+',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3009 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3010 elsif ($methylation_calls[$index] eq 'z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3011 $counting{total_unmethylated_CpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3012 print {$fhs{$filehandle_index}->{CpG}} join ("\t",$id,'-',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3013 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3014 elsif ($methylation_calls[$index] eq 'H') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3015 $counting{total_meCHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3016 print {$fhs{$filehandle_index}->{other_c}} join ("\t",$id,'+',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3017 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3018 elsif ($methylation_calls[$index] eq 'h') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3019 $counting{total_unmethylated_CHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3020 print {$fhs{$filehandle_index}->{other_c}} join ("\t",$id,'-',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3021 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3022 elsif ($methylation_calls[$index] eq '.') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3023 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3024 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3025 die "The methylation call string contained the following unrecognised character: $methylation_calls[$index]\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3026 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3027 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3028 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3029 else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3030 die "The strand information was neither + nor -: $strand\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3031 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3032 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3033
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3034 ### THIS IS THE 3-CONTEXT (CpG, CHG and CHH) DEFAULT SECTION
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3035
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3036 elsif ($full) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3037 if ($strand eq '+') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3038 for my $index (0..$#methylation_calls) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3039 ### methylated Cs (any context) will receive a forward (+) orientation
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3040 ### not methylated Cs (any context) will receive a reverse (-) orientation
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3041
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3042 if ($cigar and @comp_cigar){ # only needed for SAM reads with Indels
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3043 my ($cigar_mod,$pos_mod) = check_cigar_string($index,$cigar_offset,$pos_offset,$strand,\@comp_cigar);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3044 $cigar_offset += $cigar_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3045 $pos_offset += $pos_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3046 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3047
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3048 if ($methylation_calls[$index] eq 'X') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3049 $counting{total_meCHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3050 print {$fhs{CHG_context}} join ("\t",$id,'+',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3051 } elsif ($methylation_calls[$index] eq 'x') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3052 $counting{total_unmethylated_CHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3053 print {$fhs{CHG_context}} join ("\t",$id,'-',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3054 } elsif ($methylation_calls[$index] eq 'Z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3055 $counting{total_meCpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3056 print {$fhs{CpG_context}} join ("\t",$id,'+',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3057 } elsif ($methylation_calls[$index] eq 'z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3058 $counting{total_unmethylated_CpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3059 print {$fhs{CpG_context}} join ("\t",$id,'-',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3060 } elsif ($methylation_calls[$index] eq 'H') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3061 $counting{total_meCHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3062 print {$fhs{CHH_context}} join ("\t",$id,'+',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3063 } elsif ($methylation_calls[$index] eq 'h') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3064 $counting{total_unmethylated_CHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3065 print {$fhs{CHH_context}} join ("\t",$id,'-',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3066 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3067 elsif ($methylation_calls[$index] eq '.') {}
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3068 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3069 die "The methylation call string contained the following unrecognised character: $methylation_calls[$index]\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3070 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3071 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3072 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3073 elsif ($strand eq '-') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3074
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3075 for my $index (0..$#methylation_calls) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3076 ### methylated Cs (any context) will receive a forward (+) orientation
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3077 ### not methylated Cs (any context) will receive a reverse (-) orientation
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3078
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3079 if ($cigar and @comp_cigar){ # only needed for SAM reads with Indels
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3080 my ($cigar_mod,$pos_mod) = check_cigar_string($index,$cigar_offset,$pos_offset,$strand,\@comp_cigar);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3081 $cigar_offset += $cigar_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3082 $pos_offset += $pos_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3083 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3084
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3085 if ($methylation_calls[$index] eq 'X') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3086 $counting{total_meCHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3087 print {$fhs{CHG_context}} join ("\t",$id,'+',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3088 } elsif ($methylation_calls[$index] eq 'x') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3089 $counting{total_unmethylated_CHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3090 print {$fhs{CHG_context}} join ("\t",$id,'-',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3091 } elsif ($methylation_calls[$index] eq 'Z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3092 $counting{total_meCpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3093 print {$fhs{CpG_context}} join ("\t",$id,'+',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3094 } elsif ($methylation_calls[$index] eq 'z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3095 $counting{total_unmethylated_CpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3096 print {$fhs{CpG_context}} join ("\t",$id,'-',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3097 } elsif ($methylation_calls[$index] eq 'H') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3098 $counting{total_meCHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3099 print {$fhs{CHH_context}} join ("\t",$id,'+',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3100 } elsif ($methylation_calls[$index] eq 'h') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3101 $counting{total_unmethylated_CHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3102 print {$fhs{CHH_context}} join ("\t",$id,'-',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3103 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3104 elsif ($methylation_calls[$index] eq '.') {}
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3105 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3106 die "The methylation call string contained the following unrecognised character: $methylation_calls[$index]\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3107 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3108 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3109 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3110 else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3111 die "The read had a strand orientation which was neither + nor -: $strand\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3112 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3113 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3114
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3115 ### strand-specific methylation output
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3116 else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3117 if ($strand eq '+') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3118 for my $index (0..$#methylation_calls) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3119 ### methylated Cs (any context) will receive a forward (+) orientation
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3120 ### not methylated Cs (any context) will receive a reverse (-) orientation
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3121
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3122 if ($cigar and @comp_cigar){ # only needed for SAM reads with Indels
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3123 my ($cigar_mod,$pos_mod) = check_cigar_string($index,$cigar_offset,$pos_offset,$strand,\@comp_cigar);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3124 $cigar_offset += $cigar_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3125 $pos_offset += $pos_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3126 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3127
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3128 if ($methylation_calls[$index] eq 'X') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3129 $counting{total_meCHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3130 print {$fhs{$filehandle_index}->{CHG}} join ("\t",$id,'+',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3131 } elsif ($methylation_calls[$index] eq 'x') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3132 $counting{total_unmethylated_CHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3133 print {$fhs{$filehandle_index}->{CHG}} join ("\t",$id,'-',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3134 } elsif ($methylation_calls[$index] eq 'Z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3135 $counting{total_meCpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3136 print {$fhs{$filehandle_index}->{CpG}} join ("\t",$id,'+',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3137 } elsif ($methylation_calls[$index] eq 'z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3138 $counting{total_unmethylated_CpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3139 print {$fhs{$filehandle_index}->{CpG}} join ("\t",$id,'-',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3140 } elsif ($methylation_calls[$index] eq 'H') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3141 $counting{total_meCHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3142 print {$fhs{$filehandle_index}->{CHH}} join ("\t",$id,'+',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3143 } elsif ($methylation_calls[$index] eq 'h') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3144 $counting{total_unmethylated_CHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3145 print {$fhs{$filehandle_index}->{CHH}} join ("\t",$id,'-',$chrom,$start+$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3146 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3147 elsif ($methylation_calls[$index] eq '.') {}
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3148 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3149 die "The methylation call string contained the following unrecognised character: $methylation_calls[$index]\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3150 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3151 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3152 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3153 elsif ($strand eq '-') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3154
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3155 for my $index (0..$#methylation_calls) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3156 ### methylated Cs (any context) will receive a forward (+) orientation
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3157 ### not methylated Cs (any context) will receive a reverse (-) orientation
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3158
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3159 if ($cigar and @comp_cigar){ # only needed for SAM reads with Indels
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3160 my ($cigar_mod,$pos_mod) = check_cigar_string($index,$cigar_offset,$pos_offset,$strand,\@comp_cigar);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3161 $cigar_offset += $cigar_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3162 $pos_offset += $pos_mod;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3163 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3164
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3165 if ($methylation_calls[$index] eq 'X') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3166 $counting{total_meCHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3167 print {$fhs{$filehandle_index}->{CHG}} join ("\t",$id,'+',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3168 } elsif ($methylation_calls[$index] eq 'x') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3169 $counting{total_unmethylated_CHG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3170 print {$fhs{$filehandle_index}->{CHG}} join ("\t",$id,'-',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3171 } elsif ($methylation_calls[$index] eq 'Z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3172 $counting{total_meCpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3173 print {$fhs{$filehandle_index}->{CpG}} join ("\t",$id,'+',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3174 } elsif ($methylation_calls[$index] eq 'z') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3175 $counting{total_unmethylated_CpG_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3176 print {$fhs{$filehandle_index}->{CpG}} join ("\t",$id,'-',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3177 } elsif ($methylation_calls[$index] eq 'H') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3178 $counting{total_meCHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3179 print {$fhs{$filehandle_index}->{CHH}} join ("\t",$id,'+',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3180 } elsif ($methylation_calls[$index] eq 'h') {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3181 $counting{total_unmethylated_CHH_count}++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3182 print {$fhs{$filehandle_index}->{CHH}} join ("\t",$id,'-',$chrom,$start-$index+$pos_offset,$methylation_calls[$index]),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3183 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3184 elsif ($methylation_calls[$index] eq '.') {}
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3185 else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3186 die "The methylation call string contained the following unrecognised character: $methylation_calls[$index]\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3187 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3188 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3189 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3190 else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3191 die "The strand information was neither + nor -: $strand\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3192 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3193 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3194 }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3195
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3196
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3197
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3198 #######################################################################################################################################
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3199 ### bismark2bedGaph section - START
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3200 #######################################################################################################################################
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3201
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3202 ### has now been moved to the external script bismark2bedGraph
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3203
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3204 # sub process_bedGraph_output{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3205 # warn "="x64,"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3206 # warn "Methylation information will now be written into a bedGraph file\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3207 # warn "="x64,"\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3208 # sleep (2);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3209
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3210 # ### Closing all filehandles so that the Bismark methtylation extractor output doesn't get truncated due to buffering issues
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3211 # foreach my $fh (keys %fhs) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3212 # if ($fh =~ /^[1230]$/) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3213 # foreach my $context (keys %{$fhs{$fh}}) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3214 # close $fhs{$fh}->{$context} or die $!;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3215 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3216 # } else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3217 # close $fhs{$fh} or die $!;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3218 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3219 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3220
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3221 # ### deciding which files to use for bedGraph conversion
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3222 # foreach my $filename (@sorting_files){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3223 # # warn "$filename\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3224 # if ($filename =~ /\//){ # if files are in a different output folder we extract the filename again
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3225 # $filename =~ s/.*\///; # replacing everything up to the last slash in the filename
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3226 # # warn "$filename\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3227 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3228
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3229 # if ($CX_context){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3230 # push @bedfiles,$filename;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3231 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3232 # else{ ## CpG context only (default)
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3233 # if ($filename =~ /^CpG_/){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3234 # push @bedfiles,$filename;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3235 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3236 # else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3237 # # skipping CHH or CHG files
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3238 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3239 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3240 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3241
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3242 # warn "Using the following files as Input:\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3243 # print join ("\t",@bedfiles),"\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3244 # sleep (2);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3245
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3246 # my %temp_fhs;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3247 # my @temp_files; # writing all context files (default CpG only) to these files prior to sorting
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3248
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3249 # ### changing to the output directory
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3250 # unless ($output_dir eq ''){ # default
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3251 # chdir $output_dir or die "Failed to change directory to $output_dir\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3252 # warn "Changed directory to $output_dir\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3253 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3254
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3255 # foreach my $infile (@bedfiles) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3256
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3257 # if ($remove) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3258 # warn "Now replacing whitespaces in the sequence ID field of the Bismark methylation extractor output $infile prior to bedGraph conversion\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3259
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3260 # if ($infile =~ /gz$/){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3261 # open (READ,"zcat $infile |") or die $!;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3262 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3263 # else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3264 # open (READ,$infile) or die $!;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3265 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3266
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3267 # my $removed_spaces_outfile = $infile;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3268 # $removed_spaces_outfile =~ s/$/.spaces_removed.txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3269
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3270 # open (REM,'>',$output_dir.$removed_spaces_outfile) or die "Couldn't write to file $removed_spaces_outfile: $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3271
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3272 # unless ($no_header){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3273 # $_ = <READ>; ### Bismark version header
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3274 # print REM $_; ### Bismark version header
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3275 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3276
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3277 # while (<READ>) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3278 # chomp;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3279 # my ($id,$strand,$chr,$pos,$context) = (split (/\t/));
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3280 # $id =~ s/\s+/_/g;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3281 # print REM join ("\t",$id,$strand,$chr,$pos,$context),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3282 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3283
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3284 # close READ or die $!;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3285 # close REM or die $!;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3286
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3287 # ### changing the infile name to the new file without spaces
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3288 # $infile = $removed_spaces_outfile;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3289 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3290
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3291 # warn "Now writing methylation information for file $infile to individual files for each chromosome\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3292 # if ($infile =~ /gz$/){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3293 # open (IN,"zcat $infile |") or die $!;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3294 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3295 # else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3296 # open (IN,$infile) or die $!;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3297 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3298
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3299 # ## always ignoring the version header
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3300 # unless ($no_header){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3301 # $_ = <IN>; ### Bismark version header
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3302 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3303
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3304 # while (<IN>) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3305 # chomp;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3306 # my ($chr) = (split (/\t/))[2];
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3307 # # warn "This is the chromosome name before replacing '|' characters:\t$chr\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3308 # $chr =~ s/\|/_/g; # replacing pipe ('|') characters in the file names
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3309 # # warn "This is the chromosome name AFTER replacing '|' characters:\t$chr\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3310
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3311 # unless (exists $temp_fhs{$chr}) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3312 # open ($temp_fhs{$chr},'>','chr'.$chr.'.meth_extractor.temp') or die "Failed to open filehandle: $!";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3313 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3314 # print {$temp_fhs{$chr}} "$_\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3315 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3316
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3317 # warn "Finished writing out individual chromosome files for $infile\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3318 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3319 # warn "\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3320
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3321 # @temp_files = <*.meth_extractor.temp>;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3322
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3323 # warn "Collecting temporary chromosome file information...\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3324 # sleep (1);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3325 # warn "processing the following input file(s):\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3326 # warn join ("\n",@temp_files),"\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3327 # sleep (1);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3328
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3329 # foreach my $in (@temp_files) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3330 # if ($sort_size){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3331 # warn "Sorting input file $in by positions (using -S of '$sort_size')\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3332 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3333 # else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3334 # warn "Sorting input file $in by positions (using default memory settings)\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3335 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3336 # my $sort_dir = $output_dir;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3337 # if ($sort_dir eq ''){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3338 # $sort_dir = './';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3339 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3340 # open my $ifh, "sort -S $sort_size -T $sort_dir -k3,3 -k4,4n $in |" or die "Input file could not be sorted. $!";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3341 # # print "Chromosome\tStart Position\tEnd Position\tMethylation Percentage\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3342
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3343 # ############################################# m.a.bentley - moved the variables out of the while loop to hold the current line data {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3344
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3345 # my $name;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3346 # my $meth_state;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3347 # my $chr = "";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3348 # my $pos = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3349 # my $meth_state2;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3350
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3351 # my $last_pos;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3352 # my $last_chr;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3353
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3354 # ############################################# }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3355
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3356 # while (my $line = <$ifh>) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3357 # next if $line =~ /^Bismark/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3358 # chomp $line;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3359
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3360 # ########################################### m.a.bentley - (1) set the last_chr and last_pos variables early in the while loop, before the line split (2) removed unnecessary setting of same variables in if statement {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3361
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3362 # $last_chr = $chr;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3363 # $last_pos = $pos;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3364 # ($name, $meth_state, $chr, $pos, $meth_state2) = split "\t", $line;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3365
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3366 # if (($last_pos ne $pos) || ($last_chr ne $chr)) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3367 # generate_output($last_chr,$last_pos) if $methylcalls[2] > 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3368 # @methylcalls = qw (0 0 0);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3369 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3370
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3371 # ############################################# }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3372
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3373 # my $validated = validate_methylation_call($meth_state, $meth_state2);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3374 # unless($validated){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3375 # warn "Methylation state of sequence ($name) in file ($in) on line $. is inconsistent (meth_state is $meth_state, meth_state2 = $meth_state2)\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3376 # next;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3377 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3378 # if ($meth_state eq "+") {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3379 # $methylcalls[0]++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3380 # $methylcalls[2]++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3381 # } else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3382 # $methylcalls[1]++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3383 # $methylcalls[2]++;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3384 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3385 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3386
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3387 # ############################################# m.a.bentley - set the last_chr and last_pos variables for the last line in the file (outside the while loop's scope using the method i've implemented) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3388
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3389 # $last_chr = $chr;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3390 # $last_pos = $pos;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3391 # if ($methylcalls[2] > 0) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3392 # generate_output($last_chr,$last_pos) if $methylcalls[2] > 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3393 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3394 # ############################################# }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3395
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3396 # close $ifh or die $!;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3397
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3398 # @methylcalls = qw (0 0 0); # resetting @methylcalls
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3399
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3400 # ### deleting temporary files
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3401 # my $delete = unlink $in;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3402 # if ($delete) {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3403 # warn "Successfully deleted the temporary input file $in\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3404 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3405 # else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3406 # warn "The temporary inputfile $in could not be deleted $!\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3407 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3408 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3409 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3410
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3411 # sub generate_output{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3412 # my $methcount = $methylcalls[0];
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3413 # my $nonmethcount = $methylcalls[1];
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3414 # my $totalcount = $methylcalls[2];
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3415 # my $last_chr = shift;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3416 # my $last_pos = shift;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3417 # croak "Should not be generating output if there's no reads to this region" unless $totalcount > 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3418 # croak "Total counts ($totalcount) is not the sum of the methylated ($methcount) and unmethylated ($nonmethcount) counts" if $totalcount != ($methcount + $nonmethcount);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3419
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3420 # ############################################# m.a.bentley - declare a new variable 'bed_pos' to distinguish from bismark positions (-1) - previous scripts modified the last_pos variable earlier in the script leading to problems in meth % calculation {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3421
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3422 # my $bed_pos = $last_pos -1; ### Bismark coordinates are 1 based whereas bedGraph coordinates are 0 based.
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3423 # my $meth_percentage;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3424 # ($totalcount >= $coverage_threshold) ? ($meth_percentage = ($methcount/$totalcount) * 100) : ($meth_percentage = undef);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3425 # # $meth_percentage =~ s/(\.\d\d).+$/$1/ unless $meth_percentage =~ /^Below/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3426 # if (defined $meth_percentage){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3427 # if ($counts){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3428 # print OUT "$last_chr\t$bed_pos\t$bed_pos\t$meth_percentage\t$methcount\t$nonmethcount\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3429 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3430 # else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3431 # print OUT "$last_chr\t$bed_pos\t$bed_pos\t$meth_percentage\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3432 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3433 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3434 # ############################################# }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3435 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3436
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3437 # sub validate_methylation_call{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3438 # my $meth_state = shift;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3439 # croak "Missing (+/-) methylation call" unless defined $meth_state;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3440 # my $meth_state2 = shift;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3441 # croak "Missing alphabetical methylation call" unless defined $meth_state2;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3442 # my $is_consistent;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3443 # ($meth_state2 =~ /^z/i) ? ($is_consistent = check_CpG_methylation_call($meth_state, $meth_state2))
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3444 # : ($is_consistent = check_nonCpG_methylation_call($meth_state,$meth_state2));
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3445 # return 1 if $is_consistent;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3446 # return 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3447 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3448
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3449 # sub check_CpG_methylation_call{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3450 # my $meth1 = shift;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3451 # my $meth2 = shift;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3452 # return 1 if($meth1 eq "+" && $meth2 eq "Z");
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3453 # return 1 if($meth1 eq "-" && $meth2 eq "z");
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3454 # return 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3455 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3456
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3457 # sub check_nonCpG_methylation_call{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3458 # my $meth1 = shift;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3459 # my $meth2 = shift;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3460 # return 1 if($meth1 eq "+" && $meth2 eq "C");
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3461 # return 1 if($meth1 eq "+" && $meth2 eq "X");
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3462 # return 1 if($meth1 eq "+" && $meth2 eq "H");
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3463 # return 1 if($meth1 eq "-" && $meth2 eq "c");
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3464 # return 1 if($meth1 eq "-" && $meth2 eq "x");
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3465 # return 1 if($meth1 eq "-" && $meth2 eq "h");
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3466 # return 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3467 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3468
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3469 #######################################################################################################################################
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3470 ### bismark2bedGaph section - END
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3471 #######################################################################################################################################
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3472
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3473
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3474
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3475
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3476
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3477
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3478 # #######################################################################################################################################
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3479 # ### genome-wide cytosine methylation report - START
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3480 # #######################################################################################################################################
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3481
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3482 ### has now been moved to the external script bedGraph2cytosine
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3483
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3484 # sub generate_genome_wide_cytosine_report {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3485
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3486 # warn "="x78,"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3487 # warn "Methylation information will now be written into a genome-wide cytosine report\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3488 # warn "="x78,"\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3489 # sleep (2);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3490
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3491 # ### changing to the output directory again
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3492 # unless ($output_dir eq ''){ # default
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3493 # chdir $output_dir or die "Failed to change directory to $output_dir\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3494 # # warn "Changed directory to $output_dir\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3495 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3496
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3497 # my $in = shift;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3498 # open (IN,$in) or die $!;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3499
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3500 # my $cytosine_out = shift;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3501
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3502 # if ($CX_context){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3503 # $cytosine_out =~ s/$/genome-wide_CX_report.txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3504 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3505 # else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3506 # $cytosine_out =~ s/$/genome_wide_CpG_report.txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3507 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3508
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3509 # ### note: we are still in the folder: $output_dir, so we do not have to include this into the open commands
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3510 # unless ($split_by_chromosome){ ### writing all output to a single file (default)
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3511 # open (CYT,'>',$cytosine_out) or die $!;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3512 # warn "Writing genome-wide cytosine report to: $cytosine_out\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3513 # sleep (3);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3514 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3515
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3516 # my $last_chr;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3517 # my %chr; # storing reads for one chromosome at a time
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3518
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3519 # my $count = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3520 # while (<IN>){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3521 # chomp;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3522 # ++$count;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3523 # my ($chr,$start,$end,undef,$meth,$nonmeth) = (split /\t/);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3524
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3525 # # defining the first chromosome
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3526 # unless (defined $last_chr){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3527 # $last_chr = $chr;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3528 # # warn "Storing all covered cytosine positions for chromosome: $chr\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3529 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3530
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3531 # if ($chr eq $last_chr){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3532 # $chr{$chr}->{$start}->{meth} = $meth;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3533 # $chr{$chr}->{$start}->{nonmeth} = $nonmeth;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3534 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3535 # else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3536 # warn "Writing cytosine reports for chromosome $last_chr (stored ",scalar keys %{$chr{$last_chr}}," different covered positions)\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3537
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3538 # if ($split_by_chromosome){ ## writing output to 1 file per chromosome
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3539 # my $chromosome_out = $cytosine_out;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3540 # $chromosome_out =~ s/txt$/chr${last_chr}.txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3541 # open (CYT,'>',$chromosome_out) or die $!;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3542 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3543
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3544 # while ( $chromosomes{$last_chr} =~ /([CG])/g){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3545
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3546 # my $tri_nt = '';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3547 # my $context = '';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3548 # my $pos = pos$chromosomes{$last_chr};
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3549
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3550 # my $strand;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3551 # my $meth = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3552 # my $nonmeth = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3553
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3554 # if ($1 eq 'C'){ # C on forward strand
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3555 # $tri_nt = substr ($chromosomes{$last_chr},($pos-1),3); # positions are 0-based!
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3556 # $strand = '+';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3557 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3558 # elsif ($1 eq 'G'){ # C on reverse strand
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3559 # $tri_nt = substr ($chromosomes{$last_chr},($pos-3),3); # positions are 0-based!
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3560 # $tri_nt = reverse $tri_nt;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3561 # $tri_nt =~ tr/ACTG/TGAC/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3562 # $strand = '-';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3563 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3564 # next if (length$tri_nt < 3); # trinucleotide sequence could not be extracted
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3565
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3566 # if (exists $chr{$last_chr}->{($pos-1)}){ # stored positions are 0-based!
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3567 # $meth = $chr{$last_chr}->{$pos-1}->{meth};
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3568 # $nonmeth = $chr{$last_chr}->{$pos-1}->{nonmeth};
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3569 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3570
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3571 # ### determining cytosine context
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3572 # if ($tri_nt =~ /^CG/){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3573 # $context = 'CG';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3574 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3575 # elsif ($tri_nt =~ /^C.{1}G$/){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3576 # $context = 'CHG';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3577 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3578 # elsif ($tri_nt =~ /^C.{2}$/){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3579 # $context = 'CHH';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3580 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3581 # else{ # if the context can't be determined the positions will not be printed (it will equally not have been reported by Bismark)
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3582 # warn "The sequence context could not be determined (found: '$tri_nt'). Skipping.\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3583 # next;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3584 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3585
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3586 # if ($CpG_only){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3587 # if ($tri_nt =~ /^CG/){ # CpG context is the default
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3588 # if ($zero){ # zero based coordinates
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3589 # $pos -= 1;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3590 # print CYT join ("\t",$last_chr,$pos,$strand,$meth,$nonmeth,$context,$tri_nt),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3591 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3592 # else{ # default
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3593 # print CYT join ("\t",$last_chr,$pos,$strand,$meth,$nonmeth,$context,$tri_nt),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3594 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3595 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3596 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3597 # else{ ## all cytosines, specified with --CX
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3598 # if ($zero){ # zero based coordinates
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3599 # $pos -= 1;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3600 # print CYT join ("\t",$last_chr,$pos,$strand,$meth,$nonmeth,$context,$tri_nt),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3601 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3602 # else{ # default
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3603 # print CYT join ("\t",$last_chr,$pos,$strand,$meth,$nonmeth,$context,$tri_nt),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3604 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3605 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3606 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3607
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3608 # %chr = (); # resetting the hash
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3609
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3610 # # new first entry
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3611 # $last_chr = $chr;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3612 # $chr{$chr}->{$start}->{meth} = $meth;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3613 # $chr{$chr}->{$start}->{nonmeth} = $nonmeth;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3614 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3615 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3616
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3617 # # Last found chromosome
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3618 # warn "Writing cytosine reports for chromosome $last_chr (stored ",scalar keys %{$chr{$last_chr}}," different covered positions)\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3619
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3620 # if ($split_by_chromosome){ ## writing output to 1 file per chromosome
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3621 # my $chromosome_out = $cytosine_out;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3622 # $chromosome_out =~ s/txt$/chr${last_chr}.txt/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3623 # open (CYT,'>',$chromosome_out) or die $!;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3624 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3625
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3626 # while ( $chromosomes{$last_chr} =~ /([CG])/g){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3627
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3628 # my $tri_nt;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3629 # my $context;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3630 # my $pos = pos$chromosomes{$last_chr};
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3631
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3632 # my $strand;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3633 # my $meth = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3634 # my $nonmeth = 0;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3635
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3636 # if ($1 eq 'C'){ # C on forward strand
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3637 # $tri_nt = substr ($chromosomes{$last_chr},($pos-1),3); # positions are 0-based!
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3638 # $strand = '+';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3639 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3640 # elsif ($1 eq 'G'){ # C on reverse strand
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3641 # $tri_nt = substr ($chromosomes{$last_chr},($pos-3),3); # positions are 0-based!
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3642 # $tri_nt = reverse $tri_nt;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3643 # $tri_nt =~ tr/ACTG/TGAC/;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3644 # $strand = '-';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3645 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3646
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3647 # if (exists $chr{$last_chr}->{($pos-1)}){ # stored positions are 0-based!
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3648 # $meth = $chr{$last_chr}->{$pos-1}->{meth};
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3649 # $nonmeth = $chr{$last_chr}->{$pos-1}->{nonmeth};
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3650 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3651
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3652 # next if (length$tri_nt < 3); # trinucleotide sequence could not be extracted
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3653
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3654 # ### determining cytosine context
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3655 # if ($tri_nt =~ /^CG/){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3656 # $context = 'CG';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3657 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3658 # elsif ($tri_nt =~ /^C.{1}G$/){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3659 # $context = 'CHG';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3660 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3661 # elsif ($tri_nt =~ /^C.{2}$/){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3662 # $context = 'CHH';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3663 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3664 # else{ # if the context can't be determined the positions will not be printed (it will equally not have been reported by Bismark)
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3665 # warn "The cytosine context could not be determined (found: '$tri_nt'). Skipping.\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3666 # next;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3667 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3668
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3669 # if ($CpG_only){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3670 # if ($tri_nt =~ /^CG/){ # CpG context is the default
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3671 # if ($zero){ # zero-based coordinates
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3672 # $pos -= 1;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3673 # print CYT join ("\t",$last_chr,$pos,$strand,$meth,$nonmeth,$context,$tri_nt),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3674 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3675 # else{ # default
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3676 # print CYT join ("\t",$last_chr,$pos,$strand,$meth,$nonmeth,$context,$tri_nt),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3677 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3678 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3679 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3680 # else{ ## all cytosines, specified with --CX
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3681 # if ($zero){ # zero based coordinates
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3682 # $pos -= 1;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3683 # print CYT join ("\t",$last_chr,$pos,$strand,$meth,$nonmeth,$context,$tri_nt),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3684 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3685 # else{ # default
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3686 # print CYT join ("\t",$last_chr,$pos,$strand,$meth,$nonmeth,$context,$tri_nt),"\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3687 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3688 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3689 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3690 # close CYT or die $!;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3691 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3692
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3693
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3694 # sub read_genome_into_memory{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3695
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3696 # ## reading in and storing the specified genome in the %chromosomes hash
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3697 # chdir ($genome_folder) or die "Can't move to $genome_folder: $!";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3698 # warn "Now reading in and storing sequence information of the genome specified in: $genome_folder\n\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3699
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3700 # my @chromosome_filenames = <*.fa>;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3701
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3702 # ### if there aren't any genomic files with the extension .fa we will look for files with the extension .fasta
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3703 # unless (@chromosome_filenames){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3704 # @chromosome_filenames = <*.fasta>;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3705 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3706 # unless (@chromosome_filenames){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3707 # die "The specified genome folder $genome_folder does not contain any sequence files in FastA format (with .fa or .fasta file extensions)\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3708 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3709
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3710 # foreach my $chromosome_filename (@chromosome_filenames){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3711
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3712 # # skipping the tophat entire mouse genome fasta file
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3713 # next if ($chromosome_filename eq 'Mus_musculus.NCBIM37.fa');
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3714
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3715 # open (CHR_IN,$chromosome_filename) or die "Failed to read from sequence file $chromosome_filename $!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3716 # ### first line needs to be a fastA header
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3717 # my $first_line = <CHR_IN>;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3718 # chomp $first_line;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3719 # $first_line =~ s/\r//; # removing /r carriage returns
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3720
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3721 # ### Extracting chromosome name from the FastA header
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3722 # my $chromosome_name = extract_chromosome_name($first_line);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3723
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3724 # my $sequence;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3725 # while (<CHR_IN>){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3726 # chomp;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3727 # $_ =~ s/\r//; # removing /r carriage returns
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3728
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3729 # if ($_ =~ /^>/){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3730 # ### storing the previous chromosome in the %chromosomes hash, only relevant for Multi-Fasta-Files (MFA)
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3731 # if (exists $chromosomes{$chromosome_name}){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3732 # warn "chr $chromosome_name (",length $sequence ," bp)\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3733 # die "Exiting because chromosome name already exists. Please make sure all chromosomes have a unique name!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3734 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3735 # else {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3736 # if (length($sequence) == 0){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3737 # warn "Chromosome $chromosome_name in the multi-fasta file $chromosome_filename did not contain any sequence information!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3738 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3739 # warn "chr $chromosome_name (",length $sequence ," bp)\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3740 # $chromosomes{$chromosome_name} = $sequence;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3741 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3742 # ### resetting the sequence variable
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3743 # $sequence = '';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3744 # ### setting new chromosome name
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3745 # $chromosome_name = extract_chromosome_name($_);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3746 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3747 # else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3748 # $sequence .= uc$_;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3749 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3750 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3751
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3752 # if (exists $chromosomes{$chromosome_name}){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3753 # warn "chr $chromosome_name (",length $sequence ," bp)\t";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3754 # die "Exiting because chromosome name already exists. Please make sure all chromosomes have a unique name.\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3755 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3756 # else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3757 # if (length($sequence) == 0){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3758 # warn "Chromosome $chromosome_name in the file $chromosome_filename did not contain any sequence information!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3759 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3760 # warn "chr $chromosome_name (",length $sequence ," bp)\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3761 # $chromosomes{$chromosome_name} = $sequence;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3762 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3763 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3764 # warn "\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3765 # chdir $parent_dir or die "Failed to move to directory $parent_dir\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3766 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3767
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3768 # sub extract_chromosome_name {
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3769 # ## Bowtie extracts the first string after the inition > in the FASTA file, so we are doing this as well
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3770 # my $fasta_header = shift;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3771 # if ($fasta_header =~ s/^>//){
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3772 # my ($chromosome_name) = split (/\s+/,$fasta_header);
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3773 # return $chromosome_name;
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3774 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3775 # else{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3776 # die "The specified chromosome ($fasta_header) file doesn't seem to be in FASTA format as required!\n";
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3777 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3778 # }
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3779
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3780 # #######################################################################################################################################
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3781 # ### genome-wide cytosine methylation report - END
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3782 # #######################################################################################################################################
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3783
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3784
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3785
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3786
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3787 sub print_helpfile{
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3788
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3789 print << 'HOW_TO';
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3790
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3791
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3792 DESCRIPTION
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3793
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3794 The following is a brief description of all options to control the Bismark
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3795 methylation extractor. The script reads in a bisulfite read alignment results file
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3796 produced by the Bismark bisulfite mapper and extracts the methylation information
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3797 for individual cytosines. This information is found in the methylation call field
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3798 which can contain the following characters:
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3799
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3800 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3801 ~~~ X for methylated C in CHG context (was protected) ~~~
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3802 ~~~ x for not methylated C CHG (was converted) ~~~
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3803 ~~~ H for methylated C in CHH context (was protected) ~~~
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3804 ~~~ h for not methylated C in CHH context (was converted) ~~~
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3805 ~~~ Z for methylated C in CpG context (was protected) ~~~
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3806 ~~~ z for not methylated C in CpG context (was converted) ~~~
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3807 ~~~ . for any bases not involving cytosines ~~~
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3808 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3809
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3810 The methylation extractor outputs result files for cytosines in CpG, CHG and CHH
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3811 context (this distinction is actually already made in Bismark itself). As the methylation
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3812 information for every C analysed can produce files which easily have tens or even hundreds of
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3813 millions of lines, file sizes can become very large and more difficult to handle. The C
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3814 methylation info additionally splits cytosine methylation calls up into one of the four possible
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3815 strands a given bisulfite read aligned against:
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3816
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3817 OT original top strand
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3818 CTOT complementary to original top strand
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3819
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3820 OB original bottom strand
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3821 CTOB complementary to original bottom strand
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3822
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3823 Thus, by default twelve individual output files are being generated per input file (unless
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3824 --comprehensive is specified, see below). The output files can be imported into a genome
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3825 viewer, such as SeqMonk, and re-combined into a single data group if desired (in fact
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3826 unless the bisulfite reads were generated preserving directionality it doesn't make any
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3827 sense to look at the data in a strand-specific manner). Strand-specific output files can
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3828 optionally be skipped, in which case only three output files for CpG, CHG or CHH context
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3829 will be generated. For both the strand-specific and comprehensive outputs there is also
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3830 the option to merge both non-CpG contexts (CHG and CHH) into one single non-CpG context.
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3831
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3832
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3833 The output files are in the following format (tab delimited):
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3834
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3835 <sequence_id> <strand> <chromosome> <position> <methylation call>
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3836
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3837
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3838 USAGE: methylation_extractor [options] <filenames>
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3839
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3840
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3841 ARGUMENTS:
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3842
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3843 <filenames> A space-separated list of Bismark result files in SAM format from
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3844 which methylation information is extracted for every cytosine in
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3845 the reads. For alignment files in the older custom Bismark output
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3846 see option '--vanilla'.
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3847
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3848 OPTIONS:
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3849
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3850 -s/--single-end Input file(s) are Bismark result file(s) generated from single-end
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3851 read data. Specifying either --single-end or --paired-end is
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3852 mandatory.
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3853
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3854 -p/--paired-end Input file(s) are Bismark result file(s) generated from paired-end
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3855 read data. Specifying either --paired-end or --single-end is
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3856 mandatory.
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3857
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3858 --vanilla The Bismark result input file(s) are in the old custom Bismark format
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3859 (up to version 0.5.x) and not in SAM format which is the default as
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3860 of Bismark version 0.6.x or higher. Default: OFF.
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3861
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3862 --no_overlap For paired-end reads it is theoretically possible that read_1 and
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3863 read_2 overlap. This option avoids scoring overlapping methylation
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3864 calls twice (only methylation calls of read 1 are used for in the process
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3865 since read 1 has historically higher quality basecalls than read 2).
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3866 Whilst this option removes a bias towards more methylation calls
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3867 in the center of sequenced fragments it may de facto remove a sizable
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3868 proportion of the data. This option is highly recommended for paired-end
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3869 data.
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3870
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3871 --ignore <int> Ignore the first <int> bp at the 5' end of each read when processing the
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3872 methylation call string. This can remove e.g. a restriction enzyme site
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3873 at the start of each read.
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3874
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3875 --comprehensive Specifying this option will merge all four possible strand-specific
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3876 methylation info into context-dependent output files. The default
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3877 contexts are:
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3878 - CpG context
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3879 - CHG context
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3880 - CHH context
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3881
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3882 --merge_non_CpG This will produce two output files (in --comprehensive mode) or eight
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3883 strand-specific output files (default) for Cs in
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3884 - CpG context
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3885 - non-CpG context
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3886
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3887 --report Prints out a short methylation summary as well as the paramaters used to run
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3888 this script.
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3889
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3890 --no_header Suppresses the Bismark version header line in all output files for more convenient
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3891 batch processing.
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3892
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3893 -o/--output DIR Allows specification of a different output directory (absolute or relative
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3894 path). If not specified explicitely, the output will be written to the current directory.
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3895
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3896 --samtools_path The path to your Samtools installation, e.g. /home/user/samtools/. Does not need to be specified
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3897 explicitly if Samtools is in the PATH already.
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3898
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3899 --gzip The methylation extractor files (CpG_OT_..., CpG_OB_... etc) will be written out in
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3900 a GZIP compressed form to save disk space. This option does not work on bedGraph and
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3901 genome-wide cytosine reports as they are 'tiny' anyway.
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3902
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3903 --version Displays version information.
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3904
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3905 -h/--help Displays this help file and exits.
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3906
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3907
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3908
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3909 bedGraph specific options:
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3910
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3911 --bedGraph After finishing the methylation extraction, the methylation output is written into a
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3912 sorted bedGraph file that reports the position of a given cytosine and its methylation
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3913 state (in %, see details below). The methylation extractor output is temporarily split up into
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3914 temporary files, one per chromosome (written into the current directory or folder
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3915 specified with -o/--output); these temp files are then used for sorting and deleted
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3916 afterwards. By default, only cytosines in CpG context will be sorted. The option
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3917 '--CX_context' may be used to report all cytosines irrespective of sequence context
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3918 (this will take MUCH longer!). The default folder for temporary files during the sorting
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3919 process is the output directory. The bedGraph conversion step is performed by the external
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3920 module 'bismark2bedGraph'; this script needs to reside in the same folder as the
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3921 bismark_methylation_extractor itself.
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3922
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3923
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3924 --cutoff [threshold] The minimum number of times a methylation state has to be seen for that nucleotide
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3925 before its methylation percentage is reported. Default: 1.
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3926
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3927 --remove_spaces Replaces whitespaces in the sequence ID field with underscores to allow sorting.
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3928
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3929
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3930 --counts Adds two additional columns to the output file to enable further calculations:
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3931 col 5: number of methylated calls
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3932 col 6: number of unmethylated calls
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3933 This option is required if '--cytosine_report' is specified (and will be set automatically if
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3934 necessary).
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3935
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3936 --CX/--CX_context The sorted bedGraph output file contains information on every single cytosine that was covered
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3937 in the experiment irrespective of its sequence context. This applies to both forward and
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3938 reverse strands. Please be aware that this option may generate large temporary and output files
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3939 and may take a long time to sort (up to many hours). Default: OFF.
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3940 (i.e. Default = CpG context only).
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3941
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3942 --buffer_size <string> This allows you to specify the main memory sort buffer when sorting the methylation information.
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3943 Either specify a percentage of physical memory by appending % (e.g. --buffer_size 50%) or
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3944 a multiple of 1024 bytes, e.g. 'K' multiplies by 1024, 'M' by 1048576 and so on for 'T' etc.
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3945 (e.g. --buffer_size 20G). For more information on sort type 'info sort' on a command line.
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3946 Defaults to 2G.
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3947
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3948
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3949 Genome-wide cytosine methylation report specific options:
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3950
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3951 --cytosine_report After the conversion to bedGraph has completed, the option '--cytosine_report' produces a
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3952 genome-wide methylation report for all cytosines in the genome. By default, the output uses 1-based
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3953 chromosome coordinates (zero-based cords are optional) and reports CpG context only (all
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3954 cytosine context is optional). The output considers all Cs on both forward and reverse strands and
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3955 reports their position, strand, trinucleotide content and methylation state (counts are 0 if not
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3956 covered). The cytsoine report conversion step is performed by the external module
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3957 'bedGraph2cytosine'; this script needs to reside in the same folder as the bismark_methylation_extractor
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3958 itself.
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3959
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3960 --CX/--CX_context The output file contains information on every single cytosine in the genome irrespective of
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3961 its context. This applies to both forward and reverse strands. Please be aware that this will
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3962 generate output files with > 1.1 billion lines for a mammalian genome such as human or mouse.
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3963 Default: OFF (i.e. Default = CpG context only).
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3964
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3965 --zero_based Uses zero-based coordinates like used in e.g. bed files instead of 1-based coordinates. Default: OFF.
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3966
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3967 --genome_folder <path> Enter the genome folder you wish to use to extract sequences from (full path only). Accepted
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3968 formats are FastA files ending with '.fa' or '.fasta'. Specifying a genome folder path is mandatory.
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3969
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3970 --split_by_chromosome Writes the output into individual files for each chromosome instead of a single output file. Files
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3971 will be named to include the input filename and the chromosome number.
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3972
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3973
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3974
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3975 OUTPUT:
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3976
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3977 The bismark_methylation_extractor output is in the form:
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3978 ========================================================
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3979 <seq-ID> <methylation state*> <chromosome> <start position (= end position)> <methylation call>
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3980
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3981 * Methylated cytosines receive a '+' orientation,
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3982 * Unmethylated cytosines receive a '-' orientation.
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3983
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3984
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3985
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3986 The bedGraph output (optional) looks like this (tab-delimited):
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3987 ===============================================================
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3988 <chromosome> <start position> <end position> <methylation percentage>
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3989
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3990 The bedGraph output with '--counts' specified looks like this (tab-delimited):
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3991
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3992 <chromosome> <start position> <end position> <methylation percentage> <count methylated> <count non-methylated>
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3993
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3994
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3995
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3996 The genome-wide cytosine methylation output file is tab-delimited in the following format:
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3997 ==========================================================================================
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3998 <chromosome> <position> <strand> <count methylated> <count non-methylated> <C-context> <trinucleotide context>
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
3999
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
4000
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
4001
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
4002 This script was last modified on 21 April 2013.
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
4003
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
4004 HOW_TO
62c6da72dd4a Uploaded
bgruening
parents:
diff changeset
4005 }