============= Preprocessing ============= Use this tutorial to learn how to generate the files needed to train Corgi from scratch. You can use this to replicate the results found in the paper (still to be released). Corgi takes two input files – a SeqTree and a SeqBank. The SeqBank holds the sequence data for each accession in the dataset. The SeqTree has the information about the cross-validation partition for each accession and which node in the taxonomic tree that the accession corresponds to. Create the SeqBank ================== First, create a SeqBank with the sequences from RefSeq using the `seqbank `_ command-line tool: .. code-block:: bash seqbank refseq refseq.sb This will download each raw RefSeq file and save the data for each accession. The ``seqbank`` tool stores new SeqBanks with the RocksDict engine if it is installed and with LMDB otherwise. Use the ``--engine`` option to choose one explicitly (see :ref:`seqbank-engines` below). Create the SeqTree ================== Next, create the SeqTree and a SeqBank restricted to the accessions it contains: .. code-block:: bash corgi-tools refseq-to-seqtree \ --output corgi-max200.st \ --seqbank refseq.sb \ --seqbank-output corgi-max200.sb \ --max-seqs 200 \ --partitions 6 \ --accessions corgi-max200.txt This will download the latest version of the RefSeq catalog and create a SeqTree file ``corgi-max200.st`` which includes at most 200 accessions for each order. Only accessions found in ``refseq.sb`` are included. The sequences for these accessions are copied to the new SeqBank ``corgi-max200.sb`` and the list of accessions is saved to ``corgi-max200.txt``. Each accession will be assigned to one of six partitions. We will use partition 0 as the test set and partitions 1–5 as the cross-validation partitions. Corgi was trained with the 225 release of RefSeq. If you want to explicitly give it a RefSeq catalog, then you can specify the path to it with the ``--catalog`` option. .. _seqbank-engines: Choosing the SeqBank storage engine ----------------------------------- By default, the output SeqBank is stored with the `LMDB `_ engine. Use the ``--engine`` option to choose a different one: .. code-block:: bash corgi-tools refseq-to-seqtree \ --output corgi-max200.st \ --seqbank refseq.sb \ --seqbank-output corgi-max200.sb \ --engine rocksdict The available engines are: ``lmdb`` The default. `LMDB `_, a memory-mapped key-value store. It is always installed. ``rocksdict`` `RocksDict `_. It is optional: install it with ``pip install "bio-corgi[rocksdict]"``. ``speedict`` The legacy engine used by older SeqBanks. It requires installing ``seqbank[speedict]`` and is only available for Python versions below 3.13. The ``--engine`` option only applies when a new SeqBank is created. When Corgi opens an existing SeqBank, it detects the engine automatically, so no option is needed for training or for the other commands. SeqBanks created before engines were introduced are treated as ``speedict`` banks. If a SeqBank uses an engine that is not installed, the error message says which extra to install. To change the engine of an existing SeqBank, use the ``seqbank convert`` command, which copies it to a new directory: .. code-block:: bash seqbank convert corgi-max200.sb corgi-max200-rocksdict.sb --engine rocksdict