Skip to content

Commit

Permalink
make processing less rigid, allow passing of process funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
tlnagy committed May 12, 2016
1 parent ac09b6c commit 6d8dfae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 45 deletions.
23 changes: 15 additions & 8 deletions src/designs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ end
function teardown_screen(setup::ScreenSetup,
guides::Vector{Barcode},
bin_cells::Dict{Symbol,Vector{Int64}},
testalg::Bool)
processing_func::Function)

freqs = counts_to_freqs(bin_cells, length(guides))
raw_data = sequencing(Dict(:bin1=>setup.seq_depth,:bin2=>setup.seq_depth), guides, freqs)

analyze(raw_data, gen_plots=false, testmethod=testalg)

genes = difference_between_two_bins(raw_data)
processing_func(genes)
end

function run_exp(setup::FacsScreen, lib::Library; run_idx=-1, testalg=false)
"""
Runs a FACS screen given the parameters specified in `setup` using the
library `lib` and applies the `processing_func` function to the result.
"""
function run_exp(setup::FacsScreen, lib::Library, processing_func::Function; run_idx=-1)

guides, guide_freqs_dist = setup_screen(setup, lib)

Expand All @@ -27,16 +30,20 @@ function run_exp(setup::FacsScreen, lib::Library; run_idx=-1, testalg=false)

bin_cells = facs_sort(cells, guides, setup.bin_info, setup.σ)

[teardown_screen(setup, guides, bin_cells, testalg)...; as_array(setup)...; run_idx]
[teardown_screen(setup, guides, bin_cells, processing_func)...; as_array(setup)...; run_idx]
end

function run_exp(setup::GrowthScreen, lib::Library; run_idx=-1, testalg=false)
"""
Runs a growth screen given the parameters specified in `setup` using the
library `lib` and applies the `processing_func` function to the result.
"""
function run_exp(setup::GrowthScreen, lib::Library, processing_func::Function; run_idx=-1)

guides, guide_freqs_dist = setup_screen(setup, lib)

cells, num_doublings = transfect(setup, guides, guide_freqs_dist)

bin_cells = growth_assay(cells, guides, setup.num_bottlenecks, setup.bottleneck_representation)

[teardown_screen(setup, guides, bin_cells, testalg)...; as_array(setup)...; run_idx]
[teardown_screen(setup, guides, bin_cells, processing_func)...; as_array(setup)...; run_idx]
end
39 changes: 2 additions & 37 deletions src/processing.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function analyze(raw_data::Dict{Symbol, DataFrame}; gen_plots=false, testmethod=false)
function difference_between_two_bins(raw_data::Dict{Symbol, DataFrame})
for (bin, seq_data) in raw_data
sort!(seq_data, cols=[:barcodeid])
# add a pseudocount of 0.5 to every value to prevent -Inf's when
Expand All @@ -24,40 +24,5 @@ function analyze(raw_data::Dict{Symbol, DataFrame}; gen_plots=false, testmethod=
genes[:absmean] = abs(genes[:mean])
genes[:pvalmeanprod] = genes[:absmean] .* genes[:pvalue]

get_auroc = x -> compute_auroc(Vector(genes[x]), Vector(genes[:class]), 100)
if testmethod
auroc = map(get_auroc, [:pvalue, :absmean, :pvalmeanprod])
else
auroc = get_auroc(:pvalmeanprod)
end

if gen_plots
draw(PNG("plots/volcano_plot_by_behavior.png", 12cm, 10cm, dpi=300),
plot(genes, x=:mean, y=:pvalue, color=:behavior, Guide.xlabel("mean log2 FC"),
Guide.ylabel("-log10 pvalue"), Theme(highlight_width=0pt)))
draw(PNG("plots/volcano_plot_by_class.png", 12cm, 10cm, dpi=300),
plot(genes, x=:mean, y=:pvalue, color=:class, Theme(highlight_width=0pt)))

# remove guides that weren't observed during sorting
filtered = combined[isfinite(combined[:obs_phenotype]), :]

draw(PNG("plots/distributions_of_observed_phenotypes.png", 12cm, 6cm, dpi=300),
plot(filtered, x=:obs_phenotype, color=:class, Geom.density))
draw(PNG("plots/freq_scatter.png", 12cm, 10cm, dpi=300),
plot(filtered, x=:freqs1, y=:freqs2, color=:class, Scale.x_log10, Scale.y_log10,
Theme(highlight_width=0pt)))

# ROC plots

_, s_tprs, s_fprs = compute_roc(genes[genes[:behavior] .== :sigmoidal, :], :pvalmeanprod, 50)
_, l_tprs, l_fprs = compute_roc(genes[genes[:behavior] .== :linear, :], :pvalmeanprod, 50)

data = DataFrame(tprs=vcat(s_tprs, l_tprs), fprs = vcat(s_fprs, l_fprs),
behavior=vcat(rep(:sigmoidal,50), rep(:linear, 50)))

draw(PNG("plots/roc.png", 12cm, 10cm, dpi=300),
plot(data, x=:fprs, y=:tprs, color=:behavior, Geom.line, Coord.cartesian(fixed=true),
Guide.xlabel("fpr"), Guide.ylabel("tpr")))
end
auroc
genes
end

0 comments on commit 6d8dfae

Please sign in to comment.