forked from vikas0633/perl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVenn_to_XML.pl
60 lines (41 loc) · 1.19 KB
/
Venn_to_XML.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
#!/usr/bin/env perl
use strict;
use warnings;
my %all_objects;
my %sets;
my $file = $ARGV[0] or die "usage: $0 Venn.output\n\n";
open (my $fh, $file) or die "Error, cannot open file $file";
## populate classes
while (<$fh>) {
chomp;
my ($acc, $venn_list) = split (/\s+/);
my @atts = split (/,/, $venn_list);
foreach my $att (@atts) {
push (@{$sets{$att}}, $acc);
}
$all_objects{$acc} = 1;
}
close $fh;
print "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>
<ClassificationTree version=\"1.0\">
<ObjectSet>\n";
foreach my $acc (keys %all_objects) {
print "<Object ID=\"$acc\"><Name>$acc</Name><Location>none</Location></Object>\n";
}
print "</ObjectSet>
<ClassificationSet>\n";
print "<Classification ID=\"root\">\n"
. "<Name>16Sregions</Name>\n"
. "<Objects objectIDs=\"" . join (" ", keys %all_objects) . "\"/>\n"
. "</Classification>\n\n";
foreach my $class (keys %sets) {
print "<Classification ID=\"$class\">\n";
print "<Name>$class</Name>\n";
print "<SuperClass refs=\"root\"/>\n";
my @objects = @{$sets{$class}};
print "<Objects objectIDs=\"" . join (" ", @objects) . "\"/>\n";
print "</Classification>\n\n";
}
print "</ClassificationSet>
</ClassificationTree>\n";
exit(0);