reconstruction.spreadsheets
Subclasses of DictWriter and DictReader that parse plaintext as JSON strings, allowing for basic type parsing and fields that are dictionaries or lists. The reader also supports units and comment lines.
- class reconstruction.spreadsheets.JsonReader(*args, **kwargs)[source]
Bases:
object
Reader for a .tsv file that supports units and json-coded values. Units are denoted with a fieldname in the format ‘name (units)’ e.g. “flux standard deviation (units.mmol / units.g / units.h)”. Fields whose names start with an underscore are removed from self._fieldnames, and discarded from each row during iteration.
The first argument should be a file-like reader open in text mode.
By default, dialect=CSV_DIALECT, which is excel-tab.
- class reconstruction.spreadsheets.JsonWriter(*args, **kwargs)[source]
Bases:
DictWriter
Writer for a .tsv file to be read by JsonReader. This writes a header with quotes and dict rows in TSV format, JSON encoding, and UTF-8 encoding.
NOTE: The caller needs to remove units from the dict values and add them to the fieldnames. JsonWriter does not handle units.
The first argument should be a file-like writer open in text mode.
By default, dialect=CSV_DIALECT, which is excel-tab.
- reconstruction.spreadsheets.read_tsv(filename)[source]
Read an entire .tsv file using JsonReader and skip comment lines.