comparison scimap_plotting.py @ 4:49c178651194 draft default tip

planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/scimap commit c39cea5ae2ebf61b3d51d687fd9d2930c907b72d
author goeckslab
date Tue, 30 Jul 2024 18:20:49 +0000
parents 4c767e1a9e7c
children
comparison
equal deleted inserted replaced
3:8c55377d7f06 4:49c178651194
1 import argparse 1 import argparse
2 import json 2 import json
3 import os 3 import os
4 import warnings 4 import warnings
5 5
6 import matplotlib.pylab as plt 6 import matplotlib.pyplot as plt
7 import numpy as np 7 import numpy as np
8 import scimap as sm 8 import scimap as sm
9 import seaborn as sns 9 import seaborn as sns
10 from anndata import read_h5ad 10 from anndata import read_h5ad
11 11
35 35
36 if tool == 'stacked_barplot': 36 if tool == 'stacked_barplot':
37 37
38 # parse list text arguments 38 # parse list text arguments
39 for o in options.copy(): 39 for o in options.copy():
40 opt_list = options.pop(o) 40 opt = options.pop(o)
41 if opt_list: 41 if o == 'matplotlib_cmap':
42 options[o] = [x.strip() for x in opt_list.split(',')] 42 matplotlib_cmap = opt
43 elif opt != "":
44 options[o] = [x.strip() for x in opt.split(',')]
43 45
44 # add base args into options dict to pass to tool 46 # add base args into options dict to pass to tool
45 options['x_axis'] = params['analyses']['x_axis'] 47 options['x_axis'] = params['analyses']['x_axis']
46 options['y_axis'] = params['analyses']['y_axis'] 48 options['y_axis'] = params['analyses']['y_axis']
47 options['method'] = params['analyses']['method'] 49 options['method'] = params['analyses']['method']
48 50
49 options['return_data'] = True 51 options['return_data'] = True
50 52
51 df = sm.pl.stacked_barplot(adata, **options) 53 df = sm.pl.stacked_barplot(adata, **options)
52
53 # Pick cmap to use
54 num_phenotypes = len(df.columns) - 1
55 if num_phenotypes <= 9:
56 matplotlib_cmap = "Set1"
57 elif num_phenotypes > 9 and num_phenotypes <= 20:
58 matplotlib_cmap = plt.cm.tab20
59 else:
60 matplotlib_cmap = plt.cm.gist_ncar
61 54
62 # Plotting 55 # Plotting
63 sns.set_theme(style="white") 56 sns.set_theme(style="white")
64 ax = df.plot.bar(stacked=True, cmap=matplotlib_cmap) 57 ax = df.plot.bar(stacked=True, cmap=matplotlib_cmap)
65 fig = ax.get_figure() 58 fig = ax.get_figure()