@@ -1823,16 +1823,92 @@ def test_violin_scale_warning(monkeypatch):
1823
1823
sc .pl .StackedViolin (adata , adata .var_names [:3 ], groupby = "louvain" )
1824
1824
1825
1825
1826
- def test_dotplot_group_cmaps (image_comparer ):
1826
+ # def test_dotplot_group_cmaps(image_comparer):
1827
+ # """Check group_cmaps parameter with custom color maps per group."""
1828
+ # save_and_compare_images = partial(image_comparer, ROOT, tol=15)
1829
+
1830
+ # adata = pbmc68k_reduced()
1831
+
1832
+ # # Use markers with a good range of expression values to check color gradients
1833
+ # markers = ["SERPINB1", "IGFBP7", "GNLY", "IFITM1", "IMP3", "UBALD2", "LTB", "CLPP"]
1834
+
1835
+ # # Define a complete set of colormaps for all groups that will be plotted
1836
+ # group_cmaps = {
1837
+ # "CD14+ Monocyte": "Greys",
1838
+ # "Dendritic": "Purples",
1839
+ # "CD8+ Cytotoxic T": "Reds",
1840
+ # "CD8+/CD45RA+ Naive Cytotoxic": "Greens",
1841
+ # "CD4+/CD45RA+/CD25- Naive T": "Oranges",
1842
+ # "CD4+/CD25 T Reg": "Blues",
1843
+ # "CD4+/CD45RO+ Memory": "hot",
1844
+ # "CD19+ B": "cool",
1845
+ # "CD56+ NK": "winter",
1846
+ # "CD34+": "copper",
1847
+ # }
1848
+
1849
+ # # Call dotplot with new parameter
1850
+ # sc.pl.dotplot(
1851
+ # adata,
1852
+ # markers,
1853
+ # groupby="bulk_labels",
1854
+ # group_cmaps=group_cmaps, # Define custom color maps for each group from 'groupby'
1855
+ # dendrogram=True, # Test with dendrogram reordering
1856
+ # show=False,
1857
+ # )
1858
+
1859
+ # # This will try to save the plot and compare it to a reference
1860
+ # save_and_compare_images("dotplot_group_cmaps")
1861
+
1862
+
1863
+ # def test_dotplot_group_cmaps_swap_axes(image_comparer):
1864
+ # """Check that group_cmaps works with swapped axes."""
1865
+ # save_and_compare_images = partial(image_comparer, ROOT, tol=15)
1866
+
1867
+ # adata = pbmc68k_reduced()
1868
+
1869
+ # # Use markers with a good range of expression values to check color gradients
1870
+ # markers = ["SERPINB1", "IGFBP7", "GNLY", "IFITM1", "IMP3", "UBALD2", "LTB", "CLPP"]
1871
+
1872
+ # # Define a complete set of colormaps for all groups that will be plotted
1873
+ # group_cmaps = {
1874
+ # "CD14+ Monocyte": "Greys",
1875
+ # "Dendritic": "Purples",
1876
+ # "CD8+ Cytotoxic T": "Reds",
1877
+ # "CD8+/CD45RA+ Naive Cytotoxic": "Greens",
1878
+ # "CD4+/CD45RA+/CD25- Naive T": "Oranges",
1879
+ # "CD4+/CD25 T Reg": "Blues",
1880
+ # "CD4+/CD45RO+ Memory": "hot",
1881
+ # "CD19+ B": "cool",
1882
+ # "CD56+ NK": "winter",
1883
+ # "CD34+": "copper",
1884
+ # }
1885
+
1886
+ # sc.pl.dotplot(
1887
+ # adata,
1888
+ # markers,
1889
+ # groupby="bulk_labels",
1890
+ # group_cmaps=group_cmaps,
1891
+ # dendrogram=True,
1892
+ # swap_axes=True, # Check that group_cmaps works with swapped axes
1893
+ # show=False,
1894
+ # )
1895
+ # save_and_compare_images("dotplot_group_cmaps_swap_axes")
1896
+
1897
+ params_dotplot_group_cmaps = [
1898
+ pytest .param ("dotplot_group_cmaps" , False , id = "default" ),
1899
+ pytest .param ("dotplot_group_cmaps_swap_axes" , True , id = "swap_axes" ),
1900
+ ]
1901
+
1902
+
1903
+ @pytest .mark .parametrize (("name" , "swap_axes" ), params_dotplot_group_cmaps )
1904
+ def test_dotplot_group_cmaps (image_comparer , name , swap_axes ):
1827
1905
"""Check group_cmaps parameter with custom color maps per group."""
1828
1906
save_and_compare_images = partial (image_comparer , ROOT , tol = 15 )
1829
1907
1830
1908
adata = pbmc68k_reduced ()
1831
1909
1832
- # Use markers with a good range of expression values to check color gradients
1833
1910
markers = ["SERPINB1" , "IGFBP7" , "GNLY" , "IFITM1" , "IMP3" , "UBALD2" , "LTB" , "CLPP" ]
1834
1911
1835
- # Define a complete set of colormaps for all groups that will be plotted
1836
1912
group_cmaps = {
1837
1913
"CD14+ Monocyte" : "Greys" ,
1838
1914
"Dendritic" : "Purples" ,
@@ -1846,50 +1922,26 @@ def test_dotplot_group_cmaps(image_comparer):
1846
1922
"CD34+" : "copper" ,
1847
1923
}
1848
1924
1849
- # Call dotplot with new parameter
1850
1925
sc .pl .dotplot (
1851
1926
adata ,
1852
1927
markers ,
1853
1928
groupby = "bulk_labels" ,
1854
- group_cmaps = group_cmaps , # Define custom color maps for each group from 'groupby'
1855
- dendrogram = True , # Test with dendrogram reordering
1929
+ group_cmaps = group_cmaps ,
1930
+ dendrogram = True ,
1931
+ swap_axes = swap_axes ,
1856
1932
show = False ,
1857
1933
)
1934
+ save_and_compare_images (name )
1858
1935
1859
- # This will try to save the plot and compare it to a reference
1860
- save_and_compare_images ("dotplot_group_cmaps" )
1861
-
1862
-
1863
- def test_dotplot_group_cmaps_swap_axes (image_comparer ):
1864
- """Check that group_cmaps works with swapped axes."""
1865
- save_and_compare_images = partial (image_comparer , ROOT , tol = 15 )
1866
1936
1937
+ def test_dotplot_group_cmaps_raises_error ():
1938
+ """Check that a ValueError is raised for missing groups in group_cmaps."""
1867
1939
adata = pbmc68k_reduced ()
1940
+ markers = ["CD79A" ]
1941
+ # Intentionally incomplete dictionary to trigger the error
1942
+ group_cmaps = {"CD19+ B" : "Blues" }
1868
1943
1869
- # Use markers with a good range of expression values to check color gradients
1870
- markers = ["SERPINB1" , "IGFBP7" , "GNLY" , "IFITM1" , "IMP3" , "UBALD2" , "LTB" , "CLPP" ]
1871
-
1872
- # Define a complete set of colormaps for all groups that will be plotted
1873
- group_cmaps = {
1874
- "CD14+ Monocyte" : "Greys" ,
1875
- "Dendritic" : "Purples" ,
1876
- "CD8+ Cytotoxic T" : "Reds" ,
1877
- "CD8+/CD45RA+ Naive Cytotoxic" : "Greens" ,
1878
- "CD4+/CD45RA+/CD25- Naive T" : "Oranges" ,
1879
- "CD4+/CD25 T Reg" : "Blues" ,
1880
- "CD4+/CD45RO+ Memory" : "hot" ,
1881
- "CD19+ B" : "cool" ,
1882
- "CD56+ NK" : "winter" ,
1883
- "CD34+" : "copper" ,
1884
- }
1885
-
1886
- sc .pl .dotplot (
1887
- adata ,
1888
- markers ,
1889
- groupby = "bulk_labels" ,
1890
- group_cmaps = group_cmaps ,
1891
- dendrogram = True ,
1892
- swap_axes = True , # Check that group_cmaps works with swapped axes
1893
- show = False ,
1894
- )
1895
- save_and_compare_images ("dotplot_group_cmaps_swap_axes" )
1944
+ with pytest .raises (ValueError , match = "missing from the `group_cmaps` dictionary" ):
1945
+ sc .pl .dotplot (
1946
+ adata , markers , groupby = "bulk_labels" , group_cmaps = group_cmaps , show = False
1947
+ )
0 commit comments