Commit c23fa2db authored by Lucy McNeill's avatar Lucy McNeill
Browse files

measure distance data frame has SC ID per cell

parent b1b4773f
No preview for this file type
......@@ -14,8 +14,8 @@ importFrom(EBImage,channel)
importFrom(EBImage,colorLabels)
importFrom(EBImage,computeFeatures)
importFrom(EBImage,computeFeatures.basic)
importFrom(EBImage,computeFeatures.moment)
importFrom(EBImage,computeFeatures.haralick)
importFrom(EBImage,computeFeatures.moment)
importFrom(EBImage,computeFeatures.shape)
importFrom(EBImage,display)
importFrom(EBImage,filter2)
......
......@@ -2,7 +2,7 @@
#'
#' crop an image around each viable cell candidate.
#' @importFrom stats median sd
#' @importFrom EBImage bwlabel channel colorLabels computeFeatures computeFeatures.basic computeFeatures.moment computeFeatures.shape display filter2 makeBrush readImage rgbImage rmObjects rotate writeImage
#' @importFrom EBImage bwlabel channel colorLabels computeFeatures computeFeatures.basic computeFeatures.moment computeFeatures.shape computeFeatures.haralick display filter2 makeBrush readImage rgbImage rmObjects rotate writeImage
#' @importFrom graphics text
#' @importFrom utils str
#' @export auto_crop_fast
......@@ -18,6 +18,12 @@
#' @param test_amount, Optional number of first N images you want to run function on. For troubleshooting/testing/variable calibration purposes.
#' @param brush_size_blob, Brush size for smudging the dna channel to make blobs
#' @param sigma_blob, Sigma in Gaussian brush for smudging the dna channel to make blobs
#' @param channel1_string String appended to the files showing the channel illuminating foci. Defaults to MLH3
#' @param channel2_string String appended to the files showing the channel illuminating synaptonemal complexes. Defaults to SYCP3
#' @param channel3_string Defaults to DAPI (if third channel is on)
#' @param file_ext file extension of your images e.g. tiff jpeg or png.
#' @param third_channel Whether there is a third channel e.g. DAPI stain. On or off. Defaults to off.
#'
#' @return cropped SC and foci channels around single cells, regardless of stage
......@@ -150,6 +156,11 @@ print("viable cells")
#' @param annotation, Choice to output pipeline choices (recommended to knit)
#' @param file_base, filename base common to all three channels i.e. without -MLH3.jpeg etc.
#' @param img_path, path containing image data to analyse
#' @param channel1_string String appended to the files showing the channel illuminating foci. Defaults to MLH3
#' @param channel2_string String appended to the files showing the channel illuminating synaptonemal complexes. Defaults to SYCP3
#' @param channel3_string Defaults to DAPI (if third channel is on)
#' @param file_ext file extension of your images e.g. tiff jpeg or png.
#' @param third_channel Whether there is a third channel e.g. DAPI stain. On or off. Defaults to off.
#'
......
......@@ -11,6 +11,9 @@
#' @param brush_sigma, sigma for Gaussian smooth of foci channel. Should be small to avoid erasing foci.
#' @param foci_norm, Mean intensity to normalise all foci channels to.
#' @param annotation, Choice to output pipeline choices (recommended to knit)
#' @param channel1_string String appended to the files showing the channel illuminating foci. Defaults to MLH3
#' @param channel2_string String appended to the files showing the channel illuminating synaptonemal complexes. Defaults to SYCP3
#' @param file_ext file extension of your images e.g. tiff jpeg or png.
#' @return foci count per cell
......@@ -101,6 +104,8 @@ count_foci <- function(img_path, stage = "none", offset_px = 0.2, offset_factor
coincident_foci <- bwlabel(foci_label*strands)
### multiply strands by foci_label
if(annotation == "on"){
print("at file")
print(file)
print("cell counter is")
print(cell_count)
print("original images")
......@@ -114,6 +119,7 @@ count_foci <- function(img_path, stage = "none", offset_px = 0.2, offset_factor
print("two channels, only coincident foci")
display(rgbImage(strands,coincident_foci,coincident_foci))
}
overlap_no = table(coincident_foci)
......
......@@ -9,8 +9,12 @@
#' @param offset, Pixel value offset used in therholding for the dna (SYCP3) channel
#' @param ecc_thresh, The minimum average eccentricity of all objects in mask determined by computefeatures, for a cell to be pachytene.
#' @param area_thresh, The minimum ratio of pixels included in mask to total, for a cell to be classified as pachytene.
#' @param channel1_string String appended to the files showing the channel illuminating foci. Defaults to MLH3
#' @param channel2_string String appended to the files showing the channel illuminating synaptonemal complexes. Defaults to SYCP3
#' @param file_ext file extension of your images e.g. tiff jpeg or png.
#' @param annotation, Choice to output pipeline choices (recommended to knit)
#' @return Pairs of foci and SC channel crops for pachytene
#'
get_pachytene <- function(img_path, species_num = 20, offset = 0.2,ecc_thresh = 0.85, area_thresh = 0.06, annotation = "off", channel2_string = "SYCP3", channel1_string = "MLH3",file_ext = "jpeg")
......
......@@ -32,7 +32,7 @@ measure_distances <- function(img_path,offset_px = 0.2, offset_factor = 3, brush
img_path_new <- paste0(img_path,"/crops/",stage,"/")
file_list <- list.files(img_path_new)
df_cols <- c("file","genotype","foci_no","foci_per_strand", "total_SC_length","total_pixel_distance","foci_location_along", "fractional_distance_between_two", "pass_fail", "foci_location_x", "foci_location_y", "foci_location_x_line", "foci_location_y_line")
df_cols <- c("file","cell_id","genotype","foci_no","foci_per_strand", "SC_no_cell","SC_uid","total_SC_length","total_pixel_distance","foci_location_along", "fractional_distance_between_two", "pass_fail", "foci_location_x", "foci_location_y", "foci_location_x_line", "foci_location_y_line")
df_lengths <- data.frame(matrix(ncol = length(df_cols), nrow = 0))
#colnames(df_lengths) <- df_cols
## for each image that is *-dna.jpeg,
......@@ -99,7 +99,8 @@ measure_distances <- function(img_path,offset_px = 0.2, offset_factor = 3, brush
print(cell_count)
}
################ distance starts (make function later)
dimensionless_dist <- get_distance(strands,num_strands,new_img,foci_label, foci_count_strand, strand_iter,file,annotation,eccentricity_min, max_strand_area)
dimensionless_dist <- get_distance(strands,num_strands,new_img,foci_label, foci_count_strand, strand_iter,file,annotation,eccentricity_min, max_strand_area,cell_count)
#colnames(dimensionless_dist) <- df_cols
df_lengths <- rbind(df_lengths, dimensionless_dist)
}
}
......@@ -172,14 +173,16 @@ threshold_foci_crop <- function(image, offset_factor, brush_size, brush_sigma){
#' @param annotation, Choice to output pipeline choices (recommended to knit)
#' @param eccentricity_min, The minimum eccentricity (from computefeatures) of a strand to proceed with measuring
#' @param max_strand_area, Maximum pixel area of a strand
#' @param cell_count Unique cell counter
#' @return Data frame with properties of synaptonemal (SC) measurements
#'
get_distance <- function(strands,num_strands,new_img,foci_label, foci_count_strand, strand_iter,file,annotation, eccentricity_min, max_strand_area){
get_distance <- function(strands,num_strands,new_img,foci_label, foci_count_strand, strand_iter,file,annotation, eccentricity_min, max_strand_area,cell_count){
tryCatch({
no_strands <- nrow(num_strands)
strand_count<- 0
while(strand_count<no_strands){
strand_iter <- strand_iter + 1
strand_count <- strand_count + 1
# if area less than 150 pixels.. or not an outlier... keep
if (as.numeric(num_strands$s.area[strand_count])<max_strand_area & as.numeric(num_strands$s.area[strand_count])>10){
......@@ -295,7 +298,8 @@ get_distance <- function(strands,num_strands,new_img,foci_label, foci_count_stra
### call measure distance between 2
dimensionless_dist <- get_distance_between_two(distance_strand,distance_strand_2,per_strand,foci_label, walkers, noise_gone,start_x,start_y,start_x2,start_y2,start_dir,cx,cy,mean_x,mean_y,strand_iter,file,annotation)
dimensionless_dist <- get_distance_between_two(distance_strand,distance_strand_2,per_strand,foci_label, walkers, noise_gone,start_x,start_y,start_x2,start_y2,start_dir,cx,cy,mean_x,mean_y,strand_count,file,annotation,cell_count,strand_iter)
return(dimensionless_dist)
##### ends here
### you've got a single strand here. try and count distance between foci.
......@@ -1110,9 +1114,11 @@ get_next_second_dir <- function(new_square_2,ix2,iy2,dir_2,window,chosen_dir,dis
#' @param strand_iter, Strand number in iteration over all in cell
#' @param file, original filename that cell candidate came from. Used to identify e.g. genotype for data frame.
#' @param annotation, Choice to output pipeline choices (recommended to knit)
#' @param cell_count Unique cell number
#' @param uid_strand Unique strand number
#' @return List of fractional distances between foci for all SCs with two. Optional: total distances of SCs. Optional: images of all resulting traces/ foci locations.
#'
get_distance_between_two <- function(distance_strand,distance_strand_2,per_strand,foci_label, walkers, noise_gone,start_x,start_y,start_x2,start_y2,start_dir,cx,cy,mean_x,mean_y,strand_iter,file,annotation){
get_distance_between_two <- function(distance_strand,distance_strand_2,per_strand,foci_label, walkers, noise_gone,start_x,start_y,start_x2,start_y2,start_dir,cx,cy,mean_x,mean_y,strand_iter,file,annotation,cell_count, uid_strand){
strand_info <- computeFeatures.moment(bwlabel(per_strand),as.matrix(foci_label))
strand_info <- as.data.frame(strand_info)
foci_1_x <- strand_info$m.cx[1]
......@@ -1552,6 +1558,7 @@ get_distance_between_two <- function(distance_strand,distance_strand_2,per_stran
dim_length <- dist_between_foci/(distance_strand+ distance_strand_2)
px_length <- dist_between_foci
#strand_iter <- strand_iter +1
if(annotation == "on"){
print("the distance strands measure")
......@@ -1563,7 +1570,7 @@ get_distance_between_two <- function(distance_strand,distance_strand_2,per_stran
}
if(length_walker<149){
strand_iter <- strand_iter +1
if (dim_length >1e-6 && dim_length < 1 && (distance_strand+ distance_strand_2) > 0){
if (foci_out_2 >1){
if(distance_f1 < 10){
......@@ -1576,13 +1583,14 @@ get_distance_between_two <- function(distance_strand,distance_strand_2,per_stran
if(grepl( "--", file, fixed = TRUE) == TRUE){
genotype <- "Fancm-/-"
}
uid <- strand_iter
# SIX new columns added: foci counter, foci per strand, f1 location x, f1 location y, f2 location x, f2 location y, f1 location x (on line), f1 location y (on line), f2 location x (on line), f2 location y (on line),
# df_cols <- c("file","genotype","foci_no","foci_per_strand", "total_SC_length","total_pixel_distance","foci_location_along", "fractional_distance_between_two", "pass_fail", "foci_location_x", "foci_location_y", "foci_location_x_line", "foci_location_y_line")
dimensionless_dist_pass_f1 <- c(file, genotype,1,2, (distance_strand+ distance_strand_2), px_length,foci_location_along_1, dim_length,"pass", foci_1_x, foci_1_y, mean_y_f1, mean_x_f1)
dimensionless_dist_pass_f2 <- c(file, genotype,2,2, (distance_strand+ distance_strand_2), px_length,foci_location_along_2, dim_length,"pass", foci_2_x, foci_2_y, mean_y_f2, mean_x_f2)
dimensionless_dist_pass_f1 <- c(file,cell_count, genotype,1,2, uid,uid_strand,(distance_strand+ distance_strand_2), px_length,foci_location_along_1, dim_length,"pass", foci_1_x, foci_1_y, mean_y_f1, mean_x_f1)
dimensionless_dist_pass_f2 <- c(file, cell_count, genotype,2,2, uid,uid_strand, (distance_strand+ distance_strand_2), px_length,foci_location_along_2, dim_length,"pass", foci_2_x, foci_2_y, mean_y_f2, mean_x_f2)
dimensionless_dist_pass <- rbind(dimensionless_dist_pass_f1,dimensionless_dist_pass_f2)
rownames(dimensionless_dist_pass) <- NULL
......
No preview for this file type
......@@ -48,6 +48,16 @@ auto_crop_fast(
\item{brush_size_blob, }{Brush size for smudging the dna channel to make blobs}
\item{sigma_blob, }{Sigma in Gaussian brush for smudging the dna channel to make blobs}
\item{channel3_string}{Defaults to DAPI (if third channel is on)}
\item{channel2_string}{String appended to the files showing the channel illuminating synaptonemal complexes. Defaults to SYCP3}
\item{channel1_string}{String appended to the files showing the channel illuminating foci. Defaults to MLH3}
\item{file_ext}{file extension of your images e.g. tiff jpeg or png.}
\item{third_channel}{Whether there is a third channel e.g. DAPI stain. On or off. Defaults to off.}
}
\value{
cropped SC and foci channels around single cells, regardless of stage
......
......@@ -34,6 +34,12 @@ count_foci(
\item{foci_norm, }{Mean intensity to normalise all foci channels to.}
\item{annotation, }{Choice to output pipeline choices (recommended to knit)}
\item{channel2_string}{String appended to the files showing the channel illuminating synaptonemal complexes. Defaults to SYCP3}
\item{channel1_string}{String appended to the files showing the channel illuminating foci. Defaults to MLH3}
\item{file_ext}{file extension of your images e.g. tiff jpeg or png.}
}
\value{
foci count per cell
......
......@@ -63,6 +63,16 @@ crop_single_object_fast(
\item{cx}{centre of blob x}
\item{cy}{centre of blob y}
\item{channel3_string}{Defaults to DAPI (if third channel is on)}
\item{channel2_string}{String appended to the files showing the channel illuminating synaptonemal complexes. Defaults to SYCP3}
\item{channel1_string}{String appended to the files showing the channel illuminating foci. Defaults to MLH3}
\item{file_ext}{file extension of your images e.g. tiff jpeg or png.}
\item{third_channel}{Whether there is a third channel e.g. DAPI stain. On or off. Defaults to off.}
}
\value{
Crops around all candidates in both channels
......
......@@ -15,7 +15,8 @@ get_distance(
file,
annotation,
eccentricity_min,
max_strand_area
max_strand_area,
cell_count
)
}
\arguments{
......@@ -38,6 +39,8 @@ get_distance(
\item{eccentricity_min, }{The minimum eccentricity (from computefeatures) of a strand to proceed with measuring}
\item{max_strand_area, }{Maximum pixel area of a strand}
\item{cell_count}{Unique cell counter}
}
\value{
Data frame with properties of synaptonemal (SC) measurements
......
......@@ -22,7 +22,9 @@ get_distance_between_two(
mean_y,
strand_iter,
file,
annotation
annotation,
cell_count,
uid_strand
)
}
\arguments{
......@@ -61,6 +63,10 @@ get_distance_between_two(
\item{file, }{original filename that cell candidate came from. Used to identify e.g. genotype for data frame.}
\item{annotation, }{Choice to output pipeline choices (recommended to knit)}
\item{cell_count}{Unique cell number}
\item{uid_strand}{Unique strand number}
}
\value{
List of fractional distances between foci for all SCs with two. Optional: total distances of SCs. Optional: images of all resulting traces/ foci locations.
......
......@@ -26,6 +26,14 @@ get_pachytene(
\item{ecc_thresh, }{The minimum average eccentricity of all objects in mask determined by computefeatures, for a cell to be pachytene.}
\item{area_thresh, }{The minimum ratio of pixels included in mask to total, for a cell to be classified as pachytene.}
\item{annotation, }{Choice to output pipeline choices (recommended to knit)}
\item{channel2_string}{String appended to the files showing the channel illuminating synaptonemal complexes. Defaults to SYCP3}
\item{channel1_string}{String appended to the files showing the channel illuminating foci. Defaults to MLH3}
\item{file_ext}{file extension of your images e.g. tiff jpeg or png.}
}
\value{
Pairs of foci and SC channel crops for pachytene
......
......@@ -40,6 +40,12 @@ measure_distances(
\item{eccentricity_min, }{The minimum eccentricity (from computefeatures) of a strand to proceed with measuring}
\item{max_strand_area, }{Maximum pixel area of a strand}
\item{channel2_string}{String appended to the files showing the channel illuminating synaptonemal complexes. Defaults to SYCP3}
\item{channel1_string}{String appended to the files showing the channel illuminating foci. Defaults to MLH3}
\item{file_ext}{file extension of your images e.g. tiff jpeg or png.}
}
\value{
Data frame with properties of synaptonemal (SC) measurements
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment