-
Notifications
You must be signed in to change notification settings - Fork 8
/
00.reprint.age_gender.pl
executable file
·68 lines (61 loc) · 1.33 KB
/
00.reprint.age_gender.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
#!/usr/bin/perl
use strict;
use warnings;
my $f=shift;
die "$0 <file>
file example:
unique_id,birthday,gender
002442984c37af4ebefaf77118e41af6,1983-03-15,male
0024cf3d2cefebfd573438cb2dff0f66,1996-06-20,male
00342aea6250d2ad6f173cec55a4b71d,1998-10-30,female\n"unless $f;
# set missing --missing-phenotype
my $na="-9";
open(LOG,"> $f.log");
my $date=`date '+%Y %m'`;
chomp $date;
my @date=split(/\s/,$date);
my $year=$date[0];
my $month=$date[1];
#print "$year\t$month\n";die;
open(O,">$f.reprint");
open(I,"$f");
<I>;
while(<I>){
chomp;
my @a=split(/,/);
my $uid=$a[0];
my $birthday=$a[1];
my $gender=$a[2];
my $age;
if($birthday =~ /NA/){
$age=$na;
print LOG "$uid\t$birthday\t$birthday\t$age\n";
}elsif($birthday =~ /^(\d*)-(.*)-(.*)/){
# $age=($year-$1)+($month-$2)/12;
# $age=sprintf "%.2f",$age;
$age=($year-$1);
my $age_old=$age;
if($age<5 || $age>90){
$age=$na;
}
print LOG "$uid\t$birthday\t$age_old\t$age\n";
}else{
die "$_\n";
}
my $gender2=$na;
#if($gender =~ /NA/){
if($gender =~ /NA/ || $gender =~ /unknow/ || $gender =~/other/){
$gender2=$na;
}elsif($gender=~/^female/){
$gender2=2;
}elsif($gender=~/^male/){
$gender2=1;
}else{
die "$_\n";
}
#print "$gender\t$gender2\n";
print O "$uid\t$age\t$gender2\n";
}
close I;
close O;
close LOG;