Perl: access per REST interface -> inconsistence

11 views
Skip to first unread message

Jan

unread,
Jul 21, 2010, 6:36:13 AM7/21/10
to MirMaid
Hello there,
I really love MirMaid and it solves so many problems I had with
miRBase and I really like the REST interface which makes it so simple
to access the data.

I'm using Perl and the XML::Simple module to parse the data and I
found a inconsistence of how the data is handled by the XML parser
which is kind of annoying:

if I access the matures of a precursor like /precursors/hsa-mir-29a/
matures.xml I get a data structure in Perl as this:
$VAR1 = {
'mature' => [
{
'experiment' => 'cloned (Landgraf P 2007)',
'sequence' => 'ACUGAUUUCUUUUGGUGUUCAG',
'similarity' => {},
'name' => 'hsa-miR-29a*',
'evidence' => 'experimental',
'id' => '34545',
'accession' => 'MIMAT0004503'
},
{
'experiment' => '....',
'sequence' => 'UAGCACCAUCUGAAAUCGGUUA',
'similarity' => {},
'name' => 'hsa-miR-29a',
'evidence' => 'experimental',
'id' => '34546',
'accession' => 'MIMAT0000086'
}
]
};

So I get an array reference by accessing the data as $VAR1->{'mature'}


But if I access a data structure derived e.g. from hsa-mir-1975 I get
sth like this:
$VAR1 = {
'mature' => {
'experiment' => 'cloned (Schotte D 2009)',
'sequence' => 'CCCCCACAACCGCGCUUGACUAGCU',
'similarity' => {},
'name' => 'hsa-miR-1975',
'evidence' => 'experimental',
'id' => '44644',
'accession' => 'MIMAT0009450'
}
};
which means I dont get a array reference by $VAR1->{'matures'}

This means I have to distinct by cases because I cant use a loop over
the array items in the second case which is annoying. I know this is a
problem by the XML parser but maybe you see an easy solution how to
fix that problem.


Kind regards,
Jan

Anders Jacobsen

unread,
Jul 21, 2010, 10:07:45 AM7/21/10
to mir...@googlegroups.com
Hi Jan,

Excellent that you find miRMaid useful!
I agree that this is inconsistent behavior in the Perl XML:Simple library and we were not aware of this issue - so thanks for pointing it out. I just glanced the documentation for the library, and I think the 'forcearray' option might be a good workaround. You could either have 'forcearray=>1' as default to ensure that nested elements are always arrays. However, this introduces some overhead in the syntax. Another approach would be to only force the REST objects into arrays, i.e. 'mature', 'precursor', 'species'. If you do this, then the syntax used in our code examples should not break:

my $client = REST::Client->new();
# NoAttr  : ignore "type" attributes
# KeyAttr : no folding, array elements are by default folded to a hash based on the attributes "name","key","id"
# ForceArray: Force array representation of miRMaid REST objects
my $xs = XML::Simple->new(NoAttr=>1,KeyAttr=>[],ForceArray=>['mature','precursor','species']);
$client->setHost("http://current.mirmaid.org");

print "### 2A) Getting the mature sequences for hsa-mir-21 precursor\n";
$client->GET('/precursors/hsa-mir-21/matures.xml');
my $matures = $xs->XMLin($client->responseContent())->{'mature'};
foreach my $m (@$matures) { print $m->{'sequence'}."\n" }

print "### 2B) Getting the mature sequences for hsa-mir-1271 precursor\n";
$client->GET('/precursors/hsa-mir-1271/matures.xml');
my $matures = $xs->XMLin($client->responseContent())->{'mature'};
foreach my $m (@$matures) { print $m->{'sequence'}."\n" }


-Anders


--
You received this message because you are subscribed to the Google Groups "MirMaid" group.
To post to this group, send email to mir...@googlegroups.com.
To unsubscribe from this group, send email to mirmaid+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mirmaid?hl=en.


Reply all
Reply to author
Forward
0 new messages