Skip to content

Commit

Permalink
deal with no windows (closes #29)
Browse files Browse the repository at this point in the history
  • Loading branch information
petrelharp committed Oct 28, 2022
1 parent 690cb5f commit 8d29b40
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lostruct/R/query_vcf.R
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ vcf_windower_bp <- function (file, sites, size, samples=vcf_samples(file)) {
chrom.starts <- sapply( sites, min )
chrom.lens <- sapply( sites, max ) - chrom.starts
chrom.wins <- floor(chrom.lens / size) # number of windows
if (any(chrom.wins) == 0) {
badones = names(chrom.wins)[chrom.wins == 0]
stop(sprintf("No windows on chromosome(s) %s: these have fewer %s than the provided size of %d %s.", paste(badones, collapse=", "), "bps", size, "bps"))
}
warning(paste("Trimming from chromosome ends:",paste(paste(chroms,chrom.lens-size*chrom.wins,sep=": "),collapse=", "),"bp."))
chrom.breaks <- c(0,cumsum(chrom.wins)) # 0, and then indices of *last* windows in each chromosome
pos.fn <- function (n) {
Expand Down Expand Up @@ -233,6 +237,10 @@ vcf_windower_snp <- function (file, sites, size, samples=vcf_samples(file)) {
chroms <- names(sites)
chrom.lens <- sapply( sites, length )
chrom.wins <- floor(chrom.lens / size)
if (any(chrom.wins) == 0) {
badones = names(chrom.wins)[chrom.wins == 0]
stop(sprintf("No windows on chromosome(s) %s: these have fewer %s than the provided size of %d %s.", paste(badones, collapse=", "), "snps", size, "snps"))
}
warning(paste("Trimming from chromosome ends:",paste(paste(chroms,chrom.lens-size*chrom.wins,sep=": "),collapse=", "),"SNPs."))
chrom.breaks <- c(0,cumsum(chrom.wins)) # 0, and then indices of *last* windows in each chromosome
pos.fn <- function (n) {
Expand Down

0 comments on commit 8d29b40

Please sign in to comment.