-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmatchSampleNames.pl
More file actions
executable file
·57 lines (50 loc) · 1.13 KB
/
matchSampleNames.pl
File metadata and controls
executable file
·57 lines (50 loc) · 1.13 KB
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
use strict;
use Data::Dumper;
my $nameMapping = shift;
my $file = shift;
my $prefix = shift;
my $columns = shift;
my @columns = split(',', $columns);
my %needc;
foreach my $col (@columns){
$needc{$col} = '';
}
print STDERR Dumper (\%needc);
open MAP, "$nameMapping";
my %mapping;
while ( <MAP> ){
chomp;
my @cols = split /\t/;
$mapping{$cols[0]} = $cols[2];
}
close MAP;
open IN, "$file";
while ( <IN> ) {
chomp;
my @cols = split /\t/;
if (/^[\#]?chr\t/){ #header
for (my $i = 0; $i <= $#cols; $i++){
$cols[$i] =~ /^($prefix\d+)/;
my $sampleID = $1;
if (exists ( $mapping{$sampleID} )){
my $newName = $mapping{$sampleID};
$cols[$i] =~ s/^$sampleID/$newName/;
}
}
}
else{ #normal lines
for (my $i = 0; $i <= $#cols; $i++) {
next if (!exists($needc{$i}));
my @names = split(',', $cols[$i]);
foreach my $name (@names){
$name =~ /^($prefix\d+)/;
my $rname = $1;
my $newName = $mapping{$rname};
$name =~ s/^$prefix\d+/$newName/;
}
$cols[$i] = join(',', @names);
}
}
printf("%s\n", join("\t", @cols));
}
close IN;