Skip to content
Prev 4333 / 21307 Next

[Bioc-devel] deprecation of keepSeqlevels and renameSeqlevels

Michael,
On 05/20/2013 08:44 PM, Michael Lawrence wrote:
The seqlevels setter has no 'new2old' arg.
Permuting is straightforward with seqlevels<-:

   > seqlevels(gr)
   [1] "chr1" "chr2" "chr3"

   > seqlevels(gr) <- rev(seqlevels(gr))

   > seqlevels(gr)
   [1] "chr3" "chr2" "chr1"
Also straightforward:

   > seqlevels(gr, force=TRUE) <- "chr2"

   > seqlevels(gr)
   [1] "chr2"
There are other important use cases:

   - Dropping seqlevels that are *not* in use. This happens for example
     when subsetting a BAM file with Rsamtools::filterBam to keep only
     the alignments located on a given chromosome. The entire sequence
     dictionary (in the header) is propagated to the resulting BAM file
     so when you read the file with readGAlignments() you end up with a
     bunch of useless seqlevels that you generally start by dropping.
     You don't want to drop any alignment so force=FALSE is your friend.

   - An even more common operation is renaming: 90% of the times that's
     what I use seqlevels<- for, and that's what I tell people to use
     when they need to rename their chromosomes. Also straightforward:

       > seqlevels(gr)
       [1] "chr1" "chr2" "chr3" "chrM"

       > seqlevels(gr) <- sub("^chr", "", seqlevels(gr))
       > seqlevels(gr)
       [1] "1" "2" "3" "M"

       > seqlevels(gr)[seqlevels(gr) == "M"] <- "MT"
       > seqlevels(gr)
       [1] "1"  "2"  "3"  "MT"

     Note that this is simpler to use than renameSeqlevels() which
     always required you to build the entire right value as a named
     vector.

So the added-value of keepSeqlevels() seems to boil down to:

   (a) it always uses force=TRUE

   (b) it preserves the original object and returns the modified object

If you want to restrict the use of keepSeqlevels() to permuting and
dropping, you'll also have to disallow renaming (in addition to adding).
Then its name will more or less reflect what it does (if "keep" means
"permute" or "drop"). The final result will be something that does less
than setSeqlevels() and that is not necessarily easier to read: both
will set on the object whatever vector of seqlevels they are supplied,
except that one will fail when doing so would actually result in adding
or renaming seqlevels.

H.