-
Notifications
You must be signed in to change notification settings - Fork 7
/
chado2dot.pl
executable file
·111 lines (100 loc) · 3.88 KB
/
chado2dot.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
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 strict;
my $root_dir;
BEGIN {
$root_dir = $0;
$root_dir =~ s/[^\/]*$//;
$root_dir = "./" unless $root_dir =~ /\//;
push @INC, $root_dir;
}
use ModENCODE::Parser::Chado;
use Data::Dumper;
use DBI;
use ModENCODE::Chado::AppliedProtocol;
use ModENCODE::Chado::Protocol;
use ModENCODE::Chado::Data;
use ModENCODE::Chado::DB;
use ModENCODE::Chado::DBXref;
use ModENCODE::Chado::CV;
use ModENCODE::Chado::CVTerm;
use ModENCODE::Chado::Attribute;
use ModENCODE::Config;
use ModENCODE::ErrorHandler qw(log_error);
$ModENCODE::ErrorHandler::show_logtype = 1;
ModENCODE::Config::set_cfg($root_dir . 'validator.ini');
my $experiment_id = $ARGV[0];
my $reader = new ModENCODE::Parser::Chado({
'dbname' => ModENCODE::Config::get_cfg()->val('databases modencode', 'dbname'),
'host' => ModENCODE::Config::get_cfg()->val('databases modencode', 'host'),
'port' => ModENCODE::Config::get_cfg()->val('databases modencode', 'port'),
'username' => ModENCODE::Config::get_cfg()->val('databases modencode', 'username'),
'password' => ModENCODE::Config::get_cfg()->val('databases modencode', 'password'),
});
if (!$experiment_id) {
print "Available experiments are:\n";
my @exp_strings = map { $_->{'experiment_id'} . "\t\"" . $_->{'uniquename'} . "\"" } @{$reader->get_available_experiments()};
print " ID\tName\n";
print " " . join("\n ", @exp_strings);
print "\n";
} else {
$reader->load_experiment($experiment_id);
my $experiment = $reader->get_experiment();
print "digraph nodes {\n";
print " node [shape=record];\n";
print " experiment [rank=source,label=\"<name> experiment|<value> " . $experiment->get_uniquename() . "\"];\n";
my @seen_thing;
my @seen_rel;
for (my $i = 0; $i < $experiment->get_num_applied_protocol_slots(); $i++) {
foreach my $ap (@{$experiment->get_applied_protocols_at_slot($i)}) {
my $ap_node = "AP" . $ap->get_protocol()->get_name();
$ap_node = ($ap_node);
if (!scalar(grep { $ap_node eq $_ } @seen_thing)) {
push @seen_thing, $ap_node;
print " \"" . $ap_node . "\" [label=\"<name> Protocol|<value> " . $ap->get_protocol()->get_name() . "\"];\n";
my $rel = "\"experiment\" -> \"$ap_node\" [minlen=2]";
if (!scalar(grep { $rel eq $_ } @seen_rel)) {
push @seen_rel, $rel;
print " $rel;\n" if $i == 0;
}
}
foreach my $datum (@{$ap->get_output_data()}) {
my $dt_node = "DT" . $datum->get_heading() . "_" . $datum->get_name() . "_" . $datum->get_type()->get_cv()->get_name() . "_" . $datum->get_type()->get_name();
$dt_node = ($dt_node);
my $dt_name = $datum->get_name() || $datum->get_heading();
if (!scalar(grep { $dt_node eq $_ } @seen_thing)) {
push @seen_thing, $dt_node;
print " \"" . $dt_node . "\" [label=\"<name> $dt_name\"];\n";
}
my $rel = "\"$ap_node\" -> \"$dt_node\"";
if (!scalar(grep { $rel eq $_ } @seen_rel)) {
push @seen_rel, $rel;
print " $rel;\n";
}
}
foreach my $datum (@{$ap->get_input_data()}) {
my $dt_node = "DT" . $datum->get_heading() . "_" . $datum->get_name() . "_" . $datum->get_type()->get_cv()->get_name() . "_" . $datum->get_type()->get_name();
$dt_node = ($dt_node);
my $dt_name = $datum->get_name() || $datum->get_heading();
my $minlen = 2;
if (!scalar(grep { $dt_node eq $_ } @seen_thing)) {
push @seen_thing, $dt_node;
print " \"" . $dt_node . "\" [label=\"<name> $dt_name\"];\n";
$minlen = 1;
}
my $rel = "\"$dt_node\" -> \"$ap_node\"";
if (!scalar(grep { $rel eq $_ } @seen_rel)) {
push @seen_rel, $rel;
print " $rel [minlen=$minlen];\n";
}
}
}
}
print "}\n";
}
sub escape {
my ($str) = @_;
$str =~ s/\s/ /g;
$str =~ s/\(/(/g;
$str =~ s/\)/)/g;
return $str;
}