camlhmp.utils
¶
Below are the functions available in the camlhmp.utils
module.
camlhmp.utils.execute(cmd, directory=Path.cwd(), capture=False, stdout_file=None, stderr_file=None, allow_fail=False)
¶
A simple wrapper around executor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cmd |
str
|
The command to be executed |
required |
directory |
Path
|
The directory to execute the command in. Defaults to Path.cwd(). |
cwd()
|
capture |
bool
|
Capture the output of the command. Defaults to False. |
False
|
stdout_file |
Path
|
The file to write stdout to. Defaults to None. |
None
|
stderr_file |
Path
|
The file to write stderr to. Defaults to None. |
None
|
allow_fail |
bool
|
Allow the command to fail. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
Union[bool, list]: True if successful, otherwise a list of stdout and stderr |
Raises:
Type | Description |
---|---|
ExternalCommandFailed
|
If the command fails and allow_fail is True |
Examples:
>>> from camlhmp.utils import execute
>>> stdout, stderr = execute(
f"{cat_type} {subject} | {engine} -query {query} -subject - -outfmt '6 {outfmt}' {qcov_hsp_perc} {perc_identity}",
capture=True,
)
Source code in camlhmp/utils.py
camlhmp.utils.check_dependencies()
¶
Check if all dependencies are installed.
Examples:
Source code in camlhmp/utils.py
camlhmp.utils.get_platform()
¶
Get the platform of the executing machine
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The platform of the executing machine |
Examples:
Source code in camlhmp/utils.py
camlhmp.utils.validate_file(filename)
¶
Validate a file exists and not empty, if passing return the absolute path
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str
|
a file to validate exists |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
absolute path to file |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
if the file does not exist |
ValueError
|
if the file is empty |
Examples:
Source code in camlhmp/utils.py
camlhmp.utils.file_exists_error(filename, force=False)
¶
Determine if a file exists and raise an error if it does.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str
|
the file to check |
required |
force |
bool
|
force overwrite. Defaults to False. |
False
|
Raises:
Type | Description |
---|---|
FileExistsError
|
if the file exists and force is False |
Source code in camlhmp/utils.py
camlhmp.utils.parse_seq(seqfile, format)
¶
Parse a sequence file containing a single record.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
seqfile |
str
|
input file to be read |
required |
format |
str
|
format of the input file |
required |
Returns:
Name | Type | Description |
---|---|---|
SeqIO |
SeqIO
|
the parsed file as a SeqIO object |
Examples:
Source code in camlhmp/utils.py
camlhmp.utils.parse_seqs(seqfile, format)
¶
Parse a sequence file containing a multiple records.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
seqfile |
str
|
input file to be read |
required |
format |
str
|
format of the input file |
required |
Returns:
Name | Type | Description |
---|---|---|
SeqIO |
SeqIO
|
the parsed file as a SeqIO object |
Examples:
Source code in camlhmp/utils.py
camlhmp.utils.parse_table(csvfile, delimiter='\t', has_header=True)
¶
Parse a delimited file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
csvfile |
str
|
input delimited file to be parsed |
required |
delimiter |
str
|
delimter used to separate column values. Defaults to ' '. |
'\t'
|
has_header |
bool
|
the first line should be treated as a header. Defaults to True. |
True
|
Returns:
Type | Description |
---|---|
Union[list, dict]
|
Union[list, dict]: A dict is returned if a header is present, otherwise a list is returned |
Examples:
Source code in camlhmp/utils.py
camlhmp.utils.parse_yaml(yamlfile)
¶
Parse a YAML file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
yamlfile |
str
|
input YAML file to be read |
required |
Returns:
Type | Description |
---|---|
Union[list, dict]
|
Union[list, dict]: the values parsed from the YAML file |
Examples:
Source code in camlhmp/utils.py
camlhmp.utils.write_tsv(data, output)
¶
Write the dictionary to a TSV file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
list
|
a list of dicts to be written |
required |
output |
str
|
The output file |
required |
Examples: