amoca-bio-wasm-lib
v1.0.2
Published
A TypeScript library for integrating AMOCA bio-wasm functionalities in React applications.
Downloads
274
Maintainers
Readme
AMOCA Bio-Wasm Library
AMOCA Bio-Wasm is a TypeScript library that provides WebAssembly bindings for the AMOCA bioinformatics module, designed for seamless integration with React applications. This library allows developers to leverage the performance benefits of WebAssembly while maintaining type safety and ease of use in TypeScript.
Installation
To install the AMOCA Bio-Wasm library, use npm or yarn:
npm install amoca-bio-wasm-libor
yarn add amoca-bio-wasm-libUsage
Importing the Library
You can import the WebAssembly initializer and the individual bioinformatics functions directly:
import init, {
align_sequences,
gc_content,
find_orfs
} from 'amoca-bio-wasm-lib';Alternatively, you can use the built-in React hook for automatic initialization and state management:
import { useAmoca } from 'amoca-bio-wasm-lib';Using the Custom Hook
The useAmoca hook handles WASM initialization and provides a state-driven way to execute operations:
import React, { useState } from 'react';
import { useAmoca } from 'amoca-bio-wasm-lib';
const MyComponent: React.FC = () => {
const { data, error, loading, executeWasmFunction } = useAmoca();
const [seq, setSeq] = useState('ATGCATGC');
const handleAlign = async () => {
// executeWasmFunction handles initialization automatically
await executeWasmFunction({
type: 'align',
seq1: seq,
seq2: 'ATGCTAGC',
mode: 'global',
isProtein: false
});
};
if (loading) return <div>Loading WASM...</div>;
return (
<div>
<button onClick={handleAlign}>Run Alignment</button>
{error && <div>Error: {error}</div>}
{data && (
<div>
<h3>Alignment Result:</h3>
<pre>{JSON.stringify(data, null, 2)}</pre>
</div>
)}
</div>
);
};Direct WASM Usage
For non-React environments or low-level control, you can call the functions directly after initialization:
import init, { align_sequences } from 'amoca-bio-wasm-lib';
async function runAlignment() {
// Initialize the WASM module
await init();
// Call the WASM function directly
const result = align_sequences(
'ATGCATGC',
'ATGCTAGC',
'global',
false
);
console.log('Result:', result);
}Supported Operations
The library exports the following high-performance functions (available via direct import or the executeWasmFunction hook):
| hook type | Direct Function | Description |
| :--- | :--- | :--- |
| align | align_sequences | Global (Needleman-Wunsch) or Local (Smith-Waterman) alignment |
| identity | pairwise_identity | Fast pairwise identity percentage calculation |
| kmers | count_sequence_kmers | Frequency counting of k-mers in a sequence |
| - | kmer_frequency_spectrum | Distribution spectrum of k-mer frequencies |
| jaccard | sequence_jaccard | Jaccard similarity based on shared k-mers |
| minimizers | find_minimizers | Find minimizer seeds for indexing |
| rna | predict_rna_structure | Secondary structure prediction using Nussinov algorithm |
| - | max_base_pairs | Quickly calculate the theoretical maximum base pairs |
| gc | gc_content | Total GC content percentage |
| sliding_gc | sliding_gc | GC content across a window (profile) |
| orfs | find_orfs | Find Open Reading Frames in all 6 frames |
| motif | find_motif | Fast exact motif searching using KMP |
| composition | nucleotide_composition | Comprehensive base composition analysis |
API
useAmoca
- Returns:
data: The result of the last executed operation.error: Error message if any.loading: Boolean indicating if WASM is loading or an operation is in progress.isWasmReady: Boolean indicating if the WASM module is initialized.executeWasmFunction(input: WasmOperation): Function to run WASM operations.
- Description: This hook manages the interaction with the AMOCA bio-wasm functionalities, handling state and side effects.
Contributing
Contributions are welcome! Please feel free to submit a pull request or open an issue for any enhancements or bug fixes.
License
This project is licensed under the MIT License. See the LICENSE file for more details.
