Skip to content

Commit 3802c78

Browse files
Fix code review issues - update createExonRankings signature and add validation
Co-authored-by: jonathangoeke <[email protected]>
1 parent 3b48179 commit 3802c78

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

R/bambu-extendAnnotations-utilityExtend.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ createExonByReadClass <- function(transcriptsTibble, annotationSeqLevels) {
291291
partitioning <- PartitioningByEnd(cumsum(elementNROWS(exonsByReadClass)),
292292
names = NULL)
293293
# Create exon rankings using shared utility function
294-
rankings <- createExonRankings(exonsByReadClass, transcriptsTibble$strand)
294+
rankings <- createExonRankings(width(partitioning), transcriptsTibble$strand)
295295
unlistData$exon_rank <- unlist(rankings$exon_rank)
296296
unlistData$exon_endRank <- unlist(rankings$exon_endRank)
297297
exonsByReadClass <- relist(unlistData, partitioning)

R/bambu-processReads_utilityConstructReadClasses.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ createExonsByReadClass <- function(readTable){
222222
partitioning <- PartitioningByEnd(cumsum(elementNROWS(exonsByReadClass)),
223223
names = NULL)
224224
# Create exon rankings using shared utility function
225-
rankings <- createExonRankings(exonsByReadClass, readTable$strand)
225+
rankings <- createExonRankings(width(partitioning), readTable$strand)
226226
unlistData$exon_rank <- unlist(rankings$exon_rank)
227227
unlistData$exon_endRank <- unlist(rankings$exon_endRank)
228228
exonsByReadClass <- relist(unlistData, partitioning)

R/bambu_utilityFunctions.R

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,15 +338,17 @@ merge_wrapper <- function(x,y){
338338
}
339339

340340
#' Add exon rank and exon endRank to GRangesList
341-
#' @param grlist A GRangesList object
342-
#' @param strand_info Character vector of strand information ("+", "-", or "*")
343-
#' @return A list with two elements: exon_rank and exon_endRank
341+
#' @param size_list A list of integers representing the number of exons per transcript.
342+
#' Typically obtained from elementNROWS(grlist) or width(partitioning).
343+
#' @param strand_info Character vector of strand information ("+", "-", or "*") with
344+
#' length equal to length(size_list). One strand value per transcript.
345+
#' @return A list with two elements: exon_rank and exon_endRank, both as lists of integer vectors
344346
#' @details This function creates exon rankings based on strand information.
345347
#' For negative strand transcripts, exon_rank is reversed. exon_endRank is
346348
#' always the reverse of exon_rank.
347349
#' @noRd
348-
createExonRankings <- function(grlist, strand_info) {
349-
exon_rank <- lapply(elementNROWS(grlist), seq, from = 1)
350+
createExonRankings <- function(size_list, strand_info) {
351+
exon_rank <- lapply(size_list, seq, from = 1)
350352
negative_strand <- which(strand_info == "-")
351353
exon_rank[negative_strand] <- lapply(exon_rank[negative_strand], rev)
352354
exon_endRank <- lapply(exon_rank, rev)
@@ -360,11 +362,16 @@ createExonRankings <- function(grlist, strand_info) {
360362
#' @return A data.table object
361363
#' @details This function provides a convenient way to extract rowData from
362364
#' a SummarizedExperiment object and convert it to a data.table in one step.
365+
#' If columns are specified, they will be validated against available columns.
363366
#' @importFrom data.table data.table
364367
#' @noRd
365368
extractRowDataAsDataTable <- function(se, columns = NULL, keep.rownames = FALSE) {
366369
rd <- as.data.frame(rowData(se))
367370
if (!is.null(columns)) {
371+
missing_cols <- setdiff(columns, colnames(rd))
372+
if (length(missing_cols) > 0) {
373+
stop("Columns not found in rowData: ", paste(missing_cols, collapse = ", "))
374+
}
368375
rd <- rd[, columns, drop = FALSE]
369376
}
370377
return(data.table(rd, keep.rownames = keep.rownames))

R/prepareAnnotations_utilityFunctions.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ prepareAnnotationsFromGTF <- function(file) {
7272
names = NULL)
7373
txIdForReorder <- togroup(PartitioningByWidth(grlist))
7474
# Create exon rankings using shared utility function
75-
rankings <- createExonRankings(grlist, unlist(unique(strand(grlist))))
75+
rankings <- createExonRankings(elementNROWS(grlist), unlist(unique(strand(grlist))))
7676
unlistedExons$exon_rank <- unlist(rankings$exon_rank)
7777
unlistedExons <- unlistedExons[order(txIdForReorder,
7878
unlistedExons$exon_rank)]

0 commit comments

Comments
 (0)