-
Notifications
You must be signed in to change notification settings - Fork 0
/
fpeek
executable file
·86 lines (68 loc) · 1.31 KB
/
fpeek
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
#!/usr/bin/perl
use warnings;
use strict;
use fralib;
use Getopt::Long;
#option variables
my $verbose;
my $debug;
#variables
my $genotypeFile;
my $colNo;
my $colElement;
my $rowElement;
my $selectedRow;
my $selectedCol;
#initialize options
Getopt::Long::Configure ('bundling');
if(!GetOptions ('v'=>\$verbose, 'd'=>\$debug) || scalar(@ARGV)!=3)
{
print <<HELP;
usage: fpeek -[vd] <1> <2> <genotype-file>
v - verbose
d - debug
example: fpeek snpA sampleA pscalare.geno
Gets the value at a row, column entry of a table file.
HELP
exit(1);
}
#look for genotype file
for my $i (0..$#ARGV)
{
if (-e $ARGV[$i])
{
$genotypeFile = $ARGV[$i];
#isGeno($genotypeFile) || die "$genotypeFile not a genotype file";
splice(@ARGV, $i, 1);
}
}
$rowElement = $ARGV[0];
$colElement = $ARGV[1];
open(GENO, $genotypeFile) || die "Cannot open $genotypeFile";
while(<GENO>)
{
if ($.==1)
{
$colNo = s/\t/\t/g + 1;
my @fields = split('\t', $_, $colNo);
for my $col (1..$#fields)
{
if ($fields[$col] eq $colElement)
{
$selectedCol = $col;
}
}
}
else
{
my @fields = split('\t', $_, 2);
if ($fields[0] eq $rowElement)
{
my @selectedRowFields = split('\t', $_, $selectedCol+2);
print "$selectedRowFields[$selectedCol]\n";
close(GENO);
exit(0);
}
}
}
close(GENO);