Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from . import export_to
from . import logging
from . import queries
from .. import plotting
# unfortunately, we cannot put this here as long as we have simple global
# variables in settings... they couldn't be set in this case...
# the main drawback is that we have to import set_figure_params
# to show in the docs for that reason...
# it would be nice to make the simple data types "properties of the
# module"... putting setters and getters for all of them wouldn't be very nice
from .._settings import settings
# for now – or maybe as the permanently favored solution – put the single function here
# from ..settings import set_figure_params
set_figure_params = settings.set_figure_params
# some stuff that is not actually documented...
from .. import _utils
import sys
_utils.annotate_doc_types(sys.modules[__name__], 'scanpy')
del sys
__doc__ = """\
Global API (deprecated)
levels, _ = np.unique(color, return_inverse=True)
colors = np.array(palette[:len(levels)].by_key()['color'])
subsets = [(x_range[color == l], X[color == l, :]) for l in levels]
if ax is None:
ax = pl.subplot()
for i, (x, y) in enumerate(subsets):
ax.scatter(
x, y,
marker='.',
edgecolor='face',
s=rcParams['lines.markersize'],
c=colors[i],
label=var_names[i] if len(var_names) > 0 else '',
cmap=color_map,
rasterized=settings._vector_friendly,
)
ylim = ax.get_ylim()
for h in highlights_x:
ax.plot([h, h], [ylim[0], ylim[1]], '--', color='black')
ax.set_ylim(ylim)
if xlim is not None:
ax.set_xlim(xlim)
ax.set_xlabel(xlabel)
ax.set_ylabel(ylabel)
if yticks is not None:
ax.set_yticks(yticks)
if len(var_names) > 0 and legend:
ax.legend(frameon=False)
from . import export_to
from . import logging
from . import queries
from .. import plotting
# unfortunately, we cannot put this here as long as we have simple global
# variables in settings... they couldn't be set in this case...
# the main drawback is that we have to import set_figure_params
# to show in the docs for that reason...
# it would be nice to make the simple data types "properties of the
# module"... putting setters and getters for all of them wouldn't be very nice
from .._settings import settings
# for now - or maybe as the permanently favored solution - put the single function here
# from ..settings import set_figure_params
set_figure_params = settings.set_figure_params
# some stuff that is not actually documented...
from .. import utils
import sys
utils.annotate_doc_types(sys.modules[__name__], 'scanpy')
del sys
__doc__ = """\
Global API (deprecated)
=======================
.. warning::
.. deprecated:: 1.3.7
from cuml import UMAP
n_neighbors = adata.uns['neighbors']['params']['n_neighbors']
n_epochs = 500 if maxiter is None else maxiter # 0 is not a valid value for rapids, unlike original umap
X_contiguous = np.ascontiguousarray(X, dtype=np.float32)
umap = UMAP(
n_neighbors=n_neighbors,
n_components=n_components,
n_epochs=n_epochs,
learning_rate=alpha,
init=init_pos,
min_dist=min_dist,
spread=spread,
negative_sample_rate=negative_sample_rate,
a=a,
b=b,
verbose=settings.verbosity > 3,
)
X_umap = umap.fit_transform(X_contiguous)
adata.obsm['X_umap'] = X_umap # annotate samples with UMAP coordinates
logg.info(
' finished',
time=start,
deep=(
'added\n'
" 'X_umap', UMAP coordinates (adata.obsm)"
),
)
return adata if copy else None
def hint(msg, *, time=None, deep=None, extra=None) -> datetime:
from ._settings import settings
return settings._root_logger.hint(msg, time=time, deep=deep, extra=extra)
def burczynski06() -> AnnData:
"""\
Bulk data with conditions ulcerative colitis (UC) and Crohn's disease (CD).
The study assesses transcriptional profiles in peripheral blood mononuclear
cells from 42 healthy individuals, 59 CD patients, and 26 UC patients by
hybridization to microarrays interrogating more than 22,000 sequences.
Reference
---------
Burczynski et al., "Molecular classification of Crohn's disease and
ulcerative colitis patients using transcriptional profiles in peripheral
blood mononuclear cells"
J Mol Diagn 8, 51 (2006). PMID:16436634.
"""
filename = settings.datasetdir / 'burczynski06/GDS1615_full.soft.gz'
url = 'ftp://ftp.ncbi.nlm.nih.gov/geo/datasets/GDS1nnn/GDS1615/soft/GDS1615_full.soft.gz'
adata = read(filename, backup_url=url)
return adata
kwargs : `dict` or `None`, optional (default: None)
optional keyword arguments for irlb.
Returns
-------
**datas** : :class:`~numpy.ndarray` or :class:`~anndata.AnnData`
Corrected matrix/matrices or AnnData object/objects, depending on the
input type and `do_concatenate`.
**mnn_list** : ``List[pandas.DataFrame]``
A list containing MNN pairing information as DataFrames in each iteration step.
**angle_list** : ``List[Tuple[Optional[float], int]]`` or ``None``
A list containing angles of each batch.
"""
try:
from mnnpy import mnn_correct as mnn_cor
n_jobs = settings.n_jobs if n_jobs is None else n_jobs
datas, mnn_list, angle_list = mnn_cor(
*datas, var_index=var_index, var_subset=var_subset, batch_key=batch_key, index_unique=index_unique,
batch_categories=batch_categories, k=k, sigma=sigma, cos_norm_in=cos_norm_in, cos_norm_out=cos_norm_out,
svd_dim=svd_dim, var_adj=var_adj, compute_angle=compute_angle, mnn_order=mnn_order, svd_mode=svd_mode,
do_concatenate=do_concatenate, save_raw=save_raw, n_jobs=n_jobs, **kwargs)
return datas, mnn_list, angle_list
except ImportError:
raise ImportError(
'Please install the package mnnpy '
'(https://github.com/chriscainx/mnnpy). ')
def sample_static_data(model, dir, verbosity=0):
# fraction of connectivity as compared to fully connected
# in one direction, which amounts to dim*(dim-1)/2 edges
connectivity = 0.8
dim = 3
n_Coupls = 50
model = model.replace('static-', '')
np.random.seed(0)
if model != 'combi':
n_edges = np.zeros(n_Coupls)
for icoupl in range(n_Coupls):
Coupl, Adj, Adj_signed, n_e = sample_coupling_matrix(dim,connectivity)
if verbosity > 1:
settings.m(0,icoupl)
settings.m(0,Adj)
n_edges[icoupl] = n_e
# sample data
X = StaticCauseEffect().sim_givenAdj(Adj,model)
write_data(X, dir, Adj=Adj)
settings.m(0, 'mean edge number:', n_edges.mean())
else:
X = StaticCauseEffect().sim_combi()
Adj = np.zeros((3, 3))
Adj[2, 0] = Adj[2, 1] = 0
write_data(X, dir, Adj=Adj)
else:
ext = is_valid_filename(filename, return_ext=True)
is_present = _check_datafile_present_and_download(
filename,
backup_url=backup_url,
)
if not is_present: logg.debug(f'... did not find original file {filename}')
# read hdf5 files
if ext in {'h5', 'h5ad'}:
if sheet is None:
return read_h5ad(filename, backed=backed)
else:
logg.debug(f'reading sheet {sheet} from file {filename}')
return read_hdf(filename, sheet)
# read other file types
path_cache = settings.cachedir / _slugify(filename).replace('.' + ext, '.h5ad') # type: Path
if path_cache.suffix in {'.gz', '.bz2'}:
path_cache = path_cache.with_suffix('')
if cache and path_cache.is_file():
logg.info(f'... reading from cache file {path_cache}')
return read_h5ad(path_cache)
if not is_present:
raise FileNotFoundError(f'Did not find file {filename}.')
logg.debug(f'reading {filename}')
if not cache and not suppress_cache_warning:
logg.hint(
'This might be very slow. Consider passing `cache=True`, '
'which enables much faster reading from a cache file.'
)
# do the actual reading
if ext == 'xlsx' or ext == 'xls':