API Reference
Application
The Corgi application: training, prediction and tools built with torchapp.
- class corgi.apps.Corgi(**kwargs)
corgi - Classifier for ORganelle Genomes (Inter alia)
- bibliography = Method(func=<function TorchApp.bibliography>, methods_to_call=[], main=False, tool=False, flag=True, shortcut='', signature_ready=False)
- bibtex = Method(func=<function TorchApp.bibtex>, methods_to_call=[], main=False, tool=False, flag=True, shortcut='', signature_ready=False)
- cache_dir() Path
Returns a directory under the user’s cache folder for storing downloads, e.g. ~/.cache/torchapps/<AppName>/.
- callbacks = Method(func=<function TorchApp.callbacks>, methods_to_call=('extra_callbacks', 'checkpoint_callback'), main=False, tool=False, flag=False, shortcut='', signature_ready=False)
- checkpoint = Method(func=<function Corgi.checkpoint>, methods_to_call=[], main=False, tool=False, flag=False, shortcut='', signature_ready=False)
- checkpoint_callback = Method(func=<function TorchApp.checkpoint_callback>, methods_to_call=('monitor', 'goal'), main=False, tool=False, flag=False, shortcut='', signature_ready=False)
- data = Method(func=<function Corgi.data>, methods_to_call=[], main=False, tool=False, flag=False, shortcut='', signature_ready=False)
- extra_callbacks = Method(func=<function TorchApp.extra_callbacks>, methods_to_call=[], main=False, tool=False, flag=False, shortcut='', signature_ready=False)
- extra_hyperparameters = Method(func=<function Corgi.extra_hyperparameters>, methods_to_call=[], main=False, tool=False, flag=False, shortcut='', signature_ready=False)
- find_fasta_paths(files: list[str]) list[Path]
Finds the FASTA files to classify.
- Parameters:
files (list[str]) – Paths or URLs of files or directories.
- Returns:
The paths of the FASTA files.
- Return type:
list[Path]
- find_input_paths(files: list[str], base_extensions: set[str] | None = None) list[Path]
Finds the sequence files to classify.
Directories are searched recursively for files with a recognised sequence file extension (optionally gzipped).
- Parameters:
files (list[str]) – Paths or URLs of files or directories.
base_extensions (set[str] | None) – The file extensions to accept. If not given, then the extensions for FASTA, GenBank, tabular and FASTQ files are used.
- Returns:
The paths of the matching files.
- Return type:
list[Path]
- lightning_module = Method(func=<function TorchApp.lightning_module>, methods_to_call=('model', 'loss_function', 'extra_hyperparameters', 'input_count', 'metrics', 'module_class'), main=False, tool=False, flag=False, shortcut='', signature_ready=False)
- load_checkpoint = Method(func=<function TorchApp.load_checkpoint>, methods_to_call=('checkpoint',), main=False, tool=False, flag=False, shortcut='', signature_ready=False)
- loss_function = Method(func=<function Corgi.loss_function>, methods_to_call=[], main=False, tool=False, flag=False, shortcut='', signature_ready=False)
- metrics = Method(func=<function Corgi.metrics>, methods_to_call=[], main=False, tool=False, flag=False, shortcut='', signature_ready=False)
- model = Method(func=<function Corgi.model>, methods_to_call=('module_class', 'checkpoint'), main=False, tool=False, flag=False, shortcut='', signature_ready=False)
- module_class = Method(func=<function Corgi.module_class>, methods_to_call=[], main=False, tool=False, flag=False, shortcut='', signature_ready=False)
- monitor = Method(func=<function Corgi.monitor>, methods_to_call=[], main=False, tool=False, flag=False, shortcut='', signature_ready=False)
- node_to_str(node: SoftmaxNode) str
Converts the node to a string
- one_batch = Method(func=<function TorchApp.one_batch>, methods_to_call=('setup_and_data',), main=False, tool=False, flag=False, shortcut='', signature_ready=False)
- one_batch_loss = Method(func=<function TorchApp.one_batch_loss>, methods_to_call=('one_batch', 'lightning_module'), main=False, tool=True, flag=False, shortcut='', signature_ready=False)
- one_batch_output_size = Method(func=<function TorchApp.one_batch_output_size>, methods_to_call=('setup_and_data', 'lightning_module'), main=False, tool=True, flag=False, shortcut='', signature_ready=False)
- one_batch_size = Method(func=<function TorchApp.one_batch_size>, methods_to_call=('one_batch',), main=False, tool=True, flag=False, shortcut='', signature_ready=False)
- output_results = Method(func=<function Corgi.output_results>, methods_to_call=[], main=False, tool=False, flag=False, shortcut='', signature_ready=False)
- package_name() str
Returns the name of the package.
- predict = Method(func=<function TorchApp.predict>, methods_to_call=('load_checkpoint', 'prediction_trainer', 'prediction_dataloader', 'output_results'), main=True, tool=True, flag=False, shortcut='', signature_ready=False)
- prediction_dataloader = Method(func=<function Corgi.prediction_dataloader>, methods_to_call=[], main=False, tool=False, flag=False, shortcut='', signature_ready=False)
- prediction_trainer = Method(func=<function TorchApp.prediction_trainer>, methods_to_call=[], main=False, tool=False, flag=False, shortcut='', signature_ready=False)
- process_location(location: str, reload: bool = False) Path
Turn a URL or filesystem path into a Path that points to a local file. If it’s a URL, download (and cache) via cached_download().
- profiler = Method(func=<function TorchApp.profiler>, methods_to_call=[], main=False, tool=False, flag=False, shortcut='', signature_ready=False)
- refseq_to_seqtree = Method(func=<function Corgi.refseq_to_seqtree>, methods_to_call=[], main=False, tool=True, flag=False, shortcut='', signature_ready=False)
- setup_and_data = Method(func=<function TorchApp.setup_and_data>, methods_to_call=('setup', 'data', 'validation_dataloader'), main=False, tool=False, flag=False, shortcut='', signature_ready=False)
- train = Method(func=<function TorchApp.train>, methods_to_call=('setup_and_data', 'validation_dataloader', 'lightning_module', 'trainer'), main=False, tool=True, flag=False, shortcut='', signature_ready=False)
- trainer = Method(func=<function TorchApp.trainer>, methods_to_call=('callbacks', 'profiler', 'project_name'), main=False, tool=False, flag=False, shortcut='', signature_ready=False)
- tune = Method(func=<function TorchApp.tune>, methods_to_call=('train', 'project_name'), main=False, tool=True, flag=False, shortcut='', signature_ready=False)
- tuning_params()
Inspect the signature of self.tune(…) and return a dict of only those Param() arguments where Param.tune == True. (So that an external tuner can see which hyperparameters are tunable.)
- validate = Method(func=<function TorchApp.validate>, methods_to_call=('setup_and_data', 'load_checkpoint', 'trainer'), main=False, tool=True, flag=False, shortcut='', signature_ready=False)
- version = Method(func=<function TorchApp.version>, methods_to_call=(), main=False, tool=False, flag=True, shortcut='-v', signature_ready=False)
- corgi.apps.limit_torch_threads(num_threads: int | None) None
Limits the number of CPU threads that PyTorch uses.
- Parameters:
num_threads (int | None) – The maximum number of threads. If None, then the PyTorch default is left unchanged.
- Raises:
typer.BadParameter – If num_threads is less than 1.
- corgi.apps.output_results_bar_chart(predictions: pd.Series, top_k: int = 10, bar_size: int = 80)
Prints a table with a bar chart of the proportion of each prediction.
- Parameters:
predictions (pd.Series) – The prediction for each sequence.
top_k (int) – The number of most common predictions to show. The rest are summed into ‘Other Categories’. If zero, then all predictions are shown.
bar_size (int) – The number of characters in a bar which represents 100%.
- corgi.apps.set_alphas_with_phi(tree, phi=1.0)
Sets the alpha (loss weight) of each node in the tree to phi raised to the power of the node’s depth.
- Parameters:
tree (SoftmaxNode) – The root of the classification tree.
phi (float) – The multiplication factor for the loss at each level of the tree.
SeqTree
SeqTree: a mapping from sequence accessions to partitions and nodes in a classification tree.
- class corgi.seqtree.SeqTree(classification_tree: SoftmaxNode | None = None)
A TreeDict from sequence accessions to their partition and node in a classification tree.
Keeps corgi’s accession-based method names and adds SeqBank-specific methods.
- accessions(partition: int | None = None)
Return all accession keys or an iterator over the requested partition.
- accessions_in_partition(partition: int)
Yield accessions assigned to the given partition.
- accessions_to_file(file: Path) None
Writes all the accessions of this SeqTree to a file.
- export(seqbank: SeqBank, output: Path | str, length: int = 0, format: str = '', seed: int = 0, partition: int | None = None)
Outputs sequences from a seqbank into a file.
If the partition is given then only the accessions in the partition are exported. The format of the exported file. If not given, then it will be inferred from the file extension of the output.
The slice is taken from a random position in the sequence that is at least length long.
Random seed can be set with seed.
- intersection_seqbank(seqbank: SeqBank) List[str]
Removes any accession that is not found in a SeqBank.
Returns a list of missing accessions.
- corgi.seqtree.accessions(seqtree: Path = <typer.models.ArgumentInfo object>, partition: int | None = <typer.models.OptionInfo object>)
Prints a list of accessions in a SeqTree.
If a partition is given, then only the accessions for that partition are given.
- corgi.seqtree.count(seqtree: Path = <typer.models.ArgumentInfo object>)
Print the number of accessions in a saved SeqTree.
- corgi.seqtree.export(seqtree: Path = <typer.models.ArgumentInfo object>, seqbank: Path = <typer.models.ArgumentInfo object>, output: Path = <typer.models.ArgumentInfo object>, length: int = <typer.models.OptionInfo object>, seed: int = <typer.models.OptionInfo object>, partition: int | None = <typer.models.OptionInfo object>, format: str = <typer.models.OptionInfo object>)
Export sequences with accession and classification labels from a SeqBank.
Optionally select a partition and pass length and seed options to the exporter. Infer the sequence format from the output path if omitted.
- corgi.seqtree.intersection_seqbank(seqtree: Path = <typer.models.ArgumentInfo object>, seqbank: Path = <typer.models.ArgumentInfo object>, output: Path = <typer.models.ArgumentInfo object>)
Takes a SeqTree and removes any accession that is not found in a SeqBank.
Saves the output SeqTree to output.
- corgi.seqtree.layer_size(seqtree: Path = <typer.models.ArgumentInfo object>)
Prints the size of the neural network layer to predict the classification tree.
- corgi.seqtree.merge(seqtree: Path = <typer.models.ArgumentInfo object>, other: Path = <typer.models.ArgumentInfo object>, output: Path = <typer.models.ArgumentInfo object>)
Merge another SeqTree into this one and save.
- corgi.seqtree.node_to_str(node: SoftmaxNode) str
Converts the node to a string
- corgi.seqtree.pickle_tree(seqtree: Path = <typer.models.ArgumentInfo object>, output: Path = <typer.models.ArgumentInfo object>)
Extract the classification tree from a saved SeqTree into a pickle file.
- corgi.seqtree.prune(seqtree: Path = <typer.models.ArgumentInfo object>, max_depth: int = <typer.models.ArgumentInfo object>, output: Path = <typer.models.ArgumentInfo object>)
Prunes the tree to a maximum depth.
- corgi.seqtree.render(seqtree: Path = <typer.models.ArgumentInfo object>, output: Path | None = <typer.models.OptionInfo object>, print: bool = <typer.models.OptionInfo object>, count: bool = <typer.models.OptionInfo object>, partition_counts: bool = <typer.models.OptionInfo object>, alphabetical: bool = <typer.models.OptionInfo object>)
Render a saved SeqTree, optionally displaying or saving accession counts.
- corgi.seqtree.set_partition(seqtree: Path = <typer.models.ArgumentInfo object>, pattern: str = <typer.models.ArgumentInfo object>, partition: int = <typer.models.ArgumentInfo object>, output: Path = <typer.models.ArgumentInfo object>)
Set the partition for accessions matching a shell-style pattern and save.
- corgi.seqtree.str_to_int_hash(s: str) int
Return a deterministic 32-bit integer seed from the string’s MD5 hash.
- corgi.seqtree.sunburst(seqtree: Path = <typer.models.ArgumentInfo object>, show: bool = <typer.models.OptionInfo object>, output: Path = <typer.models.OptionInfo object>, width: int = <typer.models.OptionInfo object>, height: int = <typer.models.OptionInfo object>)
Plot accession counts as a sunburst and optionally display or save it.
Save HTML for an .html output path and an image otherwise. Default the plot height to its width when height is zero.
Data
Data loading for Corgi: sequence slicing, collation, datasets and dataloaders.
- class corgi.data.Collate
Base class for collating a batch of variable length sequences into tensors of the same length.
- get_length() int
Returns the length that the sequences in the next batch will be sliced or padded to.
- class corgi.data.CollateFixedLength(length: int)
Collates batches so that every sequence has the same fixed length.
- get_length()
Returns the fixed length.
- class corgi.data.CollateRandomLength(minimum_length: int, maximum_length: int, skewness: float = 5, loc: float = 600, scale: float = 1000, seed: int = 42)
Collates batches to a random length for each batch.
The lengths are drawn from a skew-normal distribution, truncated to the minimum and maximum lengths.
- get_length() int
Draws a length from the distribution which is between the minimum and maximum lengths (inclusive).
- class corgi.data.CorgiDataModule(seqtree: SeqTree, seqbank: SeqBank, batch_size: int, max_items: int = 0, minimum_length: int = 150, maximum_length: int = 3000, validation_length: int = 1000, validation_partition: int = 1, test_partition: int = 0, skewness: float = 5, loc: float = 600, scale: float = 1000, num_workers: int | None = None, train_all: bool = False)
A Lightning data module which loads sequences from a SeqBank for the nodes in a SeqTree.
The accessions are split into training and validation sets using the partitions in the SeqTree.
- setup(stage=None)
Creates the training and validation datasets from the partitions in the SeqTree.
The test partition is excluded. If there are no validation accessions, then the training set is used for validation.
- train_dataloader()
Returns the training dataloader, which shuffles the data and collates batches to random lengths.
- val_dataloader()
Returns the validation dataloader, which collates batches to a fixed length.
- class corgi.data.CorgiTrainingDataset(*, accessions: list[str], seqbank: SeqBank, seqtree: SeqTree, deterministic: bool = False, maximum: int = 0)
A dataset of sequences from a SeqBank, with the node in the classification tree as the target.
- Parameters:
accessions (list[str]) – The accessions in the dataset.
seqbank (SeqBank) – The SeqBank which holds the sequences.
seqtree (SeqTree) – The SeqTree which gives the node for each accession.
deterministic (bool) – Whether or not truncation of long sequences always takes the same slice for an accession.
maximum (int) – The maximum length of a sequence. Longer sequences are truncated. If zero, they are not truncated.
- reopen_seqbank()
Closes the SeqBank and replaces it with a new one on the same path and engine.
Used in DataLoader workers so that each worker has its own database handle rather than one inherited from the parent process by ‘fork’.
- class corgi.data.SeqIODataloader(files, batch_size: int = 1, min_length: int = 128, max_length: int = 5000, max_seqs: int = None, overlap: int = 256, format: str = '')
Iterates over sequence files, giving batches of chunks of sequences as tensors for prediction.
Sequences longer than max_length are split into overlapping chunks. Details of each chunk yielded are recorded in chunk_details.
- get_file_format(file)
Returns the Biopython format name of a file, inferred from its extension unless format was given.
- Raises:
ValueError – If the format cannot be determined.
- iter_records()
Yields (file, record) pairs for every record in every file.
- pad(batch)
Pads the tensors in a batch to the same length and stacks them in a one-element tuple.
- parse(file: Path)
Yields the records in a file, which may be gzipped.
- corgi.data.generate_overlapping_intervals(total: int, interval_size: int, min_overlap: int, check: bool = True, variable_size: bool = False) list[tuple[int, int]]
Creates a list of overlapping intervals within a specified range, adjusting the interval size to ensure that the overlap is approximately the same across all intervals.
- Parameters:
total (int) – The total range within which intervals are to be created.
max_interval_size (int) – The maximum size of each interval.
min_overlap (int) – The minimum number of units by which consecutive intervals overlap.
check (bool) – If True, checks are performed to ensure that the intervals meet the specified conditions.
- Returns:
A list of tuples where each tuple represents the start (inclusive) and end (exclusive) of an interval.
- Return type:
list[tuple[int, int]]
Example
>>> generate_overlapping_intervals(20, 5, 2) [(0, 5), (3, 8), (6, 11), (9, 14), (12, 17), (15, 20)]
- corgi.data.seqbank_worker_init(worker_id: int)
Gives each DataLoader worker its own SeqBank handle (not shared with the parent process).
- corgi.data.slice_tensor(tensor, size, start_index=None, pad: bool = True)
Slices a 1D tensor to a given size.
- Parameters:
tensor (Tensor) – The tensor to slice.
size (int) – The length of the slice.
start_index (int | None) – Where the slice starts. If None, then it is chosen randomly (or 0 if the tensor is no longer than size).
pad (bool) – Whether or not to pad with zeros at the end if the slice extends beyond the tensor.
- Returns:
The slice.
- Return type:
Tensor
Models
Neural network models for classifying DNA sequences.
- class corgi.models.ConvClassifier(embedding_dim=8, cnn_layers=6, output_types=None, cnn_dims_start=64, kernel_size_maxpool=2, return_embeddings: bool = False, num_embeddings=5, kernel_size=3, factor=2, padding='same', padding_mode='zeros', dropout=0.5, final_bias=True, lstm_dims: int = 0, penultimate_dims: int = 1028, include_length: bool = False, length_scaling: float = 3000.0, transformer_heads: int = 8, transformer_layers: int = 6)
A convolutional classifier with an optional transformer encoder or bidirectional LSTM.
The output is split according to output_types (e.g. for hierarchical classification).
- forward(x)
Returns the predictions for a batch of sequences.
- Parameters:
x (Tensor) – Nucleotide indices of shape (batch, sequence length).
- Returns:
The predictions split by output type. If return_embeddings is set, then the penultimate layer’s activations are also returned.
- output_types_match(output_types) bool
Returns whether the final layer of this model is already suitable for the given output types.
This is the case when the number of outputs is the same and each output type is equivalent to the corresponding current one. Hierarchical outputs are equivalent if their classification trees have the same nodes (by name and ancestry) in the same order, because the final layer’s weights are specific to each node.
- Parameters:
output_types – The output types to compare to the current output types.
- replace_output_types(output_types, final_bias: bool = None) None
Replaces the final layer so that the model has outputs for new output types.
- Parameters:
output_types – The new output types.
final_bias (bool | None) – Whether the new final layer has a bias. If None, then it matches the current layer.
- class corgi.models.ConvProcessor(in_channels=8, cnn_layers=6, cnn_dims_start=64, kernel_size_maxpool=2, kernel_size=3, factor=2, dropout=0.5, padding='same', padding_mode='zeros')
A stack of convolution, ReLU, dropout and max pooling layers which increase the number of channels.
- class corgi.models.ConvRecurrantClassifier(num_classes, embedding_dim: int = 8, filters: int = 256, cnn_layers: int = 6, kernel_size_cnn: int = 9, lstm_dims: int = 256, final_layer_dims: int = 0, dropout: float = 0.5, kernel_size_maxpool: int = 2, residual_blocks: bool = False, final_bias: bool = True, multi_kernel_sizes: bool = True)
A CNN followed by an optional bidirectional LSTM which classifies a sequence into a number of classes.
The input is a tensor of nucleotide indices (N, A, C, G, T) of shape (batch, sequence length).
- forward(x)
Returns the logits for a batch of sequences.
- Parameters:
x (Tensor) – Nucleotide indices of shape (batch, sequence length).
- Returns:
Logits of shape (batch, num_classes).
- Return type:
Tensor
- class corgi.models.PositionalEncoding(d_model: int, dropout: float = 0.1, max_len: int = 5000)
Adapted from https://pytorch.org/tutorials/beginner/transformer_tutorial.html
- forward(x: Tensor) Tensor
- Parameters:
x – Tensor, shape
[seq_len, batch_size, embedding_dim]
- class corgi.models.ResidualBlock1D(inplanes: int, planes: int, stride: int = 1, downsample: Module | None = None, norm_layer: Callable[[...], Module] | None = None)
Adapted from https://github.com/pytorch/vision/blob/main/torchvision/models/resnet.py
- forward(x: Tensor) Tensor
Applies two convolutions and adds the (possibly downsampled) input.
- class corgi.models.SequentialDebug(*args: Module)
- class corgi.models.SequentialDebug(arg: OrderedDict[str, Module])
A sequential module which prints the shapes and multiply-accumulate operations of each layer.
- forward(input)
Runs each module, printing its shape and the cumulative MACs. Requires thop.
- corgi.models.calc_cnn_dims_start(macc, seq_len: int, embedding_dim: int, cnn_layers: int, kernel_size: int, factor: float, penultimate_dims: int, num_classes: int)
Solving equation M = s k e c + sum_{l=1}^{L-1} frac{s}{2^{l} } k c^2 f^{2l-1} + c f^{L-1} p + p o for c.
- Parameters:
macc_per_base (int) – the number of multiply-accumulate operations per base pair in the sequence.
embedding_dim (int) – The size of the embedding.
cnn_layers (int) – The number of CNN layers.
kernel_size (int) – The size of the kernel in the CNN
factor (float) – The multiplying factor for the CNN output layers.
- corgi.models.conv3(in_planes: int, out_planes: int, stride: int = 1, groups: int = 1, dilation: int = 1) Conv1d
convolution of width 3 with padding
Lightning module and embeddings
Lightning module for Corgi with support for saving embeddings during prediction.
- class corgi.modules.CorgiLightningModule(*args, **kwargs)
A Lightning module which can write the model’s embeddings to a memory-mapped file during prediction.
- on_predict_epoch_end()
Flushes the embeddings to disk and writes an index file beside them.
The index has a line with the file and record ID (tab-separated) for each chunk.
- predict_step(batch)
Returns the model’s predictions for a batch, saving the embeddings if an embeddings path was set.
- Parameters:
batch (tuple) – The inputs for the model.
- set_embedding_path(embeddings_path: Path | str, dataloader)
Set the path for the memmap array and initialize it if necessary.
- corgi.modules.read_embeddings(embeddings_path: Path | str, embeddings_index: Path = None, merge: bool = True) tuple[ndarray, list[str]]
Read embeddings from a memmap file.
- corgi.modules.read_memmap(path, count, dtype: str = 'float16') memmap
Opens a memory-mapped array of embeddings.
- Parameters:
path – The path to the embeddings file.
count (int) – The number of embeddings (rows) in the file.
dtype (str) – The data type stored in the file.
RefSeq
Tools for building a SeqTree from the RefSeq catalog and taxonomy.
- class corgi.refseq.DNAType(value)
The types of DNA sequence that are classified.
- classmethod from_description(description: str)
Convert a description to a DNAType.
- corgi.refseq.get_catalogue() Path
Downloads (or reuses from the cache) the catalog for the current RefSeq release and returns its path.
- corgi.refseq.get_node(taxon, taxonomy, taxon_to_node, root, ranks)
Returns the node in the tree for a taxon, creating nodes for its ancestors at the given ranks as needed.
- Parameters:
taxon – The taxon ID.
taxonomy – The taxonomy (e.g. multitax.NcbiTx).
taxon_to_node (dict) – The nodes already created, by taxon ID.
root (SoftmaxNode) – The node to start from.
ranks (list[str]) – The ranks to include, from the highest to the lowest.
- corgi.refseq.get_node_at_rank(taxon, taxonomy, taxon_to_node, current_node, rank)
Returns the node for the taxon’s ancestor at a rank, creating it under current_node if needed.
If the taxon has no ancestor at the rank, then current_node is returned.
- Parameters:
taxon – The taxon ID.
taxonomy – The taxonomy (e.g. multitax.NcbiTx).
taxon_to_node (dict) – The nodes already created, by taxon ID.
current_node (SoftmaxNode) – The parent node for any new node.
rank (str) – The taxonomic rank.
- corgi.refseq.get_refseq_release() int
Returns the number of the current RefSeq release.
- corgi.refseq.line_count(file: Path)
Adapted from https://stackoverflow.com/a/9631635
- corgi.refseq.my_open(file)
Opens a text file for reading, or a gzipped file in binary mode.
- corgi.refseq.refseq_to_seqtree(output: Path, seqbank: Path, seqbank_output: Path | None = None, engine: str | None = 'lmdb', render: Path | None = None, accessions: Path | None = None, partitions: int = 6, max_seqs: int = 100, catalog: Path | None = None, ranks: str = 'superkingdom,kingdom,phylum,class,order', restrict_ranks: str = 'class,order', mitochondrion_ranks: str = '', plastid_ranks: str = '', plasmid_ranks: str = '', nuclear_ranks: str = '', mitochondrion_restrict_ranks: str = '', plastid_restrict_ranks: str = '', plasmid_restrict_ranks: str = '', nuclear_restrict_ranks: str = '', print_tree: bool = False)
Builds a SeqTree from the RefSeq catalog for the accessions found in a SeqBank.
Each accession is placed in the taxonomic tree and assigned to a cross-validation partition. This is available on the command line as corgi-tools refseq-to-seqtree.
- Parameters:
output (Path) – The path to save the SeqTree.
seqbank (Path) – The SeqBank with the sequences for the RefSeq accessions.
seqbank_output (Path | None) – Where to save a new SeqBank containing only the sequences selected for the SeqTree.
engine (str | None) – The storage engine for the output SeqBank: ‘lmdb’ (default), ‘rocksdict’ or ‘speedict’. ‘rocksdict’ requires the optional
bio-corgi[rocksdict]extra and ‘speedict’ requiresseqbank[speedict]. If None, then seqbank chooses: RocksDict if it is installed, otherwise LMDB.render (Path | None) – The path to render an image of the SeqTree.
accessions (Path | None) – The path to write a list of the accessions in the SeqTree.
partitions (int) – The number of cross-validation partitions.
max_seqs (int) – The maximum number of sequences for each leaf node. Use 0 for no limit.
catalog (Path | None) – The path to a RefSeq catalog. If not given, then the latest release is downloaded.
ranks (str) – The comma-separated taxonomic ranks to include in the tree.
restrict_ranks (str) – The comma-separated ranks of the nodes which sequences can be assigned to.
mitochondrion_ranks (str) – Overrides ranks for mitochondrion sequences.
plastid_ranks (str) – Overrides ranks for plastid sequences.
plasmid_ranks (str) – Overrides ranks for plasmid sequences.
nuclear_ranks (str) – Overrides ranks for nuclear sequences.
mitochondrion_restrict_ranks (str) – Overrides restrict_ranks for mitochondrion sequences.
plastid_restrict_ranks (str) – Overrides restrict_ranks for plastid sequences.
plasmid_restrict_ranks (str) – Overrides restrict_ranks for plasmid sequences.
nuclear_restrict_ranks (str) – Overrides restrict_ranks for nuclear sequences.
print_tree (bool) – Whether or not to print the tree to the screen.