molclusters.output¶
output
¶
Provides the output files of a run: where they go and how they're declared.
Classes:
- OutputFile: The declaration of a file (or family of files) an analysis writes.
- RunOutput: The service analyses write their files through during a run.
Constants:
- COMPRESSED_SUFFIXES: The file suffixes
RunOutput.appendcompresses, and how.
OutputFile
dataclass
¶
OutputFile(name: str)
A file, or a family of files, that an analysis writes.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The file name, or a pattern where each |
is_pattern
property
¶
is_pattern: bool
Whether name is a pattern, standing for a family of files.
Returns:
| Type | Description |
|---|---|
bool
|
True if |
matches
¶
Tell whether filename is this file, or one of this family of files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
A file's path relative to the output directory, with |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if |
Source code in src/molclusters/output.py
existing
¶
Find the files of this declaration that already exist in directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory
|
Path
|
The output directory. |
required |
Returns:
| Type | Description |
|---|---|
list[Path]
|
The existing files, sorted. |
Source code in src/molclusters/output.py
RunOutput
¶
Where a run's analyses write their files.
Files written once, at the end of a run, are written to path(name). Files
appended to frame by frame go through append, which buffers them: opening a
file costs milliseconds on Windows (antivirus scanning, on any file size),
which dominated runs that appended every frame to their files. The buffer is
shared by every analysis of the run, and used as a context manager it is
closed on exit (see close), even when the run is interrupted.
Every file starts over in a new run: the first flush of a file overwrites it, so an earlier run's results are never mixed with this one's.
Text is written in text mode, bytes as they are; a file takes one or the
other. A file named with one of COMPRESSED_SUFFIXES (.gz, .zst) is
compressed as it's appended to, into one stream per run (text as UTF-8), which
close completes. Every flush ends a compressed block, so a run killed before
close still leaves everything flushed readable.
Attributes:
| Name | Type | Description |
|---|---|---|
directory |
Path
|
The directory the files are written to. |
max_chars |
int
|
The buffered size, in characters (or bytes), that triggers a flush. |
Initialize the output of a run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory
|
Path
|
The directory the files are written to. |
required |
max_chars
|
int
|
The buffered size, in characters (or bytes), that triggers a flush. |
64 * 2 ** 20
|
Source code in src/molclusters/output.py
written
property
¶
path
¶
Give the path to write the file name to.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The file name, possibly in folders (see |
required |
Returns:
| Type | Description |
|---|---|
Path
|
The file's path, in |
Source code in src/molclusters/output.py
append
¶
Queue data to be appended to the file name, flushing if the buffer is full.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The file name; a compressed one ends with one of |
required |
data
|
str | bytes
|
The text, or bytes, to append. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If an uncompressed file is given text after bytes, or bytes after text. |
Source code in src/molclusters/output.py
flush
¶
Append the queued data to its files, opening each file once.
A file flushed for the first time is overwritten instead: whatever it held came from an earlier run.
Source code in src/molclusters/output.py
close
¶
Flush, and complete the compressed files' streams.
Appending to a compressed file after this starts another stream after the first (a second gzip member or zstd frame), which readers of either format read on as one.
Source code in src/molclusters/output.py
__stream
¶
__stream(name: str) -> _GzipStream | _ZstdStream | None
Give the compression stream of the file name, started on first use.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The file name. |
required |
Returns:
| Type | Description |
|---|---|
_GzipStream | _ZstdStream | None
|
The stream, or None for a file that isn't compressed. |
Source code in src/molclusters/output.py
__enter__
¶
__enter__() -> RunOutput
Use the output for a run, closed when the run ends.
Returns:
| Type | Description |
|---|---|
RunOutput
|
This output. |