Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent CBS segmentation failures due to nulls in input .cnr #914

Merged
merged 1 commit into from
Sep 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions cnvlib/segmentation/cbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,19 @@

write("Loading probe coverages into a data frame", stderr())
tbl = read.delim("%(probes_fname)s")
if (!is.null(tbl$weight)) {
# Drop any 0-weight bins
tbl = tbl[tbl$weight > 0,]
# Filter the original .cnr to valid rows (usually they're all valid)
if (!is.null(tbl$weight) && (sum(!is.na(tbl$weight)) > 0)) {
# Drop any null or 0-weight bins
tbl = tbl[!is.na(tbl$weight) & (tbl$weight > 0),]
} else {
# No bin weight information; set all equal weights
tbl$weight = 1.0
}
if ((sum(is.na(tbl$log2)) > 0)) {
# Drop any bins with null/missing log2 ratios
tbl = tbl[!is.na(tbl$log2),]
}

cna = CNA(cbind(tbl$log2), tbl$chromosome, tbl$start,
data.type="logratio", presorted=T)

Expand All @@ -25,11 +34,7 @@
cna = smooth.CNA(cna)
}

if (is.null(tbl$weight)) {
fit = segment(cna, alpha=%(threshold)g)
} else {
fit = segment(cna, weights=tbl$weight, alpha=%(threshold)g)
}
fit = segment(cna, weights=tbl$weight, alpha=%(threshold)g)

write("Setting segment endpoints to original bin start/end positions", stderr())
write("and recalculating segment means with bin weights", stderr())
Expand Down
Loading