BaselAbujamous / clust

Automatic and optimised consensus clustering of one or more heterogeneous datasets
Other
160 stars 35 forks source link

"Error: could not save clusters plots in a PDF file." with more than 11 clusters #50

Closed michallipinski closed 4 years ago

michallipinski commented 4 years ago

Hi Basel,

I just installed your fantastic package (ver 1.10.8) and it worked pretty great with a setting in which I receive 10 or 11 clusters. However when I increase the tightness on the same datasets I receive 19 clusters and I get the "Error: could not save clusters plots in a PDF file." message. The environment, computing cluster and even the command is the same (apart from -t 2). The matplotlib and all the other modules are freshly installed yesterday so they are in the most upgraded versions. I saw some other people used to have the same issue but it is already under the "closed Issues".

Best, Michal

michallipinski commented 4 years ago

I guess this might help. I removed the try/except statement from the code and added the following print line:

    # Prepare plots (figure(0) to figure(Np-1)
    for k in range(K):
        for l in range(L):
            (page, pos, row, col) = position_of_subplot(L, K, l, Cs[k])
            plt.figure(page, figsize=pagesize, frameon=False)
            print(max(maxrows_per_page, 3), maxcols_per_page, pos)
            plt.subplot(max(maxrows_per_page, 3), maxcols_per_page, pos)

This gave me the following traceback:

6.0 5 1
6.0 5 2
6.0 5 3
6.0 5 4
6.0 5 5
6.0 5 11
6.0 5 12
6.0 5 13
6.0 5 14
6.0 5 15
6.0 5 21
6.0 5 22
6.0 5 23
6.0 5 24
6.0 5 25
6.0 5 31
Traceback (most recent call last):
  File "/n/home11/mlipinski/.conda/envs/Michal_clust/bin/clust", line 12, in <module>
    sys.exit(main())
  File "/n/home11/mlipinski/.local/lib/python3.6/site-packages/clust/__main__.py", line 103, in main
    args.cs, args.np, args.optimisation, args.q3s, args.basemethods, args.deterministic)
  File "/n/home11/mlipinski/.local/lib/python3.6/site-packages/clust/clustpipeline.py", line 185, in clustpipeline
    GDM=GDM, Cs='all', setPageToDefault=True, printToPDF=True, showPlots=False)
  File "/n/home11/mlipinski/.local/lib/python3.6/site-packages/clust/scripts/graphics.py", line 136, in plotclusters
    plt.subplot(max(maxrows_per_page, 3), maxcols_per_page, pos)
  File "/n/home11/mlipinski/.local/lib/python3.6/site-packages/matplotlib/pyplot.py", line 1069, in subplot
    a = fig.add_subplot(*args, **kwargs)
  File "/n/home11/mlipinski/.local/lib/python3.6/site-packages/matplotlib/figure.py", line 1414, in add_subplot
    a = subplot_class_factory(projection_class)(self, *args, **kwargs)
  File "/n/home11/mlipinski/.local/lib/python3.6/site-packages/matplotlib/axes/_subplots.py", line 59, in __init__
    f"num must be 1 <= num <= {rows*cols}, not {num}")
ValueError: num must be 1 <= num <= 30, not 31
johnomics commented 4 years ago

Hello,

Thanks @BaselAbujamous for writing Clust, it's excellent. I hit the same problem as @michallipinski - I think the fix is to add an integer conversion to L73 of graphics.py: set_bands_per_page(int((maxrows_per_page + 1)/ (L + 1)))

Without this, my two-data-set run producing 15 clusters had a bands_per_page value of 2.333..., not 2; this causes page to be calculated incorrectly at lines 96-97:

    band = int(k / maxcols_per_page)  # Number of band relative to the beginning of the plots (0, 1, 2, 3, ...)
    page = int(band / bands_per_page)  # Page 0, 1, 2, 3, ...

For cluster 11, the first cluster on the second page with maxcols_per_page=5, band is int(11/5) = 2; as bands_per_page is 2.333..., page=int(2/2.333)=0. As page is still 0, row gets calculated as higher than maxrows_per_page and exceeds the number of subplots.

But with int(bands_per_page)=2, page=int(2/2)=1 as intended and the row value is calculated correctly.

BaselAbujamous commented 4 years ago

Thanks a lot both of you, @michallipinski and @johnomics for the question and suggestions.

Could you create a pull request with your suggestion, @johnomics ?

BaselAbujamous commented 4 years ago

I think this has been sorted out right?

johnomics commented 4 years ago

The pull request works for me, so if it works for you it's sorted! Thanks.