Skip to content

Commit

Permalink
compartmentalize simulation code and squash overwrite warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
tlnagy committed Aug 10, 2016
1 parent 65f40e3 commit db90e49
Show file tree
Hide file tree
Showing 17 changed files with 56 additions and 40 deletions.
2 changes: 2 additions & 0 deletions src/exps/common.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import CRISPulator: Delta, array_names

function build_parameter_space{T <: ScreenSetup}(::T, parameters::Dict{Symbol, Vector}, num_runs::Int)
fields = collect(keys(parameters))
n_fields = length(fields)
Expand Down
3 changes: 2 additions & 1 deletion src/exps/compare_methods.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# This experiment will compare the behavior of pvalue, effect size, and
# product over a wide range of screen and library designs
import CRISPulator: as_array

function main(filepath; debug=false, quiet=false)
function compare_methods(filepath; debug=false, quiet=false)

runs = []

Expand Down
2 changes: 1 addition & 1 deletion src/exps/facs_binning.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function main(filepath; debug=false, quiet=false)
function facs_binning(filepath; debug=false, quiet=false)
if !debug
parameters = Dict{Symbol, Vector}(
:representation => [10, 100, 1000],
Expand Down
2 changes: 1 addition & 1 deletion src/exps/facs_binning_snr.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function main(filepath; debug=false, quiet=false)
function facs_binning_snr(filepath; debug=false, quiet=false)
if !debug
parameters = Dict{Symbol, Vector}(
:representation => [10, 100, 1000],
Expand Down
2 changes: 1 addition & 1 deletion src/exps/gen_plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using Gadfly
using ColorBrewer

function main(filepath; debug=false, quiet=false)
function gen_plots(filepath; debug=false, quiet=false)
colors = palette("Accent", 4)

for screentype in [FacsScreen(), GrowthScreen()]
Expand Down
2 changes: 1 addition & 1 deletion src/exps/growth_bottleneck_snr.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function main(filepath; debug=false, quiet=false)
function growth_bottleneck_snr(filepath; debug=false, quiet=false)
if !debug
parameters = Dict{Symbol, Vector}(
:representation => [10, 100, 1000],
Expand Down
2 changes: 1 addition & 1 deletion src/exps/growth_bottlenecks.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function main(filepath; debug=false, quiet=false)
function growth_bottlenecks(filepath; debug=false, quiet=false)
if !debug
parameters = Dict{Symbol, Vector}(
:num_genes => repeat([5000], inner=[3]),
Expand Down
4 changes: 3 additions & 1 deletion src/exps/growth_representation.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
function main(filepath; debug=false, quiet=false)
import CRISPulator: flatten_both

function growth_representation(filepath; debug=false, quiet=false)
if !debug
parameters = Dict{Symbol, Vector}(
:representation => [10, 100, 1000],
Expand Down
3 changes: 2 additions & 1 deletion src/exps/growth_sensitivity_library.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Growth screens seem to be highly susceptible to the distribution of
# genes that promote growth versus that hurt it. This experiment tests
# the behavior of growth screens under several different library setups
import CRISPulator: flatten_both

function main(filepath; debug=false, quiet=false)
function growth_sensitivity_library(filepath; debug=false, quiet=false)

if !debug

Expand Down
2 changes: 1 addition & 1 deletion src/exps/scan_rep_space.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# is important: at transfection, at the bottleneck(s), and at
# sequencing.

function main(filepath; debug=false, quiet=false)
function scan_rep_space(filepath; debug=false, quiet=false)

if !debug
parameters = Dict{Symbol, Vector}(
Expand Down
47 changes: 25 additions & 22 deletions src/simulation/load.jl
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
print("Loading simulation framework...")
"""
A pooled genetic screen simulator
"""
module CRISPulator

packages = [:StatsBase,
:Distributions,
:DataFrames,
:HypothesisTests,
:Iterators]
export ScreenSetup, FacsScreen, GrowthScreen
export Library, CRISPRi, CRISPRn
export KDPhenotypeRelationship
export run_exp
export auroc, venn, auprc, signal, noise

for package in packages
eval(:(using $package))
eval(:(@everywhere using $package))
end
using StatsBase
using Distributions
using DataFrames
using HypothesisTests
using Iterators
using Compat
import Compat: UTF8String, ASCIIString, view

# Load all simulations files on all workers
@everywhere function include_all(curr_dir)
filenames = ["common.jl", "utils.jl", "library.jl", "transfection.jl",
"selection.jl", "sequencing.jl", "processing.jl",
"designs.jl"]
for filename in filenames
include(joinpath(curr_dir, filename))
end
end
curr_dir = Base.source_dir()
@eval @everywhere include_all($curr_dir)
include("common.jl")
include("utils.jl")
include("library.jl")
include("transfection.jl")
include("selection.jl")
include("sequencing.jl")
include("processing.jl")
include("designs.jl")

println("Done.")
end
8 changes: 4 additions & 4 deletions src/simulation/utils.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Base.count(labels::AbstractArray{Symbol}, pos_labels::Set{Symbol})
function partition(labels::AbstractArray{Symbol}, pos_labels::Set{Symbol})
num_pos, num_neg = 0, 0
for label in labels
if label in pos_labels
Expand All @@ -22,7 +22,7 @@ function auroc(scores::AbstractArray{Float64}, classes::AbstractArray{Symbol},
num_scores = length(scores)
ordering = sortperm(scores, rev=rev)
labels = classes[ordering]
num_pos, num_neg = count(labels, pos_labels)
num_pos, num_neg = partition(labels, pos_labels)

tprs = Array(Float64, num_scores)
fprs = Array(Float64, num_scores)
Expand Down Expand Up @@ -67,7 +67,7 @@ function auprc(scores::AbstractArray{Float64}, classes::AbstractArray{Symbol},
num_scores = length(scores) + 1
ordering = sortperm(scores, rev=rev)
labels = classes[ordering]
num_pos, num_neg = count(labels, pos_labels)
num_pos, num_neg = partition(labels, pos_labels)

tn, fn, tp, fp = 0, 0, num_pos, num_neg

Expand Down Expand Up @@ -114,7 +114,7 @@ function venn(scores::AbstractArray{Float64}, classes::AbstractArray{Symbol},
num_scores = length(scores)
ordering = sortperm(scores, rev=rev)
labels = classes[ordering]
num_pos, num_neg = count(labels, pos_labels)
num_pos, num_neg = partition(labels, pos_labels)

n_venn = round(Int, num_pos/2)
n_correct = 0
Expand Down
2 changes: 2 additions & 0 deletions test/diffcrisprtransfection.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import CRISPulator: construct_library, build_cells

function convert_cells_to_pop(cells, cell_phenotypes, guides)
cells_to_phenotypes = [DefaultDict(Float64, Int, 0) for _ in 1:length(guides)]

Expand Down
1 change: 1 addition & 0 deletions test/growth.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using StatsBase
import CRISPulator: grow!

function test_grow_function(phenotypes, expected)
@assert length(phenotypes) == length(expected)
Expand Down
2 changes: 2 additions & 0 deletions test/kdrelationships.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import CRISPulator: Linear, Sigmoidal, response

linear_response = response(Linear())

@test linear_response(0.0, 1.0) == 0.0
Expand Down
10 changes: 5 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ include(normpath(joinpath(Base.source_dir(),"..",load_file)))

using Base.Test
using DataStructures
using ColorBrewer
using Gadfly
using Compat
import Compat: UTF8String, ASCIIString, view
using Distributions
using DataFrames
using CRISPulator

println("Running tests:")
filenames = ["kdrelationships.jl",
Expand Down Expand Up @@ -54,7 +53,8 @@ for analysis in analyses
end
include(joinpath(analyses_path, analysis))
tempfile = tempname()
main(tempfile, debug=true, quiet=true)
func_name = Symbol(splitext(analysis)[1])
getfield(Main, func_name)(tempfile, debug=true, quiet=true)
println("\t\033[1m\033[32mPASSED\033[0m: $(analysis)")
catch e
errorfound = true
Expand Down
2 changes: 2 additions & 0 deletions test/selectionmethods.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import CRISPulator: Barcode, select

function testselection(setup)
N = setup.num_genes
guides = Barcode[]
Expand Down

0 comments on commit db90e49

Please sign in to comment.