NAME
Bio::Annotation::TagTree - AnnotationI with tree-like hierarchal key-value relationships ('structured tags') that can be represented as simple text.
SYNOPSIS
use Bio::Annotation::TagTree;use Bio::Annotation::Collection;my $col = Bio::Annotation::Collection->new();# data structure can be an array reference with a data structure# corresponding to that defined by Data::Stag:my $sv = Bio::Annotation::TagTree->new(-tagname => 'mytag1',-value => $data_structure);$col->add_Annotation($sv);# regular text passed is parsed based on the tagformat().my $sv2 = Bio::Annotation::TagTree->new(-tagname => 'mytag2',-tagformat => 'xml',-value => $xmltext);$col->add_Annotation($sv2);
DESCRIPTION
This takes tagged data values and stores them in a hierarchal structured element-value hierarchy (complements of Chris Mungall's Data::Stag module). Data can then be represented as text using a variety of output formats (indention, itext, xml, spxr). Furthermore, the data structure can be queried using various means. See Data::Stag for details.
Data passed in using value() or the '-value' parameter upon instantiation can either be:
1) an array reference corresponding to the data structure for Data::Stag;
2) a text string in 'xml', 'itext', 'spxr', or 'indent' format. The default format is 'xml'; this can be changed using tagformat() prior to using value() or by passing in the proper format using '-tagformat' upon instantiation;
3) another Bio::Annotation::TagTree or Data::Stag node instance. In both cases a deep copy (duplicate) of the instance is generated.
Beyond checking for an array reference no format guessing occurs (so, for roundtrip tests ensure that the IO formats correspond). For now, we recommend when using text input to set tagformat() to one of these formats prior to data loading to ensure the proper Data::Stag parser is selected. After data loading, the tagformat() can be changed to change the text string format returned by value(). (this may be rectified in the future)
This Annotation type is fully BioSQL compatible and could be considered a temporary replacement for nested Bio::Annotation::Collections, at least until BioSQL and bioperl-db can support nested annotation collections.
FEEDBACK
Mailing Lists
User feedback is an integral part of the evolution of this and other Bioperl modules. Send your comments and suggestions preferably to one of the Bioperl mailing lists. Your participation is much appreciated.
[email protected] - General discussionhttp://bioperl.org/wiki/Mailing_lists - About the mailing lists
Support
Please direct usage questions or support issues to the mailing list:
rather than to the module maintainer directly. Many experienced and reponsive experts will be able look at the problem and quickly address it. Please include a thorough description of the problem with code and data examples if at all possible.
Reporting Bugs
Report bugs to the Bioperl bug tracking system to help us keep track the bugs and their resolution. Bug reports can be submitted via or the web:
https://github.com/bioperl/bioperl-live/issues
AUTHOR
Chris Fields
APPENDIX
The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _
new
Title : newUsage : my $sv = Bio::Annotation::TagTree->new();Function: Instantiate a new TagTree objectReturns : Bio::Annotation::TagTree objectArgs : -value => $value to initialize the object data field [optional]-tagname => $tag to initialize the tagname [optional]-tagformat => format for output [optional](types 'xml', 'itext', 'sxpr', 'indent', default = 'itext')-node => Data::Stag node or Bio::Annotation::TagTree instance
AnnotationI implementing functions
as_text
Title : as_textUsage : my $text = $obj->as_textFunction: return the string "Value: $v" where $v is the valueReturns : stringArgs : none
display_text
Title : display_textUsage : my $str = $ann->display_text();Function: returns a string. Unlike as_text(), this method returns a stringformatted as would be expected for the specific implementation.One can pass a callback as an argument which allows custom textgeneration; the callback is passed the current instance and any textreturnedExample :Returns : a stringArgs : [optional] callback
hash_tree
Title : hash_treeUsage : my $hashtree = $value->hash_treeFunction: For supporting the AnnotationI interface just returns the valueas a hashref with the key 'value' pointing to the valueMaybe reimplement using Data::Stag::hash()?Returns : hashrfArgs : none
tagname
Title : tagnameUsage : $obj->tagname($newval)Function: Get/set the tagname for this annotation value.Setting this is optional. If set, it obviates the need to providea tag to AnnotationCollection when adding this object.Example :Returns : value of tagname (a scalar)Args : new value (a scalar, optional)
Specific accessors for TagTree
value
Title : valueUsage : $obj->value($newval)Function: Get/set the value for this annotation.Returns : value of valueArgs : newvalue (optional)
tagformat
Title : tagformatUsage : $obj->tagformat($newval)Function: Get/set the output tag format for this annotation.Returns : value of tagformatArgs : newvalue (optional) - format for the data passed into valuemust be of values 'xml', 'indent', 'sxpr', 'itext', 'perl'
node
Title : nodeUsage : $obj->node()Function: Get/set the topmost Data::Stag node used for this annotation.Returns : Data::Stag node implementation(default is Data::Stag::StagImpl)Args : (optional) Data::Stag node implementation(optional)'copy' => flag to create a copy of the node
Data::Stag convenience methods
Because Data::Stag uses blessed arrays and the core Bioperl class uses blessed hashes, TagTree uses an internal instance of a Data::Stag node for data storage. Therefore the following methods actually delegate to the Data:::Stag internal instance.
For consistency (since one could recursively check child nodes), methods retain the same names as Data::Stag. Also, no 'magic' (AUTOLOAD'ed) methods are employed, simply b/c full-fledged Data::Stag functionality can be attained by grabbing the Data::Stag instance using node().
element
Title : elementUsage :Function: Returns the element name (key name) for this nodeExample :Returns : scalarArgs : none
data
Title : dataUsage :Function: Returns the data structure (array ref) for this nodeExample :Returns : array refArgs : none
children
Title : childrenUsage :Function: Get the top-level array of Data::Stag nodes or (if the top level isa terminal node) a scalar value.This is similar to StructuredValue's get_values() method, with thekey difference being instead of array refs and scalars you get eitherData::Stag nodes or the value for this particular node.For consistency (since one could recursively check nodes),we use the same method name as Data::Stag children().Example :Returns : an arrayArgs : none
subnodes
Title : subnodesUsage :Function: Get the top-level array of Data::Stag nodes. Unlike children(),this only returns an array of nodes (if this is a terminal node,no value is returned)Example :Returns : an array of nodesArgs : none
get
Title : getUsage :Function: Returns the nodes or value for the named element or pathExample :Returns : returns array of nodes or a scalar (if node is terminal)dependent on wantarrayArgs : none
find
Title : findUsage :Function: Recursively searches for and returns the nodes or values for thenamed element or pathExample :Returns : returns array of nodes or scalars (for terminal nodes)Args : none
findnode
Title : findnodeUsage :Function: Recursively searches for and returns a list of nodesof the given element pathExample :Returns : returns array of nodesArgs : none
findval
Title : findvalUsage :Function:Example :Returns : returns array of nodes or valuesArgs : none
addchild
Title : addchildUsage : $struct->addchild(['name' => [['foo'=> 'bar1']]]);Function: add new child node to the current node. One can pass in a node, TagTree,or data structure; for instance, in the above, this would translateto (in XML):<name><foo>bar1</foo></name>Returns : nodeArgs : first arg = element nameall other args are added as tag-value pairs
add
Title : addUsage : $struct->add('foo', 'bar1', 'bar2', 'bar3');Function: add tag-value nodes to the current node. In the above, this wouldtranslate to (in XML):<foo>bar1</foo><foo>bar2</foo><foo>bar3</foo>Returns :Args : first arg = element nameall other args are added as tag-value pairs
set
Title : setUsage : $struct->set('foo','bar');Function: sets a single tag-value pair in the current node. Note thisdiffers from add() in that this replaces any data already presentReturns : nodeArgs : first arg = element nameall other args are added as tag-value pairs
unset
Title : unsetUsage : $struct->unset('foo');Function: unsets all key-value pairs of the passed element from thecurrent nodeReturns : nodeArgs : element name
free
Title : freeUsage : $struct->freeFunction: removes all data from the current nodeReturns :Args :
hash
Title : hashUsage : $struct->hash;Function: turns the tag-value tree into a hash, all data values are array refsReturns : hashArgs : first arg = element nameall other args are added as tag-value pairs
pairs
Title : pairsUsage : $struct->pairs;Function: turns the tag-value tree into a hash, all data values are scalarReturns : hashArgs : first arg = element nameall other args are added as tag-value pairs, note that duplicateswill be lost
qmatch
Title : qmatchUsage : @persons = $s->qmatch('person', ('name'=>'fred'));Function : returns all elements in the node tree which match theelement name and the key-value pairReturns : Array of nodesArgs : return-element str, match-element str, match-value str
tnodes
Title : tnodesUsage : @termini = $s->tnodes;Function : returns all terminal nodes below this nodeReturns : Array of nodesArgs : return-element str, match-element str, match-value str
ntnodes
Title : ntnodesUsage : @termini = $s->ntnodes;Function : returns all nonterminal nodes below this nodeReturns : Array of nodesArgs : return-element str, match-element str, match-value str
StructureValue-like methods
get_all_values
Title : get_all_valuesUsage : @termini = $s->get_all_values;Function : returns all terminal node valuesReturns : Array of valuesArgs : return-element str, match-element str, match-value str
This is meant to emulate the values one would get from StructureValue's get_all_values() method. Note, however, using this method dissociates the tag-value relationship (i.e. you only get the value list, no elements)