-
Notifications
You must be signed in to change notification settings - Fork 0
/
fluxestoJSON.pl
48 lines (42 loc) · 867 Bytes
/
fluxestoJSON.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
use strict;
use warnings;
my $filename;
if ($ARGV[0]){
$filename = $ARGV[0];
}
else {
$filename = "results.txt";
}
open(WEIGHTS, $filename);
open(EDGES, "resultstoedges.txt");
my %fluxes;
while (<WEIGHTS>) {
chomp $_;
my @splitline = split(/\t/, $_);
$fluxes{$splitline[0]} = $splitline[1];
}
my %edgeflux;
while (<EDGES>) {
chomp $_;
my @splitline = split(/\t/, $_);
my $edgename = $splitline[0];
my $fluxname = $splitline[1];
if ($fluxes{$fluxname}) {
$edgeflux{$edgename} = $fluxes{$fluxname};
}
else {
$edgeflux{$edgename} = 0;
}
}
# output as a simple table (for debug only)
# foreach (keys %edgeflux) {
# print "$_\t$edgeflux{$_}\n";
# }
open(JSON, ">".$filename."json.js");
# output as JSON
print JSON "jsonfluxes = {\n";
foreach (keys %edgeflux) {
print JSON "\t".'"'.$_.'" : '.$edgeflux{$_}.','."\n";
}
print JSON "}";
close JSON;