Bio::A...agTree(3pm)
Bio::Annotation::TagTree π
okay bestie, so this is the Bio::A...agTree(3pm) page from the User Contributed Perl Documentation, and it's literally about an AnnotationI thingy with tree-like hierarchal key-value relationships β aka 'structured tags' β that can be represented as simple text. slay.
β¨ NAME β¨
Bio::Annotation::TagTree β an AnnotationI with tree-like hierarchal key-value relationships ('structured tags') that can be represented as simple text. no cap, that's the whole vibe.
πΈ 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 π¦
So here's the tea π: 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. and on top of that, the data structure can be queried using various means. See Data::Stag for details, iykyk.
Data passed in using value() or the -value parameter upon instantiation can either be:
- an array reference corresponding to the data structure for
Data::Stag; - a text string in
'xml','itext','spxr', or'indent'format. The default format is'xml'; this can be changed usingtagformat()prior to usingvalue()or by passing in the proper format using-tagformatupon instantiation; - another Bio::Annotation::TagTree or
Data::Stagnode 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. iconic behaviour, honestly.
π 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. fr fr, they want to hear from you.
bioperl-l@bioperl.org - General discussion
http://bioperl.org/wiki/Mailing_lists - About the mailing lists
Support π
Please direct usage questions or support issues to the mailing list:
bioperl-l@bioperl.org
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. (yes, the original says "reponsive" β we keep it exactly as it is, bestie, typos are part of the lore π)
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 _. okay so here's where it gets spicy π₯
new β¨
Title : new
Usage : my $sv = Bio::Annotation::TagTree->new();
Function: Instantiate a new TagTree object
Returns : Bio::Annotation::TagTree object
Args : -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_text
Usage : my $text = $obj->as_text
Function: return the string "Value: $v" where $v is the value
Returns : string
Args : none
display_text π¦
Title : display_text
Usage : my $str = $ann->display_text();
Function: returns a string. Unlike as_text(), this method returns a string
formatted as would be expected for the specific implementation.
One can pass a callback as an argument which allows custom text
generation; the callback is passed the current instance and any text
returned
Example :
Returns : a string
Args : [optional] callback
hash_tree π
Title : hash_tree
Usage : my $hashtree = $value->hash_tree
Function: For supporting the AnnotationI interface just returns the value
as a hashref with the key 'value' pointing to the value
Maybe reimplement using Data::Stag::hash()?
Returns : hashrf
Args : none
tagname π
Title : tagname
Usage : $obj->tagname($newval)
Function: Get/set the tagname for this annotation value.
Setting this is optional. If set, it obviates the need to provide
a tag to AnnotationCollection when adding this object.
Example :
Returns : value of tagname (a scalar)
Args : new value (a scalar, optional)
β¨ Specific accessors for TagTree β¨
These are the ones that are just ours, bestie β not borrowed from anywhere. TagTree originals. π
π value
- Title: value
- Usage:
$obj->value($newval) - Function: Get/set the value for this annotation.
- Returns: value of value
- Args: newvalue (optional)
π tagformat
- Title: tagformat
- Usage:
$obj->tagformat($newval) - Function: Get/set the output tag format for this annotation.
- Returns: value of tagformat
- Args: newvalue (optional) β format for the data passed into value, must be of values
'xml','indent','sxpr','itext','perl'
π¦ node
- Title: node
- Usage:
$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
okay so real talk: Data::Stag uses blessed arrays, and the core Bioperl class uses blessed hashes. Two different whole personalities π. So TagTree keeps an internal instance of a Data::Stag node around purely for data storage. Which means the methods below don't actually do the work themselves β they delegate straight to the Data:::Stag internal instance.
And for consistency (since you could go recursively poking at child nodes), these methods keep the exact same names as Data::Stag. Also, no 'magic' (AUTOLOAD'ed) methods here β simply b/c you can get the full-fledged Data::Stag functionality by grabbing the Data::Stag instance with node(). π«
β element
- Title: element
- Usage: (empty in the original β nothing here)
- Function: Returns the element name (key name) for this node
- Example: (empty in the original)
- Returns: scalar
- Args: none
π data
- Title: data
- Usage: (empty in the original)
- Function: Returns the data structure (array ref) for this node
- Example: (empty in the original)
- Returns: array ref
- Args: none
π§ children
- Title: children
- Usage: (empty in the original)
- Function: Get the top-level array of Data::Stag nodes or (if the top level is a terminal node) a scalar value.
This is similar to StructuredValue's get_values() method, with the key difference being instead of array refs and scalars you get either Data::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: (empty in the original)
- Returns: an array
- Args: none
πΈ subnodes
- Title: subnodes
- Usage: (empty in the original)
- 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: (empty in the original)
- Returns: an array of nodes
- Args: none
π get
- Title: get
- Usage: (empty in the original)
- Function: Returns the nodes or value for the named element or path
- Example: (empty in the original)
- Returns: returns array of nodes or a scalar (if node is terminal) dependent on wantarray
- Args: none
π₯ find
- Title: find
- Usage: (empty in the original)
- Function: Recursively searches for and returns the nodes or values for the named element or path
- Example: (empty in the original)
- Returns: returns array of nodes or scalars (for terminal nodes)
- Args: none
π findnode
- Title: findnode
- Usage: (empty in the original)
- Function: Recursively searches for and returns a list of nodes of the given element path
- Example: (empty in the original)
- Returns: returns array of nodes
- Args: none
π«Ά findval
- Title: findval
- Usage: (empty in the original)
- Function: (empty in the original)
- Example: (empty in the original)
- Returns: returns array of nodes or values
- Args: none
π addchild
- Title: addchild
- Usage:
$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 translate to (in XML):
<name>
<foo>bar1</foo>
</name>
- Returns: node
- Args: first arg = element name; all other args are added as tag-value pairs
π add
- Title: add
- Usage:
$struct->add('foo', 'bar1', 'bar2', 'bar3'); - Function: add tag-value nodes to the current node. In the above, this would translate to (in XML):
<foo>bar1</foo>
<foo>bar2</foo>
<foo>bar3</foo>
- Returns: (empty in the original)
- Args: first arg = element name; all other args are added as tag-value pairs
β¨ set
- Title: set
- Usage:
$struct->set('foo','bar'); - Function: sets a single tag-value pair in the current node. Note this differs from
add()in that this replaces any data already present - Returns: node
- Args: first arg = element name; all other args are added as tag-value pairs
π unset
- Title: unset
- Usage:
$struct->unset('foo'); - Function: unsets all key-value pairs of the passed element from the current node
- Returns: node
- Args: element name
π¦ free
- Title: free
- Usage:
$struct->free - Function: removes all data from the current node
- Returns: (empty in the original)
- Args: (empty in the original)
π hash
- Title: hash
- Usage:
$struct->hash; - Function: turns the tag-value tree into a hash, all data values are array refs
- Returns: hash
- Args: first arg = element name; all other args are added as tag-value pairs
π pairs
- Title: pairs
- Usage:
$struct->pairs; - Function: turns the tag-value tree into a hash, all data values are scalar
- Returns: hash
- Args: first arg = element name; all other args are added as tag-value pairs β note that duplicates will be lost
lowkey devastating but true: duplicates do not survive pairs. π
π§ qmatch
- Title: qmatch
- Usage:
@persons = $s->qmatch('person', ('name'=>'fred')); - Function: returns all elements in the node tree which match the element name and the key-value pair
- Returns: Array of nodes
- Args: return-element str, match-element str, match-value str
β tnodes
- Title: tnodes
- Usage:
@termini = $s->tnodes; - Function: returns all terminal nodes below this node
- Returns: Array of nodes
- Args: return-element str, match-element str, match-value str
π ntnodes
- Title: ntnodes
- Usage:
@termini = $s->ntnodes; - Function: returns all nonterminal nodes below this node
- Returns: Array of nodes
- Args: return-element str, match-element str, match-value str
πΈ StructureValue-like methods
π₯ get_all_values
- Title: get_all_values
- Usage:
@termini = $s->get_all_values; - Function: returns all terminal node values
- Returns: Array of values
- Args: return-element str, match-element str, match-value str
This one is meant to emulate the values you'd get from StructureValue's get_all_values() method. But bestie, heads up β οΈ β using this method dissociates the tag-value relationship (i.e. you only get the value list, no elements). The tags are gone, it's just vibes and values now. π
okay that's the whole entire page, and we ate. π the source and version on this bad boy are perl v5.32.1 and it's dated 2021-08-15, straight out of Bio::A...agTree(3pm). go forth and annotate, bestie, you got this π
β¨π
π¦ where this page comes from
- debian bookworm: libbio-perl-perl 1.7.8-1 Β· Perl
- debian trixie: libbio-perl-perl 1.7.8-1 Β· Perl
- ubuntu jammy: libbio-perl-perl 1.7.8-1 Β· Perl
- ubuntu noble: libbio-perl-perl 1.7.8-1 Β· Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms