Skip to content

Commit 62b6b37

Browse files
committed
v0.4.0
1 parent f86c19e commit 62b6b37

4 files changed

Lines changed: 168 additions & 3 deletions

File tree

DESCRIPTION

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: TrackMateR
22
Type: Package
33
Title: Working with TrackMate outputs in R
4-
Version: 0.3.15
4+
Version: 0.4.0
55
Authors@R:
66
person(given = "Stephen J",
77
family = "Royle",
@@ -30,6 +30,8 @@ Imports:
3030
xml2,
3131
zoo
3232
Suggests:
33-
knitr,
34-
rmarkdown
33+
knitr,
34+
rmarkdown,
35+
testthat (>= 3.0.0)
3536
URL: https://quantixed.github.io/TrackMateR/
37+
Config/testthat/edition: 3

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# TrackMateR
22

3+
# TrackMateR 0.4.0
4+
5+
- Testing framework added. Bumping to 0.4.0 to reflect this major change.
6+
37
# TrackMateR 0.3.15
8+
49
- Added `convertTrackMateXML2CSV()` to convert TrackMate XML fles to csv.
510

611
# TrackMateR 0.3.14

tests/testthat.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This file is part of the standard setup for testthat.
2+
# It is recommended that you do not modify it.
3+
#
4+
# Where should you do additional test configuration?
5+
# Learn more about the roles of various files in:
6+
# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
7+
# * https://testthat.r-lib.org/articles/special-files.html
8+
9+
library(testthat)
10+
library(TrackMateR)
11+
12+
test_check("TrackMateR")
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
test_that("readTrackMateXML handles non-existent file gracefully", {
2+
res <- tryCatch(readTrackMateXML("nonexistent.xml"), error = function(e) e)
3+
expect_true(is.null(res) || inherits(res, "error"))
4+
})
5+
6+
test_that("readTrackMateXML handles wrong file suffix", {
7+
tmp <- tempfile(fileext = ".csv")
8+
file.create(tmp)
9+
on.exit(unlink(tmp))
10+
11+
res <- tryCatch(readTrackMateXML(tmp), error = function(e) e)
12+
expect_true(is.null(res) || inherits(res, "error"))
13+
})
14+
15+
test_that("readTrackMateXML handles XML with no tracks", {
16+
xml_content <- '<?xml version="1.0" encoding="UTF-8"?>
17+
<TrackMate>
18+
<Model spatialunits="pixel" timeunits="sec"/>
19+
<AllSpots/>
20+
</TrackMate>'
21+
22+
tmp <- tempfile(fileext = ".xml")
23+
writeLines(xml_content, tmp)
24+
on.exit(unlink(tmp))
25+
26+
res <- tryCatch(readTrackMateXML(tmp), error = function(e) e)
27+
expect_true(is.null(res) || inherits(res, "error"))
28+
})
29+
30+
test_that("readTrackMateXML handles XML with no filtered tracks", {
31+
xml_content <- '<?xml version="1.0" encoding="UTF-8"?>
32+
<TrackMate>
33+
<Model spatialunits="pixel" timeunits="sec"/>
34+
<AllSpots/>
35+
<AllTracks>
36+
<Track TRACK_ID="0"/>
37+
</AllTracks>
38+
<FilteredTracks/>
39+
</TrackMate>'
40+
41+
tmp <- tempfile(fileext = ".xml")
42+
writeLines(xml_content, tmp)
43+
on.exit(unlink(tmp))
44+
45+
res <- tryCatch(readTrackMateXML(tmp), error = function(e) e)
46+
expect_true(is.null(res) || inherits(res, "error"))
47+
})
48+
49+
test_that("readTrackMateXML parses valid XML correctly", {
50+
xml_content <- '<?xml version="1.0" encoding="UTF-8"?>
51+
<TrackMate>
52+
<Model spatialunits="micron" timeunits="sec"/>
53+
<AllSpots>
54+
<SpotsInFrame frame="0">
55+
<Spot ID="1" POSITION_X="10.0" POSITION_Y="20.0" POSITION_Z="0.0" POSITION_T="0.0" FRAME="0" RADIUS="2.5" QUALITY="100"/>
56+
<Spot ID="2" POSITION_X="15.0" POSITION_Y="25.0" POSITION_Z="0.0" POSITION_T="0.5" FRAME="1" RADIUS="2.5" QUALITY="100"/>
57+
</SpotsInFrame>
58+
</AllSpots>
59+
<AllTracks>
60+
<Track TRACK_ID="0">
61+
<Edge SPOT_SOURCE_ID="1" SPOT_TARGET_ID="2"/>
62+
</Track>
63+
</AllTracks>
64+
<FilteredTracks>
65+
<TrackID TRACK_ID="0"/>
66+
</FilteredTracks>
67+
</TrackMate>'
68+
69+
tmp <- tempfile(fileext = ".xml")
70+
writeLines(xml_content, tmp)
71+
on.exit(unlink(tmp))
72+
73+
res <- tryCatch(readTrackMateXML(tmp), error = function(e) { skip(paste("readTrackMateXML failed:", e$message)) })
74+
75+
# result is expected to be a list: first element the data frame, second calibration
76+
expect_true(is.list(res))
77+
result <- res[[1]]
78+
expect_true(is.data.frame(result))
79+
expect_true(all(c("track", "frame", "x", "y", "z", "time") %in% names(result)))
80+
})
81+
82+
test_that("readTrackMateXML only includes filtered tracks", {
83+
xml_content <- '<?xml version="1.0" encoding="UTF-8"?>
84+
<TrackMate>
85+
<Model spatialunits="micron" timeunits="sec"/>
86+
<AllSpots>
87+
<SpotsInFrame frame="0">
88+
<Spot ID="1" POSITION_X="10.0" POSITION_Y="20.0" POSITION_Z="0.0" POSITION_T="0.0" FRAME="0"/>
89+
<Spot ID="2" POSITION_X="15.0" POSITION_Y="25.0" POSITION_Z="0.0" POSITION_T="1.0" FRAME="1"/>
90+
<Spot ID="3" POSITION_X="100.0" POSITION_Y="200.0" POSITION_Z="0.0" POSITION_T="0.0" FRAME="0"/>
91+
<Spot ID="4" POSITION_X="105.0" POSITION_Y="205.0" POSITION_Z="0.0" POSITION_T="1.0" FRAME="1"/>
92+
</SpotsInFrame>
93+
</AllSpots>
94+
<AllTracks>
95+
<Track TRACK_ID="0">
96+
<Edge SPOT_SOURCE_ID="1" SPOT_TARGET_ID="2"/>
97+
</Track>
98+
<Track TRACK_ID="1">
99+
<Edge SPOT_SOURCE_ID="3" SPOT_TARGET_ID="4"/>
100+
</Track>
101+
</AllTracks>
102+
<FilteredTracks>
103+
<TrackID TRACK_ID="0"/>
104+
</FilteredTracks>
105+
</TrackMate>'
106+
107+
tmp <- tempfile(fileext = ".xml")
108+
writeLines(xml_content, tmp)
109+
on.exit(unlink(tmp))
110+
111+
res <- tryCatch(readTrackMateXML(tmp), error = function(e) { skip(paste("readTrackMateXML failed:", e$message)) })
112+
result <- res[[1]]
113+
114+
expect_equal(nrow(result), 2)
115+
expect_equal(nlevels(result$track), 1)
116+
expect_equal(as.character(unique(result$track)), "0")
117+
expect_false(any(result$x > 50))
118+
})
119+
120+
test_that("readTrackMateXML warns on duplicate track-frame combinations", {
121+
xml_content <- '<?xml version="1.0" encoding="UTF-8"?>
122+
<TrackMate>
123+
<Model spatialunits="micron" timeunits="sec"/>
124+
<AllSpots>
125+
<SpotsInFrame frame="0">
126+
<Spot ID="1" POSITION_X="10.0" POSITION_Y="20.0" POSITION_Z="0.0" POSITION_T="0.0" FRAME="0"/>
127+
<Spot ID="2" POSITION_X="15.0" POSITION_Y="25.0" POSITION_Z="0.0" POSITION_T="0.0" FRAME="0"/>
128+
</SpotsInFrame>
129+
</AllSpots>
130+
<AllTracks>
131+
<Track TRACK_ID="0">
132+
<Edge SPOT_SOURCE_ID="1" SPOT_TARGET_ID="2"/>
133+
</Track>
134+
</AllTracks>
135+
<FilteredTracks>
136+
<TrackID TRACK_ID="0"/>
137+
</FilteredTracks>
138+
</TrackMate>'
139+
140+
tmp <- tempfile(fileext = ".xml")
141+
writeLines(xml_content, tmp)
142+
on.exit(unlink(tmp))
143+
144+
res <- tryCatch(readTrackMateXML(tmp), error = function(e) { skip(paste("readTrackMateXML failed:", e$message)) })
145+
expect_output(invisible(res <- readTrackMateXML(tmp)), "duplicate")
146+
})

0 commit comments

Comments
 (0)