3 import importlib
.metadata
4 from packaging
import version
7 got_ver
= importlib
.metadata
.version(pkgname
)
8 if version
.parse(got_ver
) < version
.parse(min_ver
):
9 raise importlib
.VersionConflict(f
"{pkgname}>={min_ver} is needed, but found {pkgname}=={got_ver}")
11 import matplotlib
; matplotlib
.use("module://mplcairo.base")
12 from matplotlib
import pyplot
as plt
23 mbi
=sq
.read
.visium('/share/result/spatial/data/BoAo_sp/illumina/mbrain/outs/')
24 mbi
.var_names_make_unique()
25 #mbic=sc.read_visium('/share/result/spatial/data/BoAo_sp/illumina/mbrain/outs/')
26 mbs
=sq
.read
.visium('/share/result/spatial/data/BoAo_sp/salus/mbrain/outs/')
27 mbs
.var_names_make_unique()
29 mbi
.var
["mt"] = mbi
.var_names
.str.startswith("mt-") # mouse: mt-Nd1 mt-Nd2 mt-Co1 mt-Co2 mt-Atp8 mt-Atp6 mt-Co3 mt-Nd3 mt-Nd4l mt-Nd4 mt-Nd5 mt-Nd6 mt-Cytb
30 sc
.pp
.calculate_qc_metrics(mbi
, qc_vars
=["mt"], inplace
=True)
31 mbs
.var
["mt"] = mbs
.var_names
.str.startswith("mt-")
32 sc
.pp
.calculate_qc_metrics(mbs
, qc_vars
=["mt"], inplace
=True)
34 with pd
.option_context("mode.copy_on_write", True):
35 obsmbi
= mbi
.obs
[['n_genes_by_counts', 'total_counts']].copy(deep
=False)
36 obsmbs
= mbs
.obs
[['n_genes_by_counts', 'total_counts']].copy(deep
=False)
37 p1df
= pd
.concat([obsmbi
.assign(Platform
='Illumina'), obsmbs
.assign(Platform
='Salus')], ignore_index
=True).replace([np
.inf
, -np
.inf
, 0], np
.nan
).dropna()
38 p2df
= obsmbi
.join(obsmbs
,lsuffix
='_Illumina',rsuffix
='_Salus',how
='inner').replace([np
.inf
, -np
.inf
, 0], np
.nan
).dropna()
40 custom_params
= {"axes.spines.right": False, "axes.spines.top": False}
41 sns
.set_theme(style
="ticks", rc
=custom_params
, font
="STIX Two Text")
42 figA
=sns
.JointGrid(data
=p1df
, x
="total_counts", y
="n_genes_by_counts", hue
='Platform', dropna
=True)
43 #figA.plot(sns.scatterplot, sns.histplot, alpha=.7, edgecolor=".2", linewidth=.5)
44 figA
.plot_joint(sns
.scatterplot
, s
=12.7, alpha
=.6)
45 figA
.plot_marginals(sns
.histplot
, kde
=True, alpha
=.618)
46 figA
.figure
.suptitle('Gene to UMI plot - Mouse Brain')
47 figA
.set_axis_labels(xlabel
='UMIs per Barcode', ylabel
='Genes per Barcode')
48 figA
.savefig('Dmbrain.pdf', transparent
=True, dpi
=300, metadata
={'Title': 'Gene to UMI plot', 'Subject': 'Mouse Brain Data', 'Author': 'HU Xuesong'})
50 figB
=sns
.JointGrid(data
=p2df
, x
="total_counts_Illumina", y
="total_counts_Salus", dropna
=True)
51 figB
.plot_joint(sns
.scatterplot
, s
=12.7, alpha
=.6)
52 figB
.plot_marginals(sns
.histplot
, kde
=True, alpha
=.618)
53 figB
.figure
.suptitle('UMI per Barcode Counts Comparing - Mouse Brain')
54 figB
.set_axis_labels(xlabel
='UMI Counts from Illumina', ylabel
='UMI Counts from Salus')
55 figB
.savefig('Embrain.pdf', transparent
=True, dpi
=300, metadata
={'Title': 'UMI per Barcode Counts Comparing', 'Subject': 'Mouse Brain Data', 'Author': 'HU Xuesong'})
59 x1 = np.random.randn(1000)
60 y1 = np.random.randn(1000)
61 x2 = np.random.randn(1000) * 5
62 y2 = np.random.randn(1000)
63 fig, ax = plt.subplots()
64 # The figure and axes background must be made transparent.
65 fig.patch.set(alpha=0)
67 pc1 = ax.scatter(x1, y1, c='b', edgecolors='none')
68 pc2 = ax.scatter(x2, y2, c='r', edgecolors='none')
69 mplcairo.operator_t.ADD.patch_artist(pc2) # Use additive blending.