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
# Virtual Environments Guide

This guide explains how to use Python virtual environments with RustKmer to ensure clean, isolated development environments.

## ๐ŸŽฏ Why Use Virtual Environments?

### Benefits
- **๐Ÿ›ก๏ธ Isolation**: Prevents conflicts between project dependencies
- **๐Ÿ”„ Reproducibility**: Ensures consistent environments across different machines
- **๐Ÿงน Cleanliness**: Easy to remove and recreate environments
- **๐Ÿ‘ฅ Collaboration**: Share exact environment requirements with team members
- **๐Ÿ”’ Security**: Contains dependencies to specific projects

### When to Use Virtual Environments
- โœ… **Development**: When writing Python code with RustKmer
- โœ… **Research**: For bioinformatics projects with specific dependencies
- โœ… **Production**: When deploying applications with specific versions
- โœ… **Testing**: To create isolated test environments

## ๐Ÿš€ Quick Setup

### Step 1: Create Virtual Environment
```bash
# Create virtual environment named .venv
python3 -m venv .venv

# Alternative: Create with specific Python version
python3.9 -m venv .venv
```

### Step 2: Activate Environment

#### Linux / macOS
```bash
# Using bash/zsh
source .venv/bin/activate

# Verify activation
which python
# Should show: /path/to/project/.venv/bin/python
```

#### Windows
```powershell
# PowerShell
.venv\Scripts\Activate.ps1

# Command Prompt
.venv\Scripts\activate.bat

# Verify activation
where python
# Should show: C:\path\to\project\.venv\Scripts\python.exe
```

### Step 3: Install RustKmer
```bash
# Upgrade pip first
pip install --upgrade pip

# Install RustKmer
pip install rustkmer

# For development with extra dependencies
pip install rustkmer[dev]

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

### Step 4: Start Working
```bash
# Your Python prompt should show (.venv)
# Create a test script
echo 'from pyrustkmer import KmerCounter
counter = PyCounter(21)
print("๐Ÿงฌ RustKmer is ready!")' > test_rustkmer.py

# Run it
python test_rustkmer.py
```

### Step 5: Deactivate When Done
```bash
# Deactivate the virtual environment
deactivate

# Your Python prompt returns to normal
```

## ๐Ÿ“ Directory Structure

```
my_project/
โ”œโ”€โ”€ .venv/                 # Virtual environment directory
โ”‚   โ”œโ”€โ”€ bin/              # Executables (Linux/macOS)
โ”‚   โ”œโ”€โ”€ Scripts/          # Executables (Windows)
โ”‚   โ”œโ”€โ”€ include/          # C header files
โ”‚   โ”œโ”€โ”€ lib/              # Python libraries
โ”‚   โ””โ”€โ”€ share/            # Shared data
โ”œโ”€โ”€ requirements.txt      # Project dependencies
โ”œโ”€โ”€ main.py              # Your Python code
โ””โ”€โ”€ README.md            # Project documentation
```

## ๐Ÿ“‹ Environment Management

### Common Commands
```bash
# Create new environment
python3 -m venv .venv

# Activate environment
source .venv/bin/activate  # Linux/macOS
.venv\Scripts\activate     # Windows

# List installed packages
pip list

# Show package information
pip show rustkmer

# Upgrade pip
pip install --upgrade pip

# Upgrade specific package
pip install --upgrade rustkmer

# Uninstall package
pip uninstall rustkmer

# Deactivate environment
deactivate
```

### Saving Dependencies
```bash
# Save current environment to requirements.txt
pip freeze > requirements.txt

# Install from requirements.txt
pip install -r requirements.txt

# Save only main dependencies (exclude sub-dependencies)
pip list --format=freeze > requirements-main.txt
```

## ๐Ÿ”ง Advanced Usage

### Custom Environment Names
```bash
# Create environment with custom name
python3 -m venv rustkmer_env

# Activate custom environment
source rustkmer_env/bin/activate

# Deactivate
deactivate
```

### Environment with Specific Python Version
```bash
# Use Python 3.9
python3.9 -m venv .venv-py39

# Use Python 3.10
python3.10 -m venv .venv-py310

# Check Python version in environment
source .venv-py39/bin/activate
python --version
```

### Pre-commit Hooks Setup
```bash
# Install pre-commit in your environment
pip install pre-commit

# Set up hooks for your project
pre-commit install

# Run hooks manually
pre-commit run --all-files
```

## ๐Ÿ› ๏ธ Development Workflow

### For RustKmer Development
```bash
# 1. Create environment
python3 -m venv .venv
source .venv/bin/activate

# 2. Install development dependencies
pip install -r requirements-dev.txt

# 3. Install RustKmer in development mode
cd rustkmer/
pip install -e .

# 4. Run tests
pytest tests/

# 5. Deactivate when done
deactivate
```

### For Bioinformatics Projects
```bash
# 1. Create environment
python3 -m venv .venv
source .venv/bin/activate

# 2. Install RustKmer and bioinformatics tools
pip install rustkmer pandas matplotlib seaborn biopython

# 3. Save dependencies
pip freeze > requirements.txt

# 4. Start your analysis
python analyze_kmers.py
```

## ๐Ÿ› Troubleshooting

### Common Issues

#### Python Not Found
```bash
# Error: python3: command not found
# Solution: Use python instead of python3
python -m venv .venv
```

#### Activation Fails
```bash
# Error: .venv/bin/activate: No such file or directory
# Solution: Check if venv was created successfully
ls -la .venv/

# Recreate if necessary
rm -rf .venv
python3 -m venv .venv
```

#### Permission Denied (Windows PowerShell)
```powershell
# Error: Scripts\Activate.ps1 cannot be loaded
# Solution: Change execution policy
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
```

#### Package Installation Fails
```bash
# Error: Could not build wheels for rustkmer
# Solution: Check Rust installation
rustc --version
cargo --version

# Install Rust if missing
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```

#### Import Error
```bash
# Error: ModuleNotFoundError: No module named 'rustkmer'
# Solution: Check if you're in the right environment
which python
pip list | grep rustkmer

# Reinstall if necessary
pip uninstall rustkmer
pip install rustkmer
```

### Recovery Commands
```bash
# Reset environment completely
rm -rf .venv
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

# Clear pip cache if installation fails
pip cache purge
pip install rustkmer
```

## ๐Ÿ“š Best Practices

### 1. Always Use Virtual Environments
```bash
# โœ… Good: Use virtual environment
python3 -m venv .venv
source .venv/bin/activate
pip install rustkmer

# โŒ Bad: Install globally
pip install rustkmer
```

### 2. Keep .venv Out of Version Control
```gitignore
# .gitignore
.venv/
__pycache__/
*.pyc
```

### 3. Document Dependencies
```bash
# Always create requirements.txt
pip freeze > requirements.txt

# Or use specific versions
echo "rustkmer==1.0.0" > requirements.txt
echo "pandas>=1.3.0" >> requirements.txt
```

### 4. Use Meaningful Environment Names
```bash
# โœ… Good: Descriptive names
python3 -m venv rustkmer-analysis
python3 -m venv ml-experiment

# โŒ Less clear: Generic names
python3 -m venv env
python3 -m venv venv
```

### 5. Regular Maintenance
```bash
# Regularly update packages
pip list --outdated
pip install --upgrade package-name

# Clean up unused packages
pip uninstall package-name
```

## ๐Ÿ”„ Environment Sharing

### Export Environment
```bash
# Save all packages
pip freeze > requirements.txt

# Save only top-level packages
pip list --not-required --format=freeze > requirements-main.txt
```

### Recreate Environment
```bash
# Clone repository
git clone https://github.com/user/project.git
cd project

# Create and activate environment
python3 -m venv .venv
source .venv/bin/activate

# Install dependencies
pip install -r requirements.txt
```

### Using conda (Alternative)
```bash
# Create conda environment
conda create -n rustkmer python=3.9
conda activate rustkmer

# Install RustKmer
pip install rustkmer

# Export environment
conda env export > environment.yml

# Recreate from file
conda env create -f environment.yml
```

## โšก Modern Alternative: Using uv

[uv](https://github.com/astral-sh/uv) is an extremely fast Python package and project manager written in Rust. It's 10-100x faster than pip and creates virtual environments instantly.

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

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

# Or using pip
pip install uv
```

### Create Project with uv
```bash
# Create new project
uv init rustkmer-project
cd rustkmer-project

# Add RustKmer dependency
uv add rustkmer

# Add development dependencies
uv add --dev pytest pandas matplotlib

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

### uv vs Traditional venv
```bash
# Traditional venv (slower)
python3 -m venv .venv
source .venv/bin/activate
pip install rustkmer

# uv (much faster)
uv venv
source .venv/bin/activate
uv pip install rustkmer

# Or even better: let uv manage everything
uv add rustkmer
```

### Advantages of uv
- **๐Ÿš€ Speed**: 10-100x faster than pip
- **๐ŸŽฏ Simplicity**: Single tool for all Python project management
- **๐Ÿ“ฆ Projects**: Built-in project management with pyproject.toml
- **๐Ÿ”„ Caching**: Smart caching for repeatable builds
- **๐Ÿ Modern**: Designed for modern Python workflows

---

## ๐ŸŽ‰ Next Steps

Now that you have RustKmer installed in a virtual environment:

1. **[First Steps]first-steps.md** - Learn basic k-mer operations
2. **[User Guide]../user-guide/** - Explore advanced features
3. **[API Reference]../api-reference/** - Detailed Python API documentation
4. **[Examples]../tutorials/** - Practical examples and workflows

Happy k-mer counting! ๐Ÿงฌโœจ