Coder Social home page Coder Social logo

cells2numbers / migrationminer Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 0.0 262 KB

MigrationmineR is a R package to analyse and profile in vitro cell tracking and migration data. It is belongs to the cytominer-verse used for morphological profiling and allows to create temporal or dynamic profiles.

License: Other

R 100.00%
cell-migration cell-tracking

migrationminer's Introduction

Build Status codecov

migrationminer

migrationminer is a R package to analyse and profile in vitro cell tracking and migration data. It is belongs to the cytominer-verse used for morphological profiling and allows to create temporal or dynamic profiles.

It works well together with CellProiler and the CellProfiler tracking module. Beside that it is quite easy to parse other formats as long as the tracking data is available in tidy format. That means, that the data is available as csv where each row represents a cell with at least four columns

  • x coordinate
  • y coordinate
  • time point
  • track label

Installation

migrationminer is not yet available from CRAN but you can install directly from github. First, you need to install the devtools package. You can do this from CRAN. Invoke R and then type

install.packages("devtools")

Load the package using

library(devtools)

Now install migrationminer from github using

install_github("cells2numbers/migrationminer")

You should see something like

Downloading GitHub repo cells2numbers/migrationminer@master
from URL https://api.github.com/repos/cells2numbers/migrationminer/zipball/master
Installing migrationminer
'/usr/local/Cellar/r/3.4.1_2/lib/R/bin/R' --no-site-file --no-environ --no-save --no-restore --quiet CMD INSTALL  \
  '/private/var/folders/qq/v5mwx8g15655gt708s86vys8yzcpll/T/RtmpUyrzzK/devtoolse7f945c7b360/cells2numbers-migrationminer-8a95c5d'  \
  --library='/usr/local/lib/R/3.4/site-library' --install-tests 

* installing *source* package ‘migrationminer’ ...
** R
** tests
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (migrationminer)
Reloading installed migrationminer

If this does not work for you or you find any bugs, please file an issue!

migrationminer's People

Contributors

cells2numbers avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

migrationminer's Issues

add function to correct for confounding variables

example code:

Correct for three variables (age, sex and date of recording). Each combination of subset / offset
is corrected separetly


# helper function to iterate over all features 
get_lm_helper_function <- function(profiles_tmp) {
  # get feature names 
  # feature_names <- colnames(profiles_tmp) %>% str_subset("^Track")
  feature_names <- c("Track_Angle", "Track_Directionality", "Track_CI","Track_Speed","Track_yFMI", "Track_xFMI", "Track_CI","Track_DP", "Track_MSD", "Track_Speed_X","Track_Speed_Y", "Track_Speed_max")
  # calculate corrected values as residuals of lm
  df_result <- do.call(
    cbind,
    lapply(
      feature_names, 
      get_lm_model_fitted_values, 
      profiles_tmp = profiles_tmp
      )
    )
  # add experiment id Metadata_experiment
  df_result %<>% 
    mutate(Metadata_experiment = profiles_tmp$Metadata_experiment)
}

# linear model lm is used to remove date/age/sex effects
get_lm_model_fitted_values <- function(y, profiles_tmp){
  new_colname <- paste0(y)
  
  tryCatch({
      lm_formula <- paste0(y, " ~ Clinical_Parameter_Age + Clinical_Parameter_Sex + Clinical_Parameter_Date")
      lm_model <- lm(lm_formula, data = profiles_tmp,na.action = na.exclude) 
      fitted_values <- tibble( "V1" = residuals(lm_model, na.action=na.exclude))
      colnames(fitted_values) <- new_colname
    },
    fitted_values = function(err){
      fitted_values <- tibble("V1" = rep(NA, nrow(profiles_tmp))) 
      colnames(fitted_values) <- new_colname
      return(fitted_values)
    }
  )

  return(fitted_values)
} 

Correct values

profiles_corrected <- profiles %>% 
  filter(!is.na(Track_Directionality), Metadata_Frame_Subset < 180, Metadata_offset < 180) %>% 
  group_by(Metadata_Frame_Subset, Metadata_offset) %>% 
  do(get_lm_helper_function(.))

plot_windrose shows wrong x direction

Sample code

library(tidyverse)
library(migrationminer)

x = c(1,100,-2)
y = c(1,-200,1)

Track_Angle =
  atan2(tail(y, n = 1) - (y)[1],
        tail(x, n = 1) - (y)[1]
  ) %>% print

(Track_Angle >= pi / 4) &  (Track_Angle < 3 * pi / 4 )

# test windroseplot 


# up 1.5 
# down -1.5
# left 3 
# right 0

tracks <- tibble(Track_Angle = -c(-1.5, 3, -1.5, 3), Track_Speed = c(1,1,1,1), id = c(1,1,1,1))

plot_windrose(tracks)

add visualization

Add visualization including

  • roseplot / windrose plot
  • trajectory plot 2d/3d

Add windowed profiles

Add functionality to calculate the migration parameter on a windowed frame. This allows quantifying the change of migration over time.

Sample code:

create_windowed_migration_profiles <- function(df_temp, t1, offset = 20) {
  df_temp %<>% 
    filter(Metadata_frame > t1) %>% 
    filter(Metadata_frame < (t1 + offset) ) 
  
  tracks <- migrationminer::track(
      df_temp, 
      c("TrackObjects_Label"),
      t_var = "Metadata_frame"
    )  %>% 
    filter(complete.cases(.)) %>% 
    filter(Track_Length > offset/2) %>% 
    summarise_all( mean) %>% 
    mutate(Metadata_Frame_Subset = t1) %>% 
    mutate(Metadata_offset = offset) 
    
  return(tracks)
} 

Temporal change of the migration parameter 'speed' over time. Different window sizes (offsets) were chosen. The shown data belongs to an experiment that is characterized by a strong flow
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.