Skip to content

Commit bba0afe

Browse files
author
Aarya Venkat
committed
updates to v1.0.5 including sto support
1 parent 487493a commit bba0afe

17 files changed

Lines changed: 5418 additions & 152 deletions

.DS_Store

8 KB
Binary file not shown.

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,7 @@ site/
7171
# Claude Code
7272
CLAUDE.md
7373

74+
# Paper and drafts
75+
paper/
76+
REVISION_SUMMARY.md
77+

CHANGELOG.md

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,90 @@
22

33
All notable changes to GapClean will be documented in this file.
44

5+
## [1.0.5] - 2026-04-05
6+
7+
### Added
8+
- **Multi-format support** - Stockholm, Clustal, PHYLIP formats now supported
9+
- Auto-detect input format from file extension or content
10+
- Convert between formats: Stockholm (.sto), Clustal (.aln), PHYLIP (.phy), FASTA (.fa)
11+
- New `--input-format` and `--output-format` CLI flags
12+
- New `input_format` and `output_format` parameters for `clean_alignment()` API
13+
- Automatic format conversion handled internally
14+
- **Format auto-detection** - No need to specify format in most cases
15+
- Detects Stockholm (`# STOCKHOLM` header)
16+
- Detects FASTA (`>` header)
17+
- Detects Clustal (`CLUSTAL` header)
18+
- Detects PHYLIP (numeric first line)
19+
- Falls back to extension-based detection
20+
- **Progress bars for format conversion**
21+
- Shows tqdm progress when converting TO FASTA (per-sequence progress)
22+
- Time estimates and warnings when converting FROM FASTA to slow formats
23+
- Prevents users from canceling during long Stockholm conversions
24+
25+
### Changed
26+
- **Added BioPython dependency** (>=1.80) for format conversion
27+
- **Always defaults to FASTA output** for performance
28+
- Stockholm/Clustal/PHYLIP writers are very slow for large alignments (100K+ sequences)
29+
- Use `--output-format` explicitly if you need non-FASTA output
30+
- Warning displayed when requesting non-FASTA format for large datasets
31+
- Format validation now happens after conversion to FASTA
32+
- Temp file cleanup includes converted input files
33+
- Warning message if `--output-format` conflicts with file extension
34+
35+
### Fixed
36+
- **Stockholm format parsing** - Pfam alignments now work correctly
37+
- **Output format auto-detection** - Respects output filename extension instead of defaulting to input format
38+
- Proper sequence counting for non-FASTA inputs
39+
- Better error messages for format conversion failures
40+
41+
### Examples
42+
43+
```bash
44+
# Stockholm input → FASTA output (auto-detected, fast)
45+
gapclean -i pfam_seed.sto -o cleaned.fa -t 75
46+
47+
# Stockholm input → Stockholm output (explicit, slow for large alignments)
48+
gapclean -i pfam_seed.sto -o cleaned.sto --output-format stockholm -t 75
49+
50+
# Python API with Stockholm (defaults to FASTA output)
51+
from gapclean import clean_alignment
52+
stats = clean_alignment('pfam.sto', 'cleaned.fa', threshold=70)
53+
```
54+
55+
### Performance Note
56+
57+
**Stockholm/Clustal/PHYLIP output is significantly slower** than FASTA for large alignments due to BioPython's writer implementations. For the Pfam GT2 family (157K sequences):
58+
59+
- FASTA output: 11 seconds total
60+
- Stockholm output: ~5+ minutes just for format conversion
61+
62+
**Recommendation:** Always use FASTA output unless you specifically need the metadata/markup of other formats.
63+
64+
## [1.0.4] - 2026-04-05
65+
66+
### Added
67+
- **High-level Python API**: New `clean_alignment()` function for easy programmatic use
68+
- Simple one-function interface: `from gapclean import clean_alignment`
69+
- Automatic temp file management (no manual cleanup needed)
70+
- Returns statistics dict with alignment metrics and timing
71+
- Optional `verbose` parameter for quiet operation in pipelines
72+
- Full docstring with examples for all modes
73+
- Exception classes now exported from package root for better error handling
74+
- Comprehensive example Jupyter notebook using the new API
75+
76+
### Changed
77+
- Updated visualization tutorial to use new `clean_alignment()` API
78+
- Cleaner imports: `from gapclean import clean_alignment` instead of internal modules
79+
80+
### Improved
81+
- Much easier integration into Python scripts and Jupyter notebooks
82+
- No need to manage temporary files manually
83+
- Pythonic API design following best practices
84+
585
## [1.0.3] - 2026-04-05
686

787
### Added
8-
- Entropy-based gap removal mode (`-e/--entropy` flag)
88+
- Entropy-based gap removal modes (`--entropy-min` and `--entropy-max` flags)
989
- Comprehensive input validation with clear error messages
1090
- Type hints throughout codebase
1191
- Comprehensive test suite (48+ tests)

README.md

Lines changed: 108 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# GapClean (v1.0.3)
1+
# GapClean (v1.0.5)
22
###### Written by Aarya Venkat, PhD
33

44
<img src="gapclean.png" width="350">
@@ -16,22 +16,43 @@ GapClean is a memory-efficient tool for cleaning gappy multiple sequence alignme
1616
- **Seed Mode**: Remove gaps relative to a reference sequence
1717
- **Entropy Mode**: Remove low-diversity columns using Shannon entropy
1818

19-
**NEW in v1.0.3:**
19+
**NEW in v1.0.5:**
20+
- **Multi-format support**: Stockholm, Clustal, PHYLIP, FASTA
21+
- Auto-detect input format (no flags needed!)
22+
- Convert between formats seamlessly
23+
- **Works with Pfam alignments** (.sto files)
24+
25+
**Also in v1.0.4:**
26+
- Simple Python API for notebooks and scripts
27+
- Auto-managed temp files (no manual cleanup!)
28+
- Returns statistics dict with metrics and timing
29+
30+
**And v1.0.3:**
2031
- Entropy-based gap removal mode
21-
- Pure Python implementation (Windows compatible, no `awk` required!)
22-
- Comprehensive input validation
23-
- Full type hints
24-
- Extensive test coverage
25-
- Professional documentation site
32+
- Pure Python implementation (Windows compatible!)
33+
- Comprehensive testing and documentation
2634

2735
## Features
2836

2937
- **Memory Efficient**: Process alignments larger than RAM using 2D chunking
3038
- **Fast**: Optimized NumPy operations for gap detection
39+
- **Scalable**: Handles million-sequence datasets (1M+ sequences in 35 seconds)
3140
- **Cross-Platform**: Works on Windows, macOS, and Linux
3241
- **Flexible**: Three gap removal modes for different use cases
3342
- **Well-Tested**: 48+ tests ensuring reliability
3443

44+
## Performance
45+
46+
Benchmarks on Apple M1 (16 GB RAM) using Pfam protein families (70% gap threshold):
47+
48+
| Scale | Dataset | Sequences | Positions | Time | Size |
49+
|-------|---------|-----------|-----------|------|------|
50+
| Tiny | PF08087 (Conotoxin) | 42 | 36 | <0.1s | 2 KB |
51+
| Medium | PF00535 (GT2) | 157,052 | 1,285 | 11s | 206 MB |
52+
| **Large** | **PF00069 (Kinase)** | **1,051,876** | **3,667** | **35s** | **7 GB** |
53+
54+
Processing time scales linearly with alignment size (R² = 0.998). From tiny families (42 sequences) to million-sequence datasets with negligible overhead.
55+
3556
## Installation
3657

3758
```bash
@@ -55,9 +76,13 @@ gapclean -i input.fa -o output.fa -s 0
5576
```
5677

5778
### Entropy Mode (NEW!)
58-
Remove low-entropy (conserved) columns:
79+
Remove columns based on diversity:
5980
```bash
60-
gapclean -i input.fa -o output.fa -e 1.5
81+
# Keep variable regions (SNP detection)
82+
gapclean -i input.fa -o output.fa --entropy-min 1.0
83+
84+
# Keep conserved regions (alignment cleaning)
85+
gapclean -i input.fa -o output.fa --entropy-max 1.5
6186
```
6287

6388
## Usage
@@ -70,9 +95,10 @@ Required Arguments:
7095
-o, --output Output cleaned FASTA file
7196
7297
Gap Removal Mode (choose one):
73-
-t, --threshold Percentage threshold (0-100)
74-
-s, --seed Seed sequence index (0-based)
75-
-e, --entropy Entropy threshold (bits)
98+
-t, --threshold Percentage threshold (0-100)
99+
-s, --seed Seed sequence index (0-based)
100+
--entropy-min Remove columns with entropy < threshold (keep variable)
101+
--entropy-max Remove columns with entropy > threshold (keep conserved)
76102
77103
Optional Arguments:
78104
--row-chunk-size Sequences per chunk (default: 5000)
@@ -97,16 +123,85 @@ gapclean -i variants.fa -o positions.fa -s 0
97123
### SNP Detection
98124
```bash
99125
# Keep only variable positions (DNA)
100-
gapclean -i population.fa -o snps.fa -e 1.0
126+
gapclean -i population.fa -o snps.fa --entropy-min 1.0
127+
```
128+
129+
### Stockholm Format (Pfam)
130+
```bash
131+
# Auto-detects Stockholm input, outputs FASTA (fast - recommended!)
132+
gapclean -i PF00535.sto -o cleaned.fa -t 70
133+
134+
# Stockholm output (slower - only if you need the metadata)
135+
gapclean -i pfam_seed.sto -o cleaned.sto --output-format stockholm -t 75
136+
137+
# Explicit format specification
138+
gapclean -i pfam_seed.sto -o cleaned.txt -t 75 --output-format fasta
139+
```
140+
141+
### Format Conversion
142+
```bash
143+
# Convert Clustal to FASTA while cleaning (recommended - fast)
144+
gapclean -i alignment.aln -o output.fa -t 50
145+
146+
# Convert FASTA to Stockholm (slower for large alignments)
147+
gapclean -i input.fa -o output.sto --output-format stockholm -t 75
101148
```
102149

150+
**Performance Note:** Stockholm/Clustal/PHYLIP output is much slower than FASTA for large alignments (100K+ sequences) due to BioPython's format writers. GapClean defaults to FASTA output for optimal performance. Use `--output-format` only if you specifically need non-FASTA formats.
151+
103152
### Memory-Constrained Systems
104153
```bash
105154
# Process large alignment with limited RAM
106155
gapclean -i huge_alignment.fa -o cleaned.fa -t 75 \
107156
--row-chunk-size 1000 --col-chunk-size 1000
108157
```
109158

159+
## Python API
160+
161+
Use GapClean programmatically in Python scripts and Jupyter notebooks:
162+
163+
```python
164+
from gapclean import clean_alignment
165+
166+
# Threshold mode - remove columns with >50% gaps
167+
stats = clean_alignment(
168+
input_file='input.fa',
169+
output_file='output.fa',
170+
threshold=50
171+
)
172+
173+
print(f"Removed {stats['columns_removed']} columns")
174+
print(f"Took {stats['elapsed_seconds']:.1f} seconds")
175+
176+
# Stockholm format (auto-detected)
177+
stats = clean_alignment('pfam.sto', 'cleaned.fa', threshold=70)
178+
179+
# Explicit format conversion
180+
stats = clean_alignment(
181+
'input.aln', 'output.sto',
182+
threshold=50,
183+
input_format='clustal',
184+
output_format='stockholm'
185+
)
186+
187+
# Seed mode - remove gaps relative to first sequence
188+
stats = clean_alignment('input.fa', 'output.fa', seed_index=0)
189+
190+
# Entropy mode - keep only conserved regions
191+
stats = clean_alignment('input.fa', 'output.fa', entropy_max=1.5)
192+
193+
# Quiet mode for pipelines
194+
stats = clean_alignment('input.fa', 'output.fa', threshold=75, verbose=False)
195+
```
196+
197+
### Why use the Python API?
198+
199+
- **One function call**: No temp file management, no subprocess overhead
200+
- **Multi-format support**: Stockholm, Clustal, PHYLIP, FASTA - auto-detected!
201+
- **Returns statistics**: Get metrics about the cleaning operation
202+
- **Perfect for pipelines**: Integrate into larger bioinformatics workflows
203+
- **Jupyter-friendly**: See the included visualization tutorial notebook
204+
110205
## Documentation
111206

112207
**Full documentation available at: [https://arikat.github.io/GapClean/](https://arikat.github.io/GapClean/)**

0 commit comments

Comments
 (0)