Skip to content

Commit

Permalink
mostly script fixes and simple view tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Juul committed Jun 5, 2012
1 parent 018eda1 commit dea7c13
Show file tree
Hide file tree
Showing 20 changed files with 703 additions and 248 deletions.
2 changes: 2 additions & 0 deletions app/views/layouts/simple.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,10 @@

<div id='top_menu'>
<ul>
<!--
<li><%= link_to "Characterized bi-cistronic 5' UTRs", :action => "characterized_bds" %></li>
<li><%= link_to "Characterized promoters", :action => "promoters" %></li>
-->
<li><%= link_to "Randomized bi-cistronic 5' UTRs", :action => "randomized_bds" %></li>
<li><%= link_to "Promoter vs. 5' UTR", :action => "index" %></li>
<li class='last'><%= link_to "5' UTR vs. CDS", :action => "bd_gois" %></li>
Expand Down
32 changes: 16 additions & 16 deletions app/views/simple/bd_gois.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
<tr>
<th>Show plasmid</th>

<th>Plasmid ID</th>
<th>Strain ID</th>
<th>5' UTR ID</th>
<th>CDS ID</th>
<th>Plasmid BIOFAB ID</th>
<th>Strain BIOFAB ID</th>
<th>Strain performance</th>
<th>Strain performance SD</th>

<th>5' UTR performance</th>
<th>5' UTR performance SD</th>
<th>5' UTR reliability</th>
<th>5' UTR BIOFAB ID</th>
<th>5' UTR name</th>
<th>5' UTR sequence</th>

<th>CDS BIOFAB ID</th>
<th>CDS name</th>
<th>CDS sequence</th>

</tr>
</thead>
<tbody>
Expand All @@ -30,17 +30,17 @@

<td><%= design.plasmid_biofab_id.gsub(/\.0$/, '') %></td>
<td><%= design.strain_biofab_id.gsub(/\.0$/, '') %></td>
<td><%= design.fpu.biofab_id %></td>
<td><%= design.cds.biofab_id %></td>
<td><%= design.performance.round(2) %></td>
<td>?</td>
<td><%= design.fc_average.round(2) %></td>
<td><%= design.fc_sd.round(2) %></td>

<td><%= design.fpu_biofab_id %></td>
<td><%= design.fpu_name %></td>
<td><%= design.fpu_sequence %></td>

<td><%= design.fpu.part_performance.performance.round(2) %></td>
<td><%= design.fpu.part_performance.performance_sd.round(2) %></td>
<td><%= design.fpu.part_performance.reliability.round %></td>
<td><%= design.fpu.sequence %></td>

<td><%= design.cds.sequence %></td>
<td><%= design.cds_biofab_id %></td>
<td><%= design.cds_name %></td>
<td><%= design.cds_sequence %></td>

</tr>

Expand Down
2 changes: 0 additions & 2 deletions app/views/simple/characterized_bds.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<tr>
<th>5' UTR ID</th>
<th>5' UTR performance</th>
<th>5' UTR performance SD</th>
<th>5' UTR reliability</th>
<th>5' UTR sequence</th>
</tr>
Expand All @@ -17,7 +16,6 @@
<td><%= fpu.biofab_id %></td>

<td><%= fpu.part_performance.performance.round(2) %></td>
<td><%= fpu.part_performance.performance_sd.round(2) %></td>
<td><%= fpu.part_performance.reliability.round %></td>
<td><%= fpu.sequence %></td>

Expand Down
38 changes: 15 additions & 23 deletions app/views/simple/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,17 @@
<tr>
<th>Show plasmid</th>

<th>Plasmid ID</th>
<th>Strain ID</th>
<th>Promoter ID</th>
<th>5' UTR ID</th>
<th>Plasmid BIOFAB ID</th>
<th>Strain BIOFAB ID</th>
<th>Strain performance</th>
<th>Strain performance SD</th>

<th>Promoter performance</th>
<th>Promoter performance SD</th>
<th>Promoter BIOFAB ID</th>
<th>Promoter name</th>
<th>Promoter sequence</th>

<th>5' UTR performance</th>
<th>5' UTR performance SD</th>
<th>5' UTR reliability</th>
<th>5' UTR BIOFAB ID</th>
<th>5' UTR name</th>
<th>5' UTR sequence</th>

</tr>
</thead>
<tbody>
Expand All @@ -98,18 +94,14 @@

<td><%= design.plasmid_biofab_id.gsub(/\.0$/, '') %></td>
<td><%= design.strain_biofab_id.gsub(/\.0$/, '') %></td>
<td><%= design.promoter.biofab_id %></td>
<td><%= design.fpu.biofab_id %></td>
<td><%= (design.performance_normalized * 100).round(2) %></td>
<td><%= (design.performance_sd_normalized * 100).round(2) %></td>
<td><%= design.promoter.part_performance.performance.round(2) %></td>
<td><%= design.promoter.part_performance.performance_sd.round(2) %></td>
<td><%= design.promoter.sequence %></td>

<td><%= design.fpu.part_performance.performance.round(2) %></td>
<td><%= design.fpu.part_performance.performance_sd.round(2) %></td>
<td><%= design.fpu.part_performance.reliability.round %></td>
<td><%= design.fpu.sequence %></td>
<td><%= design.performance.round(2) %></td>
<td><%= design.performance_sd.round(2) %></td>
<td><%= design.promoter_biofab_id %></td>
<td><%= design.promoter_name %></td>
<td><%= design.promoter_sequence %></td>
<td><%= design.fpu_biofab_id %></td>
<td><%= design.fpu_name %></td>
<td><%= design.fpu_sequence %></td>

</tr>

Expand Down
2 changes: 0 additions & 2 deletions app/views/simple/promoters.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<tr>
<th>Promoter ID</th>
<th>Promoter performance</th>
<th>Promoter performance SD</th>
<th>Promoter sequence</th>
</tr>
</thead>
Expand All @@ -15,7 +14,6 @@
<td><%= promoter.biofab_id.gsub(/\.0$/, '') %></td>

<td><%= promoter.part_performance.performance.round(2) %></td>
<td><%= promoter.part_performance.performance_sd.round(2) %></td>
<td><%= promoter.sequence %></td>

</tr>
Expand Down
10 changes: 5 additions & 5 deletions app/views/simple/randomized_bds.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<tr>
<th>Show plasmid</th>

<th>Plasmid ID</th>
<th>Strain ID</th>
<th>Plasmid BIOFAB ID</th>
<th>Strain BIOFAB ID</th>
<th>Strain performance</th>
<th>Strain performance SD</th>
<th>5' UTR ID</th>
<th>5' UTR BIOFAB ID</th>
<th>5' UTR sequence</th>

</tr>
Expand All @@ -22,8 +22,8 @@
<td><%= design.plasmid_biofab_id.gsub(/\.0$/, '') %></td>
<td><%= design.strain_biofab_id.gsub(/\.0$/, '') %></td>

<td><%= design.fcs_normalized.round(2) %></td>
<td><%= design.fcs_sd_normalized.round(2) %></td>
<td><%= (design.fcs == 0) ? "no data" : design.fcs.round(2) %></td>
<td><%= (design.fcs_sd == 0) ? "no data" : design.fcs_sd.round(2) %></td>

<td><%= design.biofab_id %></td>
<td><%= design.sequence %></td>
Expand Down
8 changes: 8 additions & 0 deletions db/migrate/20120528123005_bc_designs_add_performance_sd.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class BcDesignsAddPerformanceSd < ActiveRecord::Migration
def up
add_column :bc_designs, :performance_sd, :float
end

def down
end
end
8 changes: 8 additions & 0 deletions db/migrate/20120602064928_design_add_fpu_name.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class DesignAddFpuName < ActiveRecord::Migration
def up
add_column :designs, :fpu_name, :string
end

def down
end
end
26 changes: 21 additions & 5 deletions script/annotate_plasmids.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

annots = Annotation.delete_all(["annotation_type_id = ?", anno_type.id])


plasmid_type = PartType.find_by_name('Plasmid')
raise "plasmid type not found" if !plasmid_type

Expand All @@ -48,8 +47,6 @@
parts = Part.where(query_parm)
raise "no parts found" if !parts || (parts.length == 0)



plasmids.each do |plasmid|
next if plasmid.sequence.blank?

Expand All @@ -72,6 +69,8 @@
annot_from = m.begin(0) + offset
annot_to = m.end(0) + offset - 1

puts " -- annotating with: #{part.biofab_id} [#{part.part_type.name}]"

anno = Annotation.new
anno.parent_part = plasmid
anno.part = part
Expand All @@ -82,7 +81,7 @@

offset += m.end(0)
mseq = mseq[offset..-1]

break if mseq.blank?
end
end

Expand All @@ -93,7 +92,24 @@
annotations.each do |outer|
next if outer == inner
if (outer.from <= inner.from) && (outer.to >= inner.to)
keep = false
# if they have the same sequence, then make sure one and only one of them is added
if outer.part.sequence.upcase == inner.part.sequence.upcase
seq_in_final_list = false
final_annos.each do |final|
if final.part.sequence.upcase == inner.part.sequence.upcase
seq_in_final_list = true
break
end
end

if seq_in_final_list
keep = false
# puts " == dropping: #{inner.part.biofab_id} [#{inner.part.part_type.name}] because it is inside #{outer.part.biofab_id} [#{outer.part.part_type.name}]"
end
else
# puts " == dropping: #{inner.part.biofab_id} [#{inner.part.part_type.name}] because it is inside #{outer.part.biofab_id} [#{outer.part.part_type.name}]"
keep = false
end
end
end
if keep
Expand Down
39 changes: 1 addition & 38 deletions script/calculate_fpu_performance.rb
Original file line number Diff line number Diff line change
@@ -1,43 +1,6 @@
#!script/rails runner
class Numeric
def square
self * self
end
end

module Enumerable

# sum of an array of numbers
def sum
return self.inject(0){|acc,i|acc +i}
end

# mean of an array of numbers
def mean
return self.sum/self.length.to_f
end

# variance of an array of numbers
def variance2
avg=self.mean
sum=self.inject(0){|acc,i|acc +(i-avg)**2}
return(1/self.length.to_f*sum)
end

def squares
self.inject(0){|a,x|x.square+a}
end

def variance
self.squares.to_f/self.size - self.mean.square
end

# standard deviation of an array of numbers
def standard_deviation
return Math.sqrt(self.variance)
end

end # module Enumerable
require 'script/math_stuff.rb'


def find_obj(objs, fpu_part_id)
Expand Down
16 changes: 10 additions & 6 deletions script/calculate_promoter_fpu_performance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ def group_by_method(designs, method_name)
:mean => nil,
:sd => nil,
:normalized_mean => nil,
:normalized_sd => nil
:normalized_sd => nil,
:strains => []
}
end

objs[key][:numbers] << design.performance
objs[key][:strains] << design.strain_biofab_id
end

max = 0
Expand All @@ -31,8 +33,8 @@ def group_by_method(designs, method_name)
end

objs.each_key do |key|
objs[key][:normalized_mean] = objs[key][:mean] / max
objs[key][:normalized_sd] = objs[key][:sd] / max
objs[key][:normalized_mean] = objs[key][:mean]
objs[key][:normalized_sd] = objs[key][:sd]
end

objs
Expand All @@ -46,6 +48,8 @@ def group_by_method(designs, method_name)
fpus = group_by_method(designs, :fpu_biofab_id)
promoters = group_by_method(designs, :promoter_biofab_id)

# TODO before merge, promoter-mean-center fpus and fpu-mean-center fpus

objs = fpus.merge(promoters) do |key, val1, val2|
raise "hash merge conflict for key #{key}"
end
Expand All @@ -56,7 +60,7 @@ def group_by_method(designs, method_name)
objs.each_key do |key|
obj = objs[key]

puts "#{obj[:key]} - #{objs[key][:numbers].length} - #{obj[:normalized_mean] * 100}"
puts "#{obj[:key]} - #{objs[key][:numbers].length} - #{obj[:normalized_mean]} - #{obj[:normalized_sd]} - #{obj[:strains]}"

part = Part.find_by_biofab_id(obj[:key])
raise "Could not find part with biofab id #{obj[:key]}" if !part
Expand All @@ -66,8 +70,8 @@ def group_by_method(designs, method_name)
perf.part_id = part.id
end

perf.performance = obj[:normalized_mean] * 100
perf.performance_sd = obj[:normalized_sd] * 100
perf.performance = obj[:normalized_mean]
perf.performance_sd = obj[:normalized_sd]

perf.save!
end
Expand Down
Loading

0 comments on commit dea7c13

Please sign in to comment.