Class: SequenceServer::Sequence

Inherits:
Struct
  • Object
show all
Defined in:
lib/sequenceserver/sequence.rb,
lib/sequenceserver/sequence.rb

Overview

Utility methods.

Defined Under Namespace

Classes: Retriever

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#accessionObject

Returns the value of attribute accession

Returns:

  • (Object)

    the current value of accession


38
39
40
# File 'lib/sequenceserver/sequence.rb', line 38

def accession
  @accession
end

#giObject

Returns the value of attribute gi

Returns:

  • (Object)

    the current value of gi


38
39
40
# File 'lib/sequenceserver/sequence.rb', line 38

def gi
  @gi
end

#seqidObject

Returns the value of attribute seqid

Returns:

  • (Object)

    the current value of seqid


38
39
40
# File 'lib/sequenceserver/sequence.rb', line 38

def seqid
  @seqid
end

#titleObject

Returns the value of attribute title

Returns:

  • (Object)

    the current value of title


38
39
40
# File 'lib/sequenceserver/sequence.rb', line 38

def title
  @title
end

#valueObject

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value


38
39
40
# File 'lib/sequenceserver/sequence.rb', line 38

def value
  @value
end

Class Method Details

.composition(sequence_string) ⇒ Object

Copied from BioRuby's `Bio::Sequence` class.

> composition(“asdfasdfffffasdf”)

> “d”=>3, “f”=>7, “s”=>3


100
101
102
103
104
105
106
# File 'lib/sequenceserver/sequence.rb', line 100

def composition(sequence_string)
  count = Hash.new(0)
  sequence_string.scan(/./) do |x|
    count[x] += 1
  end
  count
end

.guess_type(sequence) ⇒ Object

Strips all non-letter characters. If less than 10 useable characters return `nil`. If at least 90% is ACGTU, returns `:nucleotide`, else `:protein`.


79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/sequenceserver/sequence.rb', line 79

def guess_type(sequence)
  # Clean the sequence: first remove non-letter characters, then
  # ambiguous characters.
  cleaned_sequence = sequence.gsub(/[^A-Z]/i, '').gsub(/[NX]/i, '')

  return if cleaned_sequence.length < 10 # conservative

  # Count putative NA in the sequence.
  na_count = 0
  composition = composition(cleaned_sequence)
  composition.each do |character, count|
    na_count += count if character.match(/[ACGTU]/i)
  end

  na_count > (0.9 * cleaned_sequence.length) ? :nucleotide : :protein
end