-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlite2tg
executable file
·109 lines (85 loc) · 1.81 KB
/
lite2tg
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
109
#!/usr/bin/perl
use warnings;
use strict;
use fralib;
use Getopt::Long;
use File::Basename;
use Pod::Usage;
=head1 NAME
lite2tg
=head1 SYNOPSIS
affymetrix2tg [options] <affymetrix-call-file>
-h help
-o output file name (optional)
default: replaces extension of
<affymetrix-call-file> with tg
affymetrix-call-file Affymetrix calls file
example: affymetrix2tg -o pscalare.tg brlmm.calls.txt
Converts the affymetrix calls output file to a tg-file.
=head1 DESCRIPTION
=cut
my $help;
my $affymetrixFile;
my $tgFile;
my $headerProcessed = 0;
my $colNo;
#initialize options
Getopt::Long::Configure ('bundling');
if(!GetOptions ('h'=>\$help, 'o=s'=>\$tgFile) || scalar(@ARGV)!=1)
{
if ($help)
{
pod2usage(-verbose => 2);
}
else
{
pod2usage(1);
}
}
$affymetrixFile = $ARGV[0];
if (!defined($tgFile))
{
my ($name, $path, $ext) = fileparse($affymetrixFile, '\..*');
$tgFile = "$name.tg";
}
open(IN, $affymetrixFile) || die "Cannot open $affymetrixFile\n";
open(OUT, ">$tgFile") || die "Cannot open $tgFile\n";
while (<IN>)
{
s/\r?\n?$//;
if(!$headerProcessed)
{
if(/^probeset_id/)
{
$colNo = s/\t/\t/g + 1;
my @fields = split('\t',$_,$colNo);
print OUT "snp-id";
#reads in sample ids
for my $col (1 .. $#fields)
{
print OUT "\t$fields[$col]";
}
print OUT "\n";
$headerProcessed = 1;
}
}
else
{
my @fields = split(/\t/);
print OUT "$fields[0]";
for my $col (1 .. $#fields)
{
if($fields[$col]=~/^(0|1|2|-1)$/)
{
print OUT "\t$fields[$col]";
}
else
{
die "Unrecognized encoding in $affymetrixFile: $fields[$col]";
}
}
print OUT "\n";
}
}
close(OUT);
close(IN);