-
Notifications
You must be signed in to change notification settings - Fork 0
/
site.rb
42 lines (35 loc) · 1.36 KB
/
site.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require "bundler"
Bundler.require
$db = Mongo::Connection.new.db('biology')
$families = %w{cWW tWW cWH tWH cWS tWS cHH tHH cHS tHS} << /cSS/i << /tSS/i
$base_url = (`hostname` =~ /lab/ ? 'http://rna.bgsu.edu/variation_data/' : '/')
$nav_families = $families.map { |f| (f.is_a?(String) ? f : f.source) }
def first_apperance?(interaction, key = 'positions')
interaction[key][0].to_i < interaction[key][1].to_i
end
def symmetric?(interaction)
interaction['family'][1].downcase == interaction['family'][2].downcase
end
get '/' do
@title = 'All Variations'
query = Plucky::Query.new($db['interactions'])
@data = query.all(pdb: '2AW7', :family.in => $families, conserved: true)
@data.select! { |d| (symmetric?(d) && first_apperance?(d)) || !symmetric?(d) }
haml :index
end
get '/family/:family' do
halt 404 if !$families.any? { |f| f.match(params[:family]) }
@family = params[:family].upcase
@family[0] = @family[0].downcase
@title = @family
replace = ($base_url =~ /http/ ? '/variation_data/' : '')
@data = Dir["public/images/positions/#{@family}*"].map do |e|
matches = e.match(/(\d+)-(\d+)/)
{ :src => e.sub('public', replace), :positions => matches.captures }
end
if symmetric?({ 'family' => @family })
@data.select! { |d| first_apperance?(d, :positions) }
end
@data.sort_by! { |d| d[:positions].first.to_i }
haml :"family/show"
end