-
Notifications
You must be signed in to change notification settings - Fork 2
/
ds_data_extractor_new_parser
executable file
·144 lines (101 loc) · 2.86 KB
/
ds_data_extractor_new_parser
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/perl -w
use strict;
use lib ('/home/mcampbell/lib');
#use Getopt::Std;
#use vars qw($opt_t);
#getopts('t:');
use PostData;
$| = 1;
use Bio::SearchIO;
use FileHandle;
my $usage = "
USAGE: ds_data_extractor_new_parser <master org> <target org 1> <target org 2> <outfile 1> <outfile 2>
\n";
#-----------------------------------------------------------------------------
#----------------------------------- MAIN ------------------------------------
#-----------------------------------------------------------------------------
my %DATA;
my %STR;
my %BAD;
die $usage unless $ARGV[2];
my $M = shift @ARGV;
my $A = shift @ARGV;
my $B = shift @ARGV;
my $i = 0;
while (defined(my $file = shift @ARGV)){
parse($file, $i);
$i++;
}
#set_maxo();
#PostData(\%DATA);
foreach my $id (keys %DATA){
next if is_bad($id); # i.e. not present in all input files.
foreach my $o (sort {$a <=> $b} keys %{$DATA{$id}}){
my $mn;
my $an;
my $bn;
if (exists($DATA{$id}{$o}{$A}) && exists($DATA{$id}{$o}{$B})){
# $A & $B
$mn = $DATA{$id}{$o}{$A}->{q};
$an = $DATA{$id}{$o}{$A}->{s};
$bn = $DATA{$id}{$o}{$B}->{s};
my $x = $DATA{$id}{$o}{$A}->{q};
my $y = $DATA{$id}{$o}{$B}->{q};
die "Q NUC NOT SAME!\n" unless $x eq $y;
}
elsif (exists($DATA{$id}{$o}{$A})){
# $A only
$mn = $DATA{$id}{$o}{$A}->{q};
$an = $DATA{$id}{$o}{$A}->{s};
$bn = '-';
}
elsif (exists($DATA{$id}{$o}{$B})){
# $B only
$mn = $DATA{$id}{$o}{$B}->{q};
$an = '-';
$bn = $DATA{$id}{$o}{$B}->{s};
}
$STR{$id}{M} .= $mn;
$STR{$id}{A} .= $an;
$STR{$id}{B} .= $bn;
}
}
spew();
#-----------------------------------------------------------------------------
#---------------------------------- SUBS -------------------------------------
#-----------------------------------------------------------------------------
sub is_bad {
my $id = shift;
my @keys = keys %{$BAD{$id}};
return 1 if @keys < 2;
return 0;
}
#-----------------------------------------------------------------------------
sub spew {
foreach my $id (keys %STR){
print ">$id\n";
for (my $i = 0; $i < length($STR{$id}{M}); $i +=60){
print substr($M, 0, 5)." ".substr($STR{$id}{M}, $i, 60)."\n";
print substr($A, 0, 5)." ".substr($STR{$id}{A}, $i, 60)."\n";
print substr($B, 0, 5)." ".substr($STR{$id}{B}, $i, 60)."\n";
print "\n";
}
#print "\n";
}
}
#-----------------------------------------------------------------------------
sub parse {
my $file = shift;
my $i = shift;
my $fh = new FileHandle();
$fh->open($file);
while (defined(my $line = <$fh>)){
chomp($line);
my @stuff = split(/\t/, $line);
$BAD{$stuff[2]}{$i}++;
$DATA{$stuff[2]}{$stuff[3]}{$stuff[1]} =
{q => $stuff[4], s => $stuff[5]};
}
$fh->close();
}
#-----------------------------------------------------------------------------