Skip to content

Commit

Permalink
Use black default line length
Browse files Browse the repository at this point in the history
  • Loading branch information
flying-sheep committed Jan 9, 2020
1 parent fb64c0f commit 8131b05
Show file tree
Hide file tree
Showing 30 changed files with 195 additions and 501 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
max_line_length = 80
max_line_length = 88

[*.py]
indent_size = 4
Expand Down
4 changes: 1 addition & 3 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ def pytest_addoption(parser):

def pytest_collection_modifyitems(config, items):
run_internet = config.getoption("--internet-tests")
skip_internet = pytest.mark.skip(
reason="need --internet-tests option to run"
)
skip_internet = pytest.mark.skip(reason="need --internet-tests option to run")
for item in items:
# All tests marked with `pytest.mark.internet` get skipped unless
# `--run-internet` passed
Expand Down
4 changes: 1 addition & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@


html_theme = 'sphinx_rtd_theme'
html_theme_options = dict(
navigation_depth=4, logo_only=True # Only show the logo
)
html_theme_options = dict(navigation_depth=4, logo_only=True) # Only show the logo
html_context = dict(
display_github=True, # Integrate GitHub
github_user='theislab', # Username
Expand Down
7 changes: 1 addition & 6 deletions docs/extensions/function_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@


def insert_function_images(
app: Sphinx,
what: str,
name: str,
obj: Any,
options: Options,
lines: List[str],
app: Sphinx, what: str, name: str, obj: Any, options: Options, lines: List[str],
):
path = app.config.api_dir / f'{name}.png'
if what != 'function' or not path.is_file():
Expand Down
12 changes: 3 additions & 9 deletions docs/extensions/github_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,13 @@ def register_links(app: Sphinx, config: Config):
config.html_context
)
app.add_role('pr', AutoLink('pr', f'{gh_url}/pull/{{}}', 'PR {}'))
app.add_role(
'issue', AutoLink('issue', f'{gh_url}/issues/{{}}', 'issue {}')
)
app.add_role(
'noteversion', AutoLink('noteversion', f'{gh_url}/releases/tag/{{}}')
)
app.add_role('issue', AutoLink('issue', f'{gh_url}/issues/{{}}', 'issue {}'))
app.add_role('noteversion', AutoLink('noteversion', f'{gh_url}/releases/tag/{{}}'))
# tutorial links
scanpy_tutorials_url = 'https://scanpy-tutorials.readthedocs.io/en/latest/'
app.add_role(
'tutorial',
AutoLink(
'tutorial', f'{scanpy_tutorials_url}{{}}.html', '→ tutorial: {}'
),
AutoLink('tutorial', f'{scanpy_tutorials_url}{{}}.html', '→ tutorial: {}'),
)


Expand Down
4 changes: 1 addition & 3 deletions docs/extensions/typed_returns.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ def process_return(lines):


def scanpy_parse_returns_section(self, section):
lines_raw = list(
process_return(self._dedent(self._consume_to_next_section()))
)
lines_raw = list(process_return(self._dedent(self._consume_to_next_section())))
lines = self._format_block(':returns: ', lines_raw)
if lines and lines[-1]:
lines.append('')
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requires = ['setuptools', 'setuptools_scm', 'wheel']
build-backend = 'setuptools.build_meta'

[tool.black]
line-length = 80
line-length = 88
target-version = ['py36']
skip-string-normalization = true
exclude = '''
Expand Down Expand Up @@ -57,7 +57,6 @@ exclude = '''
|test_neighbors
|test_readwrite
|test_clustering
|test_qc_metrics
|test_preprocessing
|test_rank_genes_groups
|test_marker_gene_overlap
Expand Down
8 changes: 2 additions & 6 deletions scanpy/datasets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,10 @@ def moignard15() -> AnnData:
Annotated data matrix.
"""
filename = settings.datasetdir / 'moignard15/nbt.3154-S3.xlsx'
backup_url = (
'http://www.nature.com/nbt/journal/v33/n3/extref/nbt.3154-S3.xlsx'
)
backup_url = 'http://www.nature.com/nbt/journal/v33/n3/extref/nbt.3154-S3.xlsx'
adata = read(filename, sheet='dCt_values.txt', backup_url=backup_url)
# filter out 4 genes as in Haghverdi et al. (2016)
gene_subset = ~np.in1d(
adata.var_names, ['Eif2b1', 'Mrpl19', 'Polr2a', 'Ubc']
)
gene_subset = ~np.in1d(adata.var_names, ['Eif2b1', 'Mrpl19', 'Polr2a', 'Ubc'])
adata = adata[:, gene_subset] # retain non-removed genes
# choose root cell for DPT analysis as in Haghverdi et al. (2016)
adata.uns["iroot"] = 532 # note that in Matlab/R, counting starts at 1
Expand Down
7 changes: 2 additions & 5 deletions scanpy/datasets/_ebi_expression_atlas.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ def download_experiment(accession: str):
experiment_dir.mkdir(parents=True, exist_ok=True)

_download(
download_url + "experiment-design",
experiment_dir / "experimental_design.tsv",
download_url + "experiment-design", experiment_dir / "experimental_design.tsv",
)
_download(
download_url + "quantification-filtered",
Expand Down Expand Up @@ -123,9 +122,7 @@ def ebi_expression_atlas(

with ZipFile(experiment_dir / "expression_archive.zip", "r") as f:
adata = read_expression_from_archive(f)
obs = pd.read_csv(
experiment_dir / "experimental_design.tsv", sep="\t", index_col=0
)
obs = pd.read_csv(experiment_dir / "experimental_design.tsv", sep="\t", index_col=0)

adata.obs[obs.columns] = obs
adata.write(dataset_path, compression="gzip") # To be kind to disk space
Expand Down
4 changes: 1 addition & 3 deletions scanpy/external/pp/_dca.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,7 @@ def dca(
try:
from dca.api import dca
except ImportError:
raise ImportError(
'Please install dca package (>= 0.2.1) via `pip install dca`'
)
raise ImportError('Please install dca package (>= 0.2.1) via `pip install dca`')

return dca(
adata,
Expand Down
4 changes: 1 addition & 3 deletions scanpy/external/pp/_magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
@legacy_api('k', 'a')
def magic(
adata: AnnData,
name_list: Union[
Literal['all_genes', 'pca_only'], Sequence[str], None
] = None,
name_list: Union[Literal['all_genes', 'pca_only'], Sequence[str], None] = None,
*,
knn: int = 10,
decay: int = 15,
Expand Down
50 changes: 11 additions & 39 deletions scanpy/external/tl/_harmony_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,18 +208,15 @@ def __init__(
print('"sample_names" not provided, constructed internally')
rep = range(len(self.data))
self.sample_names = [
"_".join(["sample{}".format(n + 1), str(n + 1)])
for n in rep
"_".join(["sample{}".format(n + 1), str(n + 1)]) for n in rep
]
print('"sample_names": {}'.format(self.sample_names))

try:
assert self.timepoints
except AssertionError:
try:
self.timepoints = [
i.split("_")[0] for i in self.sample_names
]
self.timepoints = [i.split("_")[0] for i in self.sample_names]
except:
msg = (
'"timepoints" must be a list of Time Points!!\n\n\t'
Expand All @@ -242,9 +239,7 @@ def __init__(
assert isinstance(data[0].to_df(), pd.DataFrame)
else:
assert isinstance(data[0], pd.DataFrame)
counts = self.load_from_AnnData(
self.data, self.sample_names
)
counts = self.load_from_AnnData(self.data, self.sample_names)
logg.info("Input data is a list of scanpy.AnnData objects")
except:
raise RuntimeError(
Expand Down Expand Up @@ -286,9 +281,7 @@ def process(self, n_components: int = 1000):
self.timepoint_connections = pd.DataFrame(columns=[0, 1])
index = 0
for i in range(len(self.timepoints) - 1):
self.timepoint_connections.loc[index, :] = self.timepoints[
i : i + 2
]
self.timepoint_connections.loc[index, :] = self.timepoints[i : i + 2]
index += 1

# compute the augmented and non-augmented affinity matrices
Expand Down Expand Up @@ -317,19 +310,14 @@ def process(self, n_components: int = 1000):
self.harmony_adata.uns["aug_aff"] = self.aug_aff
self.harmony_adata.uns["sample_names"] = self.sample_names
self.harmony_adata.uns["timepoints"] = self.timepoints
self.harmony_adata.uns[
"timepoint_connections"
] = self.timepoint_connections
self.harmony_adata.uns["timepoint_connections"] = self.timepoint_connections

logg.info("End of processing, start plotting.")

return self.harmony_adata

def load_from_AnnData(
self,
data_list: list,
sample_names: list = None,
min_cell_count: int = 10,
self, data_list: list, sample_names: list = None, min_cell_count: int = 10,
):
"""
Read in scRNA-seq data from :class:`~anndata.AnnData` list
Expand Down Expand Up @@ -375,32 +363,18 @@ def load_from_AnnData(
# Concatenate cells and genes
print("Concatenating data..")
all_cells = list(
chain(
*[
list(counts_dict[sample].index)
for sample in sample_names
]
)
chain(*[list(counts_dict[sample].index) for sample in sample_names])
)
all_genes = list(
chain(
*[
list(counts_dict[sample].columns)
for sample in sample_names
]
)
chain(*[list(counts_dict[sample].columns) for sample in sample_names])
)
all_genes = list(set(all_genes))

# Counts matrix
counts = pd.DataFrame(
0, index=all_cells, columns=all_genes, dtype=np.int16
)
counts = pd.DataFrame(0, index=all_cells, columns=all_genes, dtype=np.int16)
for sample in sample_names:
sample_counts = counts_dict[sample]
counts.loc[
sample_counts.index, sample_counts.columns
] = sample_counts
counts.loc[sample_counts.index, sample_counts.columns] = sample_counts

# Filter out low detection genes
gs = counts.sum()
Expand All @@ -415,9 +389,7 @@ def log_transform(self):
@log_transform.setter
def log_transform(self, value):
if value is True:
self.data_df = self.harmony_timeseries.utils.log_transform(
self.data_df
)
self.data_df = self.harmony_timeseries.utils.log_transform(self.data_df)
logg.info("data log transformed ...")

def wrapper_cls(data, func=None, **kargs):
Expand Down
8 changes: 2 additions & 6 deletions scanpy/external/tl/_trimap.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ def trimap(
n_inliers: int = 10,
n_outliers: int = 5,
n_random: int = 5,
metric: Literal[
'angular', 'euclidean', 'hamming', 'manhattan'
] = 'euclidean',
metric: Literal['angular', 'euclidean', 'hamming', 'manhattan'] = 'euclidean',
weight_adj: float = 500.0,
lr: float = 1000.0,
n_iters: int = 400,
Expand Down Expand Up @@ -89,9 +87,7 @@ def trimap(
try:
from trimap import TRIMAP
except ImportError:
raise ImportError(
'\nplease install trimap: \n\n\tsudo pip install trimap'
)
raise ImportError('\nplease install trimap: \n\n\tsudo pip install trimap')
adata = adata.copy() if copy else adata
start = logg.info('computing TriMap')
adata = adata.copy() if copy else adata
Expand Down
Loading

0 comments on commit 8131b05

Please sign in to comment.