-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathREADME.Rmd
177 lines (126 loc) · 6 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
169
170
171
172
173
174
175
176
177
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
[![Travis build status](https://travis-ci.org/marionlouveaux/mamut2r.svg?branch=master)](https://travis-ci.org/marionlouveaux/mamut2r) [![Build status](https://ci.appveyor.com/api/projects/status/efpwpkqw79ks920o?svg=true)](https://ci.appveyor.com/project/marionlouveaux/mamut2r) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.1467431.svg)](https://doi.org/10.5281/zenodo.1467431)
# mamut2r
The goal of {mamut2r} is to imports data coming from .xml files generated with the Fiji MaMuT plugin for lineage and tracking of biological objects. {mamut2r} also allows to create lineage plots.
## How to cite
To cite {mamut2r}, call the R built-in command `citation("mamut2r")`.
> Marion Louveaux, & Sébastien Rochette. (2018, October 19). mamut2r: a R package to import and visualize xml files from the MaMuT Fiji plugin (Version v0.0.2). Zenodo. http://doi.org/10.5281/zenodo.1467431
## Installation
{mamut2r} is only available on Github.
``` r
# install.packages("devtools")
devtools::install_github("marionlouveaux/mamut2r")
```
You may need to install dependencies before:
```{r, eval=FALSE}
# rhdf5 (>= 2.24.0) on bioconductor is required
install.packages("BiocManager")
BiocManager::install("rhdf5", update = FALSE)
# Other packages on CRAN
to_install <- c("classInt", "cowplot", "dplyr", "ggplot2", "ggraph", "ggridges", "glue", "grDevices", "igraph", "knitr", "magrittr", "pkgdown", "purrr", "rhdf5", "rmarkdown", "stats", "tibble", "tidyr", "utils", "viridis", "XML", "xml2")
for (i in to_install) {
message(paste("looking for ", i))
if (!requireNamespace(i)) {
message(paste(" installing", i))
install.packages(i)
}
}
```
*For Linux and MacOS*
To install {ggraph}, you will need "udunits".
- *Ubuntu:*
```
sudo apt-get install --yes libudunits2-dev
```
- *MacOS:*
```
brew install udunits
```
## Full documentation with {pkgdown}
See full documentation created with {pkgdown} at https://marionlouveaux.github.io/mamut2r/
## Open Rmd files used to build vignettes
You may need to install {cellviz3d}, and you will need to install mamut2r with the vignettes.
```{r, eval = FALSE}
devtools::install_github("marionlouveaux/cellviz3d")
devtools::install_github("marionlouveaux/mamut2r", build_vignettes = TRUE)
file.edit(system.file(file.path("doc", "vignette_fluo.Rmd"), package = "mamut2r"))
file.edit(system.file(file.path("doc", "vignette_getting_started.Rmd"), package = "mamut2r"))
```
## Getting started
```{r, echo=TRUE, message=FALSE}
library(mamut2r)
library(dplyr)
library(cowplot)
library(purrr)
library(XML)
```
### Loading .xml MaMuT file
The mamut.xml file is loaded as a list in R using the xmlToList() function from the {XML} package.
```{r}
fileXML <- xmlToList(system.file("extdata", "MaMuT_Parhyale_demo-mamut.xml", package = "mamut2r"))
```
### Getting information relative to either nuclei (= spots) or lineages (=tracks)
The MaMuT .xml file stores two type of objects, under two types of tags: the spots and the tracks. In the case of the study of the development of an organ, spots usually refer to nuclei and tracks to cell lineages. Here, Spots.as.dataframe() and Tracks.as.dataframe() extract information from the .xml file and format them as dataframes (more precisely as tibbles).
Information regarding the spots (x, y, z location, ID...) are extracted using the Spots.as.dataframe and stored in a tibble.
```{r}
Spots_df <- Spots.as.dataframe(fileXML)
Spots_df
```
Information regarding the tracks (ID of source and target spots, track ID...) are extracted using the Tracks.as.dataframe and stored in a tibble.
```{r}
Tracks_df <- Tracks.as.dataframe(fileXML)
Tracks_df
```
### Checking tracks
Tracks are composed of nodes (the spots) and edges (between the spots). Source and target spots are respectively the origin and the end of an edge between two timepoints. checkTrack() checks the orientation of edges and ensure to always have the source spot in an earlier timepoint than the target spot. This is necessary for plotting the lineage trees afterwards with {ggraph}.
```{r}
Tracks_df <- checkTrack(Tracks_df, Spots_df)
Tracks_df
```
### Merging spots and tracks information
Spots dataframes can be enriched with information coming from the tracks using spots.and.tracks().
```{r}
Spots_Tracks <- spots.and.tracks(Spots_df, Tracks_df)
Spots_Tracks
```
### Visualising the lineage trees
track2plot() allows to plot the lineage trees with a custom color code.
Tracks are identified by their ID.
```{r}
all_tracks <- unique(Tracks_df$TRACK_ID)
```
To plot one track:
```{r onetrack}
track2plot(track = "1", Tracks_df, Spots_Tracks,
colNode = FRAME, colYaxis = "black", colNode_discrete = TRUE)
```
To plot the first six tracks:
```{r multipletracks, fig.width=9, fig.height=6, out.width="100%"}
trackset <- all_tracks[1:6]
nbrow <- 2
#display y axis only for plots on the left
colYaxis_pattern <- rep(c("black",
rep("white", (ceiling(length(trackset)/nbrow)-1) ) ), nbrow)
colYaxis <- colYaxis_pattern[1:length(trackset)]
all_layouts <- map2(trackset, colYaxis,
~track2plot(.x, Tracks_df, Spots_Tracks, colNode = TRACK_ID, colYaxis = .y, colNode_discrete=TRUE, breaks = unique(trackset)))
prow <- plot_grid(plotlist = all_layouts, nrow = nbrow)
legend <- get_legend(all_layouts[[1]]+theme(legend.position="right"))
p <- plot_grid( prow, legend, rel_widths = c(1, .3))
p
```
## Acknowledgements
Many thanks to Dr. Jean-Yves Tinevez, John Bogovic, and Dr. Tobias Pietsch for their help on MaMuT and Big Data Viewer, and to Dr. Mike Smith for his help on the getFluo() function.
## Code of conduct
Please note that the 'mamut2r' project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By contributing to this project, you agree to abide by its terms.