### Install Hybkit using SetupTools
Source: https://github.com/rennelab/hybkit/blob/master/docs/index.md
After cloning or downloading, install the package using python setuptools.
```bash
$ python setup.py install
```
--------------------------------
### Install Pytest and Run Tests
Source: https://github.com/rennelab/hybkit/blob/master/docs/index.md
Install pytest and run the unit test suite from the root directory of the hybkit package.
```bash
$ pip install pytest
$ pytest
```
--------------------------------
### Example .hyb format line
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/specification.md
A sample line demonstrating the tab-delimited structure of a .hyb file.
```default
2407_718 ATCACATTGCCAGGGATTTCCAATCCCCAACAATGTGAAAACGGCTGTC . MIMAT0000078_MirBase_miR-23a_microRNA 1 21 1 21 0.0027 ENSG00000188229_ENST00000340384_TUBB2C_mRNA 23 49 1181 1207 1.2e-06
```
--------------------------------
### Install Hybkit via Python PIP
Source: https://github.com/rennelab/hybkit/blob/master/docs/index.md
Install the hybkit package and its dependencies using pip, the Python package installer. This is the recommended installation method.
```bash
$ python3 -m pip install hybkit
```
--------------------------------
### Run hyb_check system calls
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/toolkit/hyb_check.md
Examples of executing hyb_check with single or multiple input files and optional fold files.
```default
hyb_check -i my_file_1.hyb -f my_file_1.vienna
hyb_check -i my_file_1.hyb my_file_2.hyb -f my_file_1.vienna \
my_file_2.vienna -v --custom_flags myflag
```
--------------------------------
### CT File Format Example
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/hybkit.md
Example of the .ct file format used by UNAFold and other packages. It includes sequence information, base pairing details, and energy values.
```default
41 dG = -8 dH = -93.9 seq1_name-seq2_name
1 A 0 2 0 1 0 0
2 G 1 3 0 2 0 0
...
...
...
40 G 39 41 11 17 39 41
41 T 40 0 10 18 40 0
```
--------------------------------
### Execute hyb_analyze system calls
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/toolkit/hyb_analyze.md
Examples of running the hyb_analyze utility from the command line with different input formats and plot configurations.
```bash
$ hyb_analyze -a fold -i my_file_1.hyb -f my_file_1.vienna
$ hyb_analyze -a fold -i my_file_2.hyb -f my_file_2.ct \
--make_plots False
```
--------------------------------
### Combine type and miRNA evaluation
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/toolkit/hyb_eval.md
Example of running both type and miRNA evaluations in a single command.
```bash
$ hyb_eval -t type mirna -i my_file_1.hyb \
--type_method string_match \
--type_parameters my_parameters_file.csv \
--allow_unknown_seg_types \
--mirna_types miRNA kshv-miRNA
```
--------------------------------
### Hyb Record Example Line
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/hybkit.md
An example string representing a single line in the hyb-format file, containing detailed information about a chimeric RNA sequence read.
```text
2407_718 ATCACATTGCCAGGGATTTCCAATCCCCAACAATGTGAAAACGGCTGTC . MIMAT0000078_MirBase_miR-23a_microRNA 1 21 1 21 0.0027 ENSG00000188229_ENST00000340384_TUBB2C_mRNA 23 49 1181 1207 1.2e-06
```
--------------------------------
### Vienna File Format Example
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/hybkit.md
Example of the .vienna file format used by the ViennaRNA package. It includes a sequence identifier, the nucleotide sequence, and its dot-bracket fold representation with an associated energy value.
```default
34_151138_MIMAT0000076_MirBase_miR-21_microRNA_1_19-...
TAGCTTATCAGACTGATGTTAGCTTATCAGACTGATG
.....((((((.((((((......)))))).)))))) (-11.1)
```
--------------------------------
### Static vs. Dynamic FoldRecord Alignment Example
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/hybkit.md
Illustrates the difference between static and dynamic FoldRecord sequences based on overlapping and gapped alignments. Static sequences match HybRecord.seq exactly, while dynamic sequences are reconstructed from aligned regions.
```default
Static:
seg1: 1111111111111111111111
seg2: 222222222222222222222
seq: TAGCTTATCAGACTGATGTTTTAGCTTATCAGACTGATG
Dynamic:
seg1: 1111111111111111111111
seg2: 222222222222222222222
seq: TAGCTTATCAGACTGATGTTTTTTTTAGCTTATCAGACTGATG
```
```default
Static:
seg1: 1111111111111111
seg2: 222222222222222222
seq: TTAGCTTATCAGACTGATGTTAGCTTATCAGACTGATG
Dynamic:
seg1: 1111111111111111
seg2: 222222222222222222
seq: AGCTTATCAGACTGATTAGCTTATCAGACTGATG
```
--------------------------------
### Match ANY Filtering Criteria (Default Behavior)
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/toolkit/hyb_filter.md
The default filter mode is 'any', meaning records are included if they match at least one of the specified criteria. This example outputs records with a segtype of either 'miRNA' or 'lncRNA'.
```bash
hyb_filter -i my_file_1.hyb --filter_mode any \
--filter seg_type miRNA \
--filter_2 seg_type lncRNA
```
--------------------------------
### Install Hybkit via Conda
Source: https://github.com/rennelab/hybkit/blob/master/docs/index.md
Install the hybkit package and dependencies from the Bioconda channel using the conda package manager.
```bash
$ conda install -c bioconda hybkit
```
--------------------------------
### Configure Automatic Output Naming
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/toolkit/hyb_analyze.md
Demonstrates default output naming behavior and how to customize the output directory and suffix.
```default
hyb_script -i PATH_TO/MY_FILE_1.HYB [...]
--> OUT_DIR/MY_FILE_1_ADDSUFFIX.HYB
```
```default
hyb_script -i PATH_TO/MY_FILE_1.HYB [...] --out_dir MY_OUT_DIR
--> MY_OUT_DIR/MY_FILE_1_ADDSUFFIX.HYB
```
```default
hyb_script -i PATH_TO/MY_FILE_1.HYB [...] --out_suffix MY_SUFFIX
--> OUT_DIR/MY_FILE_1_MY_SUFFIX.HYB
#OR
hyb_script -i PATH_TO/MY_FILE_1.HYB [...] --out_suffix MY_SUFFIX.HYB
--> OUT_DIR/MY_FILE_1_MY_SUFFIX.HYB
```
--------------------------------
### Create and Parse HybRecord
Source: https://context7.com/rennelab/hybkit/llms.txt
Demonstrates creating a HybRecord from scratch and parsing one from a hyb-format line. Accesses record properties and converts back to a line.
```python
import hybkit
# Create a HybRecord from scratch
seg1_props = {
'ref_name': 'MIMAT0000078_MirBase_miR-23a_microRNA',
'read_start': 1,
'read_end': 21,
'ref_start': 1,
'ref_end': 21,
'score': 0.0027
}
seg2_props = {
'ref_name': 'ENSG00000188229_ENST00000340384_TUBB2C_mRNA',
'read_start': 23,
'read_end': 49,
'ref_start': 1181,
'ref_end': 1207,
'score': 1.2e-06
}
hyb_record = hybkit.HybRecord(
id='2407_718',
seq='ATCACATTGCCAGGGATTTCCAATCCCCAACAATGTGAAAACGGCTGTC',
energy='-7.3',
seg1_props=seg1_props,
seg2_props=seg2_props
)
# Parse from a hyb-format line (typical usage)
line = "2407_718\tATCACATTGCCAGGGATTTCCAATCCCCAACAATGTGAAAACGGCTGTC\t.\tMIMAT0000078_MirBase_miR-23a_microRNA\t1\t21\t1\t21\t0.0027\tENSG00000188229_ENST00000340384_TUBB2C_mRNA\t23\t49\t1181\t1207\t1.2e-06"
hyb_record = hybkit.HybRecord.from_line(line)
# Access record properties
print(f"ID: {hyb_record.id}")
print(f"Sequence: {hyb_record.seq}")
print(f"Length: {len(hyb_record)}")
print(f"Seg1 Reference: {hyb_record.seg1_props['ref_name']}")
print(f"Seg2 Reference: {hyb_record.seg2_props['ref_name']}")
# Convert back to hyb format line
output_line = hyb_record.to_line()
```
--------------------------------
### Automate analysis with Python
Source: https://context7.com/rennelab/hybkit/llms.txt
A complete Python workflow for configuring settings, defining type matching, and initializing analysis.
```python
#!/usr/bin/env python3
import os
import hybkit
# Configuration
input_files = ['sample1.hyb', 'sample2.hyb', 'sample3.hyb']
output_dir = 'analysis_output'
os.makedirs(output_dir, exist_ok=True)
# Configure miRNA types (include custom viral miRNAs)
hybkit.settings.HybRecord_settings['mirna_types'] = ['microRNA', 'miRNA', 'KSHV-miRNA']
# Set up type finding with string matching
legend_file = 'string_match_legend.csv'
match_params = hybkit.HybRecord.TypeFinder.make_string_match_params(legend_file)
hybkit.HybRecord.TypeFinder.set_method('string_match', match_params)
# Types to exclude (QC filtering)
exclude_types = ['rRNA', 'mitoch-rRNA']
# Initialize combined analysis
combined_analysis = hybkit.analysis.Analysis(
analysis_types=['type', 'mirna', 'target'],
name='Combined_Analysis'
)
```
--------------------------------
### Create HybRecord with Basic Information
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/hybkit.md
Initialize a HybRecord object with an ID, sequence, and optional energy value. This is a basic way to create a record.
```python
hyb_record_1 = hybkit.HybRecord('1_100', 'ACTG')
hyb_record_2 = hybkit.HybRecord('2_107', 'CTAG', '-7.3')
hyb_record_3 = hybkit.HybRecord('3_295', 'CTTG', energy='-10.3')
```
--------------------------------
### Construct HybRecord from Line
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/hybkit.md
Demonstrates the preferred method for creating a HybRecord object by parsing a single line from a hyb-format file using the from_line() constructor.
```python
# line = "2407_718\tATC..."
hyb_record = hybkit.HybRecord.from_line(line)
```
--------------------------------
### GET /hybrecord/to_fields_header
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/hybkit.md
Returns a list of the fields in a HybRecord object.
```APIDOC
## GET /hybrecord/to_fields_header
### Description
Return a list of the fields in a HybRecord object for use with the to_fields() method.
### Method
GET
### Response
#### Success Response (200)
- **fields** (list) - List of field names: id, seq, energy, seg1_ref_name, seg1_read_start, seg1_read_end, seg1_ref_start, seg1_ref_end, seg1_score, seg2_ref_name, seg2_read_start, seg2_read_end, seg2_ref_start, seg2_ref_end, seg2_score, flags.
```
--------------------------------
### GET /hybrecord/to_csv_header
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/hybkit.md
Returns a comma-separated string representation of the fields in the record.
```APIDOC
## GET /hybrecord/to_csv_header
### Description
Return a comma-separated string representation of the fields in the record for use with the to_csv() method.
### Method
GET
### Parameters
#### Query Parameters
- **newline** (bool) - Optional - If True, end the returned string with a newline.
### Response
#### Success Response (200)
- **header** (string) - Comma-separated string of field names.
```
--------------------------------
### ViennaFile Constructor
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/hybkit.md
Initializes a new ViennaFile instance to wrap a Vienna-format file.
```APIDOC
## ViennaFile Constructor
### Description
Initializes the ViennaFile wrapper to process Vienna-format file lines as FoldRecord objects.
### Parameters
- **seq_type** (str) - Optional - Type of FoldRecord to return: 'static' or 'dynamic'.
- **error_mode** (str) - Optional - Error handling mode: 'raise', 'warn_return', or 'return'.
- **from_file_like** (bool) - Optional - If True, treats the first argument as a file-like object.
```
--------------------------------
### Method: open()
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/hybkit.md
Class method to open a path to a text file and return a file object.
```APIDOC
## Method open()
### Description
Open a path to a text file and return a relevant file object.
### Parameters
- **path** (str) - Required - Path to file to open.
- **seq_type** (str) - Optional - Type of FoldRecord to return.
- **error_mode** (str) - Optional - Error handling mode.
### Response
- **Return Type** (HybFile) - The opened file object.
```
--------------------------------
### Configure FoldFile Settings
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/hybkit.settings.md
Placeholder for FoldFile settings information. Currently an empty dictionary, indicating default or no specific configurations are defined here.
```python
hybkit.settings.FoldFile_settings_info = {
}
```
--------------------------------
### Find Segment Type
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/hybkit.type_finder.md
Example of the internal call structure used by the find method to determine segment types.
```default
seg_type = :meth:`TypeFinder.find_custom_method`(seg_props, :attr`TypeFinder.params`)
```
--------------------------------
### Perform miRNA evaluation with hyb_eval
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/toolkit/hyb_eval.md
Examples of using the miRNA evaluation mode to identify miRNA properties within hybrids.
```bash
$ hyb_eval -t mirna -i my_file_1.hyb
```
```bash
$ hyb_eval -t mirna -i my_file_1.hyb -f my_file_1.vienna
```
```bash
$ hyb_eval -t mirna -i my_file_1.hyb my_vile_2.hyb \
-f my_file_1.vienna my_file_2.vienna \
--mirna_types miRNA kshv-miRNA
```
--------------------------------
### HybFile Class Constructor
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/hybkit.md
Initializes a HybFile object, which wraps a hyb-format text file and returns entries as HybRecord objects.
```APIDOC
## hybkit.HybFile(path: str, *args: Any, hybformat_id: bool | None = None, hybformat_ref: bool | None = None, from_file_like: bool = False, **kwargs: Any)
### Description
Wrapper for a hyb-format text file which returns entries (lines) as HybRecord objects.
### Parameters
#### Path Parameter
- **path** (str) - Required - Path to text file to open as hyb-format file.
#### Other Parameters
- **\*args** - Arguments passed to `open()` function to open a text file for reading/writing.
- **hybformat_id** (bool, optional) - If `True`, during parsing of lines read count information from identifier in `_` format. Defaults to value in `settings['hybformat_id']`.
- **hybformat_ref** (bool, optional) - If `True`, during parsing of lines read additional record information from identifier in `___` format. Defaults to value in `settings['hybformat_ref']`.
- **from_file_like** (bool, optional) - If `True`, the first argument is treated as a file-like object (such as io.StringIO or gzip.GzipFile) and the remaining positional arguments are ignored. (Default False)
- **\*\*kwargs** - Keyword arguments passed to `open()` function to open a text file for reading/writing.
### Variables
- **hybformat_id** (bool) - Read count information from identifier during line parsing
- **hybformat_ref** (bool) - Read type information from reference name during line parsing
- **fh** (file) - Underlying file handle for the HybFile object.
#### settings *= {'hybformat_id': False, 'hybformat_ref': False}*
Class-level settings. See `hybkit.settings.HybFile_settings_info` for descriptions.
```
--------------------------------
### Perform type evaluation with hyb_eval
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/toolkit/hyb_eval.md
Examples of using the type evaluation mode to assign segment types to hybrid records.
```bash
$ hyb_eval -t type -i my_file_1.hyb
```
```bash
$ hyb_eval -t type -i my_file_1.hyb -f my_file_1.vienna
```
```bash
$ hyb_eval -t type \
-i my_file_1.hyb my_file_2.hyb \
-f my_file_1.vienna my_file_2.vienna \
--type_method string_match \
--type_parameters my_parameters_file.csv \
--allow_unknown_seg_types
```
--------------------------------
### Direct HybRecord Construction
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/hybkit.md
Illustrates how to directly construct a HybRecord object by providing the minimum required data: the sequence and its identifier. Other parameters are optional.
```python
# Example of direct construction (not shown in source, but implied by class signature)
# hyb_record = hybkit.HybRecord(id='example_id', seq='ATCGATCG')
pass
```
--------------------------------
### open
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/hybkit.md
Class method to open a path to a text file and return a ViennaFile object.
```APIDOC
## open
### Description
Opens a path to a text file and returns a relevant file object. Arguments match Python's built-in open function.
### Parameters
- **path** (str) - Required - Path to file to open.
- **seq_type** (str) - Optional - Type of FoldRecord to return.
- **error_mode** (str) - Optional - Error handling mode.
```
--------------------------------
### View hyb_analyze usage help
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/toolkit/hyb_analyze.md
Displays the full command-line interface usage and available arguments for the hyb_analyze utility.
```bash
usage: hyb_analysis [-h] -i PATH_TO/MY_FILE.HYB [PATH_TO/MY_FILE.HYB ...]
[-f [PATH_TO/MY_FILE.VIENNA [PATH_TO/MY_FILE.VIENNA ...]]]
[-o PATH_TO/OUT_BASENAME [PATH_TO/OUT_BASENAME ...]]
[-d OUT_DIR] [-u OUT_SUFFIX]
[-a {energy,type,mirna,target,fold} [{energy,type,mirna,target,fold} ...]]
[-n ANALYSIS_NAME] [-p {True,False}] [--version] [-v | -s]
[--mirna_types MIRNA_TYPES [MIRNA_TYPES ...]]
[--custom_flags CUSTOM_FLAGS [CUSTOM_FLAGS ...]]
[--hyb_placeholder HYB_PLACEHOLDER]
[--reorder_flags {True,False}]
[--allow_undefined_flags [{True,False}]]
[--allow_unknown_seg_types [{True,False}]]
[--hybformat_id [{True,False}]]
[--hybformat_ref [{True,False}]]
[--allowed_mismatches ALLOWED_MISMATCHES]
[--fold_placeholder FOLD_PLACEHOLDER]
[-y {static,dynamic}]
[--error_mode {raise,warn_return,return}]
[--error_checks {hybrecord_indel,foldrecord_nofold,max_mismatch,energy_mismatch} [{hybrecord_indel,foldrecord_nofold,max_mismatch,energy_mismatch} ...]]
[--iter_error_mode {raise,warn_return,warn_skip,skip,return}]
[--max_sequential_skips MAX_SEQUENTIAL_SKIPS]
[--quant_mode {single,reads,records}]
[--out_delim OUT_DELIM]
```
--------------------------------
### POST /hybrecord/from_line
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/hybkit.md
Constructs a HybRecord instance from a single-line hyb-format string.
```APIDOC
## POST /hybrecord/from_line
### Description
Construct a HybRecord instance from a single-line hyb-format string.
### Method
POST
### Parameters
#### Request Body
- **line** (str) - Required - hyb-format string containing record information.
- **hybformat_id** (bool) - Optional - If True, read count information from identifier in _ format.
- **hybformat_ref** (bool) - Optional - If True, read additional record information from identifier in ___ format.
### Response
#### Success Response (200)
- **HybRecord** (object) - Instance containing record information.
```
--------------------------------
### Constructor: hybkit.HybRecord
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/hybkit.md
Initializes a new HybRecord object with sequence information and optional segment properties.
```APIDOC
## Constructor: hybkit.HybRecord
### Description
Creates a new instance of a HybRecord to represent a chimeric hybrid sequence.
### Parameters
#### Request Body
- **id** (str) - Required - Identifier for the hyb record.
- **seq** (str) - Required - Nucleotide sequence of the hyb record.
- **energy** (str or float) - Optional - Predicted energy of sequence folding in kcal/mol.
- **seg1_props** (dict) - Optional - Properties of segment 1 (ref_name, read_start, read_end, ref_start, ref_end, score).
- **seg2_props** (dict) - Optional - Properties of segment 2 (ref_name, read_start, read_end, ref_start, ref_end, score).
- **flags** (dict) - Optional - Dictionary of flags for the record.
- **allow_undefined_flags** (bool) - Optional - If True, allows flags not defined in ALL_FLAGS.
### Request Example
{
"id": "2407_718",
"seq": "ATCACATTGCCAGGGATTTCCAATCCCCAACAATGTGAAAACGGCTGTC",
"seg1_props": {
"ref_name": "MIMAT0000078",
"read_start": 1,
"read_end": 21,
"score": 0.0027
}
}
```
--------------------------------
### Filter Records Where Segment Identifiers Contain a Substring
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/toolkit/hyb_filter.md
Use the `--filter` option with `seg_contains` to select records where the segment identifier string contains a specific substring. This example filters for records where the segment identifier contains 'kshv'.
```bash
hyb_filter -i my_file_1.hyb --filter seg_contains kshv
```
--------------------------------
### View hyb_check usage help
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/toolkit/hyb_check.md
Displays the full command-line argument structure for hyb_check.
```default
usage: hyb_check [-h] -i PATH_TO/MY_FILE.HYB [PATH_TO/MY_FILE.HYB ...]
[-f [PATH_TO/MY_FILE.VIENNA [PATH_TO/MY_FILE.VIENNA ...]]]
[--version] [-v | -s]
[--mirna_types MIRNA_TYPES [MIRNA_TYPES ...]]
[--custom_flags CUSTOM_FLAGS [CUSTOM_FLAGS ...]]
[--hyb_placeholder HYB_PLACEHOLDER]
[--reorder_flags {True,False}]
[--allow_undefined_flags [{True,False}]]
[--allow_unknown_seg_types [{True,False}]]
[--hybformat_id [{True,False}]]
[--hybformat_ref [{True,False}]]
[--allowed_mismatches ALLOWED_MISMATCHES]
[--fold_placeholder FOLD_PLACEHOLDER] [-y {static,dynamic}]
[--error_mode {raise,warn_return,return}]
[--error_checks {hybrecord_indel,foldrecord_nofold,max_mismatch,energy_mismatch} [{hybrecord_indel,foldrecord_nofold,max_mismatch,energy_mismatch} ...]]
[--iter_error_mode {raise,warn_return,warn_skip,skip,return}]
[--max_sequential_skips MAX_SEQUENTIAL_SKIPS]
```
--------------------------------
### Include Records with Specific Segment Types
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/toolkit/hyb_filter.md
Use `--include` to specify criteria for inclusion. This example includes records where the hyb record's segtype is 'mRNA'. Ensure input files are correctly specified with `-i` and `-f`.
```bash
hyb_filter -i my_file_1.hyb -f my_file_1.vienna \
--include seg_type mRNA
```
--------------------------------
### Path and Argument Utilities
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/hybkit_api.md
Functions for creating output file names and validating arguments.
```APIDOC
## make_out_file_name()
### Description
Creates a standardized output file name.
### Method
N/A (Python function)
### Endpoint
N/A
### Parameters
#### Path Parameters
- **base_name** (str) - Required - The base name for the output file.
- **suffix** (str) - Optional - A suffix to append to the file name.
- **extension** (str) - Optional - The file extension.
### Request Example
```python
from hybkit.util import make_out_file_name
output_file = make_out_file_name('my_analysis', suffix='_results', extension='txt')
print(output_file) # Example: my_analysis_results.txt
```
### Response
#### Success Response (str)
- **filename** (str) - The generated output file name.
### Response Example
```json
"my_analysis_results.txt"
```
## validate_args()
### Description
Validates function arguments.
### Method
N/A (Python function)
### Endpoint
N/A
### Parameters
#### Path Parameters
- **args** (dict) - Required - A dictionary of arguments to validate.
- **expected_args** (dict) - Required - A dictionary defining the expected arguments and their types/constraints.
### Request Example
```python
from hybkit.util import validate_args
my_args = {'input': 'data.fasta', 'output': 'results.txt'}
expected = {'input': str, 'output': str}
validate_args(my_args, expected)
```
### Response
#### Success Response (None)
- This function returns None on success.
## validate_args_exit()
### Description
Validates function arguments and exits if validation fails.
### Method
N/A (Python function)
### Endpoint
N/A
### Parameters
#### Path Parameters
- **args** (dict) - Required - A dictionary of arguments to validate.
- **expected_args** (dict) - Required - A dictionary defining the expected arguments and their types/constraints.
### Request Example
```python
from hybkit.util import validate_args_exit
my_args = {'input': 'data.fasta'}
expected = {'input': str, 'output': str}
validate_args_exit(my_args, expected) # Will exit if 'output' is missing
```
### Response
#### Success Response (None)
- This function returns None on success and exits the program on failure.
## set_setting()
### Description
Sets a specific configuration setting.
### Method
N/A (Python function)
### Endpoint
N/A
### Parameters
#### Path Parameters
- **key** (str) - Required - The key of the setting to set.
- **value** (any) - Required - The value to assign to the setting.
### Request Example
```python
from hybkit.util import set_setting
set_setting('log_level', 'INFO')
```
### Response
#### Success Response (None)
- This function returns None.
## set_settings_from_namespace()
### Description
Sets multiple configuration settings from a namespace object.
### Method
N/A (Python function)
### Endpoint
N/A
### Parameters
#### Path Parameters
- **namespace** (object) - Required - An object containing settings as attributes.
### Request Example
```python
from hybkit.util import set_settings_from_namespace
class Config:
def __init__(self):
self.threads = 4
self.verbose = True
config = Config()
set_settings_from_namespace(config)
```
### Response
#### Success Response (None)
- This function returns None.
```
--------------------------------
### Include Records with a Specific First Segment Type
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/toolkit/hyb_filter.md
Use `--include` with a specific segment index like `seg1_type` to filter based on the type of the first segment (5' end). This example includes records where the first segment type is 'mRNA'.
```bash
hyb_filter -i my_file_1.hyb --include seg1_type mRNA
```
--------------------------------
### Match ALL Filtering Criteria
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/toolkit/hyb_filter.md
When using multiple `--filter` or `--filter_2` options, the default behavior is 'any' match. To require all criteria to be met, use `--filter_mode all`. This example outputs records where the segment identifier contains 'kshv' AND the segtype is 'miRNA'.
```bash
hyb_filter -i my_file_1.hyb -f my_file_1.vienna \
--filter seg_contains kshv \
--filter_2 seg_type miRNA
```
--------------------------------
### Download Hybkit Package
Source: https://github.com/rennelab/hybkit/blob/master/docs/index.md
Alternatively, download the zipped package using curl and unzip it.
```bash
$ curl -OL https://github.com/RenneLab/hybkit/archive/master.zip
$ unzip master.zip
```
--------------------------------
### Iterate and Print Hyb IDs from File
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/hybkit.md
Shows how to open a hyb-format file using HybFile and iterate through each record to print its unique identifier. This utilizes the HybRecord.from_line() constructor internally.
```python
with hybkit.HybFile('path/to/file.hyb', 'r') as hyb_file:
# performs "hyb_record = hybkit.HybRecord.from_line(line)" for each line in file
for hyb_record in hyb_file:
print(hyb_record.id)
```
--------------------------------
### Include Records with Segment Types Containing a Substring
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/toolkit/hyb_filter.md
Use `--include` with `seg_type_contains` to filter records where the segment type string contains a specified substring. This example includes records with segment types containing 'RNA'. Multiple input files can be processed.
```bash
hyb_filter -i my_file_1.hyb my_file_2.hyb -f my_file_1.vienna my_file_2.vienna \
--include seg_type_contains RNA
```
--------------------------------
### set_settings_from_namespace
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/hybkit.util.md
Updates multiple settings at once using an argparse namespace object.
```APIDOC
## set_settings_from_namespace
### Description
Takes a namespace object as from an argparse parser and updates settings accordingly.
### Parameters
#### Arguments
- **nspace** (argparse.Namespace) - Required - Namespace containing settings.
- **verbose** (bool) - Optional - If True, print when changing setting.
```
--------------------------------
### Class: hybkit.CtFile
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/hybkit.md
Initializes a CtFile wrapper to iterate over .ct file records.
```APIDOC
## Class hybkit.CtFile
### Description
Ct file wrapper that returns ".ct" file lines as FoldRecord objects. Note: This class is in beta stage.
### Parameters
- **seq_type** (str) - Optional - Type of FoldRecord to return: 'static' or 'dynamic'.
- **error_mode** (str) - Optional - Error handling mode: 'raise', 'warn_return', or 'return'.
- **from_file_like** (bool) - Optional - If True, treats the first argument as a file-like object.
- **args** (Any) - Optional - Passed to open().
- **kwargs** (Any) - Optional - Passed to open().
```
--------------------------------
### Initialize Analysis Class
Source: https://context7.com/rennelab/hybkit/llms.txt
Initialize the Analysis class with desired analysis types and a name. Records can be added individually or in batches.
```python
import hybkit
# Initialize analysis with desired types
analysis = hybkit.analysis.Analysis(
analysis_types=['type', 'mirna', 'target'],
name='My_Experiment'
)
# Add records to analysis
with hybkit.HybFile('data.hyb', 'r') as hyb_file:
for hyb_record in hyb_file:
hyb_record.eval_types()
hyb_record.eval_mirna()
analysis.add_hyb_record(hyb_record)
# Or add all records at once with auto-evaluation
with hybkit.HybFile('data.hyb', 'r') as hyb_file:
records = hyb_file.read_records()
analysis.add_hyb_records(records, eval_types=True, eval_mirna=True)
# Get all results
results = analysis.get_all_results()
print(f"Type analysis count: {results['type']['types_analysis_count']}")
print(f"Hybrid types: {results['type']['hybrid_types'].most_common(5)}")
print(f"miRNAs with 5p position: {results['mirna']['mirnas_5p']}")
print(f"Top targets: {results['target']['target_names'].most_common(10)}")
# Get specific result
mirna_count = analysis.get_specific_result('has_mirna')
print(f"Records with miRNA: {mirna_count}")
# Write results to CSV files
analysis.write_analysis_results_special(out_basename='results/experiment')
# Creates: results/experiment_type_hybrid_types.csv,
# results/experiment_mirna_results.csv,
# results/experiment_target_names.csv, etc.
# Generate plots
analysis.plot_analysis_results(out_basename='results/experiment')
# Creates: results/experiment_types_hybrid_types.png,
# results/experiment_target_names.png, etc.
```
--------------------------------
### Iterate Over Paired Hyb and Fold Files
Source: https://context7.com/rennelab/hybkit/llms.txt
Synchronize iteration over paired hyb and fold files. Optionally combine them into unified HybRecord objects with attached fold information.
```python
import hybkit
# Iterate over paired hyb and fold files
with hybkit.HybFile('data.hyb', 'r') as hyb_file, \
hybkit.ViennaFile('data.vienna', 'r') as vienna_file:
# Option 1: Get separate records
fold_iter = hybkit.HybFoldIter(hyb_file, vienna_file, combine=False)
for hyb_record, fold_record in fold_iter:
print(f"Hyb: {hyb_record.id}, Fold energy: {fold_record.energy}")
# Option 2: Combine fold into hyb record (recommended)
with hybkit.HybFile('data.hyb', 'r') as hyb_file, \
hybkit.ViennaFile('data.vienna', 'r') as vienna_file:
fold_iter = hybkit.HybFoldIter(hyb_file, vienna_file, combine=True)
for hyb_record in fold_iter:
# fold_record is now attached to hyb_record
print(f"ID: {hyb_record.id}")
print(f"Fold: {hyb_record.fold_record.fold}")
print(f"Energy: {hyb_record.fold_record.energy}")
# Get miRNA fold pattern if miRNA present
hyb_record.eval_types()
hyb_record.eval_mirna()
if hyb_record.prop('has_mirna') and hyb_record.prop('mirna_not_dimer'):
mirna_fold = hyb_record.mirna_details('mirna_fold')
print(f"miRNA fold: {mirna_fold}")
# Print iteration report
fold_iter.print_report()
```
--------------------------------
### HybFoldIter Class
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/hybkit.md
Documentation for the HybFoldIter class, for concurrent iteration over HybFile and ViennaFile/CtFile.
```APIDOC
## hybkit.HybFoldIter
### Description
Class for concurrent iteration over a [`HybFile`](#hybkit.HybFile) and a [`ViennaFile`](#hybkit.ViennaFile) or [`CtFile`](#hybkit.CtFile).
### Class Signature
```python
class hybkit.HybFoldIter(hyb_file: HybFile, fold_file: ViennaFile | CtFile)
```
### Parameters
#### Path Parameters
- **hyb_file** (HybFile) - Required - An opened `HybFile` object.
- **fold_file** (ViennaFile | CtFile) - Required - An opened `ViennaFile` or `CtFile` object.
### Example Usage
```python
# Assuming hyb_file_path and vienna_file_path are valid file paths
# with hybkit.HybFile(hyb_file_path, 'r') as hyb_f, \
# hybkit.ViennaFile(vienna_file_path, 'r') as vienna_f:
# hyb_fold_iter = hybkit.HybFoldIter(hyb_f, vienna_f)
# for hyb_record, fold_record in hyb_fold_iter:
# print(f"Hyb ID: {hyb_record.id}, Structure: {fold_record.structure}")
```
```
--------------------------------
### Initialize Fold Analysis
Source: https://context7.com/rennelab/hybkit/llms.txt
Initialize fold analysis for RNA secondary structure binding patterns. Requires fold_record and eval_mirna to be set.
```python
import hybkit
# Initialize fold analysis (requires fold_record and eval_mirna)
analysis = hybkit.analysis.Analysis(
analysis_types=['fold'],
name='Fold_Analysis'
)
with hybkit.HybFile('data.hyb', 'r') as hyb_file, \
hybkit.ViennaFile('data.vienna', 'r') as vienna_file:
fold_iter = hybkit.HybFoldIter(hyb_file, vienna_file, combine=True)
for hyb_record in fold_iter:
hyb_record.eval_types()
hyb_record.eval_mirna()
# Only add miRNA-containing records with fold info
if hyb_record.prop('has_mirna'):
analysis.add_hyb_record(hyb_record)
# Get fold results
fold_results = analysis.get_analysis_results('fold')
print(f"Folds analyzed: {fold_results['fold_analysis_count']}")
print(f"Match count distribution: {fold_results['fold_match_counts']}")
print(f"Per-nucleotide binding counts: {fold_results['mirna_nt_fold_counts']}")
print(f"Per-nucleotide binding proportions: {fold_results['mirna_nt_fold_props']}")
# Write and plot
analysis.write_analysis_results_special(out_basename='fold_results')
analysis.plot_analysis_results(out_basename='fold_results')
# Creates fold histograms showing binding patterns by miRNA position
```
--------------------------------
### Provide specific output file names
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/toolkit/hyb_check.md
Overrides automatic naming by providing explicit output file paths.
```default
hyb_script [...] --out_hyb MY_OUT_DIR/OUT_FILE_1.HYB MY_OUT_DIR/OUT_FILE_2.HYB
--> MY_OUT_DIR/OUT_FILE_1.hyb
--> MY_OUT_DIR/OUT_FILE_2.hyb
```
--------------------------------
### View hyb_eval usage help
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/toolkit/hyb_eval.md
Displays the full command-line interface usage and available arguments for hyb_eval.
```bash
usage: hyb_analysis [-h] -i PATH_TO/MY_FILE.HYB [PATH_TO/MY_FILE.HYB ...]
[-f [PATH_TO/MY_FILE.VIENNA [PATH_TO/MY_FILE.VIENNA ...]]]
[-o PATH_TO/OUT_FILE.HYB [PATH_TO/OUT_FILE.HYB ...]]
[-l PATH_TO/OUT_FILE.VIENNA [PATH_TO/OUT_FILE.VIENNA ...]]
[-d OUT_DIR] [-u OUT_SUFFIX]
[-t {type,mirna} [{type,mirna} ...]]
[--type_method {hybformat,string_match,id_map}]
[--type_params_file PATH_TO/PARAMETERS_FILE]
[--set_dataset] [--version] [-v | -s]
[--mirna_types MIRNA_TYPES [MIRNA_TYPES ...]]
[--custom_flags CUSTOM_FLAGS [CUSTOM_FLAGS ...]]
[--hyb_placeholder HYB_PLACEHOLDER]
[--reorder_flags {True,False}]
[--allow_undefined_flags [{True,False}]]
[--allow_unknown_seg_types [{True,False}]]
[--hybformat_id [{True,False}]]
[--hybformat_ref [{True,False}]]
[--allowed_mismatches ALLOWED_MISMATCHES]
[--fold_placeholder FOLD_PLACEHOLDER]
[-y {static,dynamic}]
[--error_mode {raise,warn_return,return}]
[--error_checks {hybrecord_indel,foldrecord_nofold,max_mismatch,energy_mismatch} [{hybrecord_indel,foldrecord_nofold,max_mismatch,energy_mismatch} ...]]
[--iter_error_mode {raise,warn_return,warn_skip,skip,return}]
[--max_sequential_skips MAX_SEQUENTIAL_SKIPS]
```
--------------------------------
### HybFile Class Method: open
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/hybkit.md
A class method to open a path to a text file using the built-in `open()` function and return a HybFile object.
```APIDOC
## *classmethod* hybkit.HybFile.open(path: str, *args: Any, hybformat_id: bool | None = None, hybformat_ref: bool | None = None, **kwargs: Any) -> Self
### Description
Open a path to a text file using `open()` and return a HybFile object. Arguments match those of the Python3 built-in `open()` function and are passed directly to it. This method is provided as a convenience function for drop-in replacement of the built-in `open()` function.
### Parameters
#### Path Parameter
- **path** (str) - Required - Path to file to open.
#### HybFile-Specific Keyword Arguments
- **hybformat_id** (bool, optional) - If `True`, during parsing of lines read count information from identifier in `_` format. Defaults to value in `settings['hybformat_id']`.
- **hybformat_ref** (bool, optional) - If `True`, during parsing of lines read additional record information from identifier in `___` format. Defaults to value in `settings['hybformat_ref']`.
#### Other Parameters
- **\*args** - Passed directly to `open()`.
- **\*\*kwargs** - Passed directly to `open()`.
### Returns
- **HybFile** object.
### Example Usage
```python
with HybFile.open('path/to/file.hyb', 'r') as hyb_file:
for record in hyb_file:
print(record)
```
```
--------------------------------
### Open and Read HybFile
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/hybkit.md
Opens a hyb-format file for reading and iterates through its records. Use this for processing existing hyb files.
```python
with HybFile.open('path/to/file.hyb', 'r') as hyb_file:
for record in hyb_file:
print(record)
```
--------------------------------
### Clone Hybkit Repository
Source: https://github.com/rennelab/hybkit/blob/master/docs/index.md
Use git to clone the project's Github repository.
```bash
$ git clone git://github.com/RenneLab/hybkit
```
--------------------------------
### Download Hyb Data
Source: https://github.com/rennelab/hybkit/blob/master/docs/example_01_link.md
Use this command to download and uncompress the necessary Hyb data files for the analysis. The unpacked data requires approximately 2 GB of disk space.
```default
$ sh ./download_data.sh
```
--------------------------------
### Customize output directory
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/toolkit/hyb_check.md
Specifies a custom output directory for generated files.
```default
hyb_script -i PATH_TO/MY_FILE_1.HYB [...] --out_dir MY_OUT_DIR
--> MY_OUT_DIR/MY_FILE_1_ADDSUFFIX.HYB
```
--------------------------------
### Configure string match parameters
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/hybkit.type_finder.md
Defines search patterns for identifying segment types based on string matching criteria.
```default
params = {'endswith': [('_miR', 'microRNA'),
('_trans', 'mRNA') ]}
```
```default
#comment line
#search_type,search_string,seg_type
endswith,_miR,microRNA
endswith,_trans,mRNA
```
--------------------------------
### Run Command-Line Script Tests
Source: https://github.com/rennelab/hybkit/blob/master/docs/index.md
Execute the auto_test.sh script located in the auto_tests directory to test command-line scripts.
```bash
$ ./auto_tests/auto_test.sh
```
--------------------------------
### Generate string match parameters from CSV
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/hybkit.type_finder.md
Creates a parameter dictionary for method_string_match from a CSV legend file.
```default
{'endswith': [('_miR', 'microRNA'),
('_trans', 'mRNA') ]}
```
--------------------------------
### Hybkit Settings Definitions
Source: https://github.com/rennelab/hybkit/blob/master/docs/source/hybkit.settings.md
Configuration settings for core Hybkit classes.
```APIDOC
## Hybkit Settings
### HybFile_settings
- **hybformat_id** (bool) - Default: False
- **hybformat_ref** (bool) - Default: False
### FoldRecord_settings
- **allowed_mismatches** (int) - Default: 0
- **error_mode** (str) - Default: 'raise'
- **fold_placeholder** (str) - Default: '.'
- **seq_type** (str) - Default: 'static'
### FoldFile_settings
- (Empty dictionary)
### HybFoldIter_settings
- **error_checks** (list) - Default: ['hybrecord_indel', 'foldrecord_nofold', 'max_mismatch', 'energy_mismatch']
- **iter_error_mode** (str) - Default: 'warn_skip'
- **max_sequential_skips** (int) - Default: 100
### Analysis_settings
- **out_delim** (str) - Default: ','
- **quant_mode** (str) - Default: 'single'
```