Class: SequenceServer::BLAST::Hit
- Inherits:
-
Struct
- Object
- Struct
- SequenceServer::BLAST::Hit
- Includes:
- Links
- Defined in:
- lib/sequenceserver/blast/hit.rb
Overview
Hit object to store all the hits per Query.
Constant Summary
Constants included from Links
Links::NCBI_ID_PATTERN, Links::PFAM_ID_PATTERN, Links::RFAM_ID_PATTERN, Links::UNIPROT_ID_PATTERN
Instance Attribute Summary collapse
-
#accession ⇒ Object
Returns the value of attribute accession.
-
#hsps ⇒ Object
Returns the value of attribute hsps.
-
#id ⇒ Object
Returns the value of attribute id.
-
#length ⇒ Object
Returns the value of attribute length.
-
#number ⇒ Object
Returns the value of attribute number.
-
#qcovs ⇒ Object
Returns the value of attribute qcovs.
-
#query ⇒ Object
Returns the value of attribute query.
-
#sciname ⇒ Object
Returns the value of attribute sciname.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
-
#coordinates ⇒ Object
Returns tuple of tuple indicating start and end coordinates of matched regions of query and hit sequences.
-
#dbtype ⇒ Object
Returns the database type (nucleotide or protein).
-
#initialize(*args) ⇒ Hit
constructor
A new instance of Hit.
-
#links ⇒ Object
Links returns a list of Hashes that can be easily turned into an href in the client.
-
#to_json(*args) ⇒ Object
This gets called when #to_json is called on report object in routes.
-
#total_score ⇒ Object
Returns the sum of scores of all HSPs.
-
#whichdb ⇒ Object
Returns a list of databases that contain this hit.
Methods included from Links
Constructor Details
#initialize(*args) ⇒ Hit
Returns a new instance of Hit.
7 8 9 10 11 12 13 14 |
# File 'lib/sequenceserver/blast/hit.rb', line 7 def initialize(*args) args[1] = args[1].to_i args[4] = '' if args[4] == 'No definition line' args[5] = args[5].to_i args[6] = '' if args[6] == 'N/A' args[7] = args[7].to_i super end |
Instance Attribute Details
#accession ⇒ Object
Returns the value of attribute accession
5 6 7 |
# File 'lib/sequenceserver/blast/hit.rb', line 5 def accession @accession end |
#hsps ⇒ Object
Returns the value of attribute hsps
5 6 7 |
# File 'lib/sequenceserver/blast/hit.rb', line 5 def hsps @hsps end |
#id ⇒ Object
Returns the value of attribute id
5 6 7 |
# File 'lib/sequenceserver/blast/hit.rb', line 5 def id @id end |
#length ⇒ Object
Returns the value of attribute length
5 6 7 |
# File 'lib/sequenceserver/blast/hit.rb', line 5 def length @length end |
#number ⇒ Object
Returns the value of attribute number
5 6 7 |
# File 'lib/sequenceserver/blast/hit.rb', line 5 def number @number end |
#qcovs ⇒ Object
Returns the value of attribute qcovs
5 6 7 |
# File 'lib/sequenceserver/blast/hit.rb', line 5 def qcovs @qcovs end |
#query ⇒ Object
Returns the value of attribute query
5 6 7 |
# File 'lib/sequenceserver/blast/hit.rb', line 5 def query @query end |
#sciname ⇒ Object
Returns the value of attribute sciname
5 6 7 |
# File 'lib/sequenceserver/blast/hit.rb', line 5 def sciname @sciname end |
#title ⇒ Object
Returns the value of attribute title
5 6 7 |
# File 'lib/sequenceserver/blast/hit.rb', line 5 def title @title end |
Instance Method Details
#coordinates ⇒ Object
Returns tuple of tuple indicating start and end coordinates of matched regions of query and hit sequences.
59 60 61 62 63 64 65 66 |
# File 'lib/sequenceserver/blast/hit.rb', line 59 def coordinates qstart_min = hsps.map(&:qstart).min qend_max = hsps.map(&:qend).max sstart_min = hsps.map(&:sstart).min send_max = hsps.map(&:send).max [[qstart_min, qend_max], [sstart_min, send_max]] end |
#dbtype ⇒ Object
Returns the database type (nucleotide or protein).
46 47 48 |
# File 'lib/sequenceserver/blast/hit.rb', line 46 def dbtype report.dbtype end |
#links ⇒ Object
Links returns a list of Hashes that can be easily turned into an href in the client. These are derived by calling link generators, that is, instance methods of the Links module.
39 40 41 42 43 |
# File 'lib/sequenceserver/blast/hit.rb', line 39 def links links = Links.instance_methods.map { |m| send m } links.compact! links.sort_by { |link| [link[:order], link[:title]] } end |
#to_json(*args) ⇒ Object
This gets called when #to_json is called on report object in routes. We cannot use the to_json method provided by Struct class because what we want to send to the browser differs from the attributes declared with Struct class. Some of these are derived data such as score, identity, custom links. While some attributes are necessary for internal representation.
22 23 24 25 26 27 |
# File 'lib/sequenceserver/blast/hit.rb', line 22 def to_json(*args) # List all attributes that we want to send to the browser. properties = %i[number id accession title length total_score qcovs sciname hsps links] properties.inject({}) { |h, k| h[k] = send(k); h }.to_json(*args) end |
#total_score ⇒ Object
Returns the sum of scores of all HSPs. Displayed in the tabular summary of hits in the HTML report. Should probably be calculated in browser?
76 77 78 |
# File 'lib/sequenceserver/blast/hit.rb', line 76 def total_score hsps.map(&:score).reduce(:+) end |
#whichdb ⇒ Object
Returns a list of databases that contain this hit.
e.g., whichdb(‘SI_2.2.23’) => [<Database: …>, …]
53 54 55 |
# File 'lib/sequenceserver/blast/hit.rb', line 53 def whichdb report.querydb.select { |db| db.include? id } end |