NAME
Bio::Assembly::Tools::ContigSpectrum - create and manipulate contig spectra
SYNOPSIS
# Simple contig spectrum creationmy $csp1 = Bio::Assembly::Tools::ContigSpectrum->new(-id => 'csp1',-spectrum => { 1 => 10,2 => 2,3 => 1 } );# ...or another way to create a simple contig spectrummy $csp2 = Bio::Assembly::Tools::ContigSpectrum->new;$csp2->id('csp2');$csp2->spectrum({ 1 => 20, 2 => 1, 4 => 1 });# Get some informationprint "This is contig spectrum ".$csp->id."\n";print "It contains ".$csp->nof_seq." sequences\n";print "The largest contig has ".$csp->max_size." sequences\n";print "The spectrum is: ".$csp->to_string($csp->spectrum)."\n";# Let's add the contig spectramy $summed_csp = Bio::Assembly::Tools::ContigSpectrum->new;$summed_csp->add($csp1);$summed_csp->add($csp2);print "The summed contig spectrum is ".$summed_csp->to_string."\n";# Make an averagemy $avg_csp = Bio::Assembly::Tools::ContigSpectrum->new;$avg_csp = $avg_csp->average([$csp1, $csp2]);print "The average contig spectrum is ".$avg_csp->to_string."\n";# Get a contig spectrum from an assemblymy $from_assembly = Bio::Assembly::Tools::ContigSpectrum->new(-assembly => $assembly_object,-eff_asm_params => 1);print "The contig spectrum from assembly is ".$from_assembly->to_string."\n";# Report advanced information (possible because eff_asm_params = 1)print "Average sequence length: ".$from_assembly->avg_seq_len." bp\n";print "Minimum overlap length: ".$from_assembly->min_overlap." bp\n";print "Average overlap length: ".$from_assembly->avg_overlap." bp\n";print "Minimum overlap match: ".$from_assembly->min_identity." %\n";print "Average overlap match: ".$from_assembly->avg_identity." %\n";# Assuming the assembly object contains sequences from several different# metagenomes, we have a mixed contig spectrum from which a cross contig# spectrum and dissolved contig spectra can be obtainedmy $mixed_csp = $from_assembly;# Calculate a dissolved contig spectrummy $meta1_dissolved = Bio::Assembly::Tools::ContigSpectrum->new(-dissolve => [$mixed_csp, 'metagenome1'] );my $meta2_dissolved = Bio::Assembly::Tools::ContigSpectrum->new(-dissolve => [$mixed_csp, 'metagenome2'] );print "The dissolved contig spectra are:\n".$meta1_dissolved->to_string."\n".$meta2_dissolved->to_string."\n";# Determine a cross contig spectrummy $cross_csp = Bio::Assembly::Tools::ContigSpectrum->new(-cross => $mixed_csp );print "The cross contig spectrum is ".$cross_csp->to_string."\n";# Score a contig spectrum (the more abundant the contigs and the larger their# size, the larger the score)my $csp_score = $csp->score( $csp->nof_seq );
DESCRIPTION
The Bio::Assembly::Tools::ContigSpectrum Perl module enables to manually create contig spectra, import them from assemblies, manipulate them, transform between different types of contig spectra and output them.
Bio::Assembly::Tools::ContigSpectrum is a module to create, manipulate and output contig spectra, assembly-derived data used in metagenomics (community genomics) for diversity estimation.
Background
A contig spectrum is the count of the number of contigs of different size in an assembly. For example, the contig spectrum [100 5 1 0 0 ...] means that there were 100 singlets (1-contigs), 5 contigs of 2 sequences (2-contigs), 1 contig of 3 sequences (3-contig) and no larger contigs.
An assembly can be produced from a mixture of sequences from different metagenomes. The contig obtained from this assembly is a mixed contig spectrum. The contribution of each metagenome in this mixed contig spectrum can be obtained by determining a dissolved contig spectrum.
Finally, based on a mixed contig spectrum, a cross contig spectrum can be determined. In a cross contig spectrum, only contigs containing sequences from different metagenomes are kept; "pure" contigs are excluded. Additionally, the total number of singletons (1-contigs) from each region that assembles with any fragments from other regions is the number of 1-contigs in the cross contig spectrum.
Implementation
The simplest representation of a contig spectrum is as a hash representation where the key is the contig size (number of sequences making up the contig) and the value the number of contigs of this size.
In fact, it is useful to have more information associated with the contig spectrum, hence the Bio::Assembly::Tools::ContigSpectrum module implements an object containing a contig spectrum hash and additional information. The get/set methods to access them are:
id contig spectrum IDnof_rep number of repetitions (assemblies) usedmax_size size of (number of sequences in) the largest contigspectrum hash representation of a contig spectrumnof_seq number of sequencesavg_seq_len average sequence lengtheff_asm_params reports effective assembly parametersnof_overlaps number of overlaps (needs eff_asm_params)min_overlap minimum overlap length in a contig (needs eff_asm_params)min_identity minimum sequence identity percentage (needs eff_asm_params)avg_overlap average overlap length (needs eff_asm_params)avg_identity average overlap identity percentage (needs eff_asm_params)Operations on the contig spectra:to_string create a string representation of the spectrumspectrum import a hash contig spectrumassembly determine a contig spectrum from an assembly, contig or singletdissolve calculate a dissolved contig spectrum (depends on assembly)cross produce a cross contig spectrum (depends on assembly)add add a contig spectrum to an existing oneaverage make an average of several contig spectrascore score a contig spectrum: the higher the number of contigsand the larger their size, the higher the score.
When using operations that rely on knowing "where" (from what metagenomes) a sequence came from (i.e. when creating a dissolved or cross contig spectrum), make sure that the sequences used for the assembly have a name header, e.g. >metagenome1|seq1, >metagenome2|seq1, ...
Note: The following operations require the "Graph::Undirected" module:
eff_asm_params, cross, dissolve
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 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 email or the web:
[email protected]https://github.com/bioperl/bioperl-live/issues
AUTHOR - Florent E Angly
Email florent_dot_angly_at_gmail_dot_com
APPENDIX
The rest of the documentation details each of the object methods. Internal methods are usually preceded with a "_".
new
Title : newUsage : my $csp = Bio::Assembly::Tools::ContigSpectrum->new();ormy $csp = Bio::Assembly::Tools::ContigSpectrum->new(-id => 'some_name',-spectrum => { 1 => 90 , 2 => 3 , 4 => 1 },);ormy $csp = Bio::Assembly::Tools::ContigSpectrum->new(-assembly => $assembly_obj);Function: create a new contig spectrum objectReturns : reference to a contig spectrum objectArgs : none
id
Title : idUsage : $csp->idFunction: get/set contig spectrum idReturns : stringArgs : string [optional]
nof_seq
Title : nof_seqUsage : $csp->nof_seqFunction: get/set the number of sequences making up the contig spectrumReturns : integerArgs : integer [optional]
nof_rep
Title : nof_repUsage : $csp->nof_repFunction: Get/Set the number of repetitions (assemblies) used to create thecontig spectrumReturns : integerArgs : integer [optional]
max_size
Title : max_sizeUsage : $csp->max_sizeFunction: get/set the size of (number of sequences in) the largest contigReturns : integerArgs : integer [optional]
nof_overlaps
Title : nof_overlapsUsage : $csp->nof_overlapsFunction: Get/Set the number of overlaps in the assembly.Returns : integerArgs : integer [optional]
min_overlap
Title : min_overlapUsage : $csp->min_overlapFunction: get/set the assembly minimum overlap lengthReturns : integerArgs : integer [optional]
avg_overlap
Title : avg_overlapUsage : $csp->avg_overlapFunction: get/set the assembly average overlap lengthReturns : decimalArgs : decimal [optional]
min_identity
Title : min_identityUsage : $csp->min_identityFunction: get/set the assembly minimum overlap identity percentReturns : 0 < decimal < 100Args : 0 < decimal < 100 [optional]
avg_identity
Title : avg_identityUsage : $csp->avg_identityFunction: get/set the assembly average overlap identity percentReturns : 0 < decimal < 100Args : 0 < decimal < 100 [optional]
avg_seq_len
Title : avg_seq_lenUsage : $csp->avg_seq_lenFunction: get/set the assembly average sequence lengthReturns : avg_seq_lenArgs : real [optional]
eff_asm_params
Title : eff_asm_paramsUsage : $csp->eff_asm_params(1)Function: Get/set the effective assembly parameters option. It defines if theeffective assembly parameters should be determined when a contigspectrum based or derived from an assembly is calculated. Theeffective assembly parameters include avg_seq_length, nof_overlaps,min_overlap, avg_overlap, min_identity and avg_identity.1 = get them, 0 = don't.Returns : integerArgs : integer [optional]
spectrum
Title : spectrumUsage : my $spectrum = $csp->spectrum({1=>10, 2=>2, 3=>1});Function: Get the current contig spectrum represented as a hash / Update acontig spectrum object based on a contig spectrum represented as ahashThe hash representation of a contig spectrum is as following:key -> contig size (in number of sequences)value -> number of contigs of this sizeReturns : contig spectrum as a hash referenceArgs : contig spectrum as a hash reference [optional]
assembly
Title : assemblyUsage : my @obj_list = $csp->assembly();Function: get/set the contig spectrum object by adding an assembly, contig orsinglet object to it, or get the list of objects associated with itReturns : arrayref of assembly, contig and singlet objects used in the contigspectrum object (Bio::Assembly::Scaffold, Bio::Assembly::Contig andBio::Assembly::Singlet objects)Args : Bio::Assembly::Scaffold, Contig or Singlet object
drop_assembly
Title : drop_assemblyUsage : $csp->drop_assembly();Function: Remove all assembly objects associated with a contig spectrum.Assembly objects can take a lot of memory, which can be freed bycalling this method. Don't call this method if you need the assemblyobject later on, for example for creating a dissolved or crosscontig spectrum.Returns : 1 for successArgs : none
dissolve
Title : dissolveUsage : $dissolved_csp->dissolve($mixed_csp, $seq_header);Function: Dissolve a mixed contig spectrum for the set of sequences thatcontain the specified header, i.e. determine the contribution ofthese sequences to the mixed contig spectrum. The mixed contigspectrum object must have one or several assembly object(s). Inaddition, min_overlap, min_identity and eff_asm_params are takenfrom the mixed contig spectrum, unless they are specified manuallyfor the dissolved contig spectrum. The dissolved contigs underlyingthe contig spectrum can be obtained by calling the assembly() method.Returns : 1 for successArgs : Bio::Assembly::Tools::ContigSpectrum referencesequence header string
cross
Title : crossUsage : $cross_csp->cross($mixed_csp);Function: Calculate a cross contig_spectrum based on a mixed contig_spectrum.The underlying cross-contigs themselves can be obtained by callingthe assembly() method.Returns : 1 for successArgs : Bio::Assembly::Tools::ContigSpectrum reference
to_string
Title : to_stringUsage : my $csp_string = $csp->to_string;Function: Convert the contig spectrum into a string (easy to print!!).Returns : stringArgs : element separator (integer) [optional]1 -> space-separated2 -> tab-separated3 -> newline-separated
add
Title : addUsage : $csp->add($additional_csp);Function: Add a contig spectrum to an existing one: sums the spectra, updatethe number of sequences, number of repetitions, ...Returns : 1 for successArgs : Bio::Assembly::Tools::ContigSpectrum object
average
Title : averageUsage : my $avg_csp = $csp->average([$csp1, $csp2, $csp3]);Function: Average one contig spectrum or the sum of several contig spectra bythe number of repetitionsReturns : Bio::Assembly::Tools::ContigSpectrumArgs : Bio::Assembly::Tools::ContigSpectrum array referenceeff_asm_params
score
Title : scoreUsage : my $score = $csp->score();Function: Score a contig spectrum (or cross-contig spectrum) such that thehigher the number of contigs (or cross-contigs) and the larger theirsize, the higher the score.Let n : total number of sequencesc_q : number of contigs of size qq : number of sequence in a contigWe define: score = n/(n-1) * (X - 1/n)where X = sum ( c_q * q^2 ) / n**2The score ranges from 0 (singlets only) to 1 (a single large contig)It is possible to specify a value for the number of sequences toassume in the contig spectrum.Returns : contig score, or undef if there were no sequences in the contig spectrumArgs : number of total sequences to assume [optional]
_naive_assembler
Title : _naive_assemblerUsage :Function: Reassemble the specified sequences only based on their position inthe contig. This naive assembly only verifies that the minimumoverlap length and percentage identity are respected. No actualalignment is doneReturns : arrayref of contigs and singletsArgs : Bio::Assembly::Contigarray reference of sequence IDs to use [optional]minimum overlap length (integer) [optional]minimum percentage identity (integer) [optional]
_create_subcontig
Title : _create_subcontigUsage :Function: Create a subcontig from another contigReturns : Bio::Assembly::Contig objectArgs : Bio::Assembly::Contigarrayref of the IDs of the reads to includes in the subcontigID to give to the subcontig
_obj_copy
Title : _obj_copyUsage :Function: Copy (most of) an object, and optionally truncate itReturns : another a Bio::LocatableSeq, Bio::Seq::PrimaryQual, orBio::SeqFeature::Generic objectArgs : a Bio::LocatableSeq, Bio::Seq::PrimaryQual, orBio::SeqFeature::Generic objecta start positionan end position
_new_from_assembly
Title : _new_from_assemblyUsage :Function: Creates a new contig spectrum object based solely on the result ofan assembly, contig or singletReturns : Bio::Assembly::Tools::ContigSpectrum objectArgs : Bio::Assembly::Scaffold, Contig or Singlet object
_new_dissolved_csp
Title : _new_dissolved_cspUsage :Function: create a dissolved contig spectrum objectReturns : dissolved contig spectrumArgs : mixed contig spectrumheader of sequences to keep in this contig spectrum
_dissolve_contig
Title : _dissolve_contigUsage :Function: dissolve a contigReturns : arrayref of contigs and singletsArgs : mixed contig spectrumheader of sequences to keep in this contig spectrumminimum overlapminimum identity
_new_cross_csp
Title : _new_cross_cspUsage :Function: create a cross contig spectrum objectReturns : cross-contig spectrumArgs : mixed contig spectrum
_cross_contig
Title : _cross_contigUsage :Function: calculate cross contigsReturns : arrayref of cross-contigsnumber of cross-singletsArgs : contigminimum overlapminimum identity
_seq_origin
Title : _seq_originUsage :Function: determines where a sequence comes from using its header. For examplethe origin of the sequence 'metagenome1|gi|9626988|ref|NC_001508.1|'is 'metagenome1'Returns : originArgs : sequence ID
_import_assembly
Title : _import_assemblyUsage : $csp->_import_assembly($assemblyobj);Function: Update a contig spectrum object based on an assembly, contig orsinglet objectReturns : 1 for successArgs : Bio::Assembly::Scaffold, Contig or Singlet object
_import_spectrum
Title : _import_spectrumUsage : $csp->_import_spectrum({ 1 => 90 , 2 => 3 , 4 => 1 })Function: update a contig spectrum object based on a contig spectrumrepresented as a hash (key: contig size, value: number of contigs ofthis size)Returns : 1 for successArgs : contig spectrum as a hash reference
_import_dissolved_csp
Title : _import_dissolved_cspUsage : $csp->_import_dissolved_csp($mixed_csp, $seq_header);Function: Update a contig spectrum object by dissolving a mixed contigspectrum based on the header of the sequencesReturns : 1 for successArgs : Bio::Assembly::Tools::ContigSpectrumsequence header string
_import_cross_csp
Title : _import_cross_cspUsage : $csp->_import_cross_csp($mixed_csp);Function: Update a contig spectrum object by calculating the cross contigspectrum based on a mixed contig spectrumReturns : 1 for successArgs : Bio::Assembly::Tools::ContigSpectrum
_get_contig_like
Title : _get_contig_likeUsage : my @contig_like_objs = $csp->_get_contig_like($assembly_obj);Function: Get contigs and singlets from an assembly, contig or singletReturns : array of Bio::Assembly::Contig and Singlet objectsArgs : a Bio::Assembly::Scaffold, Contig or singlet object
_get_assembly_seq_stats
Title : _get_assembly_seq_statsUsage : my $seqlength = $csp->_get_assembly_seq_stats($assemblyobj);Function: Get sequence statistics from an assembly:average sequence length, number of sequencesReturns : average sequence length (decimal)number of sequences (integer)Args : Bio::Assembly::Scaffold, Contig or singlet objecthash reference with the IDs of the sequences to consider [optional]
_get_contig_seq_stats
Title : _get_contig_seq_statsUsage : my $seqlength = $csp->_get_contig_seq_stats($contigobj);Function: Get sequence statistics from a contig:average sequence length, number of sequencesReturns : average sequence length (decimal)number of sequences (integer)Args : contig object referencehash reference with the IDs of the sequences to consider [optional]
_update_seq_stats
Title : _update_seq_statsUsage :Function: Update the number of sequences and their average length 1average identity 1minimum length 1minimum identity 1number of overlaps 1 average sequence lengthReturns : average sequence lengthnumber of sequencesArgs : average sequence length 1number of sequences 1average sequence length 2number of sequences 2
_get_assembly_overlap_stats
Title : _get_assembly_overlap_statsUsage : my ($avglength, $avgidentity, $minlength, $min_identity, $nof_overlaps)= $csp->_get_assembly_overlap_stats($assemblyobj);Function: Get statistics about pairwise overlaps in contigs of an assemblyReturns : average overlap lengthaverage identity percentminimum overlap lengthminimum identity percentnumber of overlapsArgs : Bio::Assembly::Scaffold, Contig or Singlet objecthash reference with the IDs of the sequences to consider [optional]
_get_contig_overlap_stats
Title : _get_contig_overlap_statsUsage : my ($avglength, $avgidentity, $minlength, $min_identity, $nof_overlaps)= $csp->_get_contig_overlap_stats($contigobj);Function: Get statistics about pairwise overlaps in a contig or singlet. Thestatistics are obtained using graph theory: each read is a nodeand the edges between 2 reads are weighted by minus the number ofconserved residues in the alignment between the 2 reads. Theminimum spanning tree of this graph represents the overlaps thatform the contig. Overlaps that do not satisfy the minimum overlaplength and similarity get a malus on their score.Note: This function requires the optional BioPerl dependencymodule called 'Graph'Returns : average overlap lengthaverage identity percentminimum overlap lengthminimum identity percentnumber of overlapsArgs : Bio::Assembly::Contig or Singlet objecthash reference with the IDs of the sequences to consider [optional]
_update_overlap_stats
Title : _update_overlap_statsUsage :Function: update the number of overlaps and their minimum and average lengthand identityReturns :Args : average length 1average identity 1minimum length 1minimum identity 1number of overlaps 1average length 2average identity 2minimum length 2minimum identity 2number of overlaps 2
_overlap_alignment
Title : _overlap_alignmentUsage :Function: Produce an alignment of the overlapping section of two sequences ofa contig. Minimum overlap length and percentage identity can bespecified. Return undef if the sequences do not overlap or do notmeet the minimum overlap criteria.Return : Bio::SimpleAlign object referencealignment overlap lengthalignment overlap identityArgs : Bio::Assembly::Contig object referenceBio::LocatableSeq contig sequence 1Bio::LocatableSeq contig sequence 2minimum overlap length [optional]minimum overlap identity percentage[optional]
_contig_graph
Title : _contig_graphUsage :Function: Creates a graph data structure of the contig.The graph is undirected.The vertices are the reads of the contig and edges are the overlapbetween the reads. The edges are weighted by the opposite of theoverlap, so it is negative and the better the overlap, the lower theweight.Return : Graph object or undefhashref of overlaps (score, length, identity) for each read pairArgs : Bio::Assembly::Contig object referencehash reference with the IDs of the sequences to consider [optional]minimum overlap length (integer) [optional]minimum percentage identity (integer) [optional]
_draw_graph
Title : _draw_graphUsage :Function: Generates a PNG picture of the contig graph. It is mostly fordebugging purposes.Return : 1 for successArgs : a Graph objecthashref of overlaps (score, length, identity) for each read pairname of output fileoverlap info to display: 'score' (default), 'length' or 'identity'