From 326711b55000b520cf16e02c6ec9351b83615b88 Mon Sep 17 00:00:00 2001 From: nilseling Date: Sun, 10 Dec 2023 14:39:17 +0100 Subject: [PATCH] Adjusted unit tests for compImage function based on real spillover data --- tests/testthat/test_compImage.R | 587 ++++++++++++-------------------- 1 file changed, 216 insertions(+), 371 deletions(-) diff --git a/tests/testthat/test_compImage.R b/tests/testthat/test_compImage.R index 8d561df..1548522 100644 --- a/tests/testthat/test_compImage.R +++ b/tests/testthat/test_compImage.R @@ -25,48 +25,28 @@ test_that("compImage function works", { # Generate spillover images - strong spillover sm_images <- pancreasImages - channelNames(sm_images) <- c("Dy161Di", "Dy162Di", "Dy163Di", "Dy164Di", "Ho165Di") - cur_ch <- endoapply(sm_images, function(x){ - Image(apply(x, c(1,2), function(y){sum(y * sm_strong[,"Dy161Di"])})) - }) - channelNames(cur_ch) <- "Dy161Di" - setChannels(sm_images, "Dy161Di") <- cur_ch - - cur_ch <- endoapply(sm_images, function(x){ - Image(apply(x, c(1,2), function(y){sum(y * sm_strong[,"Dy162Di"])})) - }) - channelNames(cur_ch) <- "Dy162Di" - setChannels(sm_images, "Dy162Di") <- cur_ch - - cur_ch <- endoapply(sm_images, function(x){ - Image(apply(x, c(1,2), function(y){sum(y * sm_strong[,"Dy163Di"])})) - }) - channelNames(cur_ch) <- "Dy163Di" - setChannels(sm_images, "Dy163Di") <- cur_ch - - cur_ch <- endoapply(sm_images, function(x){ - Image(apply(x, c(1,2), function(y){sum(y * sm_strong[,"Dy164Di"])})) - }) - channelNames(cur_ch) <- "Dy164Di" - setChannels(sm_images, "Dy164Di") <- cur_ch - cur_ch <- endoapply(sm_images, function(x){ - Image(apply(x, c(1,2), function(y){sum(y * sm_strong[,"Ho165Di"])})) + out <- endoapply(sm_images, function(x){ + cur_out <- apply(x, c(1,2), function(y) return(y %*% sm_strong)) + cur_out <- aperm(cur_out, c(2,3,1)) + return(Image(cur_out)) }) - channelNames(cur_ch) <- "Ho165Di" - setChannels(sm_images, "Ho165Di") <- cur_ch + channelNames(out) <- channelNames(pancreasImages) + sm_images <- out # Visual inspection plotPixels(pancreasImages, colour_by = "H3") - plotPixels(sm_images, colour_by = "Dy161Di") + plotPixels(sm_images, colour_by = "H3") plotPixels(pancreasImages, colour_by = "CD99") - plotPixels(sm_images, colour_by = "Dy162Di") + plotPixels(sm_images, colour_by = "CD99") plotPixels(pancreasImages, colour_by = "PIN") - plotPixels(sm_images, colour_by = "Dy163Di") + plotPixels(sm_images, colour_by = "PIN") plotPixels(pancreasImages, colour_by = "CD8a") - plotPixels(sm_images, colour_by = "Dy164Di") + plotPixels(sm_images, colour_by = "CD8a") plotPixels(pancreasImages, colour_by = "CDH") - plotPixels(sm_images, colour_by = "Ho165Di") + plotPixels(sm_images, colour_by = "CDH") + + channelNames(sm_images) <- rownames(sm_strong) expect_silent(cur_out <- compImage(sm_images, sm_strong)) @@ -88,202 +68,120 @@ test_that("compImage function works", { expect_equal(cur_out@metadata, sm_images@metadata) expect_equal(as.vector(as.array(cur_out$E34_imc)[1:5, 1:5, 1:5]), - c(2.19091247942997, 2.84356252686191, 3.3673723610464, 3.14572847700658, - 0.983622669305094, 0.222899337345514, 1.96485523758383, 0.975483504321522, - 3.0913608704726, 1.95984734333247, 1.2249119742494, 2.23030785595094, - 0.979925379267491, 1.09383112811161, 0, 0.984049800882084, 0, - 2.14700951449616, 4.44512235501792, 0, 1.95984282166521, 1.38952853167984, - 0, 0, 0, 2.33215967202339, 0.975802822921462, 0.976676447907313, - 4.35585101567448, 0, 2.22006136192933, 0.981105558617738, 1.00600490700374, - 4.79370751533438, 0, 2.75078164753138, 0, 0, 2.05644103864334, - 1.03150187424537, 0, 0.00524125399300493, 0, 1.08051748935461, - 0, 0, 0, 0.0117787905004508, 1.04062409980771, 0.00716183064089961, - 0.315055588402477, 0.495516534300958, 0.534568548281539, 0.432929892986981, - 0.149952238758362, 0, 0.304031094587488, 0.141009838484414, 0.415572390098853, - 0.298786945215061, 0.148287560046762, 0.340029345390463, 0.149403940521257, - 0.140104743598137, 0, 0.150029779212584, 0.0265316586792683, - 0.32730164973074, 0.709689680636647, 0, 0.298759226552687, 0.211820287223255, - 0.0596239391568057, 0.0065178690321914, 0.0362531125956509, 0.463300346038719, - 2.21539693219691, 0.349579083510564, 0.805179350618355, 0.0604482747329144, - 0.320710650782931, 0.260954614190242, 0.201364068183511, 0.862480359013045, - 0.12040521563426, 0.459879033299737, 0.136987121035636, 0.0601662943949444, - 0.355198424882429, 0.135970716885409, 0.0604301955082186, 1.07899076860329, - 0.131971334957697, 0.432448305042176, 0, 0.120501372281659, 0.0854354711719541, - 2.42625619641143, 1.22805737803821, 1.47511103753946, 0.968407615883399, - 8.42292868623672, 1.02649529960838, 10.066858921215, 4.64655872894952, - 19.6775324902741, 29.3898294072017, 64.7457048612308, 27.4107824928013, - 14.9365810323236, 43.3343222889591, 22.2768840994686, 13.1043679869514, - 18.3836179718671, 24.866554665624, 11.5088084603371, 9.79035659055431, - 5.89805598850556, 1.0225441754596, 1.02304083481394, 0.0124488120807903, - 0.00882620758183113, 2.58327387916262, 8.29000698128538, 3.21541266831867 - )) + c(2.23578691482544, 2.88552832603454, 3.40094327926636, 3.22383165359497, + 0.998766601085662, 0.253727495670314, 1.99001955986022, 0.9950097799301, + 3.17507600784301, 1.99001955986023, 1.26963245868682, 2.26464223861694, + 0.995009779930112, 1.12834095954895, 0, 0.999198198318478, 0, + 2.18006634712219, 4.4866042137146, 0, 1.99001955986023, 1.41092383861542, + 0, 0, 0, 2.27523970603943, 0.982835233211518, 1.00974380970001, + 4.22755718231201, 2.20721272071921e-16, 2.12543272972107, 0.98138463497162, + 0.982144415378575, 4.6439061164856, 4.60726071214195e-16, 2.65206265449524, + 4.44857520294786e-16, 7.58915550986695e-16, 1.98678028583527, + 0.998160183429719, 7.67151408905227e-16, 0, 0, 1.13381838798523, + 0, 0, 0, 0, 0.99363511800766, 0, 0, 0, 2.4701816282689e-16, 0, + 0, 0, 2.16337061759597e-16, 0, 0, 0, 2.12880592476332e-07, 0, + 0, 0, 0, 0, 0, 1.00299690807935e-16, 0, 0, 0, 0, 0, 6.32687268151533e-16, + 0, 6.10191405892687e-17, 1.74999046325684, 0, 1.64071826474853e-16, + 3.28572770608724e-17, 1.94439564737972e-16, 2.1319274800509e-16, + 3.85965625312858e-16, 2.56614558311194e-16, 7.53835593442659e-17, + 4.57368151775708e-16, 9.7717796656081e-17, 1.15749526429746e-16, + 6.67803442275272e-17, 6.75710029006214e-18, 1.50170020269713e-16, + 0.994114995002746, 3.25868869566352e-17, 0, 0, 0, 0, 2.23528671264648, + 0.999972105026245, 1.35901546478271, 0.940284013748169, 8.39323902130127, + 0.99849933385849, 10.0154972076416, 4.637526512146, 19.6513938903809, + 29.3538608551025, 64.6947784423828, 27.3468551635742, 14.9151773452759, + 43.2846260070801, 22.2493591308594, 13.0902843475342, 18.3537216186523, + 24.8451747894287, 11.4956560134888, 9.78407001495361, 5.88088750839234, + 0.986984312534332, 1.02242743968964, 0, 0, 2.58079719543457, + 8.27865314483643, 3.21291995048523)) expect_equal(as.vector(as.array(cur_out$G01_imc)[1:5, 1:5, 1:5]), - c(42.0433486268618, 24.8502064958084, 24.8565163775208, 23.8671586508943, - 14.7721370664372, 28.6796917290198, 11.0073560703932, 35.5807413129532, - 13.2198419408514, 17.6203309734446, 31.4676799126701, 7.45659914081183, - 34.2190530240665, 25.1107542789657, 4.37200470144071, 18.8829133949791, - 27.6000216524927, 15.8781630871283, 10.0466491497996, 9.65224123615268, - 22.899059097985, 12.303893872095, 23.2060242753981, 8.77680198517962, - 5.89315975153267, 0, 0, 0, 0.619127244662373, 0, 0.348106871518595, - 0, 2.10680147303142, 0, 0, 0.833162787045088, 0.86494544216698, - 3.35127485532916, 0.426882334812537, 0, 0, 0, 0.642341377953656, - 0.792242536829195, 0, 1.52849730269222, 0, 2.58823115117122, - 0.820931139788265, 4.93170399573359, 6.40910708649243, 3.78817906460042, - 3.78918735727637, 3.91057549150629, 2.25187411374158, 4.70671929783099, - 1.67797952314402, 5.80697075963436, 2.0152472586785, 5.8408594004552, - 5.15557595240238, 1.20879370192231, 6.62983347429976, 5.1893931619719, - 0.697369307145619, 2.87856100654853, 4.20738031548391, 2.59716510881473, - 1.63592663015692, 1.47148459297048, 3.73392140851757, 1.87561667178681, - 4.87563339745428, 1.45338125990253, 2.00152645281304, 2.58503700740846, - 1.52790760087721, 1.52812997871859, 1.60150205735751, 0.90825526154206, - 1.86947132164154, 0.676740701176881, 2.5520346900347, 0.812803682167594, - 1.13778267264453, 2.11385000387633, 0.593649704324864, 2.656750333753, - 1.67195081393407, 1.35262823322088, 1.16086990401864, 1.6969152206842, - 1.09741158045001, 0.747772090268841, 0.593138171029043, 1.66642452717102, - 0.756485711591332, 3.523064698679, 1.75021391363921, 3.51604880257827, - 1.45012215382787, 2.15096184304747, 27.7770251301588, 10.3339944985449, - 2.0863925689091, 1.16828396582613, 7.65895629731013, 17.9837249664863, - 3.4537407415594, 11.4679524138153, 13.259652431308, 9.29947105385261, - 18.5842933598285, 8.06174067801254, 13.4295392824079, 23.3694911214887, - 12.2861687101164, 15.8969482208778, 45.265771088098, 51.4460358755549, - 12.7150861312118, 3.47399960222705, 34.8979564003661, 44.1063254270049, - 35.2114611713016)) + c(42.6907119750976, 25.232837677002, 25.239236831665, 24.0195350646973, + 14.9995908737183, 28.857421875, 11.1768398284912, 35.8239707946777, + 13.4233913421631, 17.8999481201172, 31.6688098907471, 7.51331901550293, + 34.4753074645996, 25.2723693847656, 4.44271850585937, 19.173656463623, + 28.0249900817871, 15.9826612472534, 10.1179981231689, 9.8008460998535, + 23.0579395294189, 12.4933423995972, 23.3956642150879, 8.8474531173706, + 6.01483392715453, 0, 0, 3.00805682867537e-15, 1.14488792419434, + 0, 0.998183071613309, 0, 2.83587074279785, 6.13080783286931e-06, + 0, 1.52557253837585, 0.998160183429719, 3.98741555213928, 0.986646056175229, + 7.75992011180919e-16, 0, 0, 0.981460273265839, 0.988971889019013, + 1.80674989038669e-15, 1.98973262310028, 0, 2.99159264564514, + 0.97893738746643, 4.8189868927002, 0, 6.03217214339641e-17, 0, + 0, 0, 0, 0, 0, 0, 2.94078779220581, 1.20622252562452e-15, 9.94543109111735e-17, + 0.999847590923308, 0.999899148941042, 0, 5.3520040343311e-18, + 0, 0, 6.00943535474613e-16, 0, 7.71311780097397e-16, 0, 0.999503374099735, + 1.59382124839064e-15, 0.997151911258697, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 2.44793419664594e-16, 0, 0, 0, 0, 0.998086810112, 1.2388428052818e-16, + 0, 4.89905647259838e-17, 2.91804912988823e-16, 6.46897126899015e-16, + 0, 0, 1.54041314125061, 0.994276285171509, 2.24675965309143, + 1.18235528469086, 1.99191880226135, 27.6025657653809, 10.1698713302612, + 1.99136519432068, 0.980086922645569, 7.58448457717896, 17.7307186126709, + 3.36774706840515, 11.305700302124, 13.0433864593506, 9.24070262908936, + 18.3178234100342, 7.87726354598999, 13.3933162689209, 23.2355976104736, + 12.103588104248, 15.78102684021, 45.1690864562988, 51.3538932800293, + 12.5505819320679, 3.39380836486816, 34.6967391967774, 44.0180168151856, + 35.1083717346192)) expect_equal(as.vector(as.array(cur_out$J02_imc)[1:5, 1:5, 1:5]), - c(2.52784678643665, 3.94732294210906, 0.979922651558483, 1.96261804369919, - 0, 2.9364163551472, 0.979922387758177, 0.979429850891626, 0, - 2.18914847046554, 1.62612164288276, 0, 0.961153472366437, 4.0652818370046, - 3.77489600016522, 4.90353065425084, 0.983612646958199, 0.962254308232961, - 0, 0, 1.59825897003124, 1.92768351046888, 0, 1.95900496760123, - 3.94999964867716, 1.62368009253514, 1.24238459027986, 0, 1.14642573626392, - 0, 0, 0, 1.00567082449753, 0, 0, 2.03014661572905, 0, 2.06713820982705, - 0.929736789503776, 0.951016208482324, 0, 0.402927448305584, 2.34125536633104, - 1.01079722375315, 0, 0, 6.15442777891983, 1.00184231263536, 0.93038665503675, - 1.89779053433036, 0.384113779712536, 0.624755029821887, 0.149387219157034, - 0.300422289135498, 0, 0.478544611201744, 0.14938560201203, 0.141554676891216, - 0, 0.333739373864907, 0.228071540353203, 0, 0.118080595497426, - 0.650174305782268, 0.60204107347724, 0.747518169093167, 0.153922340441413, - 0.112954467352711, 0, 0, 0.243682224271373, 0.198025054353821, - 0, 0.3307945668948, 0.612578760433627, 0.386179011626153, 0.423332732907551, - 0.0602243011739832, 0.28398372778675, 0, 1.26519221435643, 0.0602299110854532, - 0.201987690381892, 0, 0.134512149512616, 0.385423862745542, 0, - 0.348307989854818, 0.387369654849142, 0.3718823511537, 0.301416227598408, - 0.118293397819711, 0.386542660274728, 0.133332889570057, 0, 0.0981159471522133, - 0.977870951031461, 0.132198214001544, 1.3332364528813, 0.514476313867775, - 5.81644358434911, 2.16234216238375, 4.10134153513466, 0.019278945158285, - 1.99819805919856, 10.0543473595612, 3.23064707160147, 0.0121083498717519, - 1.99813639102084, 13.6530706285659, 5.81433380729223, 2.06607194023602, - 11.0884858960676, 1.01940269858764, 2.02803233913579, 12.171453743601, - 26.8125907733524, 1.78907634890066, 8.99556792774407, 22.0620541905847, - 23.744224545368, 7.34059062830994, 1.08813304444263, 42.1869673155035, - 22.7064987774514)) - - expect_false(isTRUE(all.equal(imageData(pancreasImages$E34_imc)[,,1], imageData(sm_images$E34_imc)[,,1], - check.attributes = FALSE, tolerance = 0.1))) - expect_equal(imageData(pancreasImages$E34_imc)[,,1], imageData(cur_out$E34_imc)[,,1], - check.attributes = FALSE, tolerance = 0.1) - expect_false(isTRUE(all.equal(imageData(pancreasImages$E34_imc)[,,2], imageData(sm_images$E34_imc)[,,2], - check.attributes = FALSE, tolerance = 0.05))) - expect_equal(imageData(pancreasImages$E34_imc)[,,2], imageData(cur_out$E34_imc)[,,2], - check.attributes = FALSE, tolerance = 0.05) - expect_false(isTRUE(all.equal(imageData(pancreasImages$E34_imc)[,,3], imageData(sm_images$E34_imc)[,,3], - check.attributes = FALSE, tolerance = 0.5))) - expect_equal(imageData(pancreasImages$E34_imc)[,,3], imageData(cur_out$E34_imc)[,,3], - check.attributes = FALSE, tolerance = 0.5) - #expect_false(isTRUE(all.equal(imageData(pancreasImages$E34_imc)[,,4], imageData(sm_images$E34_imc)[,,4], - # check.attributes = FALSE, tolerance = 0.5))) - #expect_equal(imageData(pancreasImages$E34_imc)[,,4], imageData(cur_out$E34_imc)[,,4], - # check.attributes = FALSE, tolerance = 0.5) - #expect_false(isTRUE(all.equal(imageData(pancreasImages$E34_imc)[,,5], imageData(sm_images$E34_imc)[,,5], - # check.attributes = FALSE, tolerance = 0.001))) - #expect_equal(imageData(pancreasImages$E34_imc)[,,5], imageData(cur_out$E34_imc)[,,5], - # check.attributes = FALSE, tolerance = 0.001) - - expect_false(isTRUE(all.equal(imageData(pancreasImages$G01_imc)[,,1], imageData(sm_images$G01_imc)[,,1], - check.attributes = FALSE, tolerance = 0.1))) - expect_equal(imageData(pancreasImages$G01_imc)[,,1], imageData(cur_out$G01_imc)[,,1], - check.attributes = FALSE, tolerance = 0.1) - expect_false(isTRUE(all.equal(imageData(pancreasImages$G01_imc)[,,2], imageData(sm_images$G01_imc)[,,2], - check.attributes = FALSE, tolerance = 0.1))) - expect_equal(imageData(pancreasImages$G01_imc)[,,2], imageData(cur_out$G01_imc)[,,2], - check.attributes = FALSE, tolerance = 0.1) - #expect_false(isTRUE(all.equal(imageData(pancreasImages$G01_imc)[,,3], imageData(sm_images$G01_imc)[,,3], - # check.attributes = FALSE, tolerance = 0.5))) - #expect_equal(imageData(pancreasImages$G01_imc)[,,3], imageData(cur_out$G01_imc)[,,3], - # check.attributes = FALSE, tolerance = 0.5) - #expect_false(isTRUE(all.equal(imageData(pancreasImages$G01_imc)[,,4], imageData(sm_images$G01_imc)[,,4], - # check.attributes = FALSE, tolerance = 0.5))) - #expect_equal(imageData(pancreasImages$G01_imc)[,,4], imageData(cur_out$G01_imc)[,,4], - # check.attributes = FALSE, tolerance = 0.5) - #expect_false(isTRUE(all.equal(imageData(pancreasImages$G01_imc)[,,5], imageData(sm_images$G01_imc)[,,5], - # check.attributes = FALSE, tolerance = 0.001))) - #expect_equal(imageData(pancreasImages$G01_imc)[,,5], imageData(cur_out$G01_imc)[,,5], - # check.attributes = FALSE, tolerance = 0.001) - - expect_false(isTRUE(all.equal(imageData(pancreasImages$J02_imc)[,,1], imageData(sm_images$J02_imc)[,,1], - check.attributes = FALSE, tolerance = 0.1))) - expect_equal(imageData(pancreasImages$J02_imc)[,,1], imageData(cur_out$J02_imc)[,,1], - check.attributes = FALSE, tolerance = 0.1) - expect_false(isTRUE(all.equal(imageData(pancreasImages$J02_imc)[,,2], imageData(sm_images$J02_imc)[,,2], - check.attributes = FALSE, tolerance = 0.5))) - expect_equal(imageData(pancreasImages$J02_imc)[,,2], imageData(cur_out$J02_imc)[,,2], - check.attributes = FALSE, tolerance = 0.5) - #expect_false(isTRUE(all.equal(imageData(pancreasImages$J02_imc)[,,3], imageData(sm_images$J02_imc)[,,3], - # check.attributes = FALSE, tolerance = 0.5))) - #expect_equal(imageData(pancreasImages$J02_imc)[,,3], imageData(cur_out$J02_imc)[,,3], - # check.attributes = FALSE, tolerance = 0.5) - #expect_false(isTRUE(all.equal(imageData(pancreasImages$J02_imc)[,,4], imageData(sm_images$J02_imc)[,,4], - # check.attributes = FALSE, tolerance = 0.5))) - #expect_equal(imageData(pancreasImages$J02_imc)[,,4], imageData(cur_out$J02_imc)[,,4], - # check.attributes = FALSE, tolerance = 0.5) - #expect_false(isTRUE(all.equal(imageData(pancreasImages$J02_imc)[,,5], imageData(sm_images$J02_imc)[,,5], - # check.attributes = FALSE, tolerance = 0.001))) - #expect_equal(imageData(pancreasImages$J02_imc)[,,5], imageData(cur_out$J02_imc)[,,5], - # check.attributes = FALSE, tolerance = 0.001) + c(2.56513524055481, 3.98799896240234, 0.995009779930114, 1.99001955986023, + 0, 2.98502922058105, 0.995009779930114, 0.998989760875702, 0, + 2.22285175323486, 1.66348826885223, 0, 0.995009779930113, 4.10242557525635, + 3.81057667732239, 4.97902917861938, 0.995009779930107, 0.999840378761293, + 0, 0, 1.62286090850829, 2.02285480499268, 9.98057272913661e-16, + 1.99001955986022, 3.99958419799804, 1.60733664035797, 1.27663969993591, + 1.14893049049833e-16, 1.13901674747467, 0, 6.40914067195336e-16, + 1.12921868149168e-16, 0.981931209564209, 1.10347361417425e-16, + 4.38027567992899e-16, 1.97406804561615, 0, 1.99390268325806, + 0.981185019016266, 0.994735479354859, 8.63601561217332e-16, 0.407142639160159, + 2.255375623703, 0.978140294551849, 0, 1.53651146412609e-15, 5.91469812393188, + 0.969482600688934, 0.924965262413028, 1.90180563926697, 8.00042565079957e-16, + 2.38141574816903e-16, 2.43681164872445e-18, 1.30631671547082e-16, + 0, 3.41020437597507e-17, 0, 1.33738276886231e-16, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 5.13395063957856e-16, 7.64635330341934e-17, 0, + 0, 1.25358166550498e-15, 2.17904946155624e-16, 1.44892840762785e-16, + 5.27977934518383e-16, 0, 0, 2.59678652173295e-17, 1.63205515154427e-17, + 0, 0.998832404613495, 4.04310704311885e-17, 2.62118005054629e-18, + 1.06167702530658e-17, 3.37113115874083e-17, 9.57085654436642e-17, + 0, 0, 0, 0, 1.21760103020968e-16, 2.49650223556376e-16, 0, 3.06703334435003e-17, + 0, 1.49992833090266e-16, 0, 0, 0.994928717613221, 0, 5.78729391098022, + 2.12839007377625, 4.09265995025635, 0, 1.99699997901917, 10.0292625427246, + 3.22248792648315, 0, 1.99693834781647, 13.6309814453125, 5.7886872291565, + 2.06483316421509, 11.0637636184692, 0.987166047096252, 1.99694669246674, + 12.1330223083496, 26.7878303527832, 1.76835513114929, 8.9838399887085, + 22.0488262176514, 23.7198314666748, 7.28843069076538, 1.08120548725128, + 42.1432800292969, 22.6564445495605)) + + channelNames(cur_out) <- channelNames(pancreasImages) + + expect_false(isTRUE(all.equal(imageData(pancreasImages$E34_imc)[,,1], imageData(sm_images$E34_imc)[,,1]))) + expect_equal(pancreasImages$E34_imc, cur_out$E34_imc) + expect_equal(pancreasImages$G01_imc, cur_out$G01_imc) + expect_equal(pancreasImages$J02_imc, cur_out$J02_imc) + # weak spillover sm_images <- pancreasImages - channelNames(sm_images) <- c("Dy161Di", "Dy162Di", "Dy163Di", "Dy164Di", "Ho165Di") - cur_ch <- endoapply(sm_images, function(x){ - Image(apply(x, c(1,2), function(y){sum(y * sm_real[,"Dy161Di"])})) - }) - channelNames(cur_ch) <- "Dy161Di" - setChannels(sm_images, "Dy161Di") <- cur_ch - - cur_ch <- endoapply(sm_images, function(x){ - Image(apply(x, c(1,2), function(y){sum(y * sm_real[,"Dy162Di"])})) - }) - channelNames(cur_ch) <- "Dy162Di" - setChannels(sm_images, "Dy162Di") <- cur_ch - - cur_ch <- endoapply(sm_images, function(x){ - Image(apply(x, c(1,2), function(y){sum(y * sm_real[,"Dy163Di"])})) - }) - channelNames(cur_ch) <- "Dy163Di" - setChannels(sm_images, "Dy163Di") <- cur_ch - - cur_ch <- endoapply(sm_images, function(x){ - Image(apply(x, c(1,2), function(y){sum(y * sm_real[,"Dy164Di"])})) - }) - channelNames(cur_ch) <- "Dy164Di" - setChannels(sm_images, "Dy164Di") <- cur_ch - cur_ch <- endoapply(sm_images, function(x){ - Image(apply(x, c(1,2), function(y){sum(y * sm_real[,"Ho165Di"])})) + out <- endoapply(sm_images, function(x){ + cur_out <- apply(x, c(1,2), function(y) return(y %*% sm_real)) + cur_out <- aperm(cur_out, c(2,3,1)) + return(Image(cur_out)) }) - channelNames(cur_ch) <- "Ho165Di" - setChannels(sm_images, "Ho165Di") <- cur_ch + channelNames(out) <- channelNames(pancreasImages) + sm_images <- out # Visual inspection plotPixels(pancreasImages, colour_by = "H3") - plotPixels(sm_images, colour_by = "Dy161Di") + plotPixels(sm_images, colour_by = "H3") plotPixels(pancreasImages, colour_by = "CD99") - plotPixels(sm_images, colour_by = "Dy162Di") + plotPixels(sm_images, colour_by = "CD99") plotPixels(pancreasImages, colour_by = "PIN") - plotPixels(sm_images, colour_by = "Dy163Di") + plotPixels(sm_images, colour_by = "PIN") plotPixels(pancreasImages, colour_by = "CD8a") - plotPixels(sm_images, colour_by = "Dy164Di") + plotPixels(sm_images, colour_by = "CD8a") plotPixels(pancreasImages, colour_by = "CDH") - plotPixels(sm_images, colour_by = "Ho165Di") + plotPixels(sm_images, colour_by = "CDH") + + channelNames(sm_images) <- rownames(sm_real) expect_silent(cur_out <- compImage(sm_images, sm_real)) @@ -299,166 +197,90 @@ test_that("compImage function works", { plotPixels(cur_out, colour_by = "Ho165Di") expect_equal(as.vector(as.array(cur_out$E34_imc)[1:5, 1:5, 1:5]), - c(2.235732088208, 2.8854730513074, 3.4008971202628, 3.22373821331941, - 0.99875629977235, 0.253692906479931, 1.9899866179725, 0.994985844055508, - 3.17497668451463, 1.98999903490431, 1.26958066348013, 2.26461888137977, - 0.994999517625591, 1.12830055125045, 0, 0.999187892764767, 0, - 2.18004386171178, 4.48654633170962, 0, 1.98999903444506, 1.41090928609636, - 0, 0, 0, 2.27635725972987, 0.983536654362042, 1.01017745844559, - 4.22965774864491, 0, 2.12652417304427, 0.981840137820238, 0.982626055121661, - 4.64622303248461, 0, 2.65339987458059, 0, 0, 1.98777747278492, - 0.998675102237445, 0, 0.000152043848113654, 0, 1.13428804602046, - 0, 0, 0, 0.000341872622664964, 0.994300640920651, 0.000207852687758287, - 0.00401044534673232, 0.00569775197892415, 0.00579791443161271, - 0.00589961298032481, 0.00166447452795089, 0.000685582701755591, - 0.00344078386091881, 0.00178105607914726, 0.00586967037376447, - 0.00331642833497421, 0.00244548100062844, 0.00377409633100861, - 0.00165821514968374, 0.00212745809414315, 0.000123033207785647, - 0.00166519499322897, 0.000433320776903636, 0.00363314528274224, - 0.00762427538116815, 0, 0.0033164257341525, 0.00235134579664235, - 0.000974326774952282, 0.000558344737800897, 0.000592374024752764, - 0.00418079540176943, 1.75424265942173, 0.00320579318150167, 0.00724655246304433, - 0.000559497268857626, 0.00287675328206037, 0.00237814134379035, - 0.00182108288281706, 0.00775479818315889, 0.00111475141155682, - 0.00412372257298681, 0.00126855541881744, 0.000557341887479148, - 0.00318869498623407, 0.0012839373702388, 0.000559697880852737, - 0.994893113635612, 0.00122127291936576, 0.00397407497917223, - 0, 0.00111484096120764, 0.00079042222506761, 2.23703644397587, - 1.00203308281328, 1.36007926114486, 0.94052069249707, 8.39347037048068, - 0.998709574554686, 10.0159472939418, 4.63759651653449, 19.6516501414446, - 29.3541799448566, 64.6952676067429, 27.3474321805845, 14.9153508776922, - 43.2850985815283, 22.2495882662622, 13.0904049101193, 18.3539986915052, - 24.8453837997218, 11.4957671851282, 9.78412878891609, 5.88101486063863, - 0.98724778039971, 1.02243357424814, 8.40408149755324e-05, 5.95849365792035e-05, - 2.58081283588555, 8.27876255327549, 3.21293932270747)) + c(2.23578691482544, 2.88552832603455, 3.40094327926636, 3.22383165359497, + 0.998766601085664, 0.25372749567032, 1.99001955986024, 0.99500977993013, + 3.17507600784302, 1.99001955986023, 1.26963245868683, 2.26464223861695, + 0.995009779930118, 1.12834095954895, 4.83596051887921e-15, 0.999198198318485, + 2.69332780168834e-15, 2.18006634712219, 4.4866042137146, 2.21770122912683e-16, + 1.99001955986023, 1.41092383861542, 4.55654073638636e-16, 3.32619462662008e-15, + 3.83754286353452e-16, 2.27523970603943, 0.982835233211518, 1.00974380970001, + 4.22755718231201, 0, 2.12543272972107, 0.981384634971619, 0.98214441537857, + 4.6439061164856, 6.63651264716718e-16, 2.65206265449524, 4.41551510765918e-16, + 2.20556729785805e-16, 1.98678028583527, 0.998160183429718, 1.09655057649601e-16, + 1.0327327628663e-17, 8.86478916216937e-16, 1.13381838798523, + 0, 0, 0, 0, 0.99363511800766, 0, 0, 1.22499415057453e-15, 1.11238882125062e-16, + 0, 0, 1.11200103223052e-16, 0, 1.09352185873552e-16, 0, 0, 2.12880593022593e-07, + 0, 0, 2.22308723148135e-16, 0, 0, 0, 0, 2.22459995021217e-16, + 0, 0, 0, 0, 0, 0, 0, 1.74999046325684, 4.15025262455971e-19, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.994114995002747, 0, + 1.48110139581551e-18, 0, 0, 0, 2.23528671264648, 0.999972105026245, + 1.35901546478271, 0.940284013748169, 8.39323902130127, 0.99849933385849, + 10.0154972076416, 4.637526512146, 19.6513938903809, 29.3538608551025, + 64.6947784423828, 27.3468551635742, 14.9151773452759, 43.2846260070801, + 22.2493591308594, 13.0902843475342, 18.3537216186523, 24.8451747894287, + 11.4956560134888, 9.78407001495361, 5.88088750839233, 0.986984312534332, + 1.02242743968964, 0, 9.22015961887504e-25, 2.58079719543457, + 8.27865314483642, 3.21291995048523)) expect_equal(as.vector(as.array(cur_out$G01_imc)[1:5, 1:5, 1:5]), - c(42.6902716555488, 25.2325774210941, 25.2389765105437, 24.019300011956, - 14.9994361653353, 28.8571452110096, 11.1767245488137, 35.8236030829578, - 13.4232531878661, 17.8997645591454, 31.668499738626, 7.51323576733715, - 34.4749289437561, 25.2721198472437, 4.44267015124073, 19.1734587038404, - 28.0247010274348, 15.9825015057999, 10.1178914126346, 9.80074501376742, - 23.0577003552362, 12.4932135411493, 23.3953887314381, 8.84735000741003, - 6.01468246529686, 0, 0, 0, 1.14485794697834, 0, 0.99795214031261, - 0, 2.83640893095649, 0, 0, 1.52554132309874, 0.998481453383544, - 3.9887053367071, 0.986623734889973, 3.81026772555567e-05, 0, - 0, 0.981553798214287, 0.989221025852425, 0, 1.99016397437819, - 0, 2.99289079694945, 0.979366671206552, 4.82178678092487, 0.0711453189051755, - 0.042051261503576, 0.0420619303476064, 0.0402095420806812, 0.0249972567454924, - 0.0482617648937313, 0.018626531423736, 0.0601098401926974, 0.0223708599363171, - 2.97269661995508, 0.053016680681579, 0.0126565542527279, 1.05854865891909, - 1.04287799270615, 0.00784627083829624, 0.0319534626992128, 0.0467044668210082, - 0.026782644975436, 0.0170004272158127, 0.0163334053080955, 0.0387097265901905, - 0.0208205206888476, 1.04027034688854, 0.0153132034874762, 1.00945685933091, - 0.0239160163076971, 0.0141358295053574, 0.0141392606502316, 0.0149388416733132, - 0.00840300007696997, 0.0174623663222053, 0.00626139988272876, - 0.02373226972634, 0.00752008347796783, 0.0104987624561541, 0.0197169685636446, - 0.00549632590152791, 0.0246160037015254, 0.0155958574821157, - 1.00135878860339, 0.0107412511995018, 0.0156999774765707, 0.0102228948902351, - 0.00694452722726292, 0.00549028327864336, 0.0154867311808948, - 0.00699895095575971, 1.55874220880979, 1.00127400653121, 2.25824842385221, - 1.18416525673563, 1.99299636560437, 27.6037972637719, 10.1710154073478, - 1.99201059255902, 0.981371348224494, 7.58500209516143, 17.7325080787427, - 3.36833416001096, 11.306930171416, 13.0448936544829, 9.241135287295, - 18.319766677685, 7.87857536106283, 13.3935843076446, 23.2365467504627, - 12.1048442537788, 15.7818553856384, 45.1698441261234, 51.3546153062428, - 12.551750417766, 3.39435633606025, 34.6982531233785, 44.0187133913885, - 35.1092636191178)) + c(42.6907119750977, 25.232837677002, 25.239236831665, 24.0195350646973, + 14.9995908737183, 28.857421875, 11.1768398284912, 35.8239707946777, + 13.4233913421631, 17.8999481201172, 31.6688098907471, 7.51331901550293, + 34.4753074645996, 25.2723693847656, 4.44271850585938, 19.1736564636231, + 28.0249900817871, 15.9826612472534, 10.117998123169, 9.80084609985353, + 23.057939529419, 12.4933423995972, 23.3956642150879, 8.84745311737061, + 6.01483392715455, 0, 0, 7.09533573928995e-15, 1.14488792419434, + 2.20676415100722e-16, 0.998183071613312, 8.8651733037851e-16, + 2.83587074279785, 6.13080783323267e-06, 2.16185774069926e-15, + 1.52557253837586, 0.998160183429719, 3.98741555213928, 0.986646056175232, + 9.14042689628838e-16, 7.09420260716262e-15, 1.77359768936059e-15, + 0.981460273265841, 0.988971889019014, 1.77030327197491e-15, 1.98973262310028, + 0, 2.99159264564515, 0.978937387466434, 4.8189868927002, 0, 0, + 0, 2.21960738102303e-16, 0, 1.11085698156659e-16, 0, 0, 0, 2.94078779220581, + 0, 1.10609433251125e-16, 0.99984759092331, 0.99989914894104, + 5.04325723449548e-16, 0, 0, 0, 1.09942229769164e-16, 0, 0, 0, + 0.999503374099731, 7.79541732183792e-16, 0.997151911258699, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3.3343092841449e-16, 0, 0.998086810112, + 0, 0, 0, 0, 0, 0, 0, 1.54041314125061, 0.994276285171509, 2.24675965309143, + 1.18235528469086, 1.99191880226135, 27.6025657653809, 10.1698713302612, + 1.99136519432068, 0.980086922645569, 7.58448457717896, 17.7307186126709, + 3.36774706840515, 11.305700302124, 13.0433864593506, 9.24070262908936, + 18.3178234100342, 7.87726354598999, 13.3933162689209, 23.2355976104736, + 12.103588104248, 15.78102684021, 45.1690864562988, 51.3538932800293, + 12.5505819320679, 3.39380836486816, 34.6967391967773, 44.0180168151855, + 35.1083717346191)) expect_equal(as.vector(as.array(cur_out$J02_imc)[1:5, 1:5, 1:5]), - c(2.56508757668402, 3.98794342886768, 0.994999517348545, 1.98998422231417, - 0, 2.98499406905562, 0.994999517321752, 0.998965790323043, 0, - 2.22282882676681, 1.66344320394516, 0, 0.994970471432098, 4.10237349346291, - 3.81052703435922, 4.97897782440174, 0.994994578657299, 0.9997970538085, - 0, 0, 1.62284417076302, 2.02274661580171, 0, 1.98997940497277, - 3.99951906226492, 1.60810063206105, 1.27719603994058, 0, 1.13955368237191, - 0, 7.5930059586011e-05, 0, 0.982412633292276, 0, 0, 1.9750448195261, - 0, 1.9949069988713, 0.981585765491606, 0.995150776784699, 0, - 0.407327229037369, 2.25651489186555, 0.978644885030787, 0, 0, - 5.91770134531288, 0.969982724585896, 0.92554417880411, 1.90268464362844, - 0.0044774159241067, 0.00681015336409907, 0.00165821358073044, - 0.003460233956606, 0, 0.0054149479304298, 0.00165821342899492, - 0.00178765787943071, 0, 0.00370444976340417, 0.00301859406798573, - 0, 0.00190591921529414, 0.00696456881149702, 0.00647939305632368, - 0.00829769970225082, 0.00171008221345617, 0.00194624707675346, - 0.000120562916143128, 0, 0.00270454925140364, 0.00410442932610487, - 0.000119494447738691, 0.00386758436768826, 0.00690664150005338, - 0.00350606796920903, 0.003878296226295, 0.00055739590856817, - 0.00258113037627808, 0, 1.00128777516598, 0.000557401133018344, - 0.00182342829861107, 0, 0.00124519546094502, 0.00347242964781346, - 0, 0.0031231542692791, 0.00356231491676516, 0.00341612641395389, - 0.00278925937351655, 0.00108150118653599, 0.00346233477680135, - 0.00125827795284414, 0, 0.000909010367863096, 0.00874398631336669, - 0.00124718768316171, 0.998013095160967, 0.00468901946933563, - 5.78753347378061, 2.12864791085128, 4.09272652677097, 0.000152430985151432, - 1.99701196100706, 10.0294488409872, 3.22254928193429, 0.000101148624870215, - 1.99695032943457, 13.6311571052785, 5.78891074649069, 2.06484555320168, - 11.0639917486163, 0.987404127464168, 1.99717932088095, 12.1333053770497, - 26.7880575465259, 1.76854339336152, 8.98395262825048, 22.0489585104764, - 23.7200423218009, 7.28891500810526, 1.08127019081719, 42.1436725368445, - 22.6568635847378)) + c(2.56513524055481, 3.98799896240234, 0.995009779930116, 1.99001955986023, + 4.43552575162044e-16, 2.98502922058106, 0.995009779930115, 0.998989760875703, + 8.87549248467535e-16, 2.22285175323487, 1.66348826885224, 4.43540245825365e-16, + 0.995009779930115, 4.10242557525634, 3.81057667732239, 4.97902917861939, + 0.995009779930118, 0.999840378761293, 9.82461080743612e-16, 3.54887573951098e-15, + 1.6228609085083, 2.02285480499268, 9.54709748276902e-16, 1.99001955986023, + 3.99958419799805, 1.60733664035797, 1.27663969993591, 3.32189581133068e-16, + 1.13901674747467, 0, 1.04468528051004e-15, 3.32556811569418e-16, + 0.981931209564209, 0, 0, 1.97406804561615, 0, 1.99390268325806, + 0.981185019016266, 0.994735479354859, 1.77237813972365e-15, 0.407142639160156, + 2.255375623703, 0.978140294551849, 0, 4.42882072657039e-16, 5.91469812393188, + 0.969482600688934, 0.924965262413025, 1.90180563926697, 2.22353566301504e-16, + 0, 0, 1.3718357599068e-17, 0, 7.19271442227435e-16, 0, 0, 0, + 0, 0, 0, 0, 0, 1.1119013885545e-16, 0, 0, 0, 1.30570954634137e-17, + 0, 0, 0, 6.34017592606454e-18, 7.79541732183792e-16, 2.22008617562531e-16, + 0, 1.73307244964571e-18, 0, 6.63040732823723e-18, 0, 0.998832404613496, + 0, 1.73361070713585e-18, 0, 0, 0, 0, 0, 3.46614489929143e-18, + 0, 0, 0, 0, 9.24391799796069e-19, 0, 0, 0, 0, 0.994928717613221, + 0, 5.78729391098022, 2.12839007377625, 4.09265995025635, 0, 1.99699997901916, + 10.0292625427246, 3.22248792648315, 0, 1.99693834781647, 13.6309814453125, + 5.78868722915649, 2.06483316421509, 11.0637636184692, 0.987166047096252, + 1.99694669246674, 12.1330223083496, 26.7878303527832, 1.76835513114929, + 8.9838399887085, 22.0488262176514, 23.7198314666748, 7.28843069076538, + 1.08120548725128, 42.1432800292969, 22.6564445495605)) - expect_false(isTRUE(all.equal(imageData(pancreasImages$E34_imc)[,,1], imageData(sm_images$E34_imc)[,,1], - check.attributes = FALSE, tolerance = 0.001))) - expect_equal(imageData(pancreasImages$E34_imc)[,,1], imageData(cur_out$E34_imc)[,,1], - check.attributes = FALSE, tolerance = 0.001) - expect_false(isTRUE(all.equal(imageData(pancreasImages$E34_imc)[,,2], imageData(sm_images$E34_imc)[,,2], - check.attributes = FALSE, tolerance = 0.05))) - expect_equal(imageData(pancreasImages$E34_imc)[,,2], imageData(cur_out$E34_imc)[,,2], - check.attributes = FALSE, tolerance = 0.05) - expect_false(isTRUE(all.equal(imageData(pancreasImages$E34_imc)[,,3], imageData(sm_images$E34_imc)[,,3], - check.attributes = FALSE, tolerance = 0.05))) - expect_equal(imageData(pancreasImages$E34_imc)[,,3], imageData(cur_out$E34_imc)[,,3], - check.attributes = FALSE, tolerance = 0.05) - expect_false(isTRUE(all.equal(imageData(pancreasImages$E34_imc)[,,4], imageData(sm_images$E34_imc)[,,4], - check.attributes = FALSE, tolerance = 0.05))) - expect_equal(imageData(pancreasImages$E34_imc)[,,4], imageData(cur_out$E34_imc)[,,4], - check.attributes = FALSE, tolerance = 0.05) - #expect_false(isTRUE(all.equal(imageData(pancreasImages$E34_imc)[,,5], imageData(sm_images$E34_imc)[,,5], - # check.attributes = FALSE, tolerance = 0.001))) - #expect_equal(imageData(pancreasImages$E34_imc)[,,5], imageData(cur_out$E34_imc)[,,5], - # check.attributes = FALSE, tolerance = 0.001) - - expect_false(isTRUE(all.equal(imageData(pancreasImages$G01_imc)[,,1], imageData(sm_images$G01_imc)[,,1], - check.attributes = FALSE, tolerance = 0.001))) - expect_equal(imageData(pancreasImages$G01_imc)[,,1], imageData(cur_out$G01_imc)[,,1], - check.attributes = FALSE, tolerance = 0.001) - expect_false(isTRUE(all.equal(imageData(pancreasImages$G01_imc)[,,2], imageData(sm_images$G01_imc)[,,2], - check.attributes = FALSE, tolerance = 0.005))) - expect_equal(imageData(pancreasImages$G01_imc)[,,2], imageData(cur_out$G01_imc)[,,2], - check.attributes = FALSE, tolerance = 0.005) - expect_false(isTRUE(all.equal(imageData(pancreasImages$G01_imc)[,,3], imageData(sm_images$G01_imc)[,,3], - check.attributes = FALSE, tolerance = 0.05))) - expect_equal(imageData(pancreasImages$G01_imc)[,,3], imageData(cur_out$G01_imc)[,,3], - check.attributes = FALSE, tolerance = 0.05) - expect_false(isTRUE(all.equal(imageData(pancreasImages$G01_imc)[,,4], imageData(sm_images$G01_imc)[,,4], - check.attributes = FALSE, tolerance = 0.5))) - expect_equal(imageData(pancreasImages$G01_imc)[,,4], imageData(cur_out$G01_imc)[,,4], - check.attributes = FALSE, tolerance = 0.5) - #expect_false(isTRUE(all.equal(imageData(pancreasImages$G01_imc)[,,5], imageData(sm_images$G01_imc)[,,5], - # check.attributes = FALSE, tolerance = 0.001))) - #expect_equal(imageData(pancreasImages$G01_imc)[,,5], imageData(cur_out$G01_imc)[,,5], - # check.attributes = FALSE, tolerance = 0.001) - - expect_false(isTRUE(all.equal(imageData(pancreasImages$J02_imc)[,,1], imageData(sm_images$J02_imc)[,,1], - check.attributes = FALSE, tolerance = 0.001))) - expect_equal(imageData(pancreasImages$J02_imc)[,,1], imageData(cur_out$J02_imc)[,,1], - check.attributes = FALSE, tolerance = 0.001) - expect_false(isTRUE(all.equal(imageData(pancreasImages$J02_imc)[,,2], imageData(sm_images$J02_imc)[,,2], - check.attributes = FALSE, tolerance = 0.005))) - expect_equal(imageData(pancreasImages$J02_imc)[,,2], imageData(cur_out$J02_imc)[,,2], - check.attributes = FALSE, tolerance = 0.005) - expect_false(isTRUE(all.equal(imageData(pancreasImages$J02_imc)[,,3], imageData(sm_images$J02_imc)[,,3], - check.attributes = FALSE, tolerance = 0.5))) - expect_equal(imageData(pancreasImages$J02_imc)[,,3], imageData(cur_out$J02_imc)[,,3], - check.attributes = FALSE, tolerance = 0.5) - expect_false(isTRUE(all.equal(imageData(pancreasImages$J02_imc)[,,4], imageData(sm_images$J02_imc)[,,4], - check.attributes = FALSE, tolerance = 0.05))) - expect_equal(imageData(pancreasImages$J02_imc)[,,4], imageData(cur_out$J02_imc)[,,4], - check.attributes = FALSE, tolerance = 0.05) - #expect_false(isTRUE(all.equal(imageData(pancreasImages$J02_imc)[,,5], imageData(sm_images$J02_imc)[,,5], - # check.attributes = FALSE, tolerance = 0.001))) - #expect_equal(imageData(pancreasImages$J02_imc)[,,5], imageData(cur_out$J02_imc)[,,5], - # check.attributes = FALSE, tolerance = 0.001) + channelNames(cur_out) <- channelNames(pancreasImages) + expect_false(isTRUE(all.equal(imageData(pancreasImages$E34_imc)[,,1], imageData(sm_images$E34_imc)[,,1]))) + expect_equal(imageData(pancreasImages$E34_imc), imageData(cur_out$E34_imc)) + expect_equal(imageData(pancreasImages$G01_imc), imageData(cur_out$G01_imc)) + expect_equal(imageData(pancreasImages$J02_imc), imageData(cur_out$J02_imc)) + # on disk cur_images_ondisk <- CytoImageList(sm_images, on_disk = TRUE, h5FilesPath = cur_path) @@ -477,6 +299,8 @@ test_that("compImage function works", { expect_equal(cur_out_2@elementMetadata, sm_images@elementMetadata) expect_equal(cur_out_2@metadata, sm_images@metadata) + channelNames(cur_out_2) <- channelNames(cur_out) + expect_equal(as.array(cur_out$E34_imc), as.array(cur_out_2$E34_imc)) expect_equal(as.array(cur_out$G01_imc), @@ -492,6 +316,7 @@ test_that("compImage function works", { expect_s4_class(cur_out_2$J02_imc, "DelayedArray") # Check if second layer was created + library(rhdf5) expect_true("E34_imc_comp" %in% h5ls(path(cur_out_2$E34_imc@seed))$name) expect_true("E34_imc_comp" %in% h5ls(path(cur_images_ondisk$E34_imc@seed))$name) expect_equal(h5ls(path(cur_out_2$E34_imc@seed))$name, @@ -499,6 +324,8 @@ test_that("compImage function works", { expect_silent(cur_out_3 <- compImage(cur_images_ondisk, sm_real)) + channelNames(cur_out_3) <- channelNames(cur_out) + expect_equal(as.array(cur_out$E34_imc), as.array(cur_out_3$E34_imc)) expect_equal(as.array(cur_out$G01_imc), @@ -509,6 +336,24 @@ test_that("compImage function works", { expect_equal(h5ls(path(cur_out_3$E34_imc@seed))$name, c(".E34_imc_dimnames", "3", "E34_imc", "E34_imc_comp")) + # Overwrite + cur_images_ondisk <- CytoImageList(sm_images, on_disk = TRUE, + h5FilesPath = cur_path) + + expect_silent(cur_out_2 <- compImage(cur_images_ondisk, sm_real, overwrite = TRUE)) + expect_equal(h5ls(path(cur_out_2$E34_imc@seed))$name, + c("E34_imc_comp")) + + channelNames(cur_out_2) <- channelNames(pancreasImages) + + expect_equal(as.array(cur_out$E34_imc), + as.array(cur_out_2$E34_imc)) + expect_equal(as.array(cur_out$G01_imc), + as.array(cur_out_2$G01_imc)) + expect_equal(as.array(cur_out$J02_imc), + as.array(cur_out_2$J02_imc)) + + # Fail expect_error(compImage("test"), regexp = "'object' not of type 'CytoImageList'",