Skip to content

Commit a291326

Browse files
committed
move imports lower to make --version and --help faster
1 parent 1a43f49 commit a291326

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@ tests/
1010
.idea
1111
nanomath/__pycache__/__init__.cpython-39.pyc
1212
nanomath/__pycache__/nanomath.cpython-39.pyc
13+
nanoplot.egg-info/dependency_links.txt
14+
nanoplot.egg-info/entry_points.txt
15+
nanoplot.egg-info/PKG-INFO
16+
nanoplot.egg-info/requires.txt
17+
nanoplot.egg-info/SOURCES.txt
18+
nanoplot.egg-info/top_level.txt

nanoplot/NanoPlot.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,8 @@
1313

1414
from os import path
1515
import logging
16-
import numpy as np
17-
from scipy import stats
1816
import nanoplot.utils as utils
19-
import nanoplot.report as report
20-
from nanoget import get_input
21-
from nanoplot.filteroptions import filter_and_transform_data
2217
from nanoplot.version import __version__
23-
from nanoplotter.plot import Plot
24-
import nanoplotter
25-
import nanomath
26-
import pickle
2718
import sys
2819

2920

@@ -36,10 +27,15 @@ def main():
3627
"""
3728
settings, args = utils.get_args()
3829
try:
30+
import nanoplot.report as report
31+
from nanoget import get_input
32+
from nanoplot.filteroptions import filter_and_transform_data
33+
from nanoplotter.plot import Plot
3934
utils.make_output_dir(args.outdir)
4035
utils.init_logs(args)
4136
# args.format = nanoplotter.check_valid_format(args.format)
4237
if args.pickle:
38+
import pickle
4339
datadf = pickle.load(open(args.pickle, "rb"))
4440
elif args.feather:
4541
from nanoget import combine_dfs
@@ -121,6 +117,7 @@ def main():
121117

122118

123119
def make_stats(datadf, settings, suffix, tsv_stats=True):
120+
import nanomath
124121
statsfile = settings["path"] + "NanoStats" + suffix + ".txt"
125122
stats_df = nanomath.write_stats(datadfs=[datadf], outputfile=statsfile, as_tsv=tsv_stats)
126123
logging.info("Calculated statistics")
@@ -141,6 +138,10 @@ def make_plots(datadf, settings):
141138
Call plotting functions from nanoplotter
142139
settings["lengths_pointer"] is a column in the DataFrame specifying which lengths to use
143140
"""
141+
import numpy as np
142+
from scipy import stats
143+
import nanoplotter
144+
import nanomath
144145
color = nanoplotter.check_valid_color(settings["color"])
145146
colormap = nanoplotter.check_valid_colormap(settings["colormap"])
146147

@@ -381,6 +382,7 @@ def make_report(plots, settings):
381382
which is parsed to a table (rather dodgy) or nicely if it's a pandas/tsv
382383
"""
383384
logging.info("Writing html report.")
385+
from nanoplot import report
384386

385387
html_content = [
386388
'<body class="grid">',

nanoplot/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from nanoplot.version import __version__
77
from argparse import HelpFormatter, Action, ArgumentParser
88
import textwrap as _textwrap
9-
import pandas as pd
109

1110

1211
class CustomHelpFormatter(HelpFormatter):
@@ -346,6 +345,7 @@ def init_logs(args, tool="NanoPlot"):
346345

347346

348347
def subsample_datasets(df, minimal=10000):
348+
import pandas as pd
349349
if "dataset" in df:
350350
list_df = []
351351

0 commit comments

Comments
 (0)