Skip to content

Commit

Permalink
Update plotting
Browse files Browse the repository at this point in the history
  • Loading branch information
Duy Pham committed Sep 3, 2020
1 parent 85c4447 commit aa55e91
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 75 deletions.
Empty file added stlearn/adds/scanpy.py
Empty file.
7 changes: 2 additions & 5 deletions stlearn/plotting/QC_plot.py
Expand Up @@ -17,7 +17,6 @@ def QC_plot(
show_axis: bool = False,
cropped: bool = True,
margin: int = 100,
dpi: int = 192,
output: str = None,
) -> Optional[AnnData]:
"""\
Expand All @@ -43,8 +42,6 @@ def QC_plot(
Show axis or not.
show_size_legend
Show size legend or not.
dpi
Set dpi as the resolution for the plot.
name
Name of the output figure file.
output
Expand All @@ -65,7 +62,7 @@ def QC_plot(
reads_per_spot.to_numpy().reshape(-1, 1))
genes_per_spot = adata.to_df().astype(bool).sum(axis=1)

plt.rcParams['figure.dpi'] = dpi
#plt.rcParams['figure.dpi'] = dpi

# Option for turning off showing figure
plt.ioff()
Expand Down Expand Up @@ -118,7 +115,7 @@ def QC_plot(

# fig.tight_layout()
if output is not None:
fig.savefig(output + "/" + name + ".png", dpi=dpi,
fig.savefig(output + "/" + name, dpi=plt.figure().dpi,
bbox_inches='tight', pad_inches=0)

plt.show()
1 change: 0 additions & 1 deletion stlearn/plotting/cci_plot.py
Expand Up @@ -11,7 +11,6 @@ def het_plot(
adata: AnnData,
use_cluster: str = 'louvain',
use_het: str = 'het',
dpi: int = 100,
spot_size: Union[float,int] = 6.5,
vmin: int = None,
vmax: int = None,
Expand Down
5 changes: 1 addition & 4 deletions stlearn/plotting/cluster_plot.py
Expand Up @@ -24,7 +24,6 @@ def cluster_plot(
spot_size: Union[float, int] = 6.5,
show_axis: bool = False,
show_legend: bool = True,
dpi: int = 180,
show_trajectory: bool = False,
reverse: bool = False,
show_subcluster: bool = False,
Expand Down Expand Up @@ -61,8 +60,6 @@ def cluster_plot(
Show axis or not.
show_legend
Show legend or not.
dpi
Set dpi as the resolution for the plot.
show_trajectory
Show the spatial trajectory or not. It requires stlearn.spatial.trajectory.pseudotimespace.
show_subcluster
Expand Down Expand Up @@ -210,7 +207,7 @@ def cluster_plot(
name = use_label

if output is not None:
fig.savefig(output + "/" + name + ".png", dpi=dpi,
fig.savefig(output + "/" + name, dpi=plt.figure().dpi,
bbox_inches='tight', pad_inches=0)


Expand Down
5 changes: 1 addition & 4 deletions stlearn/plotting/deconvolution_plot.py
Expand Up @@ -20,7 +20,6 @@ def deconvolution_plot(
spot_size: Union[float, int] = 10,
show_axis: bool = False,
show_legend: bool = True,
dpi: int = 180,
cropped: bool = True,
margin: int = 100,
name: str = None,
Expand Down Expand Up @@ -53,8 +52,6 @@ def deconvolution_plot(
Show axis or not.
show_legend
Show legend or not.
dpi
Set dpi as the resolution for the plot.
show_trajectory
Show the spatial trajectory or not. It requires stlearn.spatial.trajectory.pseudotimespace.
show_subcluster
Expand Down Expand Up @@ -151,7 +148,7 @@ def my_autopct(pct):
name = use_label

if output is not None:
fig.savefig(output + "/" + name + ".png", dpi=dpi,
fig.savefig(output + "/" + name, dpi=plt.figure().dpi,
bbox_inches='tight', pad_inches=0)


Expand Down
5 changes: 2 additions & 3 deletions stlearn/plotting/enrichment_analysis_plot.py
Expand Up @@ -17,7 +17,6 @@ def enrichment_analysis_plot(
save_plot: str = None,
cmap: str = "plasma",
title: str = None,
dpi: int = 192,
store: bool = True,
output: str = None,
copy: bool = False,
Expand Down Expand Up @@ -51,11 +50,11 @@ def enrichment_analysis_plot(

if output is not None:
fig.savefig(output + "/enrich_plot_factor_" + str(factor) + "_" +
gene_sets + ".png", dpi=dpi, bbox_inches='tight', pad_inches=0)
gene_sets + ".png", dpi=plt.figure().dpi, bbox_inches='tight', pad_inches=0)

if store:

fig_np = get_img_from_fig(fig, dpi)
fig_np = get_img_from_fig(fig, plt.figure().dpi)

plt.close(fig)

Expand Down
28 changes: 10 additions & 18 deletions stlearn/plotting/gene_plot.py
Expand Up @@ -26,7 +26,6 @@ def gene_plot(
show_axis: bool = False,
cropped: bool = True,
margin: int = 100,
dpi: int = 192,
name: str = None,
output: str = None,
copy: bool = False,
Expand Down Expand Up @@ -60,8 +59,6 @@ def gene_plot(
Show axis or not.
show_legend
Show legend or not.
dpi
Set dpi as the resolution for the plot.
show_trajectory
Show the spatial trajectory or not. It requires stlearn.spatial.trajectory.pseudotimespace.
show_subcluster
Expand Down Expand Up @@ -121,12 +118,6 @@ def gene_plot(
# Overlay the tissue image
a.imshow(image, alpha=tissue_alpha, zorder=-1,)

if name is None:
name = method
if output is not None:
fig.savefig(output + "/" + name + ".png", dpi=dpi,
bbox_inches='tight', pad_inches=0)

if cropped:
imagecol = adata.obs["imagecol"]
imagerow = adata.obs["imagerow"]
Expand All @@ -138,17 +129,18 @@ def gene_plot(
imagerow.max() + margin)

a.set_ylim(a.get_ylim()[::-1])
#plt.gca().invert_yaxis()

if name is None:
name = method
if output is not None:
fig.savefig(output + "/" + name, dpi=plt.figure().dpi,
bbox_inches='tight', pad_inches=0)




plt.show()
# Store figure
#fig_np = get_img_from_fig(fig,dpi)
# plt.close(fig)
# if "plots" not in adata.uns:
# adata.uns['plots'] = {}
#adata.uns['plots'].update({str(', '.join(genes)):fig_np})
# print("The plot stored in adata.uns['plot']['" +
# str(', '.join(genes)) + "']")



def _gene_plot(adata, method, genes):
Expand Down
5 changes: 1 addition & 4 deletions stlearn/plotting/microenv_plot.py
Expand Up @@ -23,7 +23,6 @@ def microenv_plot(
show_axis: bool = False,
cropped: bool = True,
margin: int = 100,
dpi: int = 192,
name: str = None,
output: str = None,
copy: bool = False,
Expand Down Expand Up @@ -53,8 +52,6 @@ def microenv_plot(
Show axis or not.
show_legend
Show legend or not.
dpi
Set dpi as the resolution for the plot.
name
Name of the output figure file.
output
Expand Down Expand Up @@ -114,7 +111,7 @@ def microenv_plot(
name = method
if output is not None:
fig.savefig(output + "/factor_" + str(i+1) + ".png",
dpi=dpi, bbox_inches='tight', pad_inches=0)
dpi=plt.figure().dpi, bbox_inches='tight', pad_inches=0)

fig_np = get_img_from_fig(fig, dpi)

Expand Down
1 change: 0 additions & 1 deletion stlearn/plotting/non_spatial_plot.py
Expand Up @@ -14,7 +14,6 @@
def non_spatial_plot(
adata: AnnData,
use_label: str = "louvain",
dpi: int = 180
) -> Optional[AnnData]:

"""\
Expand Down
5 changes: 1 addition & 4 deletions stlearn/plotting/subcluster_plot.py
Expand Up @@ -23,7 +23,6 @@ def subcluster_plot(
show_plot: bool = True,
cropped: bool = True,
margin: int = 100,
dpi: int = 192,
name: str = None,
output: str = None,
copy: bool = False,
Expand Down Expand Up @@ -55,8 +54,6 @@ def subcluster_plot(
Show axis or not.
show_legend
Show legend or not.
dpi
Set dpi as the resolution for the plot.
name
Name of the output figure file.
output
Expand Down Expand Up @@ -153,7 +150,7 @@ def subcluster_plot(
if name is None:
print("The file name is not defined!")
name = use_label
fig.savefig(output + "/" + name + ".png", dpi=dpi,
fig.savefig(output + "/" + name, dpi=plt.figure().dpi,
bbox_inches='tight', pad_inches=0)

# plt.close(fig)
Expand Down
3 changes: 1 addition & 2 deletions stlearn/plotting/trajectory/local_plot.py
Expand Up @@ -26,7 +26,6 @@ def local_plot(
show_color_bar: bool = True,
show_axis: bool = False,
show_plot: bool = True,
dpi: int = 180,
name: str = None,
output: str = None,
copy: bool = False,
Expand Down Expand Up @@ -163,7 +162,7 @@ def local_plot(
if name is None:
print("The file name is not defined!")
name = use_label
fig.savefig(output + "/" + name, dpi=dpi,
fig.savefig(output + "/" + name, dpi=matplotlib.pyplot.figure().dpi,
bbox_inches='tight', pad_inches=0)


Expand Down
5 changes: 1 addition & 4 deletions stlearn/plotting/trajectory/pseudotime_plot.py
Expand Up @@ -30,7 +30,6 @@ def pseudotime_plot(
margin: int = 100,
output: str = None,
name: str = None,
dpi: int = 180,
copy: bool = False,
) -> Optional[AnnData]:

Expand Down Expand Up @@ -71,8 +70,6 @@ def pseudotime_plot(
Show legend or not.
show_plot
Show plot or not
dpi
Set dpi as the resolution for the plot.
output
Save the figure as file or not.
copy
Expand Down Expand Up @@ -175,7 +172,7 @@ def pseudotime_plot(
#plt.gca().invert_yaxis()

if output is not None:
fig.savefig(output + "/" + name + ".png", dpi=dpi,
fig.savefig(output + "/" + name, dpi=plt.figure().dpi,
bbox_inches='tight', pad_inches=0)
if show_plot == True:
plt.show()
Expand Down
2 changes: 1 addition & 1 deletion stlearn/plotting/trajectory/tree_plot.py
Expand Up @@ -118,7 +118,7 @@ def tree_plot(
name = use_label

if output is not None:
fig.savefig(output + "/" + name + ".png", dpi=dpi,
fig.savefig(output + "/" + name, dpi=plt.figure().dpi,
bbox_inches='tight', pad_inches=0)


Expand Down
6 changes: 6 additions & 0 deletions stlearn/spatials/trajectory/global_level.py
Expand Up @@ -11,6 +11,7 @@ def global_level(
list_cluster: list = [],
return_graph: bool = False,
w: float = None,
verbose: bool = True,
copy: bool = False,
) -> Optional[AnnData]:

Expand All @@ -36,6 +37,8 @@ def global_level(
Anndata
"""



assert w <= 1, "w should be in range 0 to 1"
# Get global graph
G = adata.uns["global_graph"]
Expand All @@ -46,6 +49,9 @@ def global_level(
query_nodes = list_cluster
query_nodes = ordering_nodes(query_nodes, use_label,adata)

if verbose:
print("Start to construct the trajectory: " + " -> ".join(np.array(query_nodes).astype(str)))

query_dict = {}
order_dict = {}

Expand Down

0 comments on commit aa55e91

Please sign in to comment.