-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
168 lines (131 loc) · 4.66 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# 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 output.
**NB:** No support for LAP tracking with temporal gaps (yet)
## Installation
You can install the development version of CPTrackR with:
``` r
remotes::install_github("burgerga/CPTrackR")
```
## Usage
### Creating a lookup table (LUT)
```{r, echo=F, message = FALSE, warning=FALSE}
library(tidyverse)
library(future)
plan(multisession)
# 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 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)
```
We can create a lookup table (LUT) for a single group using `createLUTGroup`:
```{r}
library(CPTrackR)
lut <- createLUTGroup(data %>% filter(groupNumber == 1),
frame_var = groupInd,
obj_var = Nuclei_Number_Object_Number,
par_obj_var = Nuclei_TrackObjects_ParentObjectNumber_30)
lut %>%
arrange(Nuclei_Number_Object_Number, groupInd)
```
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
For illustration here the second frame, where we can see `alt_uid`s for daughter cells:
```{r}
lut %>%
filter(groupInd == 2) %>%
arrange(Nuclei_Number_Object_Number, groupInd)
```
We can also enable a progress bar (will be visible if you run this code in R):
```{r}
library(progressr)
with_progress({
lut <- createLUTGroup(data %>% filter(groupNumber == 1),
frame_var = groupInd,
obj_var = Nuclei_Number_Object_Number,
par_obj_var = Nuclei_TrackObjects_ParentObjectNumber_30)
})
lut %>%
arrange(Nuclei_Number_Object_Number, groupInd)
```
We can create a LUT for multiple groups (=movies) using `createLut`, the `group_vars` are used to denote the different groups (can be multiple columns):
```{r}
with_progress({
lut_all <- createLUT(data,
group_vars = groupNumber,
frame_var = groupInd,
obj_var = Nuclei_Number_Object_Number,
par_obj_var = Nuclei_TrackObjects_ParentObjectNumber_30)
})
lut_all
```
Now we can join the LUT to the original data
```{r}
fixed <- data %>%
left_join(lut_all)
fixed %>%
select(groupNumber, groupInd, uid, alt_uid, Nuclei_Intensity_MeanIntensity_image_green)
```
#### Parallelisation
We can also enable parallelisation using the `future` package and specifying a `plan`, this will give a considerable speed improvement if you have many movies:
```{r, eval = F}
library(future)
plan(multisession)
with_progress({
lut_all <- createLUT(data,
group_vars = groupNumber,
frame_var = groupInd,
obj_var = Nuclei_Number_Object_Number,
par_obj_var = Nuclei_TrackObjects_ParentObjectNumber_30)
})
lut_all
```
```{r, echo = F}
lut_all
```
### Plotting
With our `uid` per cell we can now plot the tracks:
```{r}
ggplot(fixed %>% filter(groupNumber == 1),
aes(Nuclei_Location_Center_X, Nuclei_Location_Center_Y,
group = uid, color = as.factor(uid))) +
geom_path() +
guides(color = F) +
coord_fixed()
```