Skip to content

Commit

Permalink
Merge pull request #54 from gsergeant/mosaic_reader
Browse files Browse the repository at this point in the history
Reader for Mosaic files
  • Loading branch information
agbeltran authored Jan 31, 2018
2 parents 5baeab0 + 6098891 commit 846b72c
Show file tree
Hide file tree
Showing 12 changed files with 741 additions and 13 deletions.
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

0 comments on commit 846b72c

Please sign in to comment.