Skip to content

Commit daf1eaa

Browse files
committed
Updated Python and schema to work with new multi-file format.
1 parent bea5396 commit daf1eaa

File tree

5 files changed

+23
-47
lines changed

5 files changed

+23
-47
lines changed

src/Python/wcon/wcon_parser.py

+14-10
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,9 @@ def load_from_file(cls, JSON_path,
643643
# CASE 1: NO "files" OBJECT, hence no multiple files. We are done.
644644
if w_current.files is None:
645645
return w_current
646+
elif ('next' not in w_current.files) and ('prev' not in w.current.files):
647+
# CASE 2: "files" object exists but no prev/next, assume nothing is there
648+
return w_current
646649
else:
647650
# The merge operations below will blast away the .files attribute
648651
# so we need to save a local copy
@@ -651,20 +654,20 @@ def load_from_file(cls, JSON_path,
651654
# OTHERWISE, CASE 2: MULTIPLE FILES
652655

653656
# The schema guarantees that if "files" is present,
654-
# "this", "prev" and "next" will exist. Also, that "this" is not
657+
# "current", will exist. Also, that "current" is not
655658
# null and whose corresponding value is a string at least one
656659
# character in length.
657-
cur_ext = current_files['this']
660+
cur_ext = current_files['current']
658661

659662
# e.g. cur_filename = 'filename_2.wcon'
660663
# cur_ext = '_2', prefix = 'filename', suffix = '.wcon'
661664
cur_filename = JSON_path
662-
if cur_filename.find(cur_ext) == -1:
663-
raise AssertionError('Cannot find the current extension "' +
664-
cur_ext + '" within the current filename "' +
665+
name_offset = cur_filename.find(cur_ext)
666+
if name_offset == -1:
667+
raise AssertionError('Mismatch between the filename given in the file "' +
668+
cur_ext + '" and the file we loaded from "' +
665669
cur_filename + '".')
666-
prefix = cur_filename[:cur_filename.find(cur_ext)]
667-
suffix = cur_filename[cur_filename.find(cur_ext) + len(cur_ext):]
670+
path_string = cur_filename[:name_offset]
668671

669672
load_chunks = {'prev': load_prev_chunks,
670673
'next': load_next_chunks}
@@ -675,12 +678,13 @@ def load_from_file(cls, JSON_path,
675678
# Same with the "next" chunks
676679
if (load_chunks[direction] and
677680
current_files is not None and
678-
current_files[direction] is not None):
681+
current_files[direction] is not None and
682+
len(current_files[direction]) > 0):
679683
cur_load_prev_chunks = (direction == 'prev')
680684
cur_load_next_chunks = (direction == 'next')
681685

682-
new_file_name = (prefix + current_files[direction][0] +
683-
suffix)
686+
new_file_name = path_string + current_files[direction][0]
687+
684688
w_new = cls.load_from_file(new_file_name,
685689
cur_load_prev_chunks,
686690
cur_load_next_chunks,

src/scala/README.md

+1-27
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ the behavior of the Scala implementation should be presumed to be authoritative.
77

88
## Requirements
99

10-
This project requires Java 8 and [Scala 2.11](http://scala-lang.org). You do
10+
This project requires Java 8 and [Scala 2.12](http://scala-lang.org). You do
1111
not need to install Scala explicitly, as the build process is managed by
1212
[SBT](http://www.scala-sbt.org/). SBT must be installed to build the project,
1313
and it will take care of downloading Scala and any needed libraries.
@@ -39,32 +39,6 @@ there (the `Right` case), and prints the error and throws an exception if
3939
not. (If you don't care about error-handling, replace the `match` and following
4040
statements with `.right.get`.)
4141

42-
The Scala reader/writer does its best to preserve the underlying structure
43-
of the data file. However, this may not be the most convenient form in which
44-
to browse the data. The `DataSet` class can extract and merge all the data
45-
by ID, using the `combined()` method. This method can take a map of functions
46-
that are used to merge data from custom tags, and these functions may fail,
47-
so the entire operation may fail. Thus, the function returns an `Either`, from
48-
which you can extract your data:
49-
50-
```scala
51-
val data = worms.combined() match {
52-
case Right(ds) => ds
53-
case Left(err) => println(err); throw new Exception
54-
}
55-
```
56-
57-
You should see something like so (except formatted on a single line):
58-
59-
```
60-
res0: Array[org.openworm.trackercommons.Data] =
61-
Array({ "id": 1, "ox": [0.6, 0.9], "oy": [0, -0.04], "t": [0, 1],
62-
"x": [ [-0.6, -0.3, 0, 0.3, 0.6], [-0.6, -0.3, 0, 0.3, 0.6] ],
63-
"y": [ [0, -0.2, 0, 0.2, 0], [-0.16, 0.04, 0.24, 0.04, -0.16] ] },
64-
{ "id": 2, "ox": [0], "oy": [1.5], "t": [1], "x": [ [0, 0.2, 0, -0.2, 0] ],
65-
"y": [ [-0.5, -0.25, 0, 0.25, 0.5] ] })
66-
```
67-
6842
## Using the reference implementation to create data
6943

7044
The Scala implementation also contains routines to create data suitable for writing in WCON format. In particular, it helps populate the standard data structures and ensure that minimal requirements are met.

tests/minimax.wcon

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
"timestamp":"2012-04-23T18:25:43.511Z",
66
"temperature":22,
77
"humidity":40.2,
8-
"dish":{ "type":"petri", "size":35, "units":"mm" },
8+
"dish":{ "style":"petri", "size":35, "units":"mm" },
99
"food":"none",
1010
"media":"agarose",
1111
"sex":"hermaphrodite",
1212
"stage":"adult",
1313
"age":18.511,
1414
"strain":"CB4856",
15-
"image_orientation":"imaged onto agar",
1615
"protocol":"text description of protocol",
1716
"software":{
1817
"tracker":{ "name":"Software Name", "version":"1.3.0"},

tests/multiworm.wcon

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
"timestamp":"2012-04-23T18:25:43.511Z",
66
"temperature":22,
77
"humidity":40.2,
8-
"dish":{ "type":"petri", "size":35, "units":"mm" },
8+
"dish":{ "style":"petri", "size":35, "units":"mm" },
99
"food":"none",
1010
"media":"agarose",
1111
"sex":"hermaphrodite",
1212
"stage":"adult",
1313
"age":18.511,
1414
"strain":"CB4856",
15-
"image_orientation":"imaged onto agar",
1615
"protocol":"text description of protocol",
1716
"software":{
1817
"tracker":{ "name":"Software Name", "version":"1.3.0"},

wcon_schema.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@
1616
"type": "object",
1717
"description": "For very long tracking experiments, it may be convenient to split a single experiment across multiple WCON files. To make it easier to reconstruct tracks across files, we support a 'files' object.",
1818
"properties": {
19-
"this": {"type":"string", "minLength":1},
19+
"current": {"type":"string"},
2020
"prev": {"oneOf": [
2121
{"type": "null"},
2222
{"type":"string"},
23-
{"type": "array", "minItems":1, "items": {"type":"string", "minLength":1}}
23+
{"type": "array", "items": {"type":"string", "minLength":1}}
2424
]},
2525
"next": {"oneOf": [
2626
{"type": "null"},
2727
{"type":"string"},
28-
{"type": "array", "minItems":1, "items": {"type":"string", "minLength":1}}
28+
{"type": "array", "items": {"type":"string", "minLength":1}}
2929
]}
3030
},
3131
"additionalProperties": false,
32-
"required": ["this"]
32+
"required": ["current"]
3333
},
3434
"units": {
3535
"type": "object",
@@ -48,6 +48,7 @@
4848
"type": "object",
4949
"description": "Information about experimental conditions and software versions; critical for reproducibility across labs.",
5050
"properties": {
51+
"id": {"type": "string"},
5152
"lab": {"type": "object"},
5253
"who": { "$ref": "#/definitions/string_or_array_of_strings" },
5354
"timestamp": {"type": "string", "format":"date-time"},
@@ -56,7 +57,7 @@
5657
"arena": {
5758
"type": "object",
5859
"properties":{
59-
"type": {"type": "string", "default":"petri"},
60+
"style": {"type": "string", "default":"petri"},
6061
"size": {"oneOf":[ {"type": "number"}, {"type": "array", "minItems":2, "items": {"type":"string"} }] },
6162
"orientation": {"type": "string"}
6263
}
@@ -67,7 +68,6 @@
6768
"stage": {"type": "string", "enum": ["L1", "L2", "L3", "L4", "adult", "dauer"]},
6869
"age": {"type": "number"},
6970
"strain": {"type": "string"},
70-
"image_orientation": {"type": "string", "enum": ["imaged onto agar", "imaged through agar"]},
7171
"protocol": { "$ref": "#/definitions/string_or_array_of_strings" },
7272
"interpolate": {"oneOf":[
7373
{ "$ref": "#/definitions/interpolate_metadata" },

0 commit comments

Comments
 (0)