-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdas2pseudo_json.pl
executable file
·83 lines (65 loc) · 2.01 KB
/
das2pseudo_json.pl
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
#!/usr/bin/perl
# Author: Luke Ulrich
# Synopsis: Convert DAS result data into pseudo JSON where each line consists of the results of
# the sequence id, a tab character, and then the JSON encoded coils for this
# sequence.
#
# The JSON encoded results consist of an array of arrays.
$| = 1;
use strict;
use warnings;
use FindBin '$Bin';
use lib "$Bin/lib";
use Common;
use Getopt::Long;
my $usage = <<"USAGE";
Usage: $0 [options] <STDIN | das result file>
Available options
-----------------
-i, --src-file = Fasta file : Source fasta file corresponding
to these results.
-e, --error-file = string : file name to write any errors to.
If the source file is provided, then this script will check that the
first and last entries correspond to those in the fasta file.
USAGE
# Globals ---------------------------------------
my $g_Help;
my $g_InFile;
my $g_ErrFile;
GetOptions("h|help", \$g_Help,
"e|error-file=s", \$g_ErrFile,
"i|src-file=s", \$g_InFile);
die $usage if ($g_Help);
my $expectedLastId = &Common::getLastIdOrDieWithError($g_InFile, $g_ErrFile);
my $lastId;
while (<>) {
if (/^!!!.*Skipped. >(\S+)/) {
my $id = $1;
&Common::printJson($id, []);
$lastId = $id;
next;
}
next if (!/^>(\S+)/ );
my $id = $1;
my @tms = ();
my $non_tm = 0;
# Read in the remainder of the prediction
while (<>) {
last if (/^\/\//);
if (/^# TMH.*Non-TM protein/) {
$non_tm = 1;
}
# $1 $2 $3 $4 $5
elsif (!$non_tm && /^\@ *(\d+) *(\S+) *core: *(\d+) *\.\. *(\d+) *(\S+)/) {
my $from = int($3);
my $to = int($4);
my $peak = int($1);
my $peak_score = $2 + 0; # Force json_encode to treat as number
my $evalue = $5 + 0;
push @tms, [$from, $to, $peak, $peak_score, $evalue];
}
}
&Common::printJson($id, \@tms);
$lastId = $id;
}
&Common::writeErrorIfInvalidLastId($expectedLastId, $lastId, $g_ErrFile);