[Bio] / FigKernelScripts / flatten_erdb_xml.pl Repository:
ViewVC logotype

Annotation of /FigKernelScripts/flatten_erdb_xml.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (view) (download) (as text)

1 : olson 1.1 use strict;
2 :     use Data::Dumper;
3 :     use XML::LibXML;
4 :    
5 :     @ARGV == 3 or die "Usage: $0 xml-file entity-file relationship-file\n";
6 :    
7 :     my $in_file = shift;
8 :     my $entity_file = shift;
9 :     my $rel_file = shift;
10 :    
11 :     my $doc = XML::LibXML->new->parse_file($in_file);
12 :     $doc or die "cannot parse $in_file\n";
13 :    
14 :     open(ENT, ">", $entity_file) or die "cannot write $entity_file: $!";
15 :     open(REL, ">", $rel_file) or die "cannot write $rel_file: $!";
16 :    
17 :     for my $e (sort { $a->getAttribute("name") cmp $b->getAttribute("name") } $doc->findnodes('//Entities/Entity'))
18 :     {
19 :     my $n = $e->getAttribute("name");
20 :     my @fields = $e->findnodes('Fields/Field');
21 :     my @fd;
22 :     for my $f (@fields)
23 :     {
24 :     my $fn = $f->getAttribute("name");
25 :     my $field_rel = $f->getAttribute("relation");
26 :     push(@fd, $field_rel ? "$fn:$field_rel" : $fn);
27 :     }
28 :     print ENT join("\t", $n, @fd), "\n";
29 :     }
30 :    
31 :     for my $e (sort { $a->getAttribute("name") cmp $b->getAttribute("name") } $doc->findnodes('//Relationships/Relationship'))
32 :     {
33 :     my $n = $e->getAttribute("name");
34 :     my $from = $e->getAttribute("from");
35 :     my $to = $e->getAttribute("to");
36 :     my $converse = $e->getAttribute("converse");
37 :     my @fields = $e->findnodes('Fields/Field');
38 :     my @fd;
39 :     for my $f (@fields)
40 :     {
41 :     my $fn = $f->getAttribute("name");
42 :     my $field_rel = $f->getAttribute("relation");
43 :     push(@fd, $field_rel ? "$fn:$field_rel" : $fn);
44 :     }
45 :    
46 :     print REL join("\t", $n, $from, $to, $converse, @fd), "\n";
47 :     }
48 :     close(ENT);
49 :     close(REL);

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3