class FileReader:
Known subclasses: pyalma.local.LocalFileReader, pyalma.ssh.SshClient
Constructor: FileReader()
Abstract base class for reading and managing different file types, both locally and remotely.
This class is designed to be subclassed by specific implementations (e.g., local or SSH).
| Method | __del__ |
Destructor to clean up temporary files if clean_on_destruction is enabled. |
| Method | __init__ |
Initializes the FileReader with default configurations. |
| Method | clean |
Deletes a temporary file if it exists. |
| Method | decode |
Decodes content based on file type, returning a DataFrame or raw string. |
| Method | download |
Abstract method. Downloads a file from a remote location. |
| Method | get |
Extracts the file extension from a given path. |
| Method | get |
Placeholder to get file size. |
| Method | is |
Checks if the reader is set to remote mode. |
| Method | isfile |
Checks if a given path exists and is a file. |
| Method | listdir |
Abstract method. Should be implemented by subclasses to list directory contents. |
| Method | load |
Placeholder for remote/local logic in loading H5AD files. |
| Method | read |
Unified file reader for local or remote paths. :param path: File path. :param type: Optional file type override (generic types: pdf, image, text, csv, zip). :param as_dataframe: Whether to parse into a DataFrame... |
| Method | read |
File reader into a dataframe for local and remote paths :param path: File path. :param type: Optional file type override (generic types: pdf, image, text, csv, zip). :param as_dataframe: Force a parsing into a DataFrame... |
| Method | read |
Reads an H5AD file using `anndatareader`. |
| Method | read |
Reads a VCF (Variant Call Format) file using `pysam`. |
| Method | set |
Sets the `clean_on_destruction` flag. |
| Method | write |
Abstract method. Writes data to a remote file. |
| Instance Variable | clean |
Undocumented |
| Instance Variable | files |
Undocumented |
| Instance Variable | remote |
Undocumented |
| Method | _is |
Undocumented |
| Method | _is |
Undocumented |
| Method | _is |
Undocumented |
pyalma.ssh.SshClientDestructor to clean up temporary files if clean_on_destruction is enabled.
pyalma.local.LocalFileReader, pyalma.ssh.SshClientInitializes the FileReader with default configurations.
- `files_to_clean`: Tracks temporary files that may need deletion.
- `remote`: Flag indicating remote operation.
- `clean_on_destruction`: Determines whether to delete files on object destruction.
Decodes content based on file type, returning a DataFrame or raw string.
:param content: Raw content (str, bytes, or file path). :param type: File type (file extension generic types: pdf, image, text, csv, zip). :param kwargs: Extra arguments for `pandas.read_csv`. :return: Decoded content (DataFrame, str, or bytes).
pyalma.ssh.SshClientAbstract method. Downloads a file from a remote location.
:raises NotImplementedError: Always.
Extracts the file extension from a given path.
:param file_path: Full path to the file. :type file_path: str
:return: File extension without the dot. :rtype: str
pyalma.ssh.SshClientPlaceholder to get file size.
:param path: Path to the file. :type path: str
:return: File size (to be implemented). :rtype: None
pyalma.ssh.SshClientChecks if a given path exists and is a file.
:param path: Path to check. :type path: str
:return: True if path exists and is a file. :rtype: bool
pyalma.local.LocalFileReader, pyalma.ssh.SshClientAbstract method. Should be implemented by subclasses to list directory contents.
:raises NotImplementedError: Always.
pyalma.ssh.SshClientPlaceholder for remote/local logic in loading H5AD files.
:param path: Path to the file. :param local_path: Local destination path. :type path: str :type local_path: str
:return: Path to use. :rtype: str
Unified file reader for local or remote paths. :param path: File path. :param type: Optional file type override (generic types: pdf, image, text, csv, zip). :param as_dataframe: Whether to parse into a DataFrame. :param as_binary: Force raw binary return.
File reader into a dataframe for local and remote paths :param path: File path. :param type: Optional file type override (generic types: pdf, image, text, csv, zip). :param as_dataframe: Force a parsing into a DataFrame. :param as_binary: Force raw binary return.
Reads an H5AD file using `anndatareader`.
:param path: Path to the `.h5ad` file. :type path: str
:return: Loaded `AnnData` object. :rtype: AnnData
Reads a VCF (Variant Call Format) file using `pysam`.
:param path: Path to the VCF file. :type path: str
:return: VCF file as a `pysam.VariantFile` object. :rtype: pysam.VariantFile
Sets the `clean_on_destruction` flag.
:param value: Enable or disable automatic cleanup. :type value: bool
pyalma.ssh.SshClientAbstract method. Writes data to a remote file.
:param data: Data to write. :param remote_path: Path on remote server. :param file_format: File format, default is 'csv'. :raises NotImplementedError: Always.