compomics / psm_utils

Common utilities for parsing and handling peptide-spectrum matches and search engine results in Python
https://psm-utils.readthedocs.io
Apache License 2.0
24 stars 6 forks source link

Add indexing methods to psm_list object #84

Closed ArthurDeclercq closed 1 month ago

ArthurDeclercq commented 2 months ago

Add some index functionality to the psm_list object similar to .index() method of lists Also give each psm an internal index

RalfG commented 1 month ago

List's .index(x) returns the index of the passed value. I'm not sure how we could implement this for a list of PSM objects, as there is not a single identifier by which to search the PSM. This could be the peptidoform, the collection + run+ spectrum_id... Therefore, an .index method it might be ambiguous. There is not a single expected behavior.

We could consider implementing a method that returns the first or all indices of PSMs with a certain peptidoform, run, or spectrum_id. Although that is, in a way, already possible through the indexing methods. For instance:

>>> psm_list[psm_list["peptidoform"] == Peptidoform("WGDIEFPPPFGR/2")]
PSMList(
    psm_list=[
        PSM(
            peptidoform=Peptidoform('WGDIEFPPPFGR/2'),
...

Or:

>>> psm_list[psm_list["spectrum_id"] == "controllerType=0 controllerNumber=1 scan=9847"]
PSMList(
    psm_list=[
        PSM(
            peptidoform=Peptidoform('WGDIEFPPPFGR/2'),
            spectrum_id='controllerType=0 controllerNumber=1 scan=9847',
...

Closing the issue for now, but could be reopened if anyone has similar feature requests and/or solutions.