Class Bio::Sequence
In: lib/bio/sequence.rb
lib/bio/sequence/aa.rb
lib/bio/sequence/common.rb
lib/bio/sequence/compat.rb
lib/bio/sequence/format.rb
lib/bio/sequence/generic.rb
lib/bio/sequence/na.rb
lib/bio/sequence/quality_score.rb
lib/bio/sequence/sequence_masker.rb
Parent: Object

DESCRIPTION

Bio::Sequence objects represent annotated sequences in bioruby. A Bio::Sequence object is a wrapper around the actual sequence, represented as either a Bio::Sequence::NA or a Bio::Sequence::AA object. For most users, this encapsulation will be completely transparent. Bio::Sequence responds to all methods defined for Bio::Sequence::NA/AA objects using the same arguments and returning the same values (even though these methods are not documented specifically for Bio::Sequence).

USAGE

  # Create a nucleic or amino acid sequence
  dna = Bio::Sequence.auto('atgcatgcATGCATGCAAAA')
  rna = Bio::Sequence.auto('augcaugcaugcaugcaaaa')
  aa = Bio::Sequence.auto('ACDEFGHIKLMNPQRSTVWYU')

  # Print it out
  puts dna.to_s
  puts aa.to_s

  # Get a subsequence, bioinformatics style (first nucleotide is '1')
  puts dna.subseq(2,6)

  # Get a subsequence, informatics style (first nucleotide is '0')
  puts dna[2,6]

  # Print in FASTA format
  puts dna.output(:fasta)

  # Print all codons
  dna.window_search(3,3) do |codon|
    puts codon
  end

  # Splice or otherwise mangle your sequence
  puts dna.splicing("complement(join(1..5,16..20))")
  puts rna.splicing("complement(join(1..5,16..20))")

  # Convert a sequence containing ambiguity codes into a
  # regular expression you can use for subsequent searching
  puts aa.to_re

  # These should speak for themselves
  puts dna.complement
  puts dna.composition
  puts dna.molecular_weight
  puts dna.translate
  puts dna.gc_percent

Methods

aa   accessions   adapter   auto   auto   guess   guess   input   na   new   read   to_s   to_str  

Included Modules

Format SequenceMasker

Classes and Modules

Module Bio::Sequence::Common
Module Bio::Sequence::Format
Module Bio::Sequence::QualityScore
Module Bio::Sequence::SequenceMasker
Class Bio::Sequence::AA
Class Bio::Sequence::NA

External Aliases

classification -> taxonomy

Attributes

classification  [RW]  Organism classification, taxonomic classification of the source organism. (Array of String)
comments  [RW]  Comments (String or an Array of String)
data_class  [RW]  Data Class defined by EMBL (String) See www.ebi.ac.uk/embl/Documentation/User_manual/usrman.html#3_1
date_created  [RW]  Created date of the sequence entry (Date, DateTime, Time, or String)
date_modified  [RW]  Last modified date of the sequence entry (Date, DateTime, Time, or String)
dblinks  [RW]  Links to other database entries. (An Array of Bio::Sequence::DBLink objects)
definition  [RW]  A String with a description of the sequence (String)
division  [RW]  Taxonomic Division defined by EMBL/GenBank/DDBJ (String) See www.ebi.ac.uk/embl/Documentation/User_manual/usrman.html#3_2
entry_id  [RW]  The sequence identifier (String). For example, for a sequence of Genbank origin, this is the locus name. For a sequence of EMBL origin, this is the primary accession number.
entry_version  [RW]  Version of the entry (String or Integer). Unlike sequence_version, entry_version is a database maintainer‘s internal version number. The version number will be changed when the database maintainer modifies the entry. The same enrty in EMBL, GenBank, and DDBJ may have different entry_version.
error_probabilities  [RW]  Error probabilities of the bases/residues in the sequence. (Array containing Float, or nil)
features  [RW]  Features (An Array of Bio::Feature objects)
id_namespace  [RW]  Namespace of the sequence IDs described in entry_id, primary_accession, and secondary_accessions methods (String). For example, ‘EMBL’, ‘GenBank’, ‘DDBJ’, ‘RefSeq’.
keywords  [RW]  Keywords (An Array of String)
molecule_type  [RW]  molecular type (String). "DNA" or "RNA" for nucleotide sequence.
moltype  [RW]  Bio::Sequence::NA/AA
organelle  [RW]  (not well supported) Organelle information (String).
other_seqids  [RW]  Sequence identifiers which are not described in entry_id, primary_accession,and secondary_accessions methods (Array of Bio::Sequence::DBLink objects). For example, NCBI GI number can be stored. Note that only identifiers of the entry itself should be stored. For database cross references, dblinks should be used.
primary_accession  [RW]  Primary accession number (String)
quality_score_type  [RW]  The meaning (calculation method) of the quality scores stored in the quality_scores attribute. Maybe one of :phred, :solexa, or nil.

Note that if it is nil, and error_probabilities is empty, some methods implicitly assumes that it is :phred (PHRED score).

quality_scores  [RW]  Quality scores of the bases/residues in the sequence. (Array containing Integer, or nil)
references  [RW]  References (An Array of Bio::Reference objects)
release_created  [RW]  Release information when created (String)
release_modified  [RW]  Release information when last-modified (String)
secondary_accessions  [RW]  Secondary accession numbers (Array of String)
seq  [RW]  The sequence object, usually Bio::Sequence::NA/AA, but could be a simple String
sequence_version  [RW]  Version number of the sequence (String or Integer). Unlike entry_version, sequence_version will be changed when the submitter of the sequence updates the entry. Normally, the same entry taken from different databases (EMBL, GenBank, and DDBJ) may have the same sequence_version.
species  [RW]  Organism species (String). For example, "Escherichia coli".
strandedness  [RW]  Strandedness (String). "single" (single-stranded), "double" (double-stranded), "mixed" (mixed-stranded), or nil.
topology  [RW]  Topology (String). "circular", "linear", or nil.

Public Class methods

Normally, users should not call this method directly. Use Bio::*to_biosequence (e.g. Bio::GenBank#to_biosequence).

Creates a new Bio::Sequence object from database data with an adapter module.

[Source]

     # File lib/bio/sequence.rb, line 461
461:   def self.adapter(source_data, adapter_module)
462:     biosequence = self.new(nil)
463:     biosequence.instance_eval {
464:       remove_instance_variable(:@seq)
465:       @source_data = source_data
466:     }
467:     biosequence.extend(adapter_module)
468:     biosequence
469:   end

Given a sequence String, guess its type, Amino Acid or Nucleic Acid, and return a new Bio::Sequence object wrapping a sequence of the guessed type (either Bio::Sequence::AA or Bio::Sequence::NA)

  s = Bio::Sequence.auto('atgc')
  puts s.seq.class                        #=> Bio::Sequence::NA

Arguments:

Returns:Bio::Sequence object

[Source]

     # File lib/bio/sequence.rb, line 281
281:   def self.auto(str)
282:     seq = self.new(str)
283:     seq.auto
284:     return seq
285:   end

Guess the class of a given sequence. Returns the class (Bio::Sequence::AA or Bio::Sequence::NA) guessed. In general, used by developers only, but if you know what you are doing, feel free.

  puts .guess('atgc')        #=> Bio::Sequence::NA

There are three optional parameters: `threshold`, `length`, and `index`.

The `threshold` value (defaults to 0.9) is the frequency of nucleic acid bases [AGCTUagctu] required in the sequence for this method to produce a Bio::Sequence::NA "guess". In the default case, if less than 90% of the bases (after excluding [Nn]) are in the set [AGCTUagctu], then the guess is Bio::Sequence::AA.

  puts Bio::Sequence.guess('atgcatgcqq')      #=> Bio::Sequence::AA
  puts Bio::Sequence.guess('atgcatgcqq', 0.8) #=> Bio::Sequence::AA
  puts Bio::Sequence.guess('atgcatgcqq', 0.7) #=> Bio::Sequence::NA

The `length` value is how much of the total sequence to use in the guess (default 10000). If your sequence is very long, you may want to use a smaller amount to reduce the computational burden.

  # limit the guess to the first 1000 positions
  puts Bio::Sequence.guess('A VERY LONG SEQUENCE', 0.9, 1000)

The `index` value is where to start the guess. Perhaps you know there are a lot of gaps at the start…

  puts Bio::Sequence.guess('-----atgcc')             #=> Bio::Sequence::AA
  puts Bio::Sequence.guess('-----atgcc',0.9,10000,5) #=> Bio::Sequence::NA

Arguments:

  • (required) str: String or Bio::Sequence::NA/AA object
  • (optional) threshold: Float in range 0,1 (default 0.9)
  • (optional) length: Fixnum (default 10000)
  • (optional) index: Fixnum (default 1)
Returns:Bio::Sequence::NA/AA

[Source]

     # File lib/bio/sequence.rb, line 379
379:   def self.guess(str, *args)
380:     self.new(str).guess(*args)
381:   end

Create a new Bio::Sequence object from a formatted string (GenBank, EMBL, fasta format, etc.)

  s = Bio::Sequence.input(str)

Arguments:

  • (required) str: string
  • (optional) format: format specification (class or nil)
Returns:Bio::Sequence object

[Source]

     # File lib/bio/sequence.rb, line 434
434:   def self.input(str, format = nil)
435:     if format then
436:       klass = format
437:     else
438:       klass = Bio::FlatFile::AutoDetect.default.autodetect(str)
439:     end
440:     obj = klass.new(str)
441:     obj.to_biosequence
442:   end

Create a new Bio::Sequence object

  s = Bio::Sequence.new('atgc')
  puts s                                  #=> 'atgc'

Note that this method does not intialize the contained sequence as any kind of bioruby object, only as a simple string

  puts s.seq.class                        #=> String

See Bio::Sequence#na, Bio::Sequence#aa, and Bio::Sequence#auto for methods to transform the basic String of a just created Bio::Sequence object to a proper bioruby object


Arguments:

Returns:Bio::Sequence object

[Source]

    # File lib/bio/sequence.rb, line 97
97:   def initialize(str)
98:     @seq = str
99:   end

alias of Bio::Sequence.input

[Source]

     # File lib/bio/sequence.rb, line 445
445:   def self.read(str, format = nil)
446:     input(str, format)
447:   end

Public Instance methods

Transform the sequence wrapped in the current Bio::Sequence object into a Bio::Sequence::NA object. This method will change the current object. This method does not validate your choice, so be careful!

  s = Bio::Sequence.new('atgc')
  puts s.seq.class                        #=> String
  s.aa
  puts s.seq.class                        #=> Bio::Sequence::AA !!!

However, if you know your sequence type, this method may be constructively used after initialization,

  s = Bio::Sequence.new('RRLE')
  s.aa

Returns:Bio::Sequence::AA

[Source]

     # File lib/bio/sequence.rb, line 420
420:   def aa
421:     @seq = AA.new(seq)
422:     @moltype = AA
423:   end

accession numbers of the sequence

Returns:Array of String

[Source]

     # File lib/bio/sequence.rb, line 452
452:   def accessions
453:     [ primary_accession, secondary_accessions ].flatten.compact
454:   end

Guess the type of sequence, Amino Acid or Nucleic Acid, and create a new sequence object (Bio::Sequence::AA or Bio::Sequence::NA) on the basis of this guess. This method will change the current Bio::Sequence object.

  s = Bio::Sequence.new('atgc')
  puts s.seq.class                        #=> String
  s.auto
  puts s.seq.class                        #=> Bio::Sequence::NA

Returns:Bio::Sequence::NA/AA object

[Source]

     # File lib/bio/sequence.rb, line 262
262:   def auto
263:     @moltype = guess
264:     if @moltype == NA
265:       @seq = NA.new(seq)
266:     else
267:       @seq = AA.new(seq)
268:     end
269:   end

Guess the class of the current sequence. Returns the class (Bio::Sequence::AA or Bio::Sequence::NA) guessed. In general, used by developers only, but if you know what you are doing, feel free.

  s = Bio::Sequence.new('atgc')
  puts s.guess                            #=> Bio::Sequence::NA

There are three parameters: `threshold`, `length`, and `index`.

The `threshold` value (defaults to 0.9) is the frequency of nucleic acid bases [AGCTUagctu] required in the sequence for this method to produce a Bio::Sequence::NA "guess". In the default case, if less than 90% of the bases (after excluding [Nn]) are in the set [AGCTUagctu], then the guess is Bio::Sequence::AA.

  s = Bio::Sequence.new('atgcatgcqq')
  puts s.guess                            #=> Bio::Sequence::AA
  puts s.guess(0.8)                       #=> Bio::Sequence::AA
  puts s.guess(0.7)                       #=> Bio::Sequence::NA

The `length` value is how much of the total sequence to use in the guess (default 10000). If your sequence is very long, you may want to use a smaller amount to reduce the computational burden.

  s = Bio::Sequence.new(A VERY LONG SEQUENCE)
  puts s.guess(0.9, 1000)  # limit the guess to the first 1000 positions

The `index` value is where to start the guess. Perhaps you know there are a lot of gaps at the start…

  s = Bio::Sequence.new('-----atgcc')
  puts s.guess                            #=> Bio::Sequence::AA
  puts s.guess(0.9,10000,5)               #=> Bio::Sequence::NA

Arguments:

  • (optional) threshold: Float in range 0,1 (default 0.9)
  • (optional) length: Fixnum (default 10000)
  • (optional) index: Fixnum (default 1)
Returns:Bio::Sequence::NA/AA

[Source]

     # File lib/bio/sequence.rb, line 326
326:   def guess(threshold = 0.9, length = 10000, index = 0)
327:     str = seq.to_s[index,length].to_s.extend Bio::Sequence::Common
328:     cmp = str.composition
329: 
330:     bases = cmp['A'] + cmp['T'] + cmp['G'] + cmp['C'] + cmp['U'] +
331:             cmp['a'] + cmp['t'] + cmp['g'] + cmp['c'] + cmp['u']
332: 
333:     total = str.length - cmp['N'] - cmp['n']
334: 
335:     if bases.to_f / total > threshold
336:       return NA
337:     else
338:       return AA
339:     end
340:   end

Transform the sequence wrapped in the current Bio::Sequence object into a Bio::Sequence::NA object. This method will change the current object. This method does not validate your choice, so be careful!

  s = Bio::Sequence.new('RRLE')
  puts s.seq.class                        #=> String
  s.na
  puts s.seq.class                        #=> Bio::Sequence::NA !!!

However, if you know your sequence type, this method may be constructively used after initialization,

  s = Bio::Sequence.new('atgc')
  s.na

Returns:Bio::Sequence::NA

[Source]

     # File lib/bio/sequence.rb, line 399
399:   def na
400:     @seq = NA.new(seq)
401:     @moltype = NA
402:   end

Return sequence as String. The original sequence is unchanged.

  seq = Bio::Sequence.new('atgc')
  puts s.to_s                             #=> 'atgc'
  puts s.to_s.class                       #=> String
  puts s                                  #=> 'atgc'
  puts s.class                            #=> Bio::Sequence

Returns:String object

[Source]

    # File lib/bio/sequence/compat.rb, line 32
32:   def to_s
33:     String.new(self.seq)
34:   end
to_str()

Alias for to_s

[Validate]