#!/usr/bin/env python3
#
# Uses the output from dada2_errmodels_pacbio.r and
# dada2_denoise_pacbio.r to create a report file for
# the DADA2 denoising process, mimicking the report
# generated by QIIME2.
# Results are written to file "dada_report.txt"
#
# Jeanette Tångrot

#-- Import libraries, do initializations  --#
import sys 

file_out = "dada_report.txt"
err = ""
ver = ""
info = ""

#-- Check arguments --#
if len( sys.argv ) != 4:
    exit( "Usage: make_dada2_report_pacbio.py <err.out> <dd.out> <chimera_method>" )

#-- Read information from files --#
with open( sys.argv[1] ) as ef:
    for line in ef:
        err = err + line

with open( sys.argv[2] ) as df:
    for line in df:
        if line.startswith('R version') or line.startswith('DADA2:'):
            ver = ver + line
        else:
            info = info + line

#-- Write to file --#
f = open( file_out, "w")
f.write( ver + "1) Filtering\n2) Learning Error Rates\n" + err +
         "3) Denoising\n" + info + "4) Remove chimeras (method = " + sys.argv[3] +
         ")\n5) Write output (absolute and relative abundances, ASV sequence file, summary statistics)" )
f.close()
