https://github.com/kojix2/ruby-libssw
Fast Smith-Waterman algorithm for Ruby
https://github.com/kojix2/ruby-libssw
bioinformatics ruby smith-waterman
Last synced: 1 day ago
JSON representation
Fast Smith-Waterman algorithm for Ruby
- Host: GitHub
- URL: https://github.com/kojix2/ruby-libssw
- Owner: kojix2
- License: mit
- Created: 2021-01-09T13:40:30.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2025-08-11T14:29:54.000Z (2 months ago)
- Last Synced: 2025-10-07T22:31:55.300Z (5 days ago)
- Topics: bioinformatics, ruby, smith-waterman
- Language: Ruby
- Homepage:
- Size: 175 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE.txt
Awesome Lists containing this project
README
# ruby-libssw

[](https://rubygems.org/gems/libssw)
[](https://rubydoc.info/gems/libssw)
[](https://zenodo.org/badge/latestdoi/328163622):checkered_flag: [libssw](https://github.com/mengyao/Complete-Striped-Smith-Waterman-Library) - fast SIMD parallelized implementation of the Smith-Waterman algorithm - for Ruby
## Installation
```ssh
gem install libssw
```Set the environment variable `LIBSSWDIR` to specify the location of the shared library.
For example, on Ubuntu, you can use libssw in the following way.```
sudo apt install libssw-dev
export LIBSSWDIR=/usr/lib/x86_64-linux-gnu/ # libssw.so
```### Installing from source
When installing from source code using the following steps, the shared library `libssw.so` or `libssw.dylib` will be packed in the Ruby gem. In this case, the environment variable `LIBSSWDIR` is not required.
```sh
git clone --recursive https://github.com/kojix2/ruby-libssw
bundle exec rake libssw:build
bundle exec rake install
```ruby-libssw does not support Windows.
## Usage
```ruby
require 'libssw'ref_str = "AAAAAAAAACGTTAAAAAAAAAA"
ref_int = SSW::DNA.to_int_array(ref_str)
# [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]read_str1 = "ACGTT"
read_str2 = SSW::DNA.revcomp(read_str1)
# "AACGT"
read_int1 = SSW::DNA.to_int_array(read_str1)
# [0, 1, 2, 3, 3]
read_int2 = SSW::DNA.to_int_array(read_str2)
# [0, 0, 1, 2, 3]mat = SSW.create_scoring_matrix(SSW::DNA::Elements, 2, -2)
# mat = [2, -2, -2, -2, 0,
# -2, 2, -2, -2, 0,
# -2, -2, 2, -2, 0,
# -2, -2, -2, 2, 0,
# 0, 0, 0, 0, 0]profile1 = SSW.init(read_int1, mat)
align1 = SSW.align(profile1, ref_int, 3, 1, 1, 0, 0)
pp align1.to_h
# {
# :score1 => 10,
# :score2 => 0,
# :ref_begin1 => 8,
# :ref_end1 => 12,
# :read_begin1 => 0,
# :read_end1 => 4,
# :ref_end2 => 0,
# :cigar => [80],
# :cigar_len => 1,
# :cigar_string => "5M"
# }profile2 = SSW.init(read_int2, mat)
align2 = SSW.align(profile2, ref_int, 3, 1, 1, 0, 0)
pp align2.to_h
# {
# :score1 => 10,
# :score2 => 0,
# :ref_begin1 => 7,
# :ref_end1 => 11,
# :read_begin1 => 0,
# :read_end1 => 4,
# :ref_end2 => 0,
# :cigar => [80],
# :cigar_len => 1,
# :cigar_string => "5M"
# }puts SSW.build_path(read_str1, ref_str, align1)
# 5M
# ACGTT
# |||||
# ACGTT
```## APIs
See [API Documentation](https://rubydoc.info/gems/libssw).
```markdown
* SSW module
* SSW.init
* SSW.init_destroy
* SSW.align
* SSW.align_destroy
* SSW.mark_mismatch
* SSW.create_scoring_matrix
* SSW.build_path
* Profile class
* attributes
* read, mat, read_len, n, bias* Align class
* attributes
* score1, score2, ref_begin1, ref_end1, read_begin1, read_end1, ref_end2
cigar, cigar_len, cigar_string
* DNA module
* DNA.to_int_array
* DNA.from_int_array
* revcomp* AASeq module
* AASeq.to_int_array
* AASeq.from_int_array* BLOSUM62
* BLOSUM50
```## Development
```sh
git clone --recursive https://github.com/kojix2/ruby-libssw
bundle exec rake libssw:build
bundle exec rake test
```Do you need commit rights to my repository?
Do you want to get admin rights and take over the project?
If so, please feel free to contact me @kojix2.## Contributing
* [Report bugs](https://github.com/kojix2/ruby-libssw/issues)
* Fix bugs and [submit pull requests](https://github.com/kojix2/ruby-libssw/pulls)
* Write, clarify, or fix documentation
* English corrections are welcome
* Suggest or add new features## License
* [MIT License](https://opensource.org/licenses/MIT).