-
Notifications
You must be signed in to change notification settings - Fork 15
/
mitochondrial_descendants.pl
executable file
·54 lines (46 loc) · 1.17 KB
/
mitochondrial_descendants.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
#!/usr/bin/perl
use warnings;
use strict;
my %foundingLine = ();
my %found = ();
my %maternalIDs = ();
my %sex = ();
while (<>) {
my @F = split(/\s+/);
$maternalIDs{$F[1]} = $F[3];
$sex{$F[1]} = $F[4];
if(($F[2] == 0) && ($F[3] == 0)){
$foundingLine{$F[1]}{$F[1]} = 1;
}
}
print(STDERR "Loaded all IDs\n");
my $changed = 1;
print(STDERR "Finding mitochondrial descendants...");
while($changed){
$changed = 0;
foreach my $line (keys(%foundingLine)){
my %lineInds = %{$foundingLine{$line}};
foreach my $ind (keys(%lineInds)){
if(!$found{$ind}){
#printf(STDERR "Finding mitochondrial descendants of <%d>\n", $ind);
foreach my $ind2 (keys(%maternalIDs)){
if($maternalIDs{$ind2} == $ind){
$foundingLine{$line}{$ind2} = 1;
}
}
$found{$ind} = 1;
$changed = 1;
}
}
}
}
print(STDERR " stored all descendants\n");
foreach my $line (sort {$a <=> $b} (keys(%foundingLine))){
if(scalar(keys(%{$foundingLine{$line}})) > 1){
printf("Mitochondrial descendants of <%s>:\n", $line);
my %lineInds = %{$foundingLine{$line}};
foreach my $ind (sort {$a <=> $b} (keys(%lineInds))){
printf(" $ind %d\n", $sex{$ind});
}
}
}