On 15/10/2021 10:10, Chris Eeles wrote:
Thanks Herve,

I actually got the updateObject method working after sending this email, but 
thanks for the information. Maybe it is worth adding a section on this topic to 
the Bioconductor developer section?

Unfortunately, I was unaware that the start of development cycle was the best 
time to implement this change. I am currently planning to have this done for 
the 3.14 release.

I am introducing new accessors as well but keeping the old ones for backwards 
compatibility using aliases.

How discouraged are slot name changes in a release? A lot of the changes on our 
road map require the slots to be renamed so it would significantly delay 
required features if I were to wait.

100% discouraged. Not an option. Worst time to do it. Please don't do it! ;-)

This a major change and is possibly very disruptive. Changing the internals of an S4 class is tricky and is likely to be disruptive. Especially if you expect others to have serialized instances of your objects around. It needs to be done very carefully and it can take time to get it right. We're way to close to the 3.14 release for such a change.

I hope you understand.

Thanks,
H.


I plan to put in the work so that those using accessors shouldn't notice a 
difference.

Best,
Chris

-----Original Message-----
From: Hervé Pagès <hpages.on.git...@gmail.com>
Sent: October 15, 2021 12:39 PM
To: Chris Eeles <christopher.ee...@outlook.com>; bioc-devel@r-project.org
Subject: Re: [Bioc-devel] Best Practices for Renaming S4 Slots

Hi Chris,

There was some formatting issues with my previous answer so I'm sending it 
again. Hopefully this time the formatting is better. See below.

On 14/10/2021 13:08, Chris Eeles wrote:
Hello BioC community,

I am the lead developer for the CoreGx, PharmacoGx, RadioGx and ToxicoGx 
packages. We have recently been working on major updates to the structure of a 
CoreSet, which is inherited by the main class in all three of the other 
packages listed.

While making these changes, we would like to rename some CoreSet slots to 
increase the amount of code that can be refactored into CoreGx, simplifying 
maintenance and development of inheriting packages in the future.

The slot names and their accessors will be made more generic, for example the 
'cell' slot will become 'sample' to allow a CoreSet derived class to store 
Biological model systems other than cancer cell lines. Similarly, 'drug' or 
'radiation' slots in inheriting packages will be replaced with a 'treatment' 
slot in the CoreSet. This will allow us to simplify inheritance, removing much 
redundant code from the inheriting packages and setting us up to integrate 
other lab packages, such as Xeva for PDX models, into the general CoreSet 
infrastructure.

I took a brief look through the Bioconductor developer documentation but didn't 
see anything talking about best practices for renaming slots.

It is easy enough to make the code changes, but my major concern is being able 
to update existing objects from these packages to use the new slot names.

I am aware of the updateObject function in BiocGenerics, but tried using it to 
update some example data in CoreGx without success.

Is this the proper function to use when you wish to update an S4 object whose 
class definition has been modified? If not, is there existing infrastructure 
for accomplishing this task?

Yes updateObject() is the proper function to use but the function has no way to 
guess how to fix your objects. The way you tell it what to do is by 
implementing methods for your objects.

For example if you renamed the 'cell' slot -> 'sample', your
updateObject() method will be something like this:


setMethod("updateObject", "CoreSet",
      function(object, ..., verbose=FALSE)
      {
          ## The "cell" slot was renamed -> "sample" in CoreGx_1.7.1.
          if (.hasSlot(object, "cell")) {
              object <- new("CoreSet",
                            sensitivity=object@sensitivity,
                            annotation=object@annotation,
                            molecularProfiles=object@molecularProfiles,
                            sample=object@cell,
                            datasetType=object@datasetType,
                            perturbation=object@perturbation,
                            curation=object@curation)
              return(object)
          }
          object
      }
)

The best time to do this internal renaming is at the beginning of the
BioC 3.15 development cycle (i.e. right after the 3.14 release).

If in the future, other slots get renamed or added, you'll need to
modify the updateObject() method above like this:

setMethod("updateObject", "CoreSet",
      function(object, ..., verbose=FALSE)
      {
          ## The "cell" slot was renamed -> "sample" in CoreGx_1.7.1.
          if (.hasSlot(object, "cell")) {
              object <- new("CoreSet",
                            sensitivity=object@sensitivity,
                            annotation=object@annotation,
                            molecularProfiles=object@molecularProfiles,
                            sample=object@cell,
                            datasetType=object@datasetType,
                            perturbation=object@perturbation,
                            titi=object@curation)  # use "titi" here too!
              return(object)
          }
          ## The "curation" slot was renamed -> "titi" in CoreGx_1.9.1.
          if (.hasSlot(object, "curation")) {
              object <- new("CoreSet",
                            sensitivity=object@sensitivity,
                            annotation=object@annotation,
                            molecularProfiles=object@molecularProfiles,
                            sample=object@sample,  # use "sample" here!
                            datasetType=object@datasetType,
                            perturbation=object@perturbation,
                            titi=object@curation)
              return(object)
          }
          object
      }
)

And so on...

Hope this helps,
H.



Any tips for implementing slot renaming, as well as links to existing 
documentation or articles on the topic would be appreciated.

Best,
---
Christopher Eeles
Software Developer
BHK 
Laboratory<https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.bhklab.ca%2F&amp;data=04%7C01%7C%7Cf7c91093d7814eb94c5208d98ffa4992%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637699127395872588%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=XBT%2B6PMhcPKef6MOg5HM%2Bc3mwYCACyHbe%2FF96ZcU00Y%3D&amp;reserved=0>
Princess Margaret Cancer 
Centre<https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.pmgenomics.ca%2Fpmgenomics%2F&amp;data=04%7C01%7C%7Cf7c91093d7814eb94c5208d98ffa4992%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637699127395872588%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=vXxluasmYdH2O27WM5nYKV52UTpnrIWhTCZYj0JxXhs%3D&amp;reserved=0>
University Health 
Network<https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.uhn.ca%2F&amp;data=04%7C01%7C%7Cf7c91093d7814eb94c5208d98ffa4992%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637699127395872588%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=bZ7EzdAVu%2FjgiZxn%2FaWQNgPR%2BT1rnawjMIS3UjvqqNA%3D&amp;reserved=0>


        [[alternative HTML version deleted]]

_______________________________________________
Bioc-devel@r-project.org mailing list
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fbioc-devel&amp;data=04%7C01%7C%7Cf7c91093d7814eb94c5208d98ffa4992%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637699127395872588%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=NUVboWMUVvEGLPc%2BZANTpraGCny%2BiN0uH6EthtVZcSg%3D&amp;reserved=0



--
Hervé Pagès

Bioconductor Core Team
hpages.on.git...@gmail.com

_______________________________________________
Bioc-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/bioc-devel

Reply via email to