Repository navigation
Expand file tree
/
Copy pathfxtract
More file actions
executable file
·108 lines (80 loc) · 2.59 KB
/
Copy pathfxtract
File metadata and controls
executable file
·108 lines (80 loc) · 2.59 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/perl -w
use Getopt::Std ;
use Cwd 'abs_path';
use File::Basename;
getopts('p:V',\%opts) ;
$parname = $opts{"p"} ;
$verbose = $opts{"V"} ;
$MB = dirname(abs_path(__FILE__)) ;
$X = $MM = $MB . "/script" ;
die ("Usage: fxtract -p <parname>") unless (defined $parname) ;
$dir = `$MM/mktmp ddd 71` ;
$tname = "tname.$$" ;
$ttname = "ttname.$$" ;
$pwd = `pwd` ;
chomp ($pwd, $dir, $tname) ;
$instem = `$MB/grabpars -p $parname -x "instem:" ` ;
$outstem = `$MB/grabpars -p $parname -x "outstem:" ` ;
$poplist = `$MB/grabpars -p $parname -x "poplistname:" ` ;
$tempdir = `$MB/grabpars -p $parname -x "tempdir:" ` ;
$indlist = `$MB/grabpars -p $parname -x "indivlistname:" ` ;
chomp $tempdir if (defined $tempdir) ;
undef ($tempdir) if ($tempdir =~ /NOTFOUND/) ;
$dir = $tempdir if (defined $tempdir) ;
printf "mkdir -p $dir\n" ;
mkdir $dir ;
##system "mkdir -p $dir" ;
chomp ($instem, $outstem, $poplist, $indlist) ;
$ilist = "fxt:$$.ind" ;
$INDLIST = "$dir/$ilist" ;
if ($indlist =~ /NOTFOUND/) {
die "no poplist or indlist\n" if ($poplist =~ /NOTFOUND/) ;
system "$MM/grepcolf 2 $poplist < $instem.ind | $MM/xtractcol 0 > $INDLIST" ;
}
else {
system "$MM/grepcolf 0 $indlist < $instem.ind | $MM/xtractcol 0 > $INDLIST" ;
}
$S = "$X/extract_individuals.py" ;
$SG = "$X/extract_individuals.py -t" ;
$M = "$X/merge_transpose.py" ;
open (I1, $INDLIST) || die ("bad $INDLIST\n") ;
$SX = $S ;
$tgfile = "$instem.tgeno" ;
$SX = $SG if (-e $tgfile) ;
print "$tgfile\n$SX\n" ;
if (-e $tgfile) {
$gfile = $tgfile ;
}
else {
$gfile = "$instem.geno" ;
}
open (BB, $gfile) || die "can't find $SX\n" ;
read(BB, $chk, 4) ;
close BB ;
##print "check: $SX $chk\n" ;
if (($chk ne "GENO") && ($chk ne "TGEN")) {
die "only tgeno and geno formats supported\n" ;
}
system "cp $instem.snp $dir/$tname.snp" ;
foreach $line (<I1>) {
($id) = split " ", $line ;
## system "python3 $S -i $instem -s $id -o $dir/$id >& /dev/null" ;
## system "$MM/grepcol 0 $id < $smallind > $dir.$id.ind" ;
system "python3 $SX -x -i $instem -o $dir/$id $id" if (defined $verbose);
system "python3 $SX -x -i $instem -o $dir/$id $id >& /dev/null" unless (defined $verbose);
print "$id extracted\n" ;
}
close I1 ;
open (I1, $INDLIST) || die ("bad $INDLIST\n") ;
chdir $dir ;
foreach $line (<I1>) {
($id) = split " ", $line ;
system "ln -f $tname.snp $id.snp" ;
}
system "python3 $M -f $ilist -o $ttname" ;
##print "got here\n" ;
chdir $pwd ;
system " cp $dir/$ttname.snp $outstem.snp" ;
system " cp $dir/$ttname.ind $outstem.ind" ;
system " cp $dir/$ttname.geno $outstem.geno" ;
unlink $dir unless (defined $tempdir) ;