diff options
-rw-r--r-- | assignments/hw01/flash4.jpg | bin | 0 -> 369783 bytes | |||
-rw-r--r-- | assignments/hw01/notes.txt | 8 | ||||
-rw-r--r-- | assignments/hw01/question1.jl | 40 | ||||
-rw-r--r-- | assignments/hw01/question2_to_8.jl | 87 | ||||
-rw-r--r-- | assignments/hw01/sampledata2.mat | bin | 0 -> 4916 bytes | |||
-rw-r--r-- | julia/misc.jl | 27 |
6 files changed, 162 insertions, 0 deletions
diff --git a/assignments/hw01/flash4.jpg b/assignments/hw01/flash4.jpg Binary files differnew file mode 100644 index 0000000..5865a58 --- /dev/null +++ b/assignments/hw01/flash4.jpg diff --git a/assignments/hw01/notes.txt b/assignments/hw01/notes.txt new file mode 100644 index 0000000..c2f0795 --- /dev/null +++ b/assignments/hw01/notes.txt @@ -0,0 +1,8 @@ + + +### Question 1: 3rd (big spike, little bump) + +### Question 2: 2nd ("There are more patients who are older than 50...") + +### Question >3: (see question2_to_8.jl) + diff --git a/assignments/hw01/question1.jl b/assignments/hw01/question1.jl new file mode 100644 index 0000000..32be340 --- /dev/null +++ b/assignments/hw01/question1.jl @@ -0,0 +1,40 @@ + +using ImageView, Images +img = imread("flash4.jpg") +img.data = img.data' +#display(img, pixelspacing = [1,1]) + +# flash is 220 to 280 in the x-axis +# flash_data = img.data[220:280,:] +flash_avg = Float64[mean(img.data[r, 220:280]) for r = 1:size(img.data,1)] +noflash_avg = Float64[mean(img.data[r, 300:400]) for r = 1:size(img.data,1)] + +# using Winston +# plot(flash_avg) +# plot(noflash_avg) + +# WRONG: background_F = Float64[mean(img.data[70:100, :])] +background_avg = Float64[mean(img.data[r, 70:100]) for r = 1:size(img.data,1)] + +flash_avg ./= background_avg +noflash_avg ./= background_avg + +function unitify(r, Ca2_baseline, K_D) + return r * K_D / ((K_D/Ca2_baseline) - r + 1) +end + +Ca2_baseline = 100 +K_D = 700 + +#Ca2_baseline = 150 +#K_D = 1000 + +dT = 1.53 +t = dT * [0:length(flash_avg)] +figure() +hold(true) +plot(t, Float64[unitify(v, Ca2_baseline, K_D) for v = flash_avg[:]], color="red") +plot(t, Float64[unitify(v, Ca2_baseline, K_D) for v = noflash_avg[:]], color="blue") +ylabel("[ca](nM)") +xlabel("Time (ms)") + diff --git a/assignments/hw01/question2_to_8.jl b/assignments/hw01/question2_to_8.jl new file mode 100644 index 0000000..3cf9dc9 --- /dev/null +++ b/assignments/hw01/question2_to_8.jl @@ -0,0 +1,87 @@ + +using MAT + +all_vars= matread("sampledata2.mat") +d = all_vars["data"] + +# ----------------------- Q2 +length(filter(x -> x > 5, d[:, 2])) / length(d[:, 2]) +# 0.19, so first statement is false + +length(filter(x -> x > 50, d[:, 1])) +# 56x over 50 + +length(filter(x -> x < 20, d[:, 1])) +# 4x under 20 +# second statement is true + +length(filter(x -> x < 5, d[:, 2])) +# 243 +length(filter(x -> x > 6, d[:, 2])) +# 34 +# third statement is false + +length(filter(x -> x > 0.5, d[:, 3])) / length(d[:, 3]) +# 0.5233333333333333 +# last statement is false + +# ----------------------- Q3 + +using Winston + +# TODO: this foldl business is ugly +with_cancer = foldl(vcat, filter(x -> x[3] > 0.5, [d[row, :] for row = 1:size(d,1)])) +without_cancer = foldl(vcat, filter(x -> x[3] < 0.5, [d[row, :] for row = 1:size(d,1)])) + +figure() +p = FramedPlot() +add(p, Histogram(hist(with_cancer[:, 1], 15:10:75)..., color="red")) + +# 1 NO (this is "without") +# 2 yes +# 3 NO +# 4 NO + +# ----------------------- Q4 + +add(p, Histogram(hist(without_cancer[:, 1], 15:10:75)..., color="green")) +# 1 YES + +# ----------------------- Q5 + +function fractional(f, d) + return length(filter(f, d)) / length(d) +end + +fractional(x -> x>55, without_cancer[:, 1]) +#0.013986013986013986 + +fractional(x -> x<25, without_cancer[:, 1]) +#0.08391608391608392 +# FALSE + +fractional(x -> x<35, without_cancer[:, 1]) +# FALSE + +fractional(x -> x<30, with_cancer[:, 1]) / fractional(x -> x>60, with_cancer[:, 1]) +# TRUE! + +fractional(x -> x>45, with_cancer[:, 1]) +# FALSE + +# ----------------------- Q6 + +fractional(x -> x>35, with_cancer[:, 1]) +# 0.802547770700637 + +# ----------------------- Q7 + +fractional(x -> x<25, d[:, 1]) +# 0.06 + +# ----------------------- Q8 + +drinkers = foldl(vcat, filter(x -> x[2] > 3, [d[row, :] for row = 1:size(d,1)])) +fractional(x -> x >0.5, drinkers[:, 3]) +# 0.6459627329192547 + diff --git a/assignments/hw01/sampledata2.mat b/assignments/hw01/sampledata2.mat Binary files differnew file mode 100644 index 0000000..86317df --- /dev/null +++ b/assignments/hw01/sampledata2.mat diff --git a/julia/misc.jl b/julia/misc.jl new file mode 100644 index 0000000..5d98e0b --- /dev/null +++ b/julia/misc.jl @@ -0,0 +1,27 @@ +### Julia image manipulation + +Pkg.update() +Pkg.add("Images") +Pkg.add("ImageView") + +using ImageView, Images +img = imread("my_photo.jpg") +# eg, rotate via a matrix transform +img.data = img.data' +display(img, pixelspacing = [1,1]) + +### Julia .mat loating + +Pkg.update() +Pkg.add("MAT") +using MAT +file = matopen("matfile.mat") +read(file, "varname") +close(file) + +file = matopen("matfile.mat", "w") +write(file, "varname", variable) +close(file) + +vars = matread("matfile.mat") + |