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

View of /FigKernelScripts/flatten_erdb_xml.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (download) (as text) (annotate)
Thu Mar 22 20:24:20 2012 UTC (7 years, 8 months ago) by olson
Branch: MAIN
CVS Tags: rast_rel_2014_0729, mgrast_version_3_2, rast_rel_2014_0912, HEAD
script to write tabular form of ERDB XML file

use strict;
use Data::Dumper;
use XML::LibXML;

@ARGV == 3 or die "Usage: $0 xml-file entity-file relationship-file\n";

my $in_file = shift;
my $entity_file = shift;
my $rel_file = shift;

my $doc = XML::LibXML->new->parse_file($in_file);
$doc or die "cannot parse $in_file\n";

open(ENT, ">", $entity_file) or die "cannot write $entity_file: $!";
open(REL, ">", $rel_file) or die "cannot write $rel_file: $!";

for my $e (sort { $a->getAttribute("name") cmp $b->getAttribute("name") }  $doc->findnodes('//Entities/Entity'))
{
    my $n = $e->getAttribute("name");
    my @fields = $e->findnodes('Fields/Field');
    my @fd;
    for my $f (@fields)
    {
	my $fn = $f->getAttribute("name");
	my $field_rel = $f->getAttribute("relation");
	push(@fd, $field_rel ? "$fn:$field_rel" : $fn);
    }
    print ENT join("\t", $n, @fd), "\n";
}

for my $e (sort { $a->getAttribute("name") cmp $b->getAttribute("name") }  $doc->findnodes('//Relationships/Relationship'))
{
    my $n = $e->getAttribute("name");
    my $from = $e->getAttribute("from");
    my $to = $e->getAttribute("to");
    my $converse = $e->getAttribute("converse");
    my @fields = $e->findnodes('Fields/Field');
    my @fd;
    for my $f (@fields)
    {
	my $fn = $f->getAttribute("name");
	my $field_rel = $f->getAttribute("relation");
	push(@fd, $field_rel ? "$fn:$field_rel" : $fn);
    }

    print REL join("\t", $n, $from, $to, $converse, @fd), "\n";
}
close(ENT);
close(REL);

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3