KrishnaswamyLab / scprep

A collection of scripts and tools for loading, processing, and handling single cell data.
MIT License
72 stars 21 forks source link

Explicitly return lineages from scprep.run.slingshot.Slingshot #122

Open alex-claman opened 3 years ago

alex-claman commented 3 years ago

Hello!

I really appreciate the wrapper you've built for the Slingshot function! It's the only way I found to use Slingshot from Python. However, I noticed something when trying to make inferences/graphs from the information provided by the function: the lineages returned by the R version of the Slingshot function are dropped with the way the function is written at the moment.

I was able to make some small modifications to scprep/scprep/run/slingshot.py to add a "lineages" key/value to the dictionary returned from the Python version of the Slingshot function.

From Line 63: list(pseudotime = slingPseudotime(sling), curves = lapply(sling@curves, function(curve) curve$s[curve$ord,])) I added a small change to also save the lineage information: list(pseudotime = slingPseudotime(sling), curves = lapply(sling@curves, function(curve) curve$s[curve$ord,]), lineages = sling@lineages)

After Line 260: slingshot["curves"] = np.array(list(slingshot["curves"].values())) I added a similar line to cast from <U1 to int: slingshot["lineages"] = {k: v.astype(int) for k, v in slingshot['lineages'].items()}

This allows me to go on to use the lineages, which are returned in a dictionary.

An example of the "lineages" key/value from the returned dictionary: 'lineages': {'Lineage1': array([7, 5, 0, 1, 4, 3, 2]), 'Lineage2': array([7, 5, 0, 1, 4, 3, 8]), 'Lineage3': array([7, 5, 0, 1, 4, 3, 9]), 'Lineage4': array([7, 5, 0, 6])}

Let me know if anything else would be helpful, if this isn't the proper forum for this request, or if I missed something that allowed for this functionality already! These would just be useful for my analyses and it would be nice for this feature to be included in the package for reproducibility and portability.

Thank you!