-
Notifications
You must be signed in to change notification settings - Fork 0
/
overlap.pl
88 lines (78 loc) · 1.52 KB
/
overlap.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/perl
use strict;
use warnings;
my $methylation_file = $ARGV[0];
my $expression_file = $ARGV[1];
my %meth_id;
my %expr_id;
my @meth_id=(0);
my @expr_id=(0);
my $i;
open(FILE,$methylation_file) || die "Can't open file $methylation_file.\n";
while(<FILE>)
{
chomp;
if ($_=~/^ID/)
{
my @temp = split("\t",$_);
$i=0;
foreach(@temp)
{
if ($_=~/^\d/)
{
$meth_id{$_}=$i;
}
$i++;
}
}
}
close FILE;
open(FILE,$expression_file) || die "Can't open file $expression_file.\n";
while(<FILE>)
{
chomp;
if ($_=~/^ID/)
{
my @temp = split("\t",$_);
$i=0;
foreach(@temp)
{
if ($_=~/^\d/)
{
$expr_id{$_}=$i;
}
$i++;
}
}
}
close FILE;
my @keys = keys %meth_id;
foreach(@keys)
{
push (@meth_id,$meth_id{$_});
push (@expr_id,$expr_id{$_});
}
my $meth_output;
open(FILE,$methylation_file) || die "Can't open file $methylation_file.\n";
while(<FILE>)
{
chomp;
my @temp = split("\t",$_);
$meth_output.=join("\t",@temp[@meth_id]) . "\n";
}
close FILE;
my $expr_output;
open(FILE,$expression_file) || die "Can't open file $expression_file.\n";
while(<FILE>)
{
chomp;
my @temp = split("\t",$_);
$expr_output.=join("\t",@temp[@expr_id]) . "\n";
}
close FILE;
open FILE, ">". $methylation_file . ".out" or die $!;
print FILE $meth_output;
close FILE;
open FILE, ">". $expression_file . ".out" or die $!;
print FILE $expr_output;
close FILE;