Class: SequenceServer::Sequence
- Inherits:
-
Struct
- Object
- Struct
- SequenceServer::Sequence
- Defined in:
- lib/sequenceserver/sequence.rb,
lib/sequenceserver/sequence.rb
Overview
Utility methods.
Defined Under Namespace
Classes: Retriever
Instance Attribute Summary collapse
-
#accession ⇒ Object
Returns the value of attribute accession.
-
#gi ⇒ Object
Returns the value of attribute gi.
-
#seqid ⇒ Object
Returns the value of attribute seqid.
-
#title ⇒ Object
Returns the value of attribute title.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
-
.composition(sequence_string) ⇒ Object
Copied from BioRuby’s ‘Bio::Sequence` class.
-
.guess_type(sequence) ⇒ Object
Strips all non-letter characters.
Instance Method Summary collapse
-
#fasta ⇒ Object
Returns FASTA formatted sequence.
-
#id ⇒ Object
Returns FASTA sequence id.
- #info ⇒ Object
-
#initialize(*args) ⇒ Sequence
constructor
A new instance of Sequence.
-
#length ⇒ Object
Returns length of the sequence.
-
#to_s ⇒ Object
Returns sequence value.
Constructor Details
#initialize(*args) ⇒ Sequence
Returns a new instance of Sequence.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/sequenceserver/sequence.rb', line 35 def initialize(*args) # If gi of the hit is 'N/A', make it nil instead. args[0] = nil if args[0] == 'N/A' # If seqid has 'lcl|' prefixed, remove it. args[1] = args[1].gsub(/^lcl\|/, '') # If hit comes from a non -parse_seqids # database, obtain seqid and title from # defline. if args[1] =~ /^gnl\|BL_ORD_ID\|\d+/ defline = args[3].split args[1] = defline.shift args[3] = defline.join(' ') end super end |
Instance Attribute Details
#accession ⇒ Object
Returns the value of attribute accession
34 35 36 |
# File 'lib/sequenceserver/sequence.rb', line 34 def accession @accession end |
#gi ⇒ Object
Returns the value of attribute gi
34 35 36 |
# File 'lib/sequenceserver/sequence.rb', line 34 def gi @gi end |
#seqid ⇒ Object
Returns the value of attribute seqid
34 35 36 |
# File 'lib/sequenceserver/sequence.rb', line 34 def seqid @seqid end |
#title ⇒ Object
Returns the value of attribute title
34 35 36 |
# File 'lib/sequenceserver/sequence.rb', line 34 def title @title end |
#value ⇒ Object
Returns the value of attribute value
34 35 36 |
# File 'lib/sequenceserver/sequence.rb', line 34 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
110 111 112 113 114 115 116 |
# File 'lib/sequenceserver/sequence.rb', line 110 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`.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/sequenceserver/sequence.rb', line 89 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 =~ /[ACGTU]/i end na_count > (0.9 * cleaned_sequence.length) ? :nucleotide : :protein end |
Instance Method Details
#fasta ⇒ Object
Returns FASTA formatted sequence.
74 75 76 77 78 79 80 |
# File 'lib/sequenceserver/sequence.rb', line 74 def fasta chars = 60 lines = (length / chars.to_f).ceil defline = ">#{id} #{title}" seqlines = (1..lines).map { |i| to_s[chars * (i - 1), chars] } [defline].concat(seqlines).join("\n") end |
#id ⇒ Object
Returns FASTA sequence id.
55 56 57 |
# File 'lib/sequenceserver/sequence.rb', line 55 def id (gi ? ['gi', gi, seqid] : [seqid]).join('|') end |
#info ⇒ Object
69 70 71 |
# File 'lib/sequenceserver/sequence.rb', line 69 def info { value: value, id: id, title: title } end |
#length ⇒ Object
Returns length of the sequence.
60 61 62 |
# File 'lib/sequenceserver/sequence.rb', line 60 def length value.length end |
#to_s ⇒ Object
Returns sequence value.
65 66 67 |
# File 'lib/sequenceserver/sequence.rb', line 65 def to_s value end |