Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reader for Mosaic files #54

Merged
merged 25 commits into from
Jan 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c61dd34
Ensure datapackage<1.0
roll Aug 29, 2017
8d2f462
readme for mosaic example
gsergeant Oct 23, 2017
768e6a7
add tracking data
gsergeant Oct 23, 2017
272174b
basic framework and preliminary assessment for mosaic reader
gsergeant Oct 23, 2017
c3599eb
basic ini file
gsergeant Oct 24, 2017
d21638c
implemented cellmia-similar reader and changed the delegator class
gsergeant Nov 22, 2017
4751e07
Testing and fixes, add output files
gsergeant Nov 22, 2017
34bbc31
infer tracks from links
gsergeant Nov 22, 2017
1b6b7f0
formatting
gsergeant Nov 22, 2017
fbcb3f0
extension check fix
gsergeant Nov 22, 2017
5baeab0
Merge pull request #53 from roll/patch-1
agbeltran Jan 28, 2018
5725834
readme for mosaic example
gsergeant Oct 23, 2017
c8e878a
add tracking data
gsergeant Oct 23, 2017
50fd785
basic framework and preliminary assessment for mosaic reader
gsergeant Oct 23, 2017
f01e070
basic ini file
gsergeant Oct 24, 2017
d3aa98b
implemented cellmia-similar reader and changed the delegator class
gsergeant Nov 22, 2017
4e03094
Testing and fixes, add output files
gsergeant Nov 22, 2017
5341419
infer tracks from links
gsergeant Nov 22, 2017
a4ee280
formatting
gsergeant Nov 22, 2017
cc1ad20
extension check fix
gsergeant Nov 22, 2017
a1d7576
Merge branch 'mosaic_reader' of https://github.com/gsergeant/biotrack…
gsergeant Jan 31, 2018
825f923
Rename readme.md to Readme.md
agbeltran Jan 31, 2018
261512d
Add tests for Mosaic reader
gsergeant Jan 31, 2018
c497286
Merge branch 'mosaic_reader' of https://github.com/gsergeant/biotrack…
gsergeant Jan 31, 2018
6098891
Fixing typo related to self variable
agbeltran Jan 31, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 41 additions & 13 deletions biotracks/readfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class AbstractReader(metaclass=ABCMeta):
"""\
Common interface for all tracking data readers.
"""

def __init__(self, fname, conf=None, log_level=None):
"""\
Set the input file name for the reader.
Expand Down Expand Up @@ -302,11 +303,11 @@ def read_objects(self):
cp_df.reset_index(inplace=True)
for index, row in cp_df.iterrows():
objects_dict[index] = [row[self.frame], row[self.x], row[self.y]]
objects_df = pd.DataFrame(
[[key, value[0], value[1], value[2]]
for key, value in objects_dict.items()],
columns=[self.obj_id, self.frame, self.x, self.y]
)
objects_df = pd.DataFrame(
[[key, value[0], value[1], value[2]]
for key, value in objects_dict.items()],
columns=[self.obj_id, self.frame, self.x, self.y]
)
objects_df.columns = [
cmso.OBJECT_ID, cmso.FRAME_ID, cmso.X_COORD, cmso.Y_COORD
]
Expand Down Expand Up @@ -393,10 +394,27 @@ def read(self):
self._links[cmso.LINK_ID] -= 1 # CELLMIA index is 1-based


class MosaicReader(AbstractReader):

MOSAIC_COLS = ["Trajectory", "Frame", "x", "y", "z"]

def read(self):
mo_df = pd.read_csv(self.fname, sep=None, usecols=self.MOSAIC_COLS)
mo_df.reset_index(inplace=True)
cols = [cmso.OBJECT_ID, cmso.LINK_ID, cmso.FRAME_ID,
cmso.X_COORD, cmso.Y_COORD, cmso.Z_COORD]
mo_df.columns = cols
self._objects = mo_df.drop(cmso.LINK_ID, 1)
self._links = mo_df.drop(
[cmso.FRAME_ID, cmso.X_COORD, cmso.Y_COORD, cmso.Z_COORD], 1)
self._links[cmso.LINK_ID] -= 1


class TracksReader(object):
"""\
Generic reader that delegates to specific ones based on file extension.
"""

def __init__(self, fname, conf=None, log_level=None):
"""\
Initialize and store a specific reader based on filename extension.
Expand All @@ -411,14 +429,24 @@ def __init__(self, fname, conf=None, log_level=None):
self.reader = TrackMateReader(
fname, conf=conf, log_level=log_level
)
elif ext == '.csv':
self.reader = CellProfilerReader(
fname, conf=conf, log_level=log_level
)
elif ext == '.txt':
self.reader = CellmiaReader(
fname, conf=conf, log_level=log_level
)
elif ext in ['.csv', '.tsv', '.txt']:
# read header and delegate to correct reader
# this pandas method can read csv, tsv and txt files
df = pd.read_csv(fname, header=None, sep=None, nrows=1)
trackname = df.iloc[0, 0]
if trackname == 'ImageNumber':
self.reader = CellProfilerReader(
fname, conf=conf, log_level=log_level
)
elif trackname == 'ID of track':
self.reader = CellmiaReader(
fname, conf=conf, log_level=log_level
)
elif trackname == 'Trajectory':
self.reader = MosaicReader(
fname, conf=conf, log_level=log_level
)

elif ext == '.json':
self.reader = BiotracksReader(
fname, conf=conf, log_level=log_level
Expand Down
41 changes: 41 additions & 0 deletions examples/Mosaic/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
## Mosaic example

The example in the *Mosaic* directory was generated using the [MosaicSuite plugin](http://mosaic.mpi-cbg.de/?q=downloads/imageJ) for ImageJ/Fiji.

Version used: `MosaicSuite-1.0.8`.

### Example 1
The dataset used in this example is the same used in the [TrackMate](../TrackMate) and other examples. The images were both detected and tracked using the Mosaic Particle Tracker tool.

#### The test dataset
The test dataset used can be uploaded in ImageJ:

`File ▶ Open Samples ▶ Tracks for TrackMate (807K)`

You can then open and run the Mosaic plugin selecting:

`Plugins ▶ Mosaic ▶ Particle Tracker 2D/3D `

Alternatively, you can download the data from this [link](http://fiji.sc/samples/FakeTracks.tif).

#### Settings to reproduce the two examples
To reproduce the example in this directory, you need to choose the following settings

- Detection settings:
- Kernel radius: 5
- Cutoff radius: 0.01
- Percentile: 0.4
- Tracking settings:
- Displacement: 10.0
- Linkrange: 3

Once you run the tracking, you can select **All Trajectories to Table**, which opens an ImageJ table that you can save to disk.


#### Running the data_package library
Move to the example directory and run the data package creation script:

```
cd examples/Mosaic/example_1
python ../../../scripts/create_dpkg.py mosaic_tracks.csv
```
8 changes: 8 additions & 0 deletions examples/Mosaic/example_1/biotracks.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[TOP_LEVEL_INFO]
author = paola masuzzo
title = A CMSO data package representation of cell tracking data
name = cmso_tracks
author_institute = VIB
author_email = [email protected]

[TRACKING_DATA]
88 changes: 88 additions & 0 deletions examples/Mosaic/example_1/dp/dp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"author": "paola masuzzo",
"author_email": "[email protected]",
"author_institute": "VIB",
"name": "cmso_tracks",
"resources": [
{
"name": "cmso_objects_table",
"path": "objects.csv",
"schema": {
"fields": [
{
"constraints": {
"unique": true
},
"description": "",
"format": "default",
"name": "cmso_object_id",
"title": "",
"type": "integer"
},
{
"description": "",
"format": "default",
"name": "cmso_frame_id",
"title": "",
"type": "integer"
},
{
"description": "",
"format": "default",
"name": "cmso_x_coord",
"title": "",
"type": "number"
},
{
"description": "",
"format": "default",
"name": "cmso_y_coord",
"title": "",
"type": "number"
},
{
"description": "",
"format": "default",
"name": "cmso_z_coord",
"title": "",
"type": "integer"
}
],
"primaryKey": "cmso_object_id"
}
},
{
"name": "cmso_links_table",
"path": "links.csv",
"schema": {
"fields": [
{
"description": "",
"format": "default",
"name": "cmso_object_id",
"title": "",
"type": "integer"
},
{
"description": "",
"format": "default",
"name": "cmso_link_id",
"title": "",
"type": "integer"
}
],
"foreignKeys": [
{
"fields": "cmso_object_id",
"reference": {
"datapackage": "",
"fields": "cmso_object_id",
"resource": "cmso_objects_table"
}
}
]
}
}
],
"title": "A CMSO data package representation of cell tracking data"
}
Loading