Basic usage
hashFrag supports 3 primary use cases.
If you already have train/test data splits
Existing train-test data splits can be handled by providing two separate FASTA files to hashFrag as input. This limits the homology search process to inter-data split comparisons. Specifically, a BLAST database is constructed over the train sequences and the test sequences are queried against this database to identify pairs with high local alignment scores.
Filter existing splits: remove test sequences exhibiting homology to the training set
Stratify the test split based on homology ot the training set.
If you want to create new splits
When a single FASTA file is provided as input, hashFrag will characterize homology for all pairwise comparisons. This involves constructing a BLAST database over all sequences in the population and then subsequently querying each sequence to the databae.
Create orthogonal, homology-aware train-test splits
Example dataset
Example usage of hashFrag is provided below on an example dataset composed of 10,000 sequences (each 200 base pairs in length).
Note that the filter_existing_splits and create_orthogonal_splits pipelines require specification of a pairwise alignment score threshold to define homology between sequences.
If users do not have a predefined threshold for homology, we recommend computing pairwise alignment scores between a set of random (e.g., dinucleotide shuffled) genomic sequences, and then defining a threshold above the distribution of values observed.
Defining homology
Defining homology in terms of alignment scores requires the specification of scoring parameters (e.g., penalty, gapopen, gapextend, and reward values).
To remain consistent with BLAST scoring parameter specification, hashFrag expects a negative value for
penaltybut a positive value forgapopenandgapextendarguments (gap penalties will be subtracted from the alignment score during calculation). A positive value is expected forreward.
Changing these parameters can drastically impact the identification process of homology. Please see permissible scoring parameter combinations for the BLASTn algorithm here (Table D1).
hashFrag syntax
By default, hashFrag generates reverse complement sequences when creating the BLAST database. This ensures that query sequences are assessed for homology for both sequence orientations. If the input FASTA files already contain both forward and reverse sequence orientations, include the --skip-revcomp argument to skip this step.
Currently, hashFrag expects reverse complementary sequences to be denoted with a
_Reversedsuffix in the sequence header.
If both sequence orentations already exist in the input FASTA file(s), make sure one of the orientations is denoted with the _Reversed suffix. For example, if a sequence has a header such as seq_A, ensure that its reverse complement has the header seq_A_Reversed.
Note that a warning will be generated if there already exists sequences with the
_Reversedsuffix and the--skip-revcompargument is NOT specified.
hashFrag commands
Filter existing splits
Filter sequences in the test split exhibiting homology with any sequences in the train split
hashFrag filter_existing_splits \
--train-fasta-path example_train_split.fa \
--test-fasta-path example_test_split.fa \
-t 60 \
--skip-revcomp \
-o filter_existing_splits.work
Expand to view the full table of arguments
Argument |
Description |
Expected input |
|---|---|---|
|
Input file containing train split sequences. |
FASTA file path (unzipped) |
|
Input file containing test split sequences. |
FASTA file path (unzipped) |
|
Length of exact match to intialize alignment score calculation ( |
integer (Default: 11) |
|
Penalty for opening a gap in the alignment ( |
positive integer (Default: 2) |
|
Penalty for extending an existing gap in the alignment ( |
positive integer (Default: 1) |
|
Nucleotide mismatch penalty ( |
negative integer (Default: -1) |
|
Nucleotide match reward ( |
positive integer (Default: 1) |
|
Maximum number of target sequences that can be returned per query sequence ( |
positive integer (Default: 500) |
|
Only run the makeblastdb command ( |
Boolean (Default: False, set to True when specified) |
|
Do not generate reverse complement of sequences comprising the BLAST database ( |
Boolean (Default: False, generated if not skipped) |
|
X-drop threshold (heuristic value in bits) for ungapped alignment extension ( |
real number (Default: 20) |
|
X-drop threshold (heuristic value in bits) for gapped alignment extension ( |
real number (Default: 30) |
|
X-drop threshold (heuristic value in bits) for final alignment extension ( |
real number (Default: 100) |
|
Likelihood threshold required to report a sequence as a match ( |
real number (Default: 10.0) |
|
Filter for low-complexity (i.e., repetitive) regions ( |
Permissible values: {‘yes’, ‘no’} (Default: ‘no’) |
|
Label for the BLAST database ( |
string (Default: None) |
|
Number of threads to use for |
positive integer (Default: 1) |
|
Alignment score threshold to define a pair of sequences as similar, or homologous ( |
all real numbers (Required) |
|
Force overwrite existing |
Boolean (Default: False, set to True when specified) |
|
Directory to write intermediate results. |
string (Default: ‘.’) |
Stratify test split
Stratify the test split sequences into an arbitrary number of levels based on their maximum alignment scores to the train split sequences.
hashFrag stratify_test_split \
--train-fasta-path example_train_split.fa \
--test-fasta-path example_test_split.fa \
--skip-revcomp \
-o stratify_test_split.work
Note that the sizes of each stratified level will not necessarily be balanced.
This can be useful to better understand a model’s behaviour over test splits at varying levels of orthogonality to the sequences the model was trained on.
Expand to view the full table of arguments
Argument |
Description |
Expected input |
|---|---|---|
|
Input file containing train split sequences. |
FASTA file path (unzipped) |
|
Input file containing test split sequences. |
FASTA file path (unzipped) |
|
Length of exact match to intialize alignment score calculation ( |
integer (Default: 11) |
|
Penalty for opening a gap in the alignment ( |
positive integer (Default: 2) |
|
Penalty for extending an existing gap in the alignment ( |
positive integer (Default: 1) |
|
Nucleotide mismatch penalty ( |
negative integer (Default: -1) |
|
Nucleotide match reward ( |
positive integer (Default: 1) |
|
Maximum number of target sequences that can be returned per query sequence ( |
positive integer (Default: 500) |
|
Only run the makeblastdb command ( |
Boolean (Default: False, set to True when specified) |
|
Do not generate reverse complement of sequences comprising the BLAST database ( |
Boolean (Default: False, generated if not skipped) |
|
X-drop threshold (heuristic value in bits) for ungapped alignment extension ( |
real number (Default: 20) |
|
X-drop threshold (heuristic value in bits) for gapped alignment extension ( |
real number (Default: 30) |
|
X-drop threshold (heuristic value in bits) for final alignment extension ( |
real number (Default: 100) |
|
Likelihood threshold required to report a sequence as a match ( |
real number (Default: 10.0) |
|
Filter for low-complexity (i.e., repetitive) regions ( |
Permissible values: {‘yes’, ‘no’} (Default: ‘no’) |
|
Label for the BLAST database ( |
string (Default: None) |
|
Number of threads to use for |
positive integer (Default: 1) |
|
Step size for how large each alignment score range is ( |
positive integer (Default: 10) |
|
Force overwrite existing |
Boolean (Default: False) |
|
Directory to write the created train-test splits. |
string (Default: ‘.’) |
Creating orthogonal splits
Create homology-aware (i.g., orthogonal) train-test data splits.
hashFrag create_orthogonal_splits \
-f example_full_dataset.fa \
-t 60 \
--skip-revcomp \
-o create_orthogonal_splits.work
The creation of orthogonal train-test splits involves determining disjoint sets of sequences with respect to homology. This is accomplished using the union-find data structure (also referred to as disjoint-set or merge-find set). From the homology cluster information, splits with no leakage can be created proportionally.
Expand to view the full table of arguments
Argument |
Description |
Expected input |
|---|---|---|
|
Input file containing all sequences in the dataset. |
FASTA file path (unzipped) |
|
Length of exact match to intialize alignment score calculation ( |
integer (Default: 11) |
|
Penalty for opening a gap in the alignment ( |
positive integer (Default: 2) |
|
Penalty for extending an existing gap in the alignment ( |
positive integer (Default: 1) |
|
Nucleotide mismatch penalty ( |
negative integer (Default: -1) |
|
Nucleotide match reward ( |
positive integer (Default: 1) |
|
Maximum number of target sequences that can be returned per query sequence ( |
positive integer (Default: 500) |
|
Only run the makeblastdb command ( |
Boolean (Default: False, set to True when specified) |
|
Do not generate reverse complement of sequences comprising the BLAST database ( |
Boolean (Default: False, generated if not skipped) |
|
X-drop threshold (heuristic value in bits) for ungapped alignment extension ( |
real number (Default: 20) |
|
X-drop threshold (heuristic value in bits) for gapped alignment extension ( |
real number (Default: 30) |
|
X-drop threshold (heuristic value in bits) for final alignment extension ( |
real number (Default: 100) |
|
Likelihood threshold required to report a sequence as a match ( |
real number (Default: 10.0) |
|
Filter for low-complexity (i.e., repetitive) regions ( |
Permissible values: {‘yes’, ‘no’} (Default: ‘no’) |
|
Label for the BLAST database ( |
string (Default: None) |
|
Number of threads to use for |
positive integer (Default: 1) |
|
Alignment score threshold to define a pair of sequences as similar, or homologous ( |
all real numbers (Required) |
|
Proportion of sequences for the newly-created train data split ( |
float (Default: 0.8) |
|
Proportion of sequences for the newly-created test data split ( |
float (Default: 0.2) |
|
Number of train-test split replicates to create ( |
positive integer (Default: 1) |
|
Random seed for creation of homology-aware train-test splits ( |
positive integer (Default: 21) |
|
Force overwrite existing |
Boolean (Default: False) |
|
Directory to write the created train-test splits. |
string (Default: ‘.’) |