Skip to content

Commit fb5564f

Browse files
committed
Fall back to unaligned pedigree plot when kinship2 alignment fails
kinship2's QP-based alignment (align=TRUE) can fail with "constraints are inconsistent, no solution!" on deep or looped pedigrees, which aborts the entire Pedigree report. Wrap the plot call in tryCatch so that this specific alignment failure is caught and retried with align=FALSE, letting the report render rather than error out. Any other error is re-raised unchanged.
1 parent d88ccb7 commit fb5564f

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

  • ehr/resources/reports/schemas/study/Pedigree

ehr/resources/reports/schemas/study/Pedigree/Pedigree.r

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,19 @@ if ((nrow(labkey.data) == 0) | (all(is.na(labkey.data$dam)) & all(is.na(labkey.d
300300
png(filename="${imgout:png_pedigree}", width = plotWidth, height=plotHeight);
301301
par(xpd=TRUE);
302302

303-
plot(ptemp, align=T, width=15, symbolsize=symSize, cex=cexSize, col=fixedPed$colors, mar=c(4.1,3.5,4.1,3.8))
303+
# kinship2's QP-based alignment (align=TRUE) can fail with "constraints are inconsistent,
304+
# no solution!" on deep/looped pedigrees. Fall back to the unaligned layout in that case so
305+
# the report still renders rather than aborting.
306+
tryCatch(
307+
plot(ptemp, align=TRUE, width=15, symbolsize=symSize, cex=cexSize, col=fixedPed$colors, mar=c(4.1,3.5,4.1,3.8)),
308+
error = function(e) {
309+
# Only the QP alignment failure is recoverable by dropping alignment; re-raise anything else.
310+
if (!grepl("constraints are inconsistent", conditionMessage(e), fixed = TRUE))
311+
stop(e)
312+
message("Pedigree alignment failed (", conditionMessage(e), "); retrying with align=FALSE.")
313+
plot(ptemp, align=FALSE, width=15, symbolsize=symSize, cex=cexSize, col=fixedPed$colors, mar=c(4.1,3.5,4.1,3.8))
314+
}
315+
)
304316
mtext("Unknown animals are marked with xxs ## or xxd ## where ## is a randomly generated unique number. This identifier is used only in this plot and is re-generated each time the plot is rendered.",
305317
side = 1, font = 3, cex = 0.95)
306318
leg.txt <- c("Male", "Female", "Deceased")

0 commit comments

Comments
 (0)