knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.align = "center"
)
library(mamut2r)
library(dplyr)
library(cowplot)
library(purrr)
library(XML)
library(tidyr)

MaMuT (Massive Multi-view Tracker) is a Fiji plugin (Wolff et al. (2018), eLife) that is used in developmental biology to mark and track over time "spots", usually cells and cell nuclei. The spots are organised into "tracks". Each track represent a cell lineage. The package {mamut2r} aims at providing an interface between R and MaMuT in order to import .xml files generated by MaMuT, display tracks and spots and modify the original .xml. The vignette below explains some of the basic functions from {mamut2r}.

Load .xml MaMuT file

The mamut.xml file is loaded as a list in R using the xmlToList() function from the {XML} package.

fileXML <- xmlToList(system.file("extdata", "MaMuT_Parhyale_demo-mamut.xml", package = "mamut2r"))

Get 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.

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.

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}.

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().

Spots_Tracks <- spots.and.tracks(Spots_df, Tracks_df)
Spots_Tracks

Lineage tree

track2plot() allows to plot the lineage trees with a custom color code.
Tracks are identified by their ID.

all_tracks <- unique(Tracks_df$TRACK_ID)

To plot one track:

track2plot(track = "1", Tracks_df, Spots_Tracks,
           colNode = FRAME, colYaxis = "black", colNode_discrete = TRUE)

To plot the first six tracks:

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


marionlouveaux/mamut2r documentation built on May 20, 2019, 9:55 a.m.