NAME
Bio::SeqIO::bsml - BSML sequence input/output stream
SYNOPSIS
It is probably best not to use this object directly, but rather go through the SeqIO handler system. 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);
DESCRIPTION
This object can transform Bio::Seq objects to and from BSML (XML) flatfiles.
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 the web:
https://github.com/bioperl/bioperl-live/issues
Things Still to Do
- •
-
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 [email protected]
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_seqUsage : my $bioSeqObj = $stream->next_seqFunction: Retrieves the next sequence from a SeqIO::bsml stream.Returns : A reference to a Bio::Seq::RichSeq objectArgs :
to_bsml
Title : to_bsmlUsage : 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 includeall the sequences in the array.Returns : A reference to the XML DOM::Document object generated / modifiedArgs : Argument array in form of -key => val. Recognized keys:-seq A Bio::Seq reference, or an array reference of many of them-xmldoc Specifies an existing XML DOM document to add the sequencesto. If included, then only data (no page formatting) willbe 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 childrenthereof, even if -xmldoc is not set.-skipfeat If set to 'all', all <Feature>s will be skipped. If it isa hash reference, any <Feature> with a class matching a keyin 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 ahash reference, those specific tags will be ignored.Skipping some or all tags and features can result innoticeable speed improvements.-nodata If true, then <Seq-data> will not be included. This may beuseful if you just want annotations and do not care aboutthe raw ACTG information.-return Default is 'xml', which will return a reference to the BSMLXML 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* havechildren but does not, and is closed as an empty elemente.g. <Styles/>. If -close is true, then such tags are givena comment child to explicitly close them e.g. <Styles><!----></Styles>. This is default true, set to "0" if you donot want this 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_seqUsage : $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 includeall 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 / modifiedArgs : Argument array. Recognized keys:-seq A Bio::Seq reference, or an array reference of many of themAlternatively, the method may be called simply as...$obj->write_seq( $bioseq )... if only a single argument is passed, it is assumed thatit is the sequence object (can also be an array ref ofmany Seq objects )-printmime If true prints "Content-type: $mimetype\n\n" at top ofdocument, where $mimetype is the value designated by thiskey. For generic XML use text/xml, for BSML use text/x-bsml-return This option will be suppressed, since the nature of thismethod is to print out the XML document. If you wish toretrieve the <Sequence> objects generated, use the to_bsmlmethod directly.
INTERNAL METHODS
The following methods are used for internal processing, and should probably not be accessed by the user.
_parse_location
Title : _parse_locationUsage : $obj->_parse_location($xmlDocument, $parentElem, $SeqFeatureObj)Function: Adds <Interval-loc> and <Site-loc> children to <$parentElem> basedon locations / sublocations found in $SeqFeatureObj. Ifsublocations exist, the original location will be ignored.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 modified1 The DOM::Element parent that you want to add to2 Reference to the Bio::SeqFeature being analyzed
_parse_bsml_feature
Title : _parse_bsml_featureUsage : $obj->_parse_bsml_feature($xmlFeature )Function: Will examine the <Feature> element provided by $xmlFeature andreturn a generic seq feature.Returns : Bio::SeqFeature::GenericArgs : 0 XML::DOM::Element <Feature> being analyzed.
_parse_bsml_location
Title : _parse_bsml_locationUsage : $obj->_parse_bsml_feature( $intOrSiteLoc, $gsfObject )Function: Will examine the <Interval-loc> or <Site-loc> element providedReturns : Bio::SeqFeature::GenericArgs : 0 XML::DOM::Element <Interval/Site-loc> being analyzed.1 Optional SeqFeature::Generic to use
_parse_reference
Title : _parse_referenceUsage : $obj->_parse_reference(@args )Function: Makes a new <Reference> object from a ::Reference, which isthen stored in an array provide by -refs. It will beappended to the XML tree later.Returns :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 isprovided, it will be placed in any <Reference> refsattribute.
_parse_annotation
Title : _parse_annotationUsage : $obj->_parse_annotation(@args )Function: Will examine any Annotations found in -obj. Data found in::Comment and ::DBLink structures, as well as Annotationdescription fields are stored in -desc for latergeneration of <Attribute>s. <Reference> objects are generatedfrom ::References, and are stored in -refs - these willbe appended to the XML tree later.Returns :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 isprovided, it will be placed in any <Reference> refsattribute.
_parse_annotation_old
Title : _parse_annotation_oldUsage : $obj->_parse_annotation_old(@args)Function: As above, but for the old Annotation system.Apparently needed because Features are still using the old-styleannotations?Returns :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 isprovided, it will be placed in any <Reference> refsattribute.
_add_page
Title : _add_pageUsage : $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 modified1 Reference to the <Sequence> object
_addel
Title : _addelUsage : $obj->_addel($parentElem, 'ChildName',{ anAttr => 'someValue', anotherAttr => 'aValue',})Function: Add an element with attribute values to a DOM treeReturns : a reference to the newly added elementArgs : 0 The DOM::Element parent that you want to add to1 The name of the new child element2 Optional hash reference containingattribute name => attribute value assignments
_show_dna
Title : _show_dnaUsage : $obj->_show_dna($newval)Function: (cut-and-pasted directly from embl.pm)Returns : value of _show_dnaArgs : newvalue (optional)
_initialize
Title : _initializeUsage : $dom = $obj->_initialize(@args)Function: Coppied from embl.pm, and augmented with initialization of theXML DOM treeReturns :Args : -file => the XML file to be parsed
_parseparams
Title : _parseparamsUsage : my $paramHash = $obj->_parseparams(@args)Function: Borrowed from Bio::Parse.pm, who borrowed it from CGI.pmLincoln Stein -> Richard Resnick -> hereReturns : A hash reference of the parameter keys (uppercase) pointing totheir values.Args : An array of key, value pairs. Easiest to pass values as:-key1 => value1, -key2 => value2, etcLeading "-" are removed.
_parse_xml
Title : _parse_xmlUsage : $dom = $obj->_parse_xml($filename)Function: uses XML::DOM to construct a DOM tree from the BSML documentReturns : a reference to the parsed DOM treeArgs : 0 Path to the XML file needing to be parsed
TESTING SCRIPT
The following script may be used to test the conversion process. You will need a file of the format you wish to test. The script will convert the file to BSML, store it in /tmp/bsmltemp, read that file into a new SeqIO stream, and write it back as the original format. Comparison of this second file to the original input file will allow you to track where data may be lost or corrupted. Note that you will need to specify $readfile and $readformat.
use Bio::SeqIO;# Tests preservation of details during round-trip conversion:# $readformat -> BSML -> $readformatmy $tempspot = "/tmp/bsmltemp"; # temp folder to hold generated filesmy $readfile = "rps4y.embl"; # The name of the file you want to testmy $readformat = "embl"; # The format of the file being testedsystem "mkdir $tempspot" unless (-d $tempspot);# Make Seq object from the $readfilemy $biostream = Bio::SeqIO->new( -file => "$readfile" );my $seq = $biostream->next_seq();# Write BSML from SeqObjectmy $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 BSMLmy $bsmlin = Bio::SeqIO->new(-file => "$tempspot/out.bsml",-format => 'bsml');my $seq2 = $bsmlin->next_seq();# Write format back from Seq Objectmy $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 (??)