Skip to content

Commit

Permalink
Merge pull request #127 from lgatto/master
Browse files Browse the repository at this point in the history
fix: all_ok check for empyt GRangesList (see issue #126)
  • Loading branch information
jorainer authored Jan 1, 2022
2 parents 7e90f99 + 6f1f3e4 commit 4f3c3cc
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions R/proteinToX.R
Original file line number Diff line number Diff line change
Expand Up @@ -324,27 +324,28 @@ proteinToGenome <- function(x, db, id = "name", idType = "protein_id") {
message("Checking CDS and protein sequence lengths ... ", appendLF = FALSE)
cds_genome <- .cds_matching_protein(db, cds_genome)
are_ok <- unlist(lapply(cds_genome, function(z) {
if (is(z, "GRangesList"))
if (is(z, "GRangesList") & length(z) > 0)
all(z[[1]]$cds_ok)
else NA
}))
message(sum(are_ok, na.rm = TRUE), "/", length(are_ok), " OK")
are_ok <- are_ok[!is.na(are_ok)]
## We've got now a list of GRanges
message(sum(are_ok), "/", length(are_ok), " OK")
## Perform the mapping for each input range with each mapped cds
res <- mapply(
cds_genome, as(coords_cds, "IRangesList"), as(x, "IRangesList"),
FUN = function(gnm, cds, prt) {
if (is.null(gnm)) {
if (!length(gnm)) { ## addresses NULL and empty elements
GRanges()
} else {
## Unlist because we'd like to have a GRanges here. Will split
## again later.
maps <- unlist(.to_genome(gnm, cds))
## Don't want to have GRanges names!
names(maps) <- NULL
mcols(maps)$protein_start <- start(prt)
mcols(maps)$protein_end <- end(prt)
mcols(maps) <- cbind(mcols(maps),
protein_start = start(prt),
protein_end = end(prt))
maps[order(maps$exon_rank)]
}
})
Expand Down

0 comments on commit 4f3c3cc

Please sign in to comment.