Skip to content
This repository has been archived by the owner on Aug 10, 2021. It is now read-only.

ModelSEED Reference

Scott Devoid edited this page Jul 25, 2012 · 4 revisions

ModelSEED::Reference

Parse and construct ModelSEED data references.

SYNOPSIS

my $ref = ModelSEED::Reference->new( ref => "biochemistry/chenry/main" );
print $ref->type;                     # 'object'
print $ref->id;                       # 'chenry/main'
print $ref->id_type;                  # 'alias'
print $ref->alias_string;             # 'main'
print $ref->alias_username;           # 'chenry'
print $ref->alias_type;               # 'biochemistry';
print $ref->base;                     # 'biochemistry/'
print $ref->class;                    # 'ModelSEED::MS::Biochemistry'

my $ref = ModelSEED::Reference->new(
    ref => "http://model-api.theseed.org/biochemistry/chenry/main/reactions"
);
print $ref->type;                      # 'collection'
print $ref->authority if $ref->is_url; # 'model-api.theseed.org'
print $ref->scheme if $ref->is_url;    # 'http'

# Construct ref from type, alias
my $ref = ModelSEED::Reference->new('alias' => 'chenry/main', type => 'biochemsitry');
print $ref->ref; # '/biochemistry/chenry/main'

# Construct ref from type, uuid, with base type and id
my $ref = ModelSEED::Reference->new(
    base_types => [ 'biochemistry' ], base_ids => [ 'chenry/main' ],
    uuid => "550e8400-e29b-41d4-a716-446655440000",
    type => 'compound'
);
print $ref->ref; # '/biochemistry/chenry/main/compound/550e8400-e29b-41d4-a716-446655440000'

Construction

The new function accepts different parameters for constructing a reference. These are divided into sets where each set contains the complete parameters needed to create a reference:

Basic string

Pass in a string to the attribute 'ref'.

my $ref = ModelSEED::Reference->new(ref => "biochemistry/chenry/main");
UUID and type

Pass in the attributes 'uuid' and 'type' for a top level object. Pass in 'uuid', 'type', 'base_ids', and 'base_types' for deep references:

my $ref = ModelSEED::Reference->new(uuid => :uuid, type => 'biochemistry');
my $ref = ModelSEED::Reference->new(uuid => :uuid, type => 'compound',
    base_types => [ 'biochemistry' ], base_ids => [ 'chenry/main' ]
);
Alias and type

Pass in the attributes 'alias' and 'type' for a top level object. Include the 'base_ids' and 'base_types' for deep refernces.

Errors

If the data provided during reference construction results in an invalid reference object, an error Invalid Reference will be thrown.

Instance Attributes

A reference instance has many attributes that can be used to act on that reference. These should all be treated as read-only accessors:

Basic Attributes

ref

The complete reference as a string. Can be passed into a new constructor.

type

A string that is either collection or object. This indicates whether the reference points to a single object, e.g. a reaction, or a collection of objects, e.g. all of the reactions in a biochemistry object.

base

If the type is an object, this would return the non-id portion of the ref string. If the type is a collection, this would correspond to the whole ref string.

id

This is defined if the type is an object. It is a string contianing the id portion of the reference.

ID Attributes

id_type

A string that is either uuid or alias indicating whether the id portion should be treated as a UUID or as an alias string.

alias_username

If id_type is "alias", this returns the username portion of the alias.

alias_string

If id_type is "alias", this returns the unrestricted portion of the alias string.

alias_type

If id_type is "alias", this returns the type associated with the alias.

URL Attributes

A reference can be passed in as a URL string, e.g.

http://model-api.theseed.org/biochemistry/alice/main

If this is the case, is_url will be true and the following attributes will be defined:

scheme

The URL schema, usually "http".

authority

The "domain" portion of the url, e.g. "model-api.theseed.org"