Skip to content
Back to skills

Python Bio Sets

ASecurity

Sets and Counter for bioinformatics: gene list operations (intersection/union/difference), k-mer deduplication, and unique element tracking. Bio-specific patterns only.

  • 4 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added May 27, 2026
data-aipython

Security analysis

A100/100

Scanned May 27, 2026

npx -y skills add Pavel-Kravchenko/Bioinformatics --skill python-bio-sets --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Python Bio Sets?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Python Bio Sets
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/pavel-kravchenko-python-bio-sets/badge)](https://www.skillsdirectory.com/skills/pavel-kravchenko-python-bio-sets)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: python-bio-sets
description: "Sets and Counter for bioinformatics: gene list operations (intersection/union/difference), k-mer deduplication, and unique element tracking. Bio-specific patterns only."
tool_type: python
primary_tool: Python
---

# Sets in Bioinformatics

## Pitfalls

- **Sets are unordered:** `my_set[0]` raises `TypeError`. Convert to `sorted(my_set)` when you need ordering.
- **Set elements must be hashable:** Lists and dicts cannot be set members. Use `frozenset` for a set of sets.
- **Empty set:** `{}` creates an empty dict. Use `set()`.
- **`in` on a set is O(1):** Converting a list to a set before repeated membership tests is a significant speedup for large gene lists.

## Set Operations Reference

| Operation | Syntax | Meaning |
|---|---|---|
| Union | `A \| B` | All elements in either set |
| Intersection | `A & B` | Elements in both sets |
| Difference | `A - B` | Elements in A but not B |
| Symmetric diff | `A ^ B` | Elements in exactly one set |
| Subset test | `A <= B` | All of A is in B |

## Key Patterns

### Gene list comparisons
```python
tumor_genes   = {'TP53', 'BRCA1', 'EGFR', 'KRAS', 'MYC'}
pathway_genes = {'EGFR', 'KRAS', 'PIK3CA', 'AKT1', 'MYC'}

in_pathway   = tumor_genes & pathway_genes   # {'EGFR', 'KRAS', 'MYC'}
all_genes    = tumor_genes | pathway_genes
tumor_only   = tumor_genes - pathway_genes
```

### Unique k-mers from a sequence
```python
seq = "ATGCGATCGATCGATCGATCG"
unique_3mers = set(seq[i:i+3] for i in range(len(seq) - 2))
```

### Fast membership lookup (gene universe filter)
```python
# O(1) per lookup vs O(n) for list
known_oncogenes = set(["TP53", "KRAS", "MYC", "EGFR", ...])
hits = [g for g in candidate_list if g in known_oncogenes]
```

### Deduplicate while preserving some information
```python
# Count unique nucleotides in a sequence
unique_nt = set(sequence)   # {'A', 'T', 'G', 'C'} — or fewer if sequence has ambiguities
has_ambiguous = bool(unique_nt - {'A', 'T', 'G', 'C'})
```

### Counter for nucleotide/k-mer frequencies
```python
from collections import Counter

nt_counts = Counter(sequence)
gc_pct = (nt_counts['G'] + nt_counts['C']) / len(sequence) * 100

kmers = [sequence[i:i+3] for i in range(len(sequence) - 2)]
kmer_counts = Counter(kmers)
top5 = kmer_counts.most_common(5)

# Compare profiles between two sequences
kmers_a = Counter(seq_a[i:i+3] for i in range(len(seq_a) - 2))
kmers_b = Counter(seq_b[i:i+3] for i in range(len(seq_b) - 2))
shared   = kmers_a & kmers_b   # min counts
combined = kmers_a + kmers_b   # sum counts
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…