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

Length zero fix #1030

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 2 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
16 changes: 11 additions & 5 deletions R/sample_swap.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ sampleSwaps = function(bams = NULL, build = "hg19", prefix = NULL, add = TRUE, m
data.table::data.table(
X_bam = names(rc_af)[idx],
Y_bam = names(rc_af)[rest_idx],
concordant_snps = concordant_snps[[1]],
discordant_snps = concordant_snps[[2]],
fract_concordant_snps = prop.table(concordant_snps)[[1]],
concordant_snps = ifelse(length(concordant_snps) > 0, concordant_snps[[1]], 0),
discordant_snps = ifelse(length(concordant_snps) > 1, concordant_snps[[2]], 0),
fract_concordant_snps = ifelse(length(concordant_snps) > 0, prop.table(concordant_snps)[[1]], 0),
cor_coef = cor_coef
)
})
Expand All @@ -126,8 +126,14 @@ sampleSwaps = function(bams = NULL, build = "hg19", prefix = NULL, add = TRUE, m
sample_matches = sample_matches[1:(length(sample_matches)-1)]

pos_mathces = lapply(sample_matches, function(sample_pair){
if(nrow(sample_pair) > 0){
unique(unlist(sample_pair[XY_possibly_paired == "Yes", .(X_bam, Y_bam)], use.names = FALSE))
if (all(c("XY_possibly_paired", "X_bam", "Y_bam") %in% colnames(sample_pair))) {
# Filter out rows where X_bam or Y_bam have length zero
valid_rows <- sapply(sample_pair$X_bam, nchar) > 0 & sapply(sample_pair$Y_bam, nchar) > 0
filtered_sample_pair <- sample_pair[valid_rows, ]

if(nrow(filtered_sample_pair) > 0){
unique(unlist(filtered_sample_pair[XY_possibly_paired == "Yes", .(X_bam, Y_bam)], use.names = FALSE))
}
}
})
pos_mathces = pos_mathces[which(lapply(pos_mathces, function(x) length(x) > 0) == TRUE)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be better to use pos_mathces[sapply(pos_mathces, function(x) length(x) > 0)]?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right. That works as well

Expand Down