Results export
gambit.results
Export query results in various formats.
gambit.results.base
- class gambit.results.base.AbstractResultsExporter
Bases:
ABC
Base for classes that export formatted query results.
Subclasses must implement
export()
.- abstract export(file_or_path, results)
Write query results to file.
- Parameters:
file_or_path (str | PathLike | IO) – Open file-like object or file path to write to.
results (QueryResults) – Results to export.
- class gambit.results.base.BaseJSONResultsExporter
Bases:
AbstractResultsExporter
Base class for JSON exporters.
Subclasses need to implement the
to_json
method.- pretty
Write in more human-readable but less compact format. Defaults to False.
- Type:
bool
- __init__(pretty=False)
Method generated by attrs for class BaseJSONResultsExporter.
- Parameters:
pretty (bool) –
- Return type:
None
- export(file_or_path, results)
Write query results to file.
- Parameters:
file_or_path (str | PathLike | TextIO) – Open file-like object or file path to write to.
results (QueryResults) – Results to export.
- to_json(obj)
Convert object to JSON-compatible format (need not work recursively).
- gambit.results.base.asdict_method(recurse=False, **kw)
Create a
to_json
method which callsattrs.asdict()
with the given options.
- gambit.results.base.export_to_buffer(results, exporter)
Export query results to a StringIO buffer.
- Parameters:
results (QueryResults) –
- Return type:
StringIO
gambit.results.json
Export results to JSON.
- class gambit.results.json.JSONResultsExporter
Bases:
BaseJSONResultsExporter
Exports query results in basic JSON format.
Currently it assumes that the query was run with
classify_strict=False
, so the only relevant information fromClassifierResult
is the closest genome match.- __init__(pretty=False)
Method generated by attrs for class JSONResultsExporter.
- Parameters:
pretty (bool) –
- Return type:
None
- to_json(obj)
- to_json(results)
- to_json(item)
- to_json(input)
- to_json(gset)
- to_json(taxon)
- to_json(genome)
Convert object to JSON-compatible format (need not work recursively).
gambit.results.csv
Export query results to CSV.
- class gambit.results.csv.CSVResultsExporter
Bases:
AbstractResultsExporter
Exports query results in CSV format.
- format_opts
Dialect and other formatting arguments passed to
csv.write()
.- Type:
Dict[str, Any]
- __init__(**format_opts)
- export(file_or_path, results)
Write query results to file.
- Parameters:
file_or_path (str | PathLike | TextIO) – Open file-like object or file path to write to.
results (QueryResults) – Results to export.
- get_header()
Get values for header row.
- Return type:
List[str]
- get_row(item)
Get row values for single result item.
- Parameters:
item (QueryResultItem) –
- Return type:
List
gambit.results.archive
Export results to JSON.
- class gambit.results.archive.ResultsArchiveReader
Bases:
object
Loads query results from file created by
ResultsArchiveWriter
.- session
SQLAlchemy session used to load database objects.
- Type:
sqlalchemy.orm.session.Session
- __init__(session)
- read(file_or_path)
Read query results from JSON file.
- Parameters:
file_or_path (str | PathLike | IO) – Readable file object or file path.
- Return type:
- class gambit.results.archive.ResultsArchiveWriter
Bases:
BaseJSONResultsExporter
Exports query results to “archive” format which captures all stored data.
This format is not intended to be read by users of the application. The exported data can be read and converted back into an identical
QueryResults
object usingResultsArchiveReader
.- install_info
Add results of
gambit.util.dev.install_info()
to theQueryResults.extra
dict.- Type:
bool
- __init__(pretty=False, install_info=False)
Method generated by attrs for class ResultsArchiveWriter.
- Parameters:
pretty (bool) –
install_info (bool) –
- Return type:
None
- to_json(obj)
- to_json(obj)
- to_json(obj)
- to_json(obj)
- to_json(results)
- to_json(gset)
- to_json(taxon)
- to_json(genome)
Convert object to JSON-compatible format (need not work recursively).