Coder Social home page Coder Social logo

metacell / minian Goto Github PK

View Code? Open in Web Editor NEW

This project forked from denisecailab/minian

1.0 1.0 0.0 1.05 GB

miniscope analysis pipeline with interactive visualizations

License: GNU General Public License v3.0

Jupyter Notebook 38.14% Python 61.68% Dockerfile 0.18%

minian's Introduction

About MiniAn

MiniAn is an analysis pipeline and visualization tool inspired by both CaImAn and MIN1PIPE package specifically for Miniscope data.

Quick Start Guide

Option #1: conda

  1. Download and install conda.
  2. Make sure your conda is up to date: conda update -n base -c default conda
  3. Download the MiniAn package: git clone https://github.com/DeniseCaiLab/minian.git
  4. Go into MiniAn folder you just cloned: cd minian/
  5. Create an conda environment: conda env create -n minian -f environment.yml
  6. Activate the conda enviornment you created during minian installation: source activate minian
  7. Fire up jupyter: jupyter notebook and open the notebook "pipeline_noted.ipynb"

Option #2: docker

  1. Download and install docker.
  2. Read the notes below first then run: docker run -p 8888:8888 -v MY_DATA_PATH:/media denisecailab/minian:latest
  3. Once you read the following, open a browser and navigate to localhost:8888:

The Jupyter Notebook is running at:
http://blahblah:8888
Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

Note: this approach runs everything in a more isolated docker container, which makes customizing/extending the code harder and may affect performance. It is recommended to use this approach only when you encounter errors during installation or running demo data with the first conda option, in which case it is highly recommended to submit an issue first as well.

As a result of isolation, you have to explicitly expose resources from within the container to your machine. In our case we want to expose two things: the network port that jupyter is listening to and a file system shared across your machine and the container. The -p 8888:8888 argument in the docker command expose port 8888 from within the container to port 8888 on your machine. If you prefer another port, for example in case another jupyter application is already running and occupies port 8888, change the number after the colon. The -v MY_DATA_PATH:/media argument creates a bind mount from MY_DATA_PATH on your machine to /media within the container, so that files under this two paths are synced and act as one, and you can refer to anything under MY_DATA_PATH by substituting that with /media from the notebook within the container. See here for more details and change the path to suit your needs.

As a final note, everything within the container does not persist across sessions except those in the bind mount, which means all the modifications you made to the default notebook under /minian will be reset to the state in the original image. Thus it is advised to keep a working copy of minian on your local machine and mount them in the container if you are using this in production mode.

License

This project is licensed under GNU GPLv3.

minian's People

Contributors

phildong avatar denisecai avatar dz-bendog avatar wmau avatar zachpenn avatar joezaki avatar mable avatar eichlab avatar susiefeng avatar

Stargazers

Eric Thomson avatar

Watchers

James Cloos avatar

minian's Issues

Update parameter dicts rather than reassigning values

One of the first cells sets default parameters, which are dicts. As a user runs through the pipeline, they will typically change parameters by reassigning the value to the one inside the dict and key that they want. For example, param_first_spatial['sparse_penal'] = 0.05. There is a risk of human error that isn't currently caught by the pipeline. For example, if I make a typo: param_first_spatial['sparse_pena'] = 0.05, and then run update_spatial(required_args, sparse_penal=param_first_spatial['sparse_penal'], I will end up accidentally using the default.

There should be a way to catch invalid dict keys. One possibility is to use **param in each function so that the function will throw an error when it encounters an invalid argument name in the dict key that's being passed. Another is to use classes rather than dicts, using __slots__: https://docs.python.org/2.5/ref/slots.html

Optimize memory usage / profiling investigation

Some parts of the pipeline consume a lot of RAM (memory) causing the Jupyter notebook kernel to crash.

for example this step:
visualization
generate_videos(minian, varr, dpath, param_save_minian['fname'] + ".mp4", scale='auto')

rework datastructure for seeds

currently seeds is a pandas dataframe and result of refinement steps are stored as boolean mask columns. This doesn't play well if the users run refinement steps in a non-linear order.

Freeze environment.yml

People are still running into environment issues like here. We need to lock package versions in the environment.yml.

cross registration ValueError

step 1
...
id_dims = {'animal','session'}
...

step 4
...
minian_ds = open_minian_mf(
dpath, id_dims, pattern=f_pattern, backend='zarr')
...

ValueError                                Traceback (most recent call last)
<ipython-input-4-810a24a5dde9> in <module>
----> 1 minian_ds = open_minian_mf(
      2     dpath, id_dims, pattern=f_pattern, backend='zarr')

/opt/projects/metacell/minian/minian/minian/utilities.py in open_minian_mf(dpath, index_dims, result_format, pattern, sub_dirs, exclude, **kwargs)
    711             print(["{}: {}".format(d, v) for d, v in zip(index_dims, key)])
    712     if result_format is 'xarray':
--> 713         return xrconcat_recursive(minian_dict, index_dims)
    714     elif result_format is 'pandas':
    715         minian_df = pd.Series(minian_dict).rename('minian')

/opt/projects/metacell/minian/minian/minian/utilities.py in xrconcat_recursive(var, dims)
    767             pass
    768         var_ps = pd.Series(var_dict)
--> 769         var_ps.index.set_names(dims, inplace=True)
    770         xr_ls = []
    771         for idx, v in var_ps.groupby(level=dims[0]):

~/miniconda3/envs/minian/lib/python3.8/site-packages/pandas/core/indexes/base.py in set_names(self, names, level, inplace)
   1323         else:
   1324             idx = self._shallow_copy()
-> 1325         idx._set_names(names, level=level)
   1326         if not inplace:
   1327             return idx

~/miniconda3/envs/minian/lib/python3.8/site-packages/pandas/core/indexes/base.py in _set_names(self, values, level)
   1237             raise ValueError("Names must be a list-like")
   1238         if len(values) != 1:
-> 1239             raise ValueError(f"Length of new names must be 1, got {len(values)}")
   1240 
   1241         # GH 20527

ValueError: Length of new names must be 1, got 2

batch-processing support

there use to be a notebook to carry out batch-processing using papermill. The two biggest question is:

  1. how should be parameters be encoded in a json-friendly way?
  2. what features are important for this other than a big for loop?

better handling of metadata

Currently the metadata are recorded as coordinates of xarray and pulled from folder names with the meta_dict. This is often overlooked by users. The result is that people often ended up with same/messed up coordinates with session, which in turn will mess up cross-session registration. A few thoughts on how to make this better:

  1. write a function to quickly fix the metadata and resave all the datasets (I have a half-working one already somewhere in the code).
  2. find alternative way to record metadata and inform the cross-session registration process.
  3. forget about metadata and carry out cross-session registration on unlabeled arrays (register across certain axis).

progressbar not defined in cross-registration notebook

step 3

NameError                                 Traceback (most recent call last)
<ipython-input-3-cb61fb1036bb> in <module>
     17 from minian.visualization import AlignViewer
     18 hv.notebook_extension('bokeh', width=100)
---> 19 pbar = ProgressBar(minimum=2)
     20 pbar.register()

NameError: name 'ProgressBar' is not defined

cross registration SyntaxWarning messages

step 3 (load modules) of the cross registration notebook produces SyntaxWarning messages:

/opt/projects/metacell/minian/minian/minian/utilities.py:667: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if backend is 'netcdf':
/opt/projects/metacell/minian/minian/minian/utilities.py:669: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if chunks is 'auto':
/opt/projects/metacell/minian/minian/minian/utilities.py:679: SyntaxWarning: "is" with a literal. Did you mean "=="?
  elif backend is 'zarr':
/opt/projects/metacell/minian/minian/minian/utilities.py:683: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if chunks is 'auto':
/opt/projects/metacell/minian/minian/minian/utilities.py:712: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if result_format is 'xarray':
/opt/projects/metacell/minian/minian/minian/utilities.py:714: SyntaxWarning: "is" with a literal. Did you mean "=="?
  elif result_format is 'pandas':
/opt/projects/metacell/minian/minian/minian/utilities.py:730: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if backend is 'netcdf':
/opt/projects/metacell/minian/minian/minian/utilities.py:737: SyntaxWarning: "is" with a literal. Did you mean "=="?
  elif backend is 'zarr':

replace replace the if a is b: syntax with if a == b:

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.