Skip to content

Commit

Permalink
cbs: remove/replace any nulls from .cnr before segmenting
Browse files Browse the repository at this point in the history
Addresses #436, #582, maybe #760, #896, #901 and sarek#1625
  • Loading branch information
etal committed Sep 22, 2024
1 parent 5c4fd71 commit 4cfb84a
Showing 1 changed file with 13 additions and 8 deletions.
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

0 comments on commit 4cfb84a

Please sign in to comment.