theislab/paga

Replacement of / Alternative to the ForceAtlas2 package

jasonleongbio opened this issue · 0 comments

Dear developers of PAGA,

I'm recently new to PAGA and thanks so much for developing this wonderful tool! I was following the tutorials (the official and some other tutorials elsewhere), but could not reproduce the figure where the ForceAtlas2 algorithm was used to visualize the data in low-dimensional space.

The warning message said:

drawing single-cell graph using layout 'fa'
WARNING: Package 'fa2' is not installed, falling back to layout 'fr'.To use the faster and better ForceAtlas2 layout, install package 'fa2' (`pip install fa2`).
    finished: added
    'X_draw_graph_fr', graph_drawing coordinates (adata.obsm) (0:00:04)

I tried to follow the instruction, but could not successfully install the fa2 package (even after installing/updating additional dependency packages such as setuptools). I realized that this has been repetitively discussed in the original ForceAtlas2 repository (such as here). Indeed many people (not only in the bioinformatics field but also the others) encountered the very same problem.

(My environment is macOS, mamba virtual environment, Python 3.11, Scanpy 1.10, but these do not matter so much, as I show below.)

An alternative was to use a modified version by the community, called the fa2_modified. I installed it by

pip install -U fa2_modified

(Probably can be installed via conda-forge as well)

Having this installed does not automatically replace the use of fa2 in PAGA, so I additionally went to manually modify the tools/_draw_graph.py script in the Scanpy package installed in my virtual environment (line 138):

    # see whether fa2 is installed
    if layout == "fa":
        try:
            #from fa2 import ForceAtlas2
            from fa2_modified import ForceAtlas2
        except ImportError:
            logg.warning(
                "Package 'fa2' is not installed, falling back to layout 'fr'."
                "To use the faster and better ForceAtlas2 layout, "
                "install package 'fa2' (`pip install fa2`)."
            )
            layout = "fr"

After replacing the fa2 with fa2_modified, which is much easier to install, now I can run the ForceAtlas2 layout with PAGA, and reproduce the same result shown in the tutorial.

Hope this can help the team and the community improve the tool.

Best,
Jason Leong.