Bio::SeqIO::bsml(3pm)

πŸ“¦
version 1.7.8 Β· 3 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble

πŸ’– 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.pm system. However, Annotations associated with a Feature object still seem to use the old system, so parsing with the old methods are included..
  • Generate Seq objects with no sequence data but an assigned length. This appears to be an issue with Bio::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 (or RangeI::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 β€” A Bio::Seq reference, 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 new XML::DOM::Document will 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 -xmldoc is 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 -close is 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 -close exists, 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 β€” A Bio::Seq reference, 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 $mimetype is the value designated by this key. For generic XML use text/xml, for BSML use text/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 the to_bsml method 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::Document being modified
    • 1 β€” The DOM::Element parent that you want to add to
    • 2 β€” Reference to the Bio::SeqFeature being analyzed

🧚 _parse_bsml_feature

  • Title: _parse_bsml_feature
  • Usage: $obj->_parse_bsml_feature($xmlFeature )
  • Function: Will examine the <Feature> element provided by $xmlFeature and return a generic seq feature.
  • Returns: Bio::SeqFeature::Generic
  • Args:
    • 0 β€” XML::DOM::Element <Feature> being analyzed.

🧚 _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::Generic to use

🧚 _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 β€” The DOM::Document being modified
    • -refobj β€” The Annotation::Reference Object
    • -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 ::Comment and ::DBLink structures, as well as Annotation description fields are stored in -desc for 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 β€” The DOM::Document being 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 β€” The DOM::Document being 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::Document being modified
    • 1 β€” Reference to the <Sequence> object

🧚 _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::Element parent that you want to add to
    • 1 β€” The name of the new child element
    • 2 β€” Optional hash reference containing attribute name => attribute value assignments

🧚 _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 from CGI.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, etc Leading - are removed.

🧚 _parse_xml

  • Title: _parse_xml
  • Usage: $dom = $obj->_parse_xml($filename)
  • Function: uses XML::DOM to 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