rustkmer 0.5.2

High-performance k-mer counting tool in Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
# Installation

RustKmer offers multiple installation methods to suit different use cases and environments. Choose the one that best fits your needs.

## Quick Install

### Python with Virtual Environment (Recommended for most users) ๐Ÿ

Using a virtual environment is highly recommended to avoid conflicts with system packages:

```bash
# Create a virtual environment
python3 -m venv .venv

# Activate the virtual environment
# On Linux/macOS:
source .venv/bin/activate
# On Windows:
.venv\Scripts\activate

# Install RustKmer
pip install rustkmer

# Verify installation
python -c "from pyrustkmer import KmerCounter; print('โœ… RustKmer installed successfully!')"

# Deactivate when done
deactivate
```

**Benefits of using .venv:**
- ๐Ÿ›ก๏ธ **Isolation**: Prevents conflicts with system Python packages
- ๐Ÿ”„ **Reproducibility**: Ensures consistent environments across projects
- ๐Ÿงน **Cleanliness**: Easy to remove or recreate environments
- ๐Ÿ‘ฅ **Collaboration**: Share exact environment requirements with team

### System-wide Python Installation
```bash
pip install rustkmer
```

### Modern Python with uv (Ultra-fast) โšก

[uv](https://github.com/astral-sh/uv) is a next-generation Python package manager written in Rust that's 10-100x faster than pip:

```bash
# Install uv (macOS/Linux)
curl -LsSf https://astral.sh/uv/install.sh | sh

# Install uv (Windows PowerShell)
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"

# Or install uv with pip
pip install uv

# Create new RustKmer project with uv
uv init rustkmer-analysis
cd rustkmer-analysis

# Add RustKmer dependency
uv add rustkmer

# Run RustKmer immediately
uv run python -c "from pyrustkmer import KmerCounter; print('โœ… RustKmer ready with uv!')"

# Create a simple analysis script
echo 'from pyrustkmer import KmerCounter
counter = PyCounter(21, canonical=True)
print("๐Ÿงฌ RustKmer is ready for k-mer analysis!")' > analysis.py

# Run your analysis
uv run python analysis.py
```

**Why choose uv?**
- ๐Ÿš€ **Speed**: 10-100x faster than pip
- ๐ŸŽฏ **Simplicity**: Single command for environment setup
- ๐Ÿ“ฆ **Projects**: Built-in project management
- ๐Ÿ”„ **Reliability**: Better caching and dependency resolution

### Rust (For library integration) ๐Ÿฆ€
```bash
cargo install rustkmer
```

---

## Detailed Installation Methods

### Method 1: Python Package Manager (PyPI) with Virtual Environment ๐Ÿ

The recommended way to install RustKmer for Python development and bioinformatics workflows.

#### Step 1: Create Virtual Environment
```bash
# Create a dedicated virtual environment for RustKmer
python3 -m venv .venv
```

#### Step 2: Activate Virtual Environment
```bash
# On Linux and macOS:
source .venv/bin/activate

# On Windows (Command Prompt):
.venv\Scripts\activate.bat

# On Windows (PowerShell):
.venv\Scripts\Activate.ps1
```

#### Step 3: Install RustKmer
```bash
# Install the latest version
pip install rustkmer

# Install a specific version
pip install rustkmer==1.0.0

# Install with development dependencies (optional)
pip install rustkmer[dev]
```

#### Step 4: Verify Installation
```bash
python -c "from pyrustkmer import KmerCounter; print('โœ… RustKmer installed successfully!')"
```

**Verification:**
```bash
python -c "from pyrustkmer import KmerCounter; print('โœ… RustKmer installed successfully!')"
```

**System Requirements:**
- Python 3.8 or higher
- 64-bit operating system (Linux, macOS, Windows)
- 50MB disk space for the package

---

### Method 2: Rust Package Manager (Cargo) ๐Ÿฆ€

Install the command-line tool for system-wide k-mer analysis.

```bash
# Install from crates.io
cargo install rustkmer

# Install from source (requires Rust toolchain)
git clone https://github.com/rustkmer/rustkmer
cd rustkmer
cargo install --path .
```

**Verification:**
```bash
rustkmer --version
# Expected output: rustkmer 1.0.0
```

**System Requirements:**
- Rust 1.80 or higher
- Cargo package manager
- Compiler toolchain (gcc/clang on Linux/macOS, MSVC on Windows)

---

### Method 3: Build from Source ๐Ÿ”ง

For development or when you need the latest features.

#### Prerequisites

**Required Dependencies:**
- Rust 1.80+
- Python 3.8+ (for Python bindings)
- C++ compiler (gcc/clang/MSVC)
- Git

#### Build Steps

```bash
# Clone the repository
git clone https://github.com/rustkmer/rustkmer.git
cd rustkmer

# Build the Rust library
cargo build --release

# Build Python bindings (optional)
cd python
maturin develop --release

# Install command-line tool
cargo install --path .
```

**Verification:**
```bash
# Test Rust CLI
rustkmer --version

# Test Python bindings
python -c "from pyrustkmer import KmerCounter; print('โœ… Build successful!')"
```

---

### Method 4: Container Installation ๐Ÿณ

Using Docker for reproducible environments.

#### Pull Pre-built Image
```bash
# Pull the official image
docker pull rustkmer/rustkmer:latest

# Run container
docker run --rm -it rustkmer/rustkmer:latest rustkmer --version
```

#### Build from Source
```bash
# Clone repository
git clone https://github.com/rustkmer/rustkmer.git
cd rustkmer

# Build Docker image
docker build -t rustkmer:local .

# Run your build
docker run --rm -it rustkmer:local rustkmer --version
```

---

## Installation Verification

### Python Installation Test

```python
#!/usr/bin/env python3
"""Test RustKmer installation."""

try:
    from pyrustkmer import KmerCounter, Database
    print("โœ… Python installation successful!")

    # Test basic functionality
    counter = PyCounter(21, canonical=True)
    counter.add_sequence("ATCGATCGATCGATCGATCG")

    print(f"โœ… Basic functionality working!")
    print(f"   K-mer size: 21")
    print(f"   Canonical mode: True")
    print(f"   Test sequence processed successfully")

except ImportError as e:
    print(f"โŒ Installation failed: {e}")
    print("Please check that RustKmer is properly installed.")
    exit(1)

except Exception as e:
    print(f"โŒ Runtime error: {e}")
    exit(1)
```

### Command Line Installation Test

```bash
#!/bin/bash
"""Test RustKmer CLI installation."""

# Test command availability
if command -v rustkmer &> /dev/null; then
    echo "โœ… RustKmer CLI found in PATH"

    # Test basic functionality
    rustkmer --version > /dev/null 2>&1
    if [ $? -eq 0 ]; then
        echo "โœ… CLI functionality working!"
        version=$(rustkmer --version)
        echo "   Version: $version"
    else
        echo "โŒ CLI functionality test failed"
        exit 1
    fi
else
    echo "โŒ RustKmer CLI not found in PATH"
    echo "Please ensure ~/.cargo/bin is in your PATH"
    echo "Or add it to your shell configuration:"
    echo "  export PATH=\"\$HOME/.cargo/bin:\$PATH\""
    exit 1
fi
```

---

## Platform-Specific Notes

### Linux

#### Ubuntu/Debian
```bash
# Install Python build tools
sudo apt update
sudo apt install python3-dev python3-pip

# Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source "$HOME/.cargo/env"

# Install RustKmer
pip install rustkmer
```

#### CentOS/RHEL/Fedora
```bash
# Install development tools
sudo dnf install python3-devel python3-pip gcc

# Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source "$HOME/.cargo/env"

# Install RustKmer
pip install rustkmer
```

### macOS

#### Homebrew (Recommended)
```bash
# Install Python and Rust
brew install python rust

# Install RustKmer
pip install rustkmer

# Add Cargo to PATH (if not already)
echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
```

#### MacPorts
```bash
# Install Python and Rust
sudo port install python3 rust

# Install RustKmer
pip install rustkmer
```

### Windows

#### Using Chocolatey
```powershell
# Install Python and Rust
choco install python rust

# Install RustKmer
pip install rustkmer
```

#### Manual Installation
1. Install Python from [python.org]https://python.org
2. Install Rust from [rust-lang.org]https://rust-lang.org
3. Add Rust to system PATH
4. Install RustKmer: `pip install rustkmer`

---

## Troubleshooting

### Common Installation Issues

#### ImportError on Python
```bash
# Error: ModuleNotFoundError: No module named 'rustkmer'
# Solution: Install using pip
pip install rustkmer

# Or ensure you're using the right Python environment
which python
python -m pip install rustkmer
```

#### Cargo Not Found
```bash
# Error: cargo: command not found
# Solution: Install Rust or add to PATH
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source "$HOME/.cargo/env"
```

#### Compilation Errors
```bash
# Error: Build failed during compilation
# Solution: Install required system dependencies

# Ubuntu/Debian
sudo apt-get install build-essential

# macOS (with Xcode command line tools)
xcode-select --install

# Windows (with Visual Studio Build Tools)
# Install Visual Studio Community with C++ development tools
```

#### Permission Errors
```bash
# Error: Permission denied when installing packages
# Solution: Use virtual environment or user installation

# Create virtual environment
python3 -m venv rustkmer_env
source rustkmer_env/bin/activate
pip install rustkmer

# Or install for current user
pip install --user rustkmer
```

### Getting Help

If you encounter installation issues:

1. **Check System Requirements**: Ensure Python 3.8+ and Rust 1.80+ are installed
2. **Verify PATH**: Make sure `pip` and/or `cargo` are in your system PATH
3. **Clear Cache**: Sometimes clearing pip cache helps: `pip cache purge`
4. **Update Packages**: Ensure `pip` and `rustup` are up to date

---

## Next Steps

Once RustKmer is installed, you're ready to start counting k-mers! Continue to [First Steps](first-steps.md) for your first k-mer counting operations.

### Quick Preview

```bash
# Python usage
from pyrustkmer import KmerCounter
counter = PyCounter(21, canonical=True)
counter.add_from_fasta("genome.fa.gz")
print(f"Counted {counter.get_stats().total_kmers):,} k-mers!")

# Command line usage
rustkmer count -k 21 -i genome.fa.gz -o genome_k21.rkdb
```

Ready to dive in? Let's move to [First Steps](first-steps.md)!