Class: SequenceServer::BLAST::Hit

Inherits:
Struct
  • Object
show all
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

Instance Method Summary collapse

Methods included from Links

#ncbi, #pfam, #rfam, #uniprot

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

#accessionObject

Returns the value of attribute accession

Returns:

  • (Object)

    the current value of accession



5
6
7
# File 'lib/sequenceserver/blast/hit.rb', line 5

def accession
  @accession
end

#hspsObject

Returns the value of attribute hsps

Returns:

  • (Object)

    the current value of hsps



5
6
7
# File 'lib/sequenceserver/blast/hit.rb', line 5

def hsps
  @hsps
end

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



5
6
7
# File 'lib/sequenceserver/blast/hit.rb', line 5

def id
  @id
end

#lengthObject

Returns the value of attribute length

Returns:

  • (Object)

    the current value of length



5
6
7
# File 'lib/sequenceserver/blast/hit.rb', line 5

def length
  @length
end

#numberObject

Returns the value of attribute number

Returns:

  • (Object)

    the current value of number



5
6
7
# File 'lib/sequenceserver/blast/hit.rb', line 5

def number
  @number
end

#qcovsObject

Returns the value of attribute qcovs

Returns:

  • (Object)

    the current value of qcovs



5
6
7
# File 'lib/sequenceserver/blast/hit.rb', line 5

def qcovs
  @qcovs
end

#queryObject

Returns the value of attribute query

Returns:

  • (Object)

    the current value of query



5
6
7
# File 'lib/sequenceserver/blast/hit.rb', line 5

def query
  @query
end

#scinameObject

Returns the value of attribute sciname

Returns:

  • (Object)

    the current value of sciname



5
6
7
# File 'lib/sequenceserver/blast/hit.rb', line 5

def sciname
  @sciname
end

#titleObject

Returns the value of attribute title

Returns:

  • (Object)

    the current value of title



5
6
7
# File 'lib/sequenceserver/blast/hit.rb', line 5

def title
  @title
end

Instance Method Details

#coordinatesObject

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

#dbtypeObject

Returns the database type (nucleotide or protein).



46
47
48
# File 'lib/sequenceserver/blast/hit.rb', line 46

def dbtype
  report.dbtype
end

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_scoreObject

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

#whichdbObject

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