Skip to contents

Get first stranded GRanges feature per GRangesList

Usage

getFirstStrandedFromGRL(
  grl,
  method = c("direct", "endoapply", "flank"),
  verbose = FALSE,
  ...
)

Arguments

grl

GRangesList

method

character with method to use, default 'direct':

  • 'direct' uses IRanges::heads() or IRanges::tails() depending upon the strandedness. This approach is vectorized and is preferred.

  • 'endoapply' uses S4Vectors::endoapply() to iterate each GRangesList element, then returns the result from head() or tail(). This approach is not vectorized and may be substantially slower than 'direct'.

verbose

logical indicating whether to print verbose output.

...

additional arguments are ignored.

Value

GRangesList containing only the first stranded GRanges feature per input GRangesList element. When method="flank" the output contains no metadata values, but this method is deprecated.

Details

This function returns the first feature per GRangesList, relative to the strand of the GRangesList. It assumes each GRangesList element has only one strand and one seqname, and will stop otherwise.

See also

Other ALE and codon functions: ale2violin(), codonUsage2df(), dna2codon(), jamCai(), tx2ale()

Examples

gr12 <- GenomicRanges::GRanges(seqnames=rep("chr1", 9),
   ranges=IRanges::IRanges(
      start=c(100, 200, 400, 500, 300, 100, 200, 400, 600),
      width=c(50,50,50, 50,50,50, 50,50,50)
   ),
   strand=rep(c("+", "-", "+"), c(3,3,3)),
   gene_name=rep(c("GeneA", "GeneB", "GeneC"), each=3)
)
grl <- GenomicRanges::split(gr12, GenomicRanges::values(gr12)$gene_name)
getFirstStrandedFromGRL(grl)
#> (14:30:00) 29Jul2026: GenomicRanges::strand(grl2@unlistData):
#> factor-Rle of length 3 with 3 runs
#>   Lengths: 1 1 1
#>   Values : + - +
#> Levels(3): + - *
#> (14:30:00) 29Jul2026: lengths(grl):
#> GeneA GeneB GeneC 
#>     3     3     3 
#> (14:30:00) 29Jul2026: lengths(grl2):
#> GeneA GeneB GeneC 
#>     1     1     1 
#> GRangesList object of length 3:
#> $GeneA
#> GRanges object with 1 range and 1 metadata column:
#>       seqnames    ranges strand |   gene_name
#>          <Rle> <IRanges>  <Rle> | <character>
#>   [1]     chr1   100-149      + |       GeneA
#>   -------
#>   seqinfo: 1 sequence from an unspecified genome; no seqlengths
#> 
#> $GeneB
#> GRanges object with 1 range and 1 metadata column:
#>       seqnames    ranges strand |   gene_name
#>          <Rle> <IRanges>  <Rle> | <character>
#>   [1]     chr1   500-549      - |       GeneB
#>   -------
#>   seqinfo: 1 sequence from an unspecified genome; no seqlengths
#> 
#> $GeneC
#> GRanges object with 1 range and 1 metadata column:
#>       seqnames    ranges strand |   gene_name
#>          <Rle> <IRanges>  <Rle> | <character>
#>   [1]     chr1   200-249      + |       GeneC
#>   -------
#>   seqinfo: 1 sequence from an unspecified genome; no seqlengths
#>