https://github.com/kentwait/alignmentrs
Quickly read and manipulate multiple sequence alignments in Python
https://github.com/kentwait/alignmentrs
Last synced: 5 months ago
JSON representation
Quickly read and manipulate multiple sequence alignments in Python
- Host: GitHub
- URL: https://github.com/kentwait/alignmentrs
- Owner: kentwait
- License: mit
- Created: 2019-01-29T05:05:09.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-09-13T06:34:23.000Z (almost 7 years ago)
- Last Synced: 2025-10-29T01:08:23.461Z (8 months ago)
- Language: Python
- Size: 618 KB
- Stars: 1
- Watchers: 2
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# alignmentrs
Quickly read and manipulate multiple sequence alignments in Python
## Installation
pip install alignmentrs
## Quickstart
### Import alignment into Python
```python
>>> import alignmentrs as rs
>>> aln = rs.Alignment.from_fasta('hiv.fna', 'HIV_alignment')
>>> aln
Alignment(nsamples=10, nsites=120, nmarkers=0)
>>> aln.sample_ids
['sample01', 'sample02', 'sample03', 'sample04', 'sample05', 'sample06'
'sample07', 'sample08', 'sample09', 'sample10']
```
### Select sites to remove from the alignment
```python
>>> sites_to_remove = [i for i in range(120) if (i-2) % 3 != 0] # remove 1st and 2nd position in codon triplet
>>> aln.remove_sites(sites_to_remove, copy=False) # manipulate inplace, copy=True returns a new copy
Alignment(nsamples=10, nsites=40, nmarkers=0)
```
### Select sites to retain in the alignment
```python
>>> sites_to_retain = list(range(2, 3, 120)) # third position in codon triplet
>>> aln.retain_sites(sites_to_retain, copy=False) # manipulate inplace, copy=True returns a new copy
Alignment(nsamples=10, nsites=40, nmarkers=0)
```
### Get a subset of samples and sites
```python
>>> sub_aln = aln.subset(samples=['sample01', 'sample03', 'sample05'], sites=list(range(2, 3, 120)))
>>> sub_aln
Alignment(nsamples=3, nsites=40, nmarkers=0)
```
## License
[MIT License](https://github.com/kentwait/alignmentrs/blob/master/LICENSE)