-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclean_chr.pl
More file actions
executable file
·57 lines (47 loc) · 1003 Bytes
/
clean_chr.pl
File metadata and controls
executable file
·57 lines (47 loc) · 1003 Bytes
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
my @chrs = qw(chr1 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr20 chr21 chr22 chrX chrY chrM);
my %chrs;
foreach my $id (@chrs){
$chrs{$id} = '';
}
my $file = shift;
my $remove = shift;
#print "#$file\n";
open IN, "$file";
while ( <IN> ){
if (/^#/){
print "$_";
next;
}
if ($remove ne ''){
if ($remove eq 'yes'){
$_ =~ s/^chr//;
print "$_";
next;
} elsif ($remove eq 'hs') {
$_ = 'hs'.$_ if $_ !~ /^hs/;
$_ =~ s/\t/ /g;
print "$_";
next;
}
}
$_ =~ /^(\S+)/;
my $chr_now = $1;
my $chr_now_full = 'chr'.$chr_now;
if ( $chr_now eq 'chrMT' ) {
$_ =~ s/^chrMT/chrM/;
print "$_";
next;
}
elsif ($chr_now_full eq 'chrMT'){
$_ =~ s/^MT/M/;
print "chr$_";
next;
}
if (exists $chrs{$chr_now_full}) {
print "chr$_";
}
elsif (exists $chrs{$chr_now}){
print "$_";
}
}
close IN;