Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Lucy McNeill
synapsis
Commits
ed7cdbc8
Commit
ed7cdbc8
authored
Jul 12, 2021
by
Lucy McNeill
Browse files
= assignements changed to <-
parent
825fb10e
Changes
7
Hide whitespace changes
Inline
Side-by-side
.DS_Store
View file @
ed7cdbc8
No preview for this file type
R/auto_crop.R
View file @
ed7cdbc8
...
...
@@ -41,25 +41,25 @@ auto_crop <- function(img_path, max_cell_area = 20000, min_cell_area = 7000, me
## for each image that is *-dna.jpeg,
for
(
img_file
in
file_list
){
print
(
img_file
)
file_base
=
img_file
filename_path_test
=
paste0
(
img_path
,
"/"
,
img_file
)
img_file
=
filename_path_test
file_base
<-
img_file
filename_path_test
<-
paste0
(
img_path
,
"/"
,
img_file
)
img_file
<-
filename_path_test
if
(
grepl
(
"*DAPI.jpeg$"
,
img_file
)){
file_DAPI
=
img_file
file_DAPI
<-
img_file
image
<-
readImage
(
file_DAPI
)
img_orig_DAPI
<-
channel
(
image
,
"grey"
)
antibody3_store
<-
1
}
if
(
grepl
(
"*SYCP3.jpeg$"
,
img_file
)){
file_dna
=
img_file
file_dna
<-
img_file
image
<-
readImage
(
file_dna
)
img_orig
<-
channel
(
2
*
image
,
"grey"
)
antibody1_store
<-
1
}
if
(
grepl
(
"*MLH3.jpeg$"
,
img_file
)){
file_foci
=
img_file
file_foci
<-
img_file
image
<-
readImage
(
file_foci
)
img_orig_foci
<-
channel
(
image
,
"gray"
)
# call functions: get
...
...
@@ -76,7 +76,7 @@ auto_crop <- function(img_path, max_cell_area = 20000, min_cell_area = 7000, me
## call it on img_orig, optional offset
blob_th
<-
get_blobs
(
img_orig
,
blob_factor
,
bg_blob_factor
,
offset
,
final_blob_amp
,
brush_size_blob
,
sigma_blob
)
blob_label
=
bwlabel
(
blob_th
)
blob_label
<-
bwlabel
(
blob_th
)
blob_label
<-
channel
(
blob_label
,
"gray"
)
candidate
<-
bwlabel
(
blob_label
)
...
...
@@ -152,12 +152,12 @@ get_blobs <- function(img_orig, blob_factor, bg_blob_factor, offset,final_blob_a
img_tmp_dna
<-
img_orig
img_tmp
<-
thresh
#w = makeBrush(size = 51, shape = 'gaussian', sigma = 15)
w
=
makeBrush
(
size
=
brush_size_blob
,
shape
=
'gaussian'
,
sigma
=
sigma_blob
)
img_flo
=
filter2
(
img_tmp
,
w
)
w
<-
makeBrush
(
size
=
brush_size_blob
,
shape
=
'gaussian'
,
sigma
=
sigma_blob
)
img_flo
<-
filter2
(
img_tmp
,
w
)
## default amplification
bg
<-
mean
(
bg_blob_factor
*
img_tmp
)
#if(crop_method == "regular"){
blob_th
=
final_blob_amp
*
img_flo
>
bg
+
offset
blob_th
<-
final_blob_amp
*
img_flo
>
bg
+
offset
#}
#if(crop_method == "watershed"){
...
...
@@ -193,7 +193,7 @@ keep_cells <- function(candidate, max_cell_area, min_cell_area, cell_aspect_rati
while
(
counter
<
OOI
){
counter
<-
counter
+1
pixel_area
=
x
$
s.area
[
counter
]
pixel_area
<-
x
$
s.area
[
counter
]
semi_maj
<-
x
$
s.radius.max
[
counter
]
semi_min
<-
x
$
s.radius.min
[
counter
]
# if statement checking if it's the wrong area
...
...
@@ -269,9 +269,9 @@ crop_single_object <- function(retained, OOI_final,counter_final,img_orig,img_or
row_list
<-
c
()
col_list
<-
c
()
# I think this is quick enough for now.. takes less than 10s...
xx
=
data.frame
(
as.numeric
(
tmp_img
))
xx
<-
data.frame
(
as.numeric
(
tmp_img
))
xx
<-
data.frame
(
bwlabel
(
tmp_img
))
my_matrix
=
t
(
as.matrix
(
xx
))
my_matrix
<-
t
(
as.matrix
(
xx
))
i
<-
0
### now loop over matrix
for
(
row
in
1
:
nrow
(
my_matrix
))
{
...
...
@@ -328,19 +328,19 @@ crop_single_object <- function(retained, OOI_final,counter_final,img_orig,img_or
print
(
file_dna
)
file_dna
<-
gsub
(
'-SYCP3.jpeg'
,
''
,
file_base
)
print
(
file_dna
)
filename_crop
=
paste0
(
img_path
,
"/crops/"
,
file_dna
,
"-crop-"
,
cell_count
,
"-SYCP3.jpeg"
)
filename_crop
<-
paste0
(
img_path
,
"/crops/"
,
file_dna
,
"-crop-"
,
cell_count
,
"-SYCP3.jpeg"
)
writeImage
(
new_img
,
filename_crop
)
new_img_foci
<-
noise_gone_foci
[
ix
,
iy
]
#file_foci <- tools::file_path_sans_ext(file_foci)
file_foci
<-
gsub
(
'-MLH3.jpeg'
,
''
,
file_foci
)
filename_crop_foci
=
paste0
(
img_path
,
"/crops/"
,
file_dna
,
"-crop-"
,
cell_count
,
"-MLH3.jpeg"
)
filename_crop_foci
<-
paste0
(
img_path
,
"/crops/"
,
file_dna
,
"-crop-"
,
cell_count
,
"-MLH3.jpeg"
)
writeImage
(
new_img_foci
,
filename_crop_foci
)
new_img_DAPI
<-
noise_gone_DAPI
[
ix
,
iy
]
#file_foci <- tools::file_path_sans_ext(file_foci)
file_DAPI
<-
gsub
(
'-DAPI.jpeg'
,
''
,
file_DAPI
)
filename_crop_DAPI
=
paste0
(
img_path
,
"/crops/"
,
file_dna
,
"-crop-"
,
cell_count
,
"-DAPI.jpeg"
)
filename_crop_DAPI
<-
paste0
(
img_path
,
"/crops/"
,
file_dna
,
"-crop-"
,
cell_count
,
"-DAPI.jpeg"
)
writeImage
(
new_img_DAPI
,
filename_crop_DAPI
)
if
(
annotation
==
"on"
){
...
...
R/auto_crop_fast.R
View file @
ed7cdbc8
...
...
@@ -44,13 +44,13 @@ auto_crop_fast <- function(img_path, max_cell_area = 20000, min_cell_area = 700
## for each image that is *-dna.jpeg,
for
(
img_file
in
file_list
){
file_base
=
img_file
filename_path_test
=
paste0
(
img_path
,
"/"
,
img_file
)
img_file
=
filename_path_test
file_base
<-
img_file
filename_path_test
<-
paste0
(
img_path
,
"/"
,
img_file
)
img_file
<-
filename_path_test
#if(grepl("*DAPI.jpeg$", file)){
if
(
third_channel
==
"on"
){
if
(
grepl
(
paste0
(
'*'
,
channel3_string
,
'.'
,
file_ext
,
'$'
),
img_file
)){
file_DAPI
=
img_file
file_DAPI
<-
img_file
image
<-
readImage
(
file_DAPI
)
img_orig_DAPI
<-
channel
(
image
,
"grey"
)
antibody3_store
<-
1
...
...
@@ -59,7 +59,7 @@ auto_crop_fast <- function(img_path, max_cell_area = 20000, min_cell_area = 700
#if(grepl("*SYCP3.jpeg$", file)){
if
(
grepl
(
paste0
(
'*'
,
channel2_string
,
'.'
,
file_ext
,
'$'
),
img_file
)){
file_dna
=
img_file
file_dna
<-
img_file
print
(
file
)
image
<-
readImage
(
file_dna
)
img_orig
<-
channel
(
2
*
image
,
"grey"
)
...
...
@@ -67,7 +67,7 @@ auto_crop_fast <- function(img_path, max_cell_area = 20000, min_cell_area = 700
}
#if(grepl("*MLH3.jpeg$", file)){
if
(
grepl
(
paste0
(
'*'
,
channel1_string
,
'.'
,
file_ext
,
'$'
),
img_file
)){
file_foci
=
img_file
file_foci
<-
img_file
image
<-
readImage
(
file_foci
)
img_orig_foci
<-
channel
(
image
,
"gray"
)
# call functions: get
...
...
@@ -85,7 +85,7 @@ auto_crop_fast <- function(img_path, max_cell_area = 20000, min_cell_area = 700
#### function: blur the image
## call it on img_orig, optional offset
blob_th
<-
get_blobs
(
img_orig
,
blob_factor
,
bg_blob_factor
,
offset
,
final_blob_amp
,
brush_size_blob
,
sigma_blob
)
blob_label
=
bwlabel
(
blob_th
)
blob_label
<-
bwlabel
(
blob_th
)
blob_label
<-
channel
(
blob_label
,
"gray"
)
candidate
<-
bwlabel
(
blob_label
)
## function: remove things that aren't cells
...
...
@@ -228,20 +228,20 @@ crop_single_object_fast <- function(retained, OOI_final,counter_final,img_orig,i
#file_dna <- tools::file_path_sans_ext(file_dna)
file_stub
<-
paste0
(
'-'
,
channel2_string
,
'.'
,
file_ext
)
file_dna
<-
gsub
(
file_stub
,
''
,
file_base
)
filename_crop
=
paste0
(
img_path
,
"/crops/"
,
file_dna
,
"-crop-"
,
cell_count
,
file_stub
)
filename_crop
<-
paste0
(
img_path
,
"/crops/"
,
file_dna
,
"-crop-"
,
cell_count
,
file_stub
)
writeImage
(
new_img
,
filename_crop
)
new_img_foci
<-
noise_gone_foci
[
ix
,
iy
]
file_stub
<-
paste0
(
'-'
,
channel1_string
,
'.'
,
file_ext
)
file_foci
<-
gsub
(
file_stub
,
''
,
file_foci
)
filename_crop_foci
=
paste0
(
img_path
,
"/crops/"
,
file_dna
,
"-crop-"
,
cell_count
,
file_stub
)
filename_crop_foci
<-
paste0
(
img_path
,
"/crops/"
,
file_dna
,
"-crop-"
,
cell_count
,
file_stub
)
writeImage
(
new_img_foci
,
filename_crop_foci
)
if
(
third_channel
==
"on"
){
new_img_DAPI
<-
noise_gone_DAPI
[
ix
,
iy
]
#file_DAPI <- gsub('-DAPI.jpeg','', file_DAPI)
file_stub
<-
paste0
(
'-'
,
channel3_string
,
'.'
,
file_ext
)
file_DAPI
<-
gsub
(
file_stub
,
''
,
file_DAPI
)
filename_crop_DAPI
=
paste0
(
img_path
,
"/crops/"
,
file_dna
,
"-crop-"
,
cell_count
,
file_stub
)
filename_crop_DAPI
<-
paste0
(
img_path
,
"/crops/"
,
file_dna
,
"-crop-"
,
cell_count
,
file_stub
)
writeImage
(
new_img_DAPI
,
filename_crop_DAPI
)
}
...
...
R/count_foci.R
View file @
ed7cdbc8
...
...
@@ -48,16 +48,16 @@ count_foci <- function(img_path, stage = "none", offset_px = 0.2, offset_factor
## for each image that is *-dna.jpeg,
for
(
img_file
in
file_list
){
if
(
stage
==
"pachytene"
){
filename_path_test
=
paste0
(
img_path
,
"/crops/"
,
stage
,
"/"
,
img_file
)
filename_path_test
<-
paste0
(
img_path
,
"/crops/"
,
stage
,
"/"
,
img_file
)
}
else
{
filename_path_test
=
paste0
(
img_path
,
"/crops/"
,
img_file
)
filename_path_test
<-
paste0
(
img_path
,
"/crops/"
,
img_file
)
}
img_file
=
filename_path_test
img_file
<-
filename_path_test
#if(grepl("*SYCP3.jpeg", file)){
if
(
grepl
(
paste0
(
'*'
,
channel2_string
,
'.'
,
file_ext
,
'$'
),
img_file
)){
file_dna
=
img_file
file_dna
<-
img_file
image_count
<-
image_count
+1
image
<-
readImage
(
file_dna
)
img_orig
<-
channel
(
2
*
image
,
"grey"
)
...
...
@@ -65,7 +65,7 @@ count_foci <- function(img_path, stage = "none", offset_px = 0.2, offset_factor
}
#if(grepl("*MLH3.jpeg", file)){
if
(
grepl
(
paste0
(
'*'
,
channel1_string
,
'.'
,
file_ext
,
'$'
),
img_file
)){
file_foci
=
img_file
file_foci
<-
img_file
image
<-
readImage
(
file_foci
)
img_orig_foci
<-
channel
(
image
,
"gray"
)
# call functions: get
...
...
@@ -77,15 +77,15 @@ count_foci <- function(img_path, stage = "none", offset_px = 0.2, offset_factor
cell_count
<-
cell_count
+
1
new_img
<-
img_orig
disc
=
makeBrush
(
21
,
"disc"
)
disc
=
disc
/
sum
(
disc
)
localBackground
=
filter2
(
new_img
,
disc
)
offset
=
offset_px
disc
<-
makeBrush
(
21
,
"disc"
)
disc
<-
disc
/
sum
(
disc
)
localBackground
<-
filter2
(
new_img
,
disc
)
offset
<-
offset_px
if
(
stage
==
"pachytene"
){
thresh_crop
=
(
new_img
-
localBackground
>
offset
)
thresh_crop
<-
(
new_img
-
localBackground
>
offset
)
}
else
{
thresh_crop
=
new_img
>
offset
thresh_crop
<-
new_img
>
offset
}
strands
<-
bwlabel
(
thresh_crop
)
color_img_strands
<-
colorLabels
(
strands
,
normalize
=
TRUE
)
...
...
@@ -98,23 +98,23 @@ count_foci <- function(img_path, stage = "none", offset_px = 0.2, offset_factor
img_orig_foci
<-
img_orig_foci
*
mean_factor
#### normalise the foci image
offset
=
offset_factor
*
bg
offset
<-
offset_factor
*
bg
if
(
stage
!=
"pachytene"
){
foci_th
=
foci_mask_crop
>
bg
+
offset
foci_th
<-
foci_mask_crop
>
bg
+
offset
#foci_th <- watershed(bwlabel(foci_th)*as.matrix(img_orig_foci),tolerance=0.05, ext=1)
}
else
{
### smooth it
img_tmp_contrast
=
foci_mask_crop
w
=
makeBrush
(
size
=
brush_size
,
shape
=
'gaussian'
,
sigma
=
brush_sigma
)
img_tmp_contrast
<-
foci_mask_crop
w
<-
makeBrush
(
size
=
brush_size
,
shape
=
'gaussian'
,
sigma
=
brush_sigma
)
#w = makeBrush(size = 1, shape = 'gaussian', sigma = 3)
img_flo
=
filter2
(
img_tmp_contrast
,
w
)
img_flo
<-
filter2
(
img_tmp_contrast
,
w
)
## smooth foci channel
foci_th
=
img_flo
>
bg
+
offset
foci_th
<-
img_flo
>
bg
+
offset
}
foci_label
=
bwlabel
(
foci_th
)
foci_label
<-
bwlabel
(
foci_th
)
foci_label
<-
channel
(
foci_label
,
"grey"
)
num_strands
<-
computeFeatures.shape
(
strands
)
num_strands
<-
data.frame
(
num_strands
)
...
...
@@ -149,7 +149,7 @@ count_foci <- function(img_path, stage = "none", offset_px = 0.2, offset_factor
plot
(
rgbImage
(
strands
,
coincident_foci
,
coincident_foci
))
}
overlap_no
=
table
(
coincident_foci
)
overlap_no
<-
table
(
coincident_foci
)
foci_per_cell
<-
length
(
overlap_no
)
if
(
annotation
==
"on"
){
print
(
"which counts this many foci:"
)
...
...
R/get_pachytene.R
View file @
ed7cdbc8
...
...
@@ -37,13 +37,13 @@ get_pachytene <- function(img_path, species_num = 20, offset = 0.2,ecc_thresh =
file_list
<-
list.files
(
img_path_new
)
## for each image that is *-dna.jpeg,
for
(
img_file
in
file_list
){
file_base
=
img_file
filename_path_test
=
paste0
(
img_path
,
"/crops/"
,
img_file
)
img_file
=
filename_path_test
file_base
<-
img_file
filename_path_test
<-
paste0
(
img_path
,
"/crops/"
,
img_file
)
img_file
<-
filename_path_test
#if(grepl("*SYCP3.jpeg", file)){
if
(
grepl
(
paste0
(
'*'
,
channel2_string
,
'.'
,
file_ext
,
'$'
),
img_file
)){
file_dna
=
img_file
file_base_dna
=
file_base
file_dna
<-
img_file
file_base_dna
<-
file_base
image_count
<-
image_count
+1
image
<-
readImage
(
file_dna
)
img_orig
<-
channel
(
image
,
"grey"
)
...
...
@@ -51,8 +51,8 @@ get_pachytene <- function(img_path, species_num = 20, offset = 0.2,ecc_thresh =
}
#if(grepl("*MLH3.jpeg", file)){
if
(
grepl
(
paste0
(
'*'
,
channel1_string
,
'.'
,
file_ext
,
'$'
),
img_file
)){
file_base_foci
=
file_base
file_foci
=
img_file
file_base_foci
<-
file_base
file_foci
<-
img_file
#print(file_foci)
image
<-
readImage
(
file_foci
)
img_orig_foci
<-
channel
(
image
,
"gray"
)
...
...
@@ -64,10 +64,10 @@ get_pachytene <- function(img_path, species_num = 20, offset = 0.2,ecc_thresh =
antibody2_store
<-
0
new_img
<-
img_orig
#### now see which have the right amount of strands
disc
=
makeBrush
(
21
,
"disc"
)
disc
=
disc
/
sum
(
disc
)
localBackground
=
filter2
(
new_img
,
disc
)
thresh_crop
=
(
new_img
-
localBackground
>
offset
)
disc
<-
makeBrush
(
21
,
"disc"
)
disc
<-
disc
/
sum
(
disc
)
localBackground
<-
filter2
(
new_img
,
disc
)
thresh_crop
<-
(
new_img
-
localBackground
>
offset
)
strands
<-
bwlabel
(
thresh_crop
)
color_img_strands
<-
colorLabels
(
strands
,
normalize
=
TRUE
)
num_strands
<-
computeFeatures.shape
(
strands
)
...
...
@@ -111,14 +111,14 @@ get_pachytene <- function(img_path, species_num = 20, offset = 0.2,ecc_thresh =
df_cells
<-
rbind
(
df_cells
,
t
(
c
(
img_file
,
cell_count
,
genotype
,
px_mask
,
px_total
,
px_fraction
,
mean_ecc
,
mean_ratio
,
skew
,
sd_bright_px
,
stage_classification
)))
pachytene_count
<-
pachytene_count
+
1
file_dna
<-
tools
::
file_path_sans_ext
(
file_base_dna
)
filename_crop
=
paste0
(
img_path_new
,
"/pachytene/"
,
file_dna
,
".jpeg"
)
filename_crop
<-
paste0
(
img_path_new
,
"/pachytene/"
,
file_dna
,
".jpeg"
)
writeImage
(
img_orig
,
filename_crop
)
if
(
annotation
==
"on"
){
print
(
"decided the following is pachytene"
)
display
(
img_orig
)
}
file_foci
<-
tools
::
file_path_sans_ext
(
file_base_foci
)
filename_crop_foci
=
paste0
(
img_path_new
,
"/pachytene/"
,
file_foci
,
".jpeg"
)
filename_crop_foci
<-
paste0
(
img_path_new
,
"/pachytene/"
,
file_foci
,
".jpeg"
)
writeImage
(
img_orig_foci
,
filename_crop_foci
)
}
}
...
...
R/measure_distances.R
View file @
ed7cdbc8
...
...
@@ -44,11 +44,11 @@ measure_distances <- function(img_path,offset_px = 0.2, offset_factor = 3, brush
#colnames(df_lengths) <- df_cols
## for each image that is *-dna.jpeg,
for
(
img_file
in
file_list
){
filename_path_test
=
paste0
(
img_path
,
"/crops/"
,
stage
,
"/"
,
img_file
)
img_file
=
filename_path_test
filename_path_test
<-
paste0
(
img_path
,
"/crops/"
,
stage
,
"/"
,
img_file
)
img_file
<-
filename_path_test
if
(
grepl
(
paste0
(
'*'
,
channel2_string
,
'.'
,
file_ext
,
'$'
),
img_file
)){
#if(grepl("*SYCP3.jpeg", file)){
file_dna
=
img_file
file_dna
<-
img_file
image_count
<-
image_count
+1
image
<-
readImage
(
file_dna
)
img_orig
<-
channel
(
2
*
image
,
"grey"
)
...
...
@@ -56,7 +56,7 @@ measure_distances <- function(img_path,offset_px = 0.2, offset_factor = 3, brush
}
if
(
grepl
(
paste0
(
'*'
,
channel1_string
,
'.'
,
file_ext
,
'$'
),
img_file
)){
#if(grepl("*MLH3.jpeg", file)){
file_foci
=
img_file
file_foci
<-
img_file
image
<-
readImage
(
file_foci
)
img_orig_foci
<-
channel
(
image
,
"gray"
)
# call functions: get
...
...
@@ -69,15 +69,15 @@ measure_distances <- function(img_path,offset_px = 0.2, offset_factor = 3, brush
new_img
<-
img_orig
#display(new_img)
#### now see which have the right amount of strands
disc
=
makeBrush
(
21
,
"disc"
)
disc
=
disc
/
sum
(
disc
)
localBackground
=
filter2
(
new_img
,
disc
)
offset
=
offset_px
disc
<-
makeBrush
(
21
,
"disc"
)
disc
<-
disc
/
sum
(
disc
)
localBackground
<-
filter2
(
new_img
,
disc
)
offset
<-
offset_px
if
(
stage
==
"pachytene"
){
thresh_crop
=
(
new_img
-
localBackground
>
offset
)
thresh_crop
<-
(
new_img
-
localBackground
>
offset
)
}
else
{
thresh_crop
=
new_img
>
offset
thresh_crop
<-
new_img
>
offset
}
strands
<-
bwlabel
(
thresh_crop
)
#display(strands)
...
...
@@ -106,7 +106,7 @@ measure_distances <- function(img_path,offset_px = 0.2, offset_factor = 3, brush
coincident_foci
<-
watershed
(
bwlabel
(
foci_label
*
strands
)
*
as.matrix
(
img_orig_foci
),
tolerance
=
watershed_tol
,
ext
=
watershed_radius
)
}
#coincident_foci <- bwlabel(foci_label*strands)
overlap_no
=
table
(
coincident_foci
)
overlap_no
<-
table
(
coincident_foci
)
foci_per_cell
<-
length
(
overlap_no
)
### foci counting stuff ends
image_mat
<-
as.matrix
(
foci_mask_crop
)
...
...
@@ -143,10 +143,10 @@ measure_distances <- function(img_path,offset_px = 0.2, offset_factor = 3, brush
#' @return A black white mask with SCs as objects
#'
threshold_SC_crop
<-
function
(
image
,
offset
){
disc
=
makeBrush
(
21
,
"disc"
)
disc
=
disc
/
sum
(
disc
)
localBackground
=
filter2
(
image
,
disc
)
thresh_crop
=
(
image
-
localBackground
>
offset
)
disc
<-
makeBrush
(
21
,
"disc"
)
disc
<-
disc
/
sum
(
disc
)
localBackground
<-
filter2
(
image
,
disc
)
thresh_crop
<-
(
image
-
localBackground
>
offset
)
strands
<-
bwlabel
(
thresh_crop
)
return
(
strands
)
}
...
...
@@ -167,23 +167,23 @@ threshold_SC_crop <- function(image, offset){
#'
threshold_foci_crop
<-
function
(
image
,
offset_factor
,
brush_size
,
brush_sigma
,
stage
){
bg
<-
mean
(
image
)
offset
=
offset_factor
*
bg
offset
<-
offset_factor
*
bg
### new stuff July
if
(
stage
!=
"pachytene"
){
foci_th
=
image
>
bg
+
offset
foci_th
<-
image
>
bg
+
offset
#foci_th <- watershed(bwlabel(foci_th)*as.matrix(img_orig_foci),tolerance=0.05, ext=1)
}
else
{
### smooth it
img_tmp_contrast
=
image
w
=
makeBrush
(
size
=
brush_size
,
shape
=
'gaussian'
,
sigma
=
brush_sigma
)
img_tmp_contrast
<-
image
w
<-
makeBrush
(
size
=
brush_size
,
shape
=
'gaussian'
,
sigma
=
brush_sigma
)
#w = makeBrush(size = 1, shape = 'gaussian', sigma = 3)
img_flo
=
filter2
(
img_tmp_contrast
,
w
)
img_flo
<-
filter2
(
img_tmp_contrast
,
w
)
## smooth foci channel
foci_th
=
img_flo
>
bg
+
offset
foci_th
<-
img_flo
>
bg
+
offset
}
foci_label
=
bwlabel
(
foci_th
)
foci_label
<-
bwlabel
(
foci_th
)
foci_label
<-
channel
(
foci_label
,
"grey"
)
return
(
foci_label
)
}
...
...
@@ -256,13 +256,13 @@ get_distance <- function(strands,num_strands,new_img,foci_label, foci_count_stra
window2
<-
window
*
3
### start function here
bright_loc
<-
find_start
(
window
,
noise_gone
,
cx
,
cy
)
mean_x
=
as.numeric
(
bright_loc
[
1
,
1
])
+
cx
-
window2
-1
mean_y
=
as.numeric
(
bright_loc
[
1
,
2
])
+
cy
-
window2
-1
mean_x
<-
as.numeric
(
bright_loc
[
1
,
1
])
+
cx
-
window2
-1
mean_y
<-
as.numeric
(
bright_loc
[
1
,
2
])
+
cy
-
window2
-1
##
ix
<-
(
round
(
mean_x
)
-
window
)
:
(
round
(
mean_x
)
+
window
)
iy
<-
(
round
(
mean_y
)
-
window
)
:
(
round
(
mean_y
)
+
window
)
chosen_dir
<-
get_first_dir
(
noise_gone
,
ix
,
iy
,
window
)
walkers
[
round
(
mean
(
ix
)),
round
(
mean
(
iy
))]
=
1
walkers
[
round
(
mean
(
ix
)),
round
(
mean
(
iy
))]
<-
1
ix1
<-
ix
ix2
<-
ix
iy1
<-
iy
...
...
@@ -281,8 +281,8 @@ get_distance <- function(strands,num_strands,new_img,foci_label, foci_count_stra
dir_2
<-
first_step
[(
4
*
next_cord
+4
)]
new_square_1
<-
noise_gone
[
ix1
,
iy1
]
new_square_2
<-
noise_gone
[
ix2
,
iy2
]
walkers
[
round
(
mean
(
ix1
)),
round
(
mean
(
iy1
))]
=
1
walkers
[
round
(
mean
(
ix2
)),
round
(
mean
(
iy2
))]
=
1
walkers
[
round
(
mean
(
ix1
)),
round
(
mean
(
iy1
))]
<-
1
walkers
[
round
(
mean
(
ix2
)),
round
(
mean
(
iy2
))]
<-
1
## take step in the opposite direction. record new coordinates.
## now loop in both directions
## set directions to "not done yet" = 0. "done" = 1
...
...
@@ -303,7 +303,7 @@ get_distance <- function(strands,num_strands,new_img,foci_label, foci_count_stra
first_dir
<-
dir_1_out
[(
2
*
next_cord
+3
)]
start_dir
<-
dir_1_out
[(
2
*
next_cord
+4
)]
walkers
[
round
(
mean
(
ix1
)),
round
(
mean
(
iy1
))]
=
1
walkers
[
round
(
mean
(
ix1
)),
round
(
mean
(
iy1
))]
<-
1
## make the new cropped image.
new_square_1
<-
noise_gone
[
ix1
,
iy1
]
if
(
distance_strand
>
100
){
...
...
@@ -321,7 +321,7 @@ get_distance <- function(strands,num_strands,new_img,foci_label, foci_count_stra
dir_2
<-
dir_2_out
[(
2
*
next_cord
+1
)]
second_dir
<-
dir_2_out
[(
2
*
next_cord
+3
)]
start_dir2
<-
dir_2_out
[(
2
*
next_cord
+4
)]
walkers
[
round
(
mean
(
ix2
)),
round
(
mean
(
iy2
))]
=
1
walkers
[
round
(
mean
(
ix2
)),
round
(
mean
(
iy2
))]
<-
1
## make the new cropped image.
new_square_2
<-
noise_gone
[
ix2
,
iy2
]
if
(
distance_strand_2
>
100
){
...
...
@@ -1189,23 +1189,23 @@ get_distance_between_two <- function(distance_strand,distance_strand_2,per_stran
#### find max. plot these onto the images.
bright_loc_f1
<-
which
(
my_distance_matrix_f1
==
min
(
my_distance_matrix_f1
),
arr.ind
=
TRUE
)
mean_x_f1
=
as.numeric
(
bright_loc_f1
[
1
,
1
])
mean_y_f1
=
as.numeric
(
bright_loc_f1
[
1
,
2
])
mean_x_f1
<-
as.numeric
(
bright_loc_f1
[
1
,
1
])
mean_y_f1
<-
as.numeric
(
bright_loc_f1
[
1
,
2
])
distance_f1
<-
(
foci_1_y
-
mean_x_f1
)
^
2
+
(
foci_1_x
-
mean_y_f1
)
^
2
###
bright_loc_f2
<-
which
(
my_distance_matrix_f2
==
min
(
my_distance_matrix_f2
),
arr.ind
=
TRUE
)
mean_x_f2
=
as.numeric
(
bright_loc_f2
[
1
,
1
])
mean_y_f2
=
as.numeric
(
bright_loc_f2
[
1
,
2
])
mean_x_f2
<-
as.numeric
(
bright_loc_f2
[
1
,
1
])
mean_y_f2
<-
as.numeric
(
bright_loc_f2
[
1
,
2
])
distance_f2
<-
(
foci_2_y
-
mean_x_f2
)
^
2
+
(
foci_2_x
-
mean_y_f2
)
^
2
# deleting for now
if
(
annotation
==
"on"
){
ch1
=
bwlabel
(
noise_gone
)
ch1
<-
bwlabel
(
noise_gone
)
ch1
<-
channel
(
noise_gone
,
"grey"
)
ch2
=
bwlabel
(
foci_label
)
ch2
<-
bwlabel
(
foci_label
)
ch2
<-
channel
(
foci_label
,
"grey"
)
bluered
<-
rgbImage
(
ch1
,
ch2
,
0
*
ch1
)
plot
(
bluered
)
...
...
@@ -1663,11 +1663,11 @@ get_distance_between_two <- function(distance_strand,distance_strand_2,per_stran
plot
(
noise_gone
)
text
(
x
=
foci_1_x
,
y
=
foci_1_y
,
label
=
"+"
,
col
=
"red"
,
cex
=
2
)
text
(
x
=
foci_2_x
,
y
=
foci_2_y
,
label
=
"+"
,
col
=
"blue"
,
cex
=
2
)
ch1
=
bwlabel
(
walkers
)
ch1
<-
bwlabel
(
walkers
)
ch1
<-
channel
(
ch1
,
"grey"
)
ch2
=
bwlabel
(
noise_gone
)
ch2
<-
bwlabel
(
noise_gone
)
ch2
<-
channel
(
noise_gone
,
"grey"
)
ch3
=
bwlabel
(
per_strand
)
ch3
<-
bwlabel
(
per_strand
)
ch3
<-
channel
(
per_strand
,
"grey"
)
bluered
<-
rgbImage
(
ch2
,
ch1
,
ch3
)
#print("break")
...
...
R/measure_distances_general.R
View file @
ed7cdbc8
...
...
@@ -44,11 +44,11 @@ measure_distances_general <- function(img_path,offset_px = 0.2, offset_factor =
#colnames(df_lengths) <- df_cols
## for each image that is *-dna.jpeg,
for
(
img_file
in
file_list
){
filename_path_test
=
paste0
(
img_path
,
"/crops/"
,
stage
,
"/"
,
img_file
)
img_file
=
filename_path_test
filename_path_test
<-
paste0
(
img_path
,
"/crops/"
,
stage
,
"/"
,
img_file
)
img_file
<-
filename_path_test
if
(
grepl
(
paste0
(
'*'
,
channel2_string
,
'.'
,
file_ext
,
'$'
),
img_file
)){
#if(grepl("*SYCP3.jpeg", file)){
file_dna
=
img_file
file_dna
<-
img_file
image_count
<-
image_count
+1
image
<-
readImage
(
file_dna
)
img_orig
<-
channel
(
2
*
image
,
"grey"
)
...
...
@@ -56,7 +56,7 @@ measure_distances_general <- function(img_path,offset_px = 0.2, offset_factor =
}
if
(
grepl
(
paste0
(
'*'
,
channel1_string
,
'.'
,
file_ext
,
'$'
),
img_file
)){
#if(grepl("*MLH3.jpeg", file)){
file_foci
=
img_file
file_foci
<-
img_file
image
<-
readImage
(
file_foci
)
img_orig_foci
<-
channel
(
image
,
"gray"
)
# call functions: get
...
...
@@ -69,11 +69,11 @@ measure_distances_general <- function(img_path,offset_px = 0.2, offset_factor =
new_img
<-
img_orig
#display(new_img)
#### now see which have the right amount of strands
disc
=
makeBrush
(
21
,
"disc"
)
disc
=
disc
/
sum
(
disc
)
localBackground
=
filter2
(
new_img
,
disc
)
offset
=
offset_px
thresh_crop
=
(
new_img
-
localBackground
>
offset
)
disc
<-
makeBrush
(
21
,
"disc"
)
disc
<-
disc
/
sum
(
disc
)
localBackground
<-
filter2
(
new_img
,
disc
)
offset
<-
offset_px
thresh_crop
<-
(
new_img
-
localBackground
>
offset
)
strands
<-
bwlabel
(
thresh_crop
)
#display(strands)
color_img_strands
<-
colorLabels
(
strands
,
normalize
=
TRUE
)
...
...
@@ -90,7 +90,7 @@ measure_distances_general <- function(img_path,offset_px = 0.2, offset_factor =
num_strands
<-
computeFeatures.shape
(
strands
)
num_strands
<-
data.frame
(
num_strands
)
coincident_foci
<-
bwlabel
(
foci_label
*
strands
)
overlap_no
=
table
(
coincident_foci
)
overlap_no
<-
table
(
coincident_foci
)
foci_per_cell
<-
length
(
overlap_no
)
image_mat
<-
as.matrix
(
foci_mask_crop
)
image_mat
<-
image_mat
[
image_mat
>
1e-06
]
...
...
@@ -193,13 +193,13 @@ get_distance_general <- function(strands,num_strands,new_img,foci_label, foci_co
window2
<-
window
*
3
### start function here
bright_loc
<-
find_start
(
window
,
noise_gone
,
cx
,
cy
)
mean_x
=
as.numeric
(
bright_loc
[
1
,
1
])
+
cx
-
window2
-1
mean_y
=
as.numeric
(
bright_loc
[
1
,
2
])
+
cy
-
window2
-1
mean_x
<-
as.numeric
(
bright_loc
[
1
,
1
])
+
cx
-
window2
-1
mean_y
<-
as.numeric
(
bright_loc
[
1
,
2
])
+
cy
-
window2
-1
##
ix
<-
(
round
(
mean_x
)
-
window
)
:
(
round
(
mean_x
)
+
window
)
iy
<-
(
round
(
mean_y
)
-
window
)
:
(
round
(
mean_y
)
+
window
)
chosen_dir
<-
get_first_dir
(
noise_gone
,
ix
,
iy
,
window
)
walkers
[
round
(
mean
(
ix
)),
round
(
mean
(
iy
))]
=
1
walkers
[
round
(
mean
(
ix
)),
round
(
mean
(
iy
))]
<-
1
ix1
<-
ix
ix2
<-
ix
iy1
<-
iy
...
...
@@ -218,8 +218,8 @@ get_distance_general <- function(strands,num_strands,new_img,foci_label, foci_co
dir_2
<-
first_step
[(
4
*
next_cord
+4
)]
new_square_1
<-
noise_gone
[
ix1
,
iy1
]
new_square_2
<-
noise_gone
[
ix2
,
iy2
]
walkers
[
round
(
mean
(
ix1
)),
round
(
mean
(
iy1
))]
=
1
walkers
[
round
(
mean
(
ix2
)),
round
(
mean
(
iy2
))]
=
1
walkers
[
round
(
mean
(
ix1
)),
round
(
mean
(
iy1
))]
<-
1
walkers
[
round
(
mean
(
ix2
)),
round
(
mean
(
iy2
))]
<-
1
## take step in the opposite direction. record new coordinates.
## now loop in both directions
## set directions to "not done yet" = 0. "done" = 1
...
...
@@ -240,7 +240,7 @@ get_distance_general <- function(strands,num_strands,new_img,foci_label, foci_co