Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
burgerga committed Dec 13, 2023
1 parent 4a4177c commit d0e15b0
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 38 deletions.
18 changes: 14 additions & 4 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,33 @@ remotes::install_github("burgerga/CPTrackR")

### Creating a lookup table (LUT)

Assuming `data` contains some data from a CellProfiler tsv:

```{r, echo=F, message = FALSE, warning=FALSE}
library(tidyverse)
library(future)
plan(multisession)
data <- read_tsv(file.path("~/../../Downloads","20190925_BrittData_singleCell_1hrDelay_withoutT01.txt"))
# Example data is generated from a dataset from Britt (shared by Muriel)
# all_data <- read_tsv(file.path("~/../../Downloads","20190925_BrittData_singleCell_1hrDelay_withoutT01.txt"))
# data = all_data |>
# filter(groupNumber <= 2) |>
# select(groupNumber,
# groupInd,
# Nuclei_TrackObjects_ParentObjectNumber_30,
# Nuclei_Number_Object_Number,
# Nuclei_Intensity_MeanIntensity_image_green,
# starts_with("Nuclei_Location_Center_"))
theme_set(theme_classic(base_size = 13))
```

Show some example uncorrected data:
Show some example uncorrected data extracted from a CellProfiler tsv:

```{r}
library(CPTrackR)
library(tidyverse)
data <- read_tsv(system.file("extdata", "cptrackr_example_data.tsv.xz", package="CPTrackR"), show_col_types = F)
data %>%
select(groupNumber,
groupInd,
Expand Down
79 changes: 45 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
# CPTrackR

<!-- badges: start -->

[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4725472.svg)](https://doi.org/10.5281/zenodo.4725472)
[![R-CMD-check](https://github.com/burgerga/CPTrackR/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/burgerga/CPTrackR/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->

The goal of CPTrackR is to add unique track ids to CellProfiler tracking
Expand All @@ -24,32 +26,36 @@ remotes::install_github("burgerga/CPTrackR")

### Creating a lookup table (LUT)

Assuming `data` contains some data from a CellProfiler tsv:

Show some example uncorrected data:
Show some example uncorrected data extracted from a CellProfiler tsv:

``` r
library(CPTrackR)
library(tidyverse)

data <- read_tsv(system.file("extdata", "cptrackr_example_data.tsv.xz", package="CPTrackR"), show_col_types = F)
data %>%
select(groupNumber,
groupInd,
Nuclei_TrackObjects_ParentObjectNumber_30,
Nuclei_Number_Object_Number,
Nuclei_Intensity_MeanIntensity_image_green)
#> # A tibble: 370,598 x 5
#> groupNumber groupInd Nuclei_TrackObject~ Nuclei_Number_Ob~ Nuclei_Intensity_~
#> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 1 1 0 1 0.000135
#> 2 1 1 0 2 0.0000847
#> 3 1 1 0 3 0.000223
#> 4 1 1 0 4 0.000110
#> 5 1 1 0 5 0.000952
#> 6 1 1 0 6 0.00346
#> 7 1 1 0 7 0.0000498
#> 8 1 1 0 8 0.000108
#> 9 1 1 0 9 0.00982
#> 10 1 1 0 10 0.000639
#> # ... with 370,588 more rows
#> # A tibble: 15,225 × 5
#> groupNumber groupInd Nuclei_TrackObjects_ParentObjec…¹ Nuclei_Number_Object…²
#> <dbl> <dbl> <dbl> <dbl>
#> 1 1 1 0 1
#> 2 1 1 0 2
#> 3 1 1 0 3
#> 4 1 1 0 4
#> 5 1 1 0 5
#> 6 1 1 0 6
#> 7 1 1 0 7
#> 8 1 1 0 8
#> 9 1 1 0 9
#> 10 1 1 0 10
#> # ℹ 15,215 more rows
#> # ℹ abbreviated names: ¹​Nuclei_TrackObjects_ParentObjectNumber_30,
#> # ²​Nuclei_Number_Object_Number
#> # ℹ 1 more variable: Nuclei_Intensity_MeanIntensity_image_green <dbl>
```

We can create a lookup table (LUT) for a single group using
Expand All @@ -63,7 +69,7 @@ lut <- createLUTGroup(data %>% filter(groupNumber == 1),
par_obj_var = Nuclei_TrackObjects_ParentObjectNumber_30)
lut %>%
arrange(Nuclei_Number_Object_Number, groupInd)
#> # A tibble: 10,304 x 5
#> # A tibble: 10,304 × 5
#> groupInd Nuclei_Number_Object_Number cid uid alt_uid
#> <dbl> <dbl> <dbl> <dbl> <chr>
#> 1 1 1 1 1 1
Expand All @@ -76,15 +82,15 @@ lut %>%
#> 8 8 1 252 311 252
#> 9 9 1 252 311 252
#> 10 10 1 252 311 252
#> # ... with 10,294 more rows
#> # 10,294 more rows
```

Three new columns are added:

- `cid`: id of the original cell (daughter cells share `cid` with
parent)
- `uid`: unique id (daughter cells don’t share `uid` with parent)
- `alt_uid`: character id of cells that show lineage with suffixes
- `cid`: id of the original cell (daughter cells share `cid` with
parent)
- `uid`: unique id (daughter cells don’t share `uid` with parent)
- `alt_uid`: character id of cells that show lineage with suffixes

For illustration here the second frame, where we can see `alt_uid`s for
daughter cells:
Expand All @@ -93,7 +99,7 @@ daughter cells:
lut %>%
filter(groupInd == 2) %>%
arrange(Nuclei_Number_Object_Number, groupInd)
#> # A tibble: 200 x 5
#> # A tibble: 200 × 5
#> groupInd Nuclei_Number_Object_Number cid uid alt_uid
#> <dbl> <dbl> <dbl> <dbl> <chr>
#> 1 2 1 1 1 1
Expand All @@ -106,7 +112,7 @@ lut %>%
#> 8 2 8 10 10 10
#> 9 2 9 11 11 11
#> 10 2 10 13 13 13
#> # ... with 190 more rows
#> # 190 more rows
```

We can also enable a progress bar (will be visible if you run this code
Expand All @@ -122,7 +128,7 @@ with_progress({
})
lut %>%
arrange(Nuclei_Number_Object_Number, groupInd)
#> # A tibble: 10,304 x 5
#> # A tibble: 10,304 × 5
#> groupInd Nuclei_Number_Object_Number cid uid alt_uid
#> <dbl> <dbl> <dbl> <dbl> <chr>
#> 1 1 1 1 1 1
Expand All @@ -135,7 +141,7 @@ lut %>%
#> 8 8 1 252 311 252
#> 9 9 1 252 311 252
#> 10 10 1 252 311 252
#> # ... with 10,294 more rows
#> # 10,294 more rows
```

We can create a LUT for multiple groups (=movies) using `createLut`, the
Expand All @@ -151,7 +157,7 @@ with_progress({
par_obj_var = Nuclei_TrackObjects_ParentObjectNumber_30)
})
lut_all
#> # A tibble: 370,598 x 6
#> # A tibble: 15,225 × 6
#> groupNumber groupInd Nuclei_Number_Object_Number cid uid alt_uid
#> <dbl> <dbl> <dbl> <dbl> <dbl> <chr>
#> 1 1 1 1 1 1 1
Expand All @@ -164,18 +170,18 @@ lut_all
#> 8 1 1 8 8 8 8
#> 9 1 1 9 9 9 9
#> 10 1 1 10 10 10 10
#> # ... with 370,588 more rows
#> # ℹ 15,215 more rows
```

Now we can join the LUT to the original data

``` r
fixed <- data %>%
left_join(lut_all)
#> Joining, by = c("groupInd", "groupNumber", "Nuclei_Number_Object_Number")
#> Joining with `by = join_by(groupNumber, groupInd, Nuclei_Number_Object_Number)`
fixed %>%
select(groupNumber, groupInd, uid, alt_uid, Nuclei_Intensity_MeanIntensity_image_green)
#> # A tibble: 370,598 x 5
#> # A tibble: 15,225 × 5
#> groupNumber groupInd uid alt_uid Nuclei_Intensity_MeanIntensity_image_green
#> <dbl> <dbl> <dbl> <chr> <dbl>
#> 1 1 1 1 1 0.000135
Expand All @@ -188,7 +194,7 @@ fixed %>%
#> 8 1 1 8 8 0.000108
#> 9 1 1 9 9 0.00982
#> 10 1 1 10 10 0.000639
#> # ... with 370,588 more rows
#> # ℹ 15,215 more rows
```

#### Parallelisation
Expand All @@ -210,7 +216,7 @@ with_progress({
lut_all
```

#> # A tibble: 370,598 x 6
#> # A tibble: 15,225 × 6
#> groupNumber groupInd Nuclei_Number_Object_Number cid uid alt_uid
#> <dbl> <dbl> <dbl> <dbl> <dbl> <chr>
#> 1 1 1 1 1 1 1
Expand All @@ -223,7 +229,7 @@ lut_all
#> 8 1 1 8 8 8 8
#> 9 1 1 9 9 9 9
#> 10 1 1 10 10 10 10
#> # ... with 370,588 more rows
#> # ℹ 15,215 more rows

### Plotting

Expand All @@ -236,6 +242,11 @@ ggplot(fixed %>% filter(groupNumber == 1),
geom_path() +
guides(color = F) +
coord_fixed()
#> Warning: The `<scale>` argument of `guides()` cannot be `FALSE`. Use "none" instead as
#> of ggplot2 3.3.4.
#> This warning is displayed once every 8 hours.
#> Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
#> generated.
```

<img src="man/figures/README-unnamed-chunk-11-1.png" width="100%" />
Binary file added inst/extdata/cptrackr_example_data.tsv.xz
Binary file not shown.
Binary file modified man/figures/README-unnamed-chunk-11-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d0e15b0

Please sign in to comment.