fabilab / northstar

Single cell type annotation guided by cell atlases, with freedom to be queer
https://northstar.readthedocs.io/
MIT License
25 stars 6 forks source link

Leidenalg optimise_partition no longer uses fixed_nodes param #3

Closed NicoleEO closed 2 years ago

NicoleEO commented 3 years ago

Leidenalg no longer supports the param fixed_nodes in optimise_partition as of 26Aug. This results in the below error. fixed_nodes should be changed to is_membership_fixed.

Error:

image

Lines to fix to optimise_partition in northstar:

https://github.com/northstaratlas/northstar/blob/7fe63704dc50680366460d20c8ff42b9cf94d718/northstar/cluster_with_annotations.py#L82-L113

Commit in Leidenalg updating the params:

https://github.com/vtraag/leidenalg/commit/808bfdfef8a7005d03d7e192b2df5191ed3e5467#diff-e55f439ba556c8d66c1c73c19874c80a110699da462ea70f36cad3515e2565d9

MRE:

import northstar
from anndata import AnnData
import pandas as pd
import numpy as np
import string

# Choose an atlas
atlas_name = 'Darmanis_2015'

# Get a gene expression matrix of the new dataset (here a
# random matrix for simplicity)
N = 200
L = 50
af = northstar.AtlasFetcher()
dar_atlas = af.fetch_atlas( "Darmanis_2015")
dar_genes = dar_atlas.var_names
new_dataset = pd.DataFrame(
    data=np.random.rand(L, N).astype(np.float32),
    index=list(np.random.choice(list(dar_genes), L)),
    columns=['cell_'+str(i+1) for i in range(N)],
    )

# Initialize northstar classes
model = northstar.Averages(
        atlas='Darmanis_2015',
        n_neighbors=5,
        n_pcs=10,
        )

# Run the classifier
model.fit(new_dataset)

# Get the cluster memberships for the new cells
membership = model.membership
iosonofabio commented 3 years ago

Thanks Nicole, I pushed a new commit fixing that, will make a new release when it passes CI.

NicoleEO commented 3 years ago

I made a typo it is is_membership_fixed not is_member_fixed.

iosonofabio commented 3 years ago

Corrected, but it seems like Travis is having a short vacation. Perhaps you can just clone the master branch from this repo if you need it sooner ;-)

NicoleEO commented 3 years ago

Thanks Fabio. I've updated locally.

iosonofabio commented 2 years ago

Finally pushed this to pypi, thanks @NicoleEO and @vtraag.

Long story short I was moving several repos to github actions at the time because Travis was bought out, and this was left in the cold.