Skip to content

Fixed and updated file writing - #69

Open
KasperThystrup wants to merge 3 commits into
phac-nml:masterfrom
KasperThystrup:KasperThystrup-patch-1
Open

Fixed and updated file writing#69
KasperThystrup wants to merge 3 commits into
phac-nml:masterfrom
KasperThystrup:KasperThystrup-patch-1

Conversation

@KasperThystrup

Copy link
Copy Markdown

Made some updates to file writing which should improve when writing results:

  • Moved module imports to top of script to avoid missing modules like cPickle (since py3.5+) which only comes up with the -f pickle argument
  • Updated pandas.to_csv calls to use destionation string, rather than open() write handler
  • Replaced open() with with(open, ...) as fh:
  • Restructured file writing directly into the write function to improve readability (IMHO) and save a few lines

open() filehandling object doesn't work with pandas.to_csv.

Import Path for directory creation, as siistr fails if parent dir does not exist.

My guess is that the same goes for json dumping and pickle. But that remains to be tested
* Implemented json and pickle writers directly into write function (As I did with pandas writing)
* Reimplemented normal write handling for json files and binary write handling for pickle files
@KasperThystrup

KasperThystrup commented Jun 2, 2026

Copy link
Copy Markdown
Author

Note, this has been tested locally using conda 26.1.1 to install with following instructions:
sistr_cmd.yaml:

name: sistr_cmd
dependencies:
  - bioconda::sistr_cmd
  - conda-forge::numpy>=1.11.1,<2.0
  - conda-forge::setuptools<82.0.0

Executed with the following (and succeeding):

sistr -f tab --qc -t 4 -l /paht/2/Senterica_serovar.txt --cgmlst-profiles /path/2/shovill_cgmlst_profiles.csv --alleles-output /outdir/shovill_allele-results.json --output-prediction /outdir/shovill_sistr.tab /path/2/shovill.fasta

sistr -f csv --qc -t 4 -l /paht/2/Senterica_serovar.txt --cgmlst-profiles /path/2/shovill_cgmlst_profiles.csv --alleles-output /outdir/shovill_allele-results.json --output-prediction /outdir/shovill_sistr.csv /path/2/shovill.fasta

sistr -f json --qc -t 4 -l /paht/2/Senterica_serovar.txt --cgmlst-profiles /path/2/shovill_cgmlst_profiles.csv --alleles-output /outdir/shovill_allele-results.json --output-prediction /outdir/shovill_sistr.json /path/2/shovill.fasta

sistr -f pickle --qc -t 4 -l /paht/2/Senterica_serovar.txt --cgmlst-profiles /path/2/shovill_cgmlst_profiles.csv --alleles-output /outdir/shovill_allele-results.json --output-prediction /outdir/shovill_sistr.pickle /path/2/shovill.fasta

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant