-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathlabid2UUID.pl
executable file
·55 lines (47 loc) · 1.56 KB
/
labid2UUID.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
#!/usr/bin/perl
use warnings;
use strict;
use Text::CSV;
open(my $idLookupFile, "<", "/home/gringer/bioinf/GU-2012-Apr-01-RLMB/Miles/individuals/NI_UUID_Ped_2012-Oct-23.csv") or die("Cannot open lookup file");
my $csv = Text::CSV->new ({ binary => 1, eol => $/ });
my %col = ();
my $headerRow = $csv->getline($idLookupFile);
my $fieldCount = 0;
foreach my $field (@$headerRow){
$col{$field} = $fieldCount++;
}
my %dataReplacement = ();
my $fileType = "tfam";
while (my $row = $csv->getline($idLookupFile)){
my @fields = @$row;
if($fields[$col{"LAB_ID"}] ne "NA"){
my $labid = $fields[$col{"LAB_ID"}];
my $uuid = $fields[$col{"UUID"}];
my $gender = $fields[$col{"Gender"}];
my $genderVal = ($gender eq "Male")?1:($gender eq "Female")?2:0;
if(($fileType eq "tfam") || ($fileType eq "ped")){
$dataReplacement{$labid} =
join(" ",1,$uuid,
($fields[$col{"patID"}] eq "NA")?0:$fields[$col{"patID"}],
($fields[$col{"matID"}] eq "NA")?0:$fields[$col{"matID"}],
$genderVal);
} else {
$dataReplacement{$labid} = $uuid;
}
}
}
close($idLookupFile);
while(<>){
if(($fileType eq "tfam") || ($fileType eq "ped")){
my $output = $_;
my @fields = split(/\s+/,$output,6);
if(exists($dataReplacement{$fields[1]})){
# try the 'individual' column first
$output = $dataReplacement{$fields[1]}." ".$fields[5];
} elsif(exists($dataReplacement{$fields[0]})){
# try the 'family' column
$output = $dataReplacement{$fields[0]}." ".$fields[5];
}
print($output);
}
}