From 6c5ba9f86a8d3a4cb0c40314cb2536bdcb2d6d1f Mon Sep 17 00:00:00 2001 From: fgvieira <1151762+fgvieira@users.noreply.github.com> Date: Mon, 30 Jun 2025 10:20:25 +0200 Subject: [PATCH] Output gzip stats file --- metaDMG.cpp | 15 +++++++-------- test/testAll.sh | 8 ++++---- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/metaDMG.cpp b/metaDMG.cpp index b2f4f05..0678f51 100644 --- a/metaDMG.cpp +++ b/metaDMG.cpp @@ -311,24 +311,23 @@ int main_getdamage(int argc, char **argv) { // write stat char buf[1024]; - snprintf(buf, 1024, "%s.stat", onam); + snprintf(buf, 1024, "%s.stat.gz", onam); fprintf(stderr, "\t-> Outputting overall statistic in file: \"%s\"\n", buf); - FILE *fpstat = NULL; - assert(((fpstat = fopen(buf, "wb"))) != NULL); - fprintf(fpstat,"taxid\tnreads\tmea_len\tvar_len\tmean_gc\tvar_gc\tlca\trank\n"); + gzFile fpstat = NULL; + assert((fpstat = gzopen(buf, "wb")) != NULL); + gzprintf(fpstat,"taxid\tnreads\tmea_len\tvar_len\tmean_gc\tvar_gc\tlca\trank\n"); for (std::map >::iterator it = gcconts.begin(); it != gcconts.end(); it++) { std::map::iterator it2 = dmg->assoc.find(it->first); assert(it2 != dmg->assoc.end()); std::map >::iterator it3 = seqlens.find(it->first); assert(it3 != seqlens.end()); if (0) - fprintf(fpstat, "%d\t%lu\t%f\t%f\t%f\t%f\tNA\tNA\n", it->first, it2->second.nreads, mean(it3->second), var(it3->second), mean(it->second), var(it->second)); + gzprintf(fpstat, "%d\t%lu\t%f\t%f\t%f\t%f\tNA\tNA\n", it->first, it2->second.nreads, mean(it3->second), var(it3->second), mean(it->second), var(it->second)); else - fprintf(fpstat, "%s\t%lu\t%f\t%f\t%f\t%f\tNA\tNA\n", sam_hdr_tid2name(hdr, it->first), it2->second.nreads, mean(it3->second), var(it3->second), mean(it->second), var(it->second)); + gzprintf(fpstat, "%s\t%lu\t%f\t%f\t%f\t%f\tNA\tNA\n", sam_hdr_tid2name(hdr, it->first), it2->second.nreads, mean(it3->second), var(it3->second), mean(it->second), var(it->second)); } - if (fpstat != NULL) - fclose(fpstat); + gzclose(fpstat); sam_hdr_destroy(hdr); bam_destroy1(b); diff --git a/test/testAll.sh b/test/testAll.sh index 8afc006..a93b754 100755 --- a/test/testAll.sh +++ b/test/testAll.sh @@ -66,7 +66,7 @@ if [[ $? -ne 0 ]]; then echo "Problem running command: ${CMD}" RVAL=$((32+RVAL)) fi -gunzip -c output/test_lca.lca.gz |cut -f1,3-100 >output/test_lca.lca.sub +gunzip -c output/test_lca.lca.gz | cut -f1,3-100 >output/test_lca.lca.sub echo "Running aggregate" CMD="${PRG} aggregate output/test_lca.bdamage.gz --nodes data/nodes.dmp.gz --names data/names.dmp.gz --lcastat output/test_lca.stat.gz --out_prefix output/test_aggregate" @@ -87,13 +87,13 @@ fi echo "Running test of output/test_dfit_local.dfit.gz by gzip -t output/test_dfit_local.dfit.gz " gzip -t output/test_dfit_local.dfit.gz echo -ne "Return value of test $?\nWill now run gunzip -c output/test_dfit_local.dfit.gz|wc -c\n" - gunzip -c output/test_dfit_local.dfit.gz|wc -c +gunzip -c output/test_dfit_local.dfit.gz | wc -c gunzip -c output/test_dfit_local.dfit.gz > tmp.txt head -n 10 tmp.txt > tmp2.txt #rm tmp.txt -cut -f 1-6,8- tmp2.txt| numfmt -d $'\t' --header --format='%.2f' --field=2- --invalid=ignore > output/test_dfit_local.dfit.fix +cut -f 1-6,8- tmp2.txt | numfmt -d $'\t' --header --format='%.2f' --field=2- --invalid=ignore > output/test_dfit_local.dfit.fix #rm tmp2.txt #zcat output/test_dfit_local.dfit.gz | head -n 10|cut -f 1-6,8- | numfmt -d $'\t' --header --format='%.2f' --field=2- --invalid=ignore > output/test_dfit_local.dfit.fix #exit 0 @@ -112,7 +112,7 @@ fi gunzip -c output/test_dfit_local_10threads.dfit.gz > tmp.txt head -n 10 tmp.txt > tmp2.txt rm tmp.txt -cut -f 1-6,8- tmp2.txt| numfmt -d $'\t' --header --format='%.2f' --field=2- --invalid=ignore | sort -r > output/test_dfit_local_10threads.dfit.fix +cut -f 1-6,8- tmp2.txt | numfmt -d $'\t' --header --format='%.2f' --field=2- --invalid=ignore | sort -r > output/test_dfit_local_10threads.dfit.fix rm tmp2.txt echo "Running dfit global"