-
Notifications
You must be signed in to change notification settings - Fork 1
/
MitochondrialmatrixGeneration.pl
63 lines (54 loc) · 1.51 KB
/
MitochondrialmatrixGeneration.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/perl -w
# Merge ChrM methlation level from bismark coverage output (Same Format Single Column files to One-Matrix)
# # 4: MF; #6: total coverage>10
# Contact: Shicheng Guo
# Version 1.3
# Update: 2016-12-19
# Following R script to make boxplot to check the variation
# mitometh<-read.table("C:\\Users\\shicheng\\Downloads\\CHR.Methylation.txt",head=T,row.names=1,as.is=T)
# colnames(mitometh)<-unlist(lapply(colnames(mitometh),function(x) substr(x,1,6)))
# rownames(mitometh)<-lapply(rownames(mitometh),function(x) unlist(strsplit(x,"[:-]"))[2])
# boxplot(t(mitometh),outline = F,horizontal = T)
# par(las=2,cex=0.6,mar=c(6,6,1,4))
# boxplot(t(mitometh),outline = T,horizontal = T)
# par(las=2,cex=0.6,mar=c(6,6,1,4))
# boxplot((mitometh),outline = T,horizontal = T)
use strict;
use Cwd;
my $dir=getcwd;
chdir $dir;
my @file=glob("*chrM");
my %mhb;
my %pos;
my %sam;
foreach my $sam(@file){
$sam{$sam}=$sam;
open F,$sam;
while(<F>){
chomp;
my ($chr,$start,$end,$percent,$Mnum,$Tnum)=split /\t/;
my $cpg="$chr:$start-$end";
$pos{$cpg}=$cpg;
next if $Tnum<10;
$mhb{$cpg}{$sam}=$percent;
}
}
######## Print Matrix-header
my @sam;
foreach my $sam(sort keys %sam){
push(@sam,$sam);
}
my $head=join("\t",@sam);
print "\t$head\n";
foreach my $pos(sort keys %mhb){
print "$pos";
foreach my $sam (sort keys %sam){
if( ! exists $mhb{$pos}{$sam}||! defined $mhb{$pos}{$sam}||$mhb{$pos}{$sam}=~/NA/){
print "\tNA";
}else{
my $R2=sprintf("%.3f",$mhb{$pos}{$sam});
print "\t$R2";
}
}
print "\n";
}