Skip to content

Commit

Permalink
remove changes to matplotlib defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Hie committed Mar 29, 2020
1 parent a437be5 commit 3f4a5f5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
11 changes: 6 additions & 5 deletions bin/mouse_brain_sketched.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,28 @@

datasets = datasets_merged

labels = []
names = []
curr_label = 0
for i, a in enumerate(datasets_dimred):
labels += list(np.zeros(a.shape[0]) + curr_label)
names.append(data_names[i])
curr_label += 1
labels = np.array(labels, dtype=int)

mouse_brain_genes = [
'Gja1', 'Flt1', 'Gabra6', 'Syt1', 'Gabrb2', 'Gabra1',
'Meg3', 'Mbp', 'Rgs5',
]

# Downsample for visualization purposes
rand_idxs = []
labels = []
curr_label = 0
for i in range(len(data_names)):
ds = datasets_dimred[i]
rand_idx = np.random.choice(ds.shape[0], size=int(ds.shape[0]/10),
replace=False)
datasets_dimred[i] = ds[rand_idx, :]
datasets[i] = datasets[i][rand_idx, :]
labels += list(np.zeros(datasets_dimred[i].shape[0]) + curr_label)
curr_label += 1
labels = np.array(labels, dtype=int)

embedding = visualize(datasets_dimred,
labels, NAMESPACE + '_ds', names,
Expand Down
13 changes: 5 additions & 8 deletions scanorama/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import errno
from fbpca import pca
import matplotlib as mpl
mpl.rcParams['figure.figsize'] = [10.0, 9.0]
mpl.use('Agg')
import matplotlib.pyplot as plt
from matplotlib import cm
import numpy as np
Expand All @@ -22,7 +19,7 @@ def dispersion(X):
dispersion[mean > 1e-10] = temp.A1
dispersion[mean <= 1e-10] = float('-inf')
return dispersion

def reduce_dimensionality(X, dim_red_k=100):
k = min((dim_red_k, X.shape[0], X.shape[1]))
U, s, Vt = pca(X, k=k) # Automatically centers.
Expand All @@ -48,16 +45,16 @@ def visualize_cluster(coords, cluster, cluster_labels,
c=colors[1], s=size)
plt.title(str(cluster_name))
plt.savefig(image_fname, dpi=500)

def visualize_expr(X, coords, genes, viz_gene, image_suffix='.svg',
new_fig=True, size=1, viz_prefix='ve'):
genes = [ gene.upper() for gene in genes ]
viz_gene = viz_gene.upper()

if not viz_gene.upper() in genes:
sys.stderr.write('Warning: Could not find gene {}\n'.format(viz_gene))
return

image_fname = '{}_{}{}'.format(
viz_prefix, viz_gene, image_suffix
)
Expand Down Expand Up @@ -111,7 +108,7 @@ def visualize_dropout(X, coords, image_suffix='.svg',
plt.scatter(coords[:, 0], coords[:, 1],
c=colors, cmap=cm.get_cmap('Reds'), s=size)
plt.savefig(image_fname, dpi=500)

def mkdir_p(path):
try:
os.makedirs(path)
Expand Down

0 comments on commit 3f4a5f5

Please sign in to comment.