Skip to content

Commit

Permalink
use scprep
Browse files Browse the repository at this point in the history
  • Loading branch information
scottgigante committed Sep 3, 2018
1 parent 6035c0a commit bc6ea1b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
15 changes: 15 additions & 0 deletions python/magic/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ def load_csv(filename, cell_axis='row', delimiter=',',
-------
data : pd.DataFrame
"""
warnings.warn("magic.io is deprecated. Please use scprep.io instead. "
"Read more at http://scprep.readthedocs.io",
FutureWarning)
if cell_axis not in ['row', 'column', 'col']:
raise ValueError(
"cell_axis {} not recognized. Expected 'row' or 'column'".format(
Expand Down Expand Up @@ -309,6 +312,9 @@ def load_fcs(filename, gene_names=True, cell_names=True,
-------
data : pd.DataFrame
"""
warnings.warn("magic.io is deprecated. Please use scprep.io instead. "
"Read more at http://scprep.readthedocs.io",
FutureWarning)
if cell_names is True:
cell_names = None
if gene_names is True:
Expand Down Expand Up @@ -347,6 +353,9 @@ def load_mtx(mtx_file, cell_axis='row',
-------
data : pd.DataFrame
"""
warnings.warn("magic.io is deprecated. Please use scprep.io instead. "
"Read more at http://scprep.readthedocs.io",
FutureWarning)
if cell_axis not in ['row', 'column', 'col']:
raise ValueError(
"cell_axis {} not recognized. Expected 'row' or 'column'".format(
Expand Down Expand Up @@ -435,6 +444,9 @@ def load_10X(data_dir, sparse=True, gene_labels='symbol',
data: pandas.DataFrame shape = (n_cell, n_genes)
imported data matrix
"""
warnings.warn("magic.io is deprecated. Please use scprep.io instead. "
"Read more at http://scprep.readthedocs.io",
FutureWarning)

if gene_labels not in ['id', 'symbol', 'both']:
raise ValueError("gene_labels not in ['id', 'symbol', 'both']")
Expand Down Expand Up @@ -551,6 +563,9 @@ def load_10X_HDF5(filename, genome=None, sparse=True, gene_labels='symbol',
If sparse, data will be a pd.SparseDataFrame. Otherwise, data will
be a pd.DataFrame.
"""
warnings.warn("magic.io is deprecated. Please use scprep.io instead. "
"Read more at http://scprep.readthedocs.io",
FutureWarning)
with tables.open_file(filename, 'r') as f:
if genome is None:
genomes = [node._v_name for node in f.list_nodes(f.root)]
Expand Down
5 changes: 5 additions & 0 deletions python/magic/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import numpy as np
from scipy import sparse
import pandas as pd
import warnings


def library_size_normalize(data, verbose=False):
Expand All @@ -25,6 +26,10 @@ def library_size_normalize(data, verbose=False):
data_norm : ndarray [n, p]
2 dimensional array with normalized gene expression values
"""
warnings.warn("magic.preprocessing is deprecated. "
"Please use scprep.normalize instead. "
"Read more at http://scprep.readthedocs.io",
FutureWarning)
if verbose:
print("Normalizing library sizes for %s cells" % (data.shape[0]))

Expand Down
25 changes: 14 additions & 11 deletions python/magic/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

from __future__ import print_function, division, absolute_import
import magic
import pandas as pd
import numpy as np
import scprep
try:
import anndata
except (ImportError, SyntaxError):
Expand All @@ -13,23 +13,26 @@


def test_scdata():
scdata = pd.read_csv("../data/test_data.csv")
scdata_norm = magic.preprocessing.library_size_normalize(scdata)
scdata = scprep.io.read_csv("../data/test_data.csv")
scdata_norm = scprep.filter.remove_empty_cells(scdata)
scdata_norm = scprep.filter.remove_empty_genes(scdata)
scdata_norm = scprep.normalize.library_size_normalize(scdata_norm)
scdata_norm = scprep.transform.sqrt(scdata_norm)
assert scdata.shape == scdata_norm.shape
fast_magic_operator = magic.MAGIC(t='auto', a=20, k=10)
str_gene_magic = fast_magic_operator.fit_transform(
magic_op = magic.MAGIC(t='auto', a=20, k=10)
str_gene_magic = magic_op.fit_transform(
scdata_norm, genes=['VIM', 'ZEB1'])
int_gene_magic = fast_magic_operator.fit_transform(
int_gene_magic = magic_op.fit_transform(
scdata_norm, genes=[-2, -1])
assert str_gene_magic.shape[0] == scdata_norm.shape[0]
assert np.all(str_gene_magic == int_gene_magic)
pca_magic = fast_magic_operator.fit_transform(
pca_magic = magic_op.fit_transform(
scdata_norm, genes="pca_only")
assert pca_magic.shape[0] == scdata_norm.shape[0]
assert pca_magic.shape[1] == fast_magic_operator.n_pca
fast_magic = fast_magic_operator.fit_transform(scdata_norm,
genes="all_genes")
assert scdata_norm.shape == fast_magic.shape
assert pca_magic.shape[1] == magic_op.n_pca
magic_all_genes = magic_op.fit_transform(scdata_norm,
genes="all_genes")
assert scdata_norm.shape == magic_all_genes.shape


def test_anndata():
Expand Down

0 comments on commit bc6ea1b

Please sign in to comment.