-
Notifications
You must be signed in to change notification settings - Fork 0
/
fxtract
executable file
·82 lines (61 loc) · 1.35 KB
/
fxtract
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
#!/usr/bin/perl
use warnings;
use strict;
use fralib;
use File::Basename;
use Getopt::Long;
use Pod::Usage;
=head1 NAME
fxtract
=head1 SYNOPSIS
fxtract [options] genotype-file
-h help
example: fxtract pscalare.gt
fxtract pscalare.tg
Extracts sample-ids and snp-ids from a gt or tg file.
=head1 DESCRIPTION
=cut
#option variables
my $help;
my $genotypeFile;
my $genotypeSkeletonFile;
my $headerProcessed;
#initialize options
Getopt::Long::Configure ('bundling');
if(!GetOptions ('h'=>\$help) || scalar(@ARGV)!=1)
{
if ($help)
{
pod2usage(-verbose => 2);
}
else
{
pod2usage(1);
}
}
$genotypeFile = $ARGV[0];
isGtOrTg($genotypeFile) || die "$genotypeFile not a genotype file";
if(!defined($genotypeSkeletonFile))
{
my($name, $path, $ext) = fileparse($genotypeFile, '\..*');
$genotypeSkeletonFile = "$name$ext" . "s";
}
open(GENO_SKELETON, ">$genotypeSkeletonFile") || die "Cannot open $genotypeSkeletonFile";
open(GENO, "$genotypeFile") || die "Cannot open $genotypeFile";
$headerProcessed = 0;
while (<GENO>)
{
s/\r?\n?$//;
if(!$headerProcessed)
{
print GENO_SKELETON "$_\n";
$headerProcessed = 1;
}
else
{
my @fields = split('\t', $_, 2);
print GENO_SKELETON "$fields[0]\n";
}
}
close(GENO_SKELETON);
close(GENO);