Skip to content

Commit

Permalink
enabling stats as properly formatted TSV
Browse files Browse the repository at this point in the history
as requested by wdecoster/nanostat#29
  • Loading branch information
wdecoster committed Aug 19, 2020
1 parent bb7aaa3 commit b5f8898
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
14 changes: 9 additions & 5 deletions nanocomp/NanoComp.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,14 @@ def main():
if args.barcoded:
datadf["dataset"] = datadf["barcode"]
identifiers = list(datadf["dataset"].unique())
write_stats(
stats_df = write_stats(
datadfs=[datadf[datadf["dataset"] == i] for i in identifiers],
outputfile=settings["path"] + "NanoStats.txt",
names=identifiers)
names=identifiers,
as_tsv=args.tsv_stats)
if args.plot != 'false':
plots = make_plots(datadf, settings)
make_report(plots, settings["path"])
make_report(plots, settings["path"], stats_df=stats_df)
logging.info("Succesfully processed all input.")
except Exception as e:
logging.error(e, exc_info=True)
Expand Down Expand Up @@ -181,7 +182,7 @@ def make_plots(df, settings):
return plots


def make_report(plots, path):
def make_report(plots, path, stats_df):
'''
Creates a fat html report based on the previously created files
plots is a list of Plot objects defined by a path and title
Expand All @@ -208,7 +209,10 @@ def make_report(plots, path):
</head>"""
html_content = ["\n<body>\n<h1>NanoComp report</h1>"]
html_content.append("<h2>Summary statistics</h2>")
html_content.append(utils.stats2html(path + "NanoStats.txt"))
if stats_df is not None:
html_content.append(stats_df.to_html())
else:
html_content.append(utils.stats2html(path + "NanoStats.txt"))
html_content.append('\n<br>\n<br>\n<br>\n<br>')
html_content.append("<h2>Plots</h2>")
for plot in plots:
Expand Down
4 changes: 4 additions & 0 deletions nanocomp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def chunks(values, chunks):


def stats2html(statsf):
'''for legacy stats output files'''
df = pd.read_csv(statsf, sep=':', header=None, names=['feature', 'value'])
values = df["value"].str.strip().str.replace('\t', ' ').str.split().replace(np.nan, '')
num = len(values[0]) or 1
Expand Down Expand Up @@ -154,6 +155,9 @@ def get_args():
general.add_argument("--store",
help="Store the extracted data in a pickle file for future plotting.",
action="store_true")
general.add_argument("--tsv_stats",
help="Output the stats file as a properly formatted TSV.",
action='store_true')
filtering = parser.add_argument_group(
title='Options for filtering or transforming input prior to plotting')
filtering.add_argument("--readtype",
Expand Down
2 changes: 1 addition & 1 deletion nanocomp/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.11.3"
__version__ = "1.12.0"
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
install_requires=['pandas',
'numpy',
'nanoget>=1.4.0',
'nanomath>=0.23.1',
'nanomath>=1.0.0',
'NanoPlot>=1.21.0',
'psutil',
'plotly>=3.4.2',
Expand Down

0 comments on commit b5f8898

Please sign in to comment.