Bio::SeqIO::bsml(3pm)
π Bio::SeqIO::bsml β BSML sequence input/output stream π
okay bestie, gather round, because this is Bio::SeqIO::bsml from the User Contributed Perl Documentation, and it's literally your plug for reading and writing BSML. π¦
β¨ NAME β¨
Bio::SeqIO::bsml β BSML sequence input/output stream. that's the whole vibe. π
πΈ SYNOPSIS πΈ
ngl, the smart move here is not to use this object directly β go through the SeqIO handler system like a main character. To read a BSML file:
$stream = Bio::SeqIO->new( -file => $filename, -format => 'bsml');
while ( my $bioSeqObj = $stream->next_seq() ) {
# do something with $bioSeqObj
}
To write a Seq object to the current file handle in BSML XML format:
$stream->write_seq( -seq => $seqObj);
If instead you would like a XML::DOM object containing the BSML, use:
my $newXmlObject = $stream->to_bsml( -seq => $seqObj);
periodt. π
π DESCRIPTION π
This object can transform Bio::Seq objects to and from BSML (XML) flatfiles. that's it, that's the whole job, and it does it beautifully. π
π«Ά 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. (the more detail the better, bestie β give them the receipts π§Ύ)
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 the web:
https://github.com/bioperl/bioperl-live/issues
Things Still to Do
okay so here's the honest to-do list, no gatekeeping:
- The module now uses the new
Collection.pmsystem. However, Annotations associated with aFeatureobject still seem to use the old system, so parsing with the old methods are included.. - Generate
Seqobjects with no sequence data but an assigned length. This appears to be an issue withBio::Seq. It is possible (and reasonable) to make a BSML document with features but no sequence data. - Support
"Seq-data-import". Do not know how commonly this is used. - Some features are awaiting implementation in later versions of BSML. These include:
- Nested feature support
- Complex feature (ie joins)
- Unambiguity in strand (ie
-1,0,1, not just'complement') - More friendly dblink structures
Location.pm(orRangeI::union?) appears to have a bug when'expand'is used.- More intelligent hunting for sequence and feature titles? It is not terribly clear where the most appropriate field is located, better grepping (eg looking for a reasonable count for spaces and numbers) may allow for titles better than
"AE008041".
π AUTHOR - Charles Tilford π
Bristol-Myers Squibb Bioinformatics
Email tilfordc@bms.com
I have developed the BSML specific code for this package, but have used code from other SeqIO packages for much of the nuts-and-bolts. In particular I have used code from the embl.pm module either directly or as a framework for many of the subroutines that are common to SeqIO modules.
π METHODS π
next_seq
Title : next_seq
Usage : my $bioSeqObj = $stream->next_seq
Function: Retrieves the next sequence from a SeqIO::bsml stream.
Returns : A reference to a Bio::Seq::RichSeq object
Args :
no args, no drama. just hand it the stream and it hands you back the next sequence. π«
to_bsml
Title : to_bsml
Usage : my $domDoc = $obj->to_bsml(@args)
Function: Generates an XML structure for one or more Bio::Seq objects.
If $seqref is an array ref, the XML tree generated will include
all the sequences in the array.
Returns : A reference to the XML DOM::Document object generated / modified
Args : Argument array in form of -key => val. Recognized keys:
Here's the arg menu, bestie β pick your toppings:
-seqβ ABio::Seqreference, or an array reference of many of them-xmldocβ Specifies an existing XML DOM document to add the sequences to. If included, then only data (no page formatting) will be added. If not, a newXML::DOM::Documentwill be made, and will be populated with both<Sequence>data, as well as<Page>display elements.-nodispβ Do not generate<Display>elements, or any children thereof, even if-xmldocis not set.-skipfeatβ If set to'all', all<Feature>s will be skipped. If it is a hash reference, any<Feature>with a class matching a key in the hash will be skipped - for example, to skip'source'and'score'features, use:
-skipfeat => { source => 'Y', score => 'Y' }
-skiptagsβ As above: if set to'all', no tags are included, and if a hash reference, those specific tags will be ignored.
Skipping some or all tags and features can result in noticeable speed improvements. (speedrun strats π₯)
-nodataβ If true, then<Seq-data>will not be included. This may be useful if you just want annotations and do not care about the raw ACTG information.-returnβ Default is'xml', which will return a reference to the BSML XML object. If set to'seq'will return an array ref of the<Sequence>objects added (rather than the whole XML object)-closeβ Early BSML browsers will crash if an element could have children but does not, and is closed as an empty element e.g.<Styles/>. If-closeis true, then such tags are given a comment child to explicitly close them e.g.<Styles><!-- --></Styles>. This is default true, set to"0"if you do not want this behavior.
π¨ heads up bestie: early BSML browsers crashing on empty elements is the reason-closeexists, and it defaults to true. set it to"0"only if you know you don't want that behavior.
Examples :
my $domObj = $stream->to_bsml( -seq => \@fourCoolSequenceObjects,
-skipfeat => { source => 1 },
);
# Or add sequences to an existing BSML document:
$stream->to_bsml(-seq => \@fourCoolSequenceObjects,
-skipfeat => { source => 1 },
-xmldoc => $myBsmlDocumentInProgress, );
write_seq
Title : write_seq
Usage : $obj->write_seq(@args)
Function: Prints out an XML structure for one or more Bio::Seq objects.
If $seqref is an array ref, the XML tree generated will include
all the sequences in the array. This method is fairly simple,
most of the processing is performed within to_bsml.
Returns : A reference to the XML object generated / modified
Args : Argument array. Recognized keys:
the keys, laid out for you:
-seqβ ABio::Seqreference, or an array reference of many of them
Alternatively, the method may be called simply as...
$obj->write_seq( $bioseq )
... if only a single argument is passed, it is assumed that it is the sequence object (can also be an array ref of many Seq objects )
-printmimeβ If true prints"Content-type: $mimetype\n\n"at top of document, where$mimetypeis the value designated by this key. For generic XML usetext/xml, for BSML usetext/x-bsml-returnβ This option will be suppressed, since the nature of this method is to print out the XML document. If you wish to retrieve the<Sequence>objects generated, use theto_bsmlmethod directly.
π οΈ INTERNAL METHODS π οΈ
Okay bestie, these are the internal methods β the ones doing the behind-the-scenes work. You probably shouldn't be calling them directly, but here's the tea anyway. β
π§ _parse_location
- Title:
_parse_location - Usage:
$obj->_parse_location($xmlDocument, $parentElem, $SeqFeatureObj) - Function: Adds
<Interval-loc>and<Site-loc>children to<$parentElem>based on locations / sublocations found in$SeqFeatureObj. If sublocations exist, the original location will be ignored. periodt. - Returns: An array ref containing the elements added to the parent. These will have already been added to
<$parentElem>. β¨ - Args:
- 0 β The
DOM::Documentbeing modified - 1 β The
DOM::Elementparent that you want to add to - 2 β Reference to the
Bio::SeqFeaturebeing analyzed
- 0 β The
π§ _parse_bsml_feature
- Title:
_parse_bsml_feature - Usage:
$obj->_parse_bsml_feature($xmlFeature ) - Function: Will examine the
<Feature>element provided by$xmlFeatureand return a generic seq feature. - Returns:
Bio::SeqFeature::Generic - Args:
- 0 β
XML::DOM::Element<Feature>being analyzed.
- 0 β
π§ _parse_bsml_location
- Title:
_parse_bsml_location - Usage:
$obj->_parse_bsml_feature( $intOrSiteLoc, $gsfObject ) - Function: Will examine the
<Interval-loc>or<Site-loc>element provided - Returns:
Bio::SeqFeature::Generic - Args:
- 0 β
XML::DOM::Element<Interval/Site-loc>being analyzed. - 1 β Optional
SeqFeature::Genericto use
- 0 β
π§ _parse_reference
- Title:
_parse_reference - Usage:
$obj->_parse_reference(@args ) - Function: Makes a new
<Reference>object from a::Reference, which is then stored in an array provide by-refs. It will be appended to the XML tree later. - Returns: (nothing listed, bestie β it's a mystery π)
- Args: Argument array. Recognized keys:
-xmlβ TheDOM::Documentbeing modified-refobjβ TheAnnotation::ReferenceObject-refsβ An array reference to hold the new<Reference>DOM object-idβ Optional. If the XML id for the 'calling' element is provided, it will be placed in any<Reference>refs attribute.
π§ _parse_annotation
- Title:
_parse_annotation - Usage:
$obj->_parse_annotation(@args ) - Function: Will examine any Annotations found in
-obj. Data found in::Commentand::DBLinkstructures, as well as Annotation description fields are stored in-descfor later generation of<Attribute>s.<Reference>objects are generated from::References, and are stored in-refsβ these will be appended to the XML tree later. - Returns: (nothing listed again, iconic π)
- Args: Argument array. Recognized keys:
-xmlβ TheDOM::Documentbeing modified-objβ Reference to the Bio object being analyzed-descrβ An array reference for holding description text items-refsβ An array reference to hold<Reference>DOM objects-idβ Optional. If the XML id for the 'calling' element is provided, it will be placed in any<Reference>refs attribute.
π§ _parse_annotation_old
- Title:
_parse_annotation_old - Usage:
$obj->_parse_annotation_old(@args) - Function: As above, but for the old Annotation system. Apparently needed because Features are still using the old-style annotations? iykyk
- Returns: (still nothing, keep scrolling π )
- Args: Argument array. Recognized keys:
-xmlβ TheDOM::Documentbeing modified-objβ Reference to the Bio object being analyzed-descrβ An array reference for holding description text items-refsβ An array reference to hold<Reference>DOM objects-idβ Optional. If the XML id for the 'calling' element is provided, it will be placed in any<Reference>refs attribute.
π§ _add_page
- Title:
_add_page - Usage:
$obj->_add_page($xmlDocument, $xmlSequenceObject) - Function: Adds a simple
<Page>and<View>structure for a<Sequence> - Returns: a reference to the newly created
<Page> - Args:
- 0 β The
DOM::Documentbeing modified - 1 β Reference to the
<Sequence>object
- 0 β The
π§ _addel
- Title:
_addel - Usage:
$obj->_addel($parentElem, 'ChildName',
{ anAttr => 'someValue', anotherAttr => 'aValue',})
- Function: Add an element with attribute values to a DOM tree
- Returns: a reference to the newly added element
- Args:
- 0 β The
DOM::Elementparent that you want to add to - 1 β The name of the new child element
- 2 β Optional hash reference containing attribute name => attribute value assignments
- 0 β The
π§ _show_dna
- Title:
_show_dna - Usage:
$obj->_show_dna($newval) - Function: (cut-and-pasted directly from
embl.pm) β yes, the original says that, we're just the messengers π«Ά - Returns: value of
_show_dna - Args:
newvalue(optional)
π§ _initialize
- Title:
_initialize - Usage:
$dom = $obj->_initialize(@args) - Function: Coppied from
embl.pm, and augmented with initialization of the XML DOM tree - Returns: (nothing listed, the suspense is real π)
- Args:
-file => the XML file to be parsed
π§ _parseparams
- Title:
_parseparams - Usage:
my $paramHash = $obj->_parseparams(@args) - Function: Borrowed from
Bio::Parse.pm, who borrowed it fromCGI.pmβ Lincoln Stein -> Richard Resnick -> here - Returns: A hash reference of the parameter keys (uppercase) pointing to their values.
- Args: An array of key, value pairs. Easiest to pass values as:
-key1 => value1, -key2 => value2, etcLeading-are removed.
π§ _parse_xml
- Title:
_parse_xml - Usage:
$dom = $obj->_parse_xml($filename) - Function: uses
XML::DOMto construct a DOM tree from the BSML document - Returns: a reference to the parsed DOM tree
- Args:
- 0 β Path to the XML file needing to be parsed
π§ͺ TESTING SCRIPT π§ͺ
Okay so here's a script that lowkey stress-tests the conversion process. You need a file in whatever format you wanna test. The script takes it, converts it to BSML, dumps that in /tmp/bsmltemp, reads it back into a fresh SeqIO stream, and writes it back out in the original format. Then you can diff that second file against your original and see exactly where data got lost or corrupted. Don't forget to set $readfile and $readformat β no cap. π
use Bio::SeqIO;
# Tests preservation of details during round-trip conversion:
# $readformat -> BSML -> $readformat
my $tempspot = "/tmp/bsmltemp"; # temp folder to hold generated files
my $readfile = "rps4y.embl"; # The name of the file you want to test
my $readformat = "embl"; # The format of the file being tested
system "mkdir $tempspot" unless (-d $tempspot);
# Make Seq object from the $readfile
my $biostream = Bio::SeqIO->new( -file => "$readfile" );
my $seq = $biostream->next_seq();
# Write BSML from SeqObject
my $bsmlout = Bio::SeqIO->new(-format => 'bsml',
-file => ">$tempspot/out.bsml");
warn "\nBSML written to $tempspot/out.bsml\n";
$bsmlout->write_seq($seq);
# Need to kill object for following code to work... Why is this so?
$bsmlout = "";
# Make Seq object from BSML
my $bsmlin = Bio::SeqIO->new(-file => "$tempspot/out.bsml",
-format => 'bsml');
my $seq2 = $bsmlin->next_seq();
# Write format back from Seq Object
my $genout = Bio::SeqIO->new(-format => $readformat,
-file => ">$tempspot/out.$readformat");
$genout->write_seq($seq2);
warn "$readformat written to $tempspot/out.$readformat\n";
# BEING LOST:
# Join information (not possible in BSML 2.2)
# Sequence type (??)
And that's the whole vibe, bestie. This page came from perl v5.32.1 and was stamped 2021-08-15 β iconic, honestly. π
π¦ 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