一键导入
filter-sequences
Filter FASTA/FASTQ records by length, identity, regex on headers, GC window, complexity, and custom predicates — streaming with Biopython 1.83+.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Filter FASTA/FASTQ records by length, identity, regex on headers, GC window, complexity, and custom predicates — streaming with Biopython 1.83+.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Pass work between ORS skills with a Material Passport — a structured JSON envelope that captures inputs, outputs, decisions, and provenance so a downstream skill can resume without re-deriving context. Use when one skill produces output that another skill must consume, especially across category boundaries (e.g. analysis → writing, sequencing → statistics).
Discover and maintain `## Cross-references` between ORS skills. Given a new or edited skill, suggest related skills (same category, shared tags, complementary workflows). Verify all xref slugs resolve to existing SKILL.md files. Use when adding a new skill, when sibling skills move, or when an audit reveals dangling xrefs.
7-mode AI failure-mode checklist applied before publishing any ORS artifact (skill, manuscript section, dataset card, agent output). Catches: fabricated citations, silent failures, scope creep, missing provenance, unsupervised writes, version drift, hallucinated APIs. Use as the final pass before any 'publish', 'release', 'merge', or 'finalize' action.
Version, changelog, and marketplace workflow for ORS skills. Semver discipline, breaking-change protocol, marketplace.json update, README refresh, and the v0.X.Y → v1.0.0 graduation criteria. Use when bumping a skill version, publishing a release, or upgrading the ORS package version.
Author a new ORS skill from scratch using the v0.4.0 schema. Produces a valid SKILL.md (frontmatter + metadata + sections) following spec/skill-format.md, guided by spec/author-guide.md, validated by scripts/validate-skills.py. Use when a user says 'add a new skill', 'create a skill for X', or 'I want to contribute a skill'.
Process many FASTA/FASTQ/GenBank files in batch — merge, split, convert, summarize, organize — using Biopython 1.83+.
| name | filter-sequences |
| description | Filter FASTA/FASTQ records by length, identity, regex on headers, GC window, complexity, and custom predicates — streaming with Biopython 1.83+. |
| license | MIT |
chr[1-9XY], drop chrUn_*).fastp (single-tool, much faster).kraken2, minimap2 against a host DB, or nf-core modules.umi-tools dedup or fab are better than custom code.biopython>=1.83, regex>=2024.5 (better Unicode support than re).seqkit (C) is ~50x faster.bool.SeqIO.write.from Bio import SeqIO
def length_filter(records, min_len=500, max_len=10_000_000):
for rec in records:
if min_len <= len(rec.seq) <= max_len:
yield rec
with open("filtered.fasta", "w") as out:
n_in = n_out = 0
for rec in SeqIO.parse("input.fasta", "fasta"):
n_in += 1
if min_len := 500 <= len(rec.seq):
SeqIO.write(rec, out, "fasta")
n_out += 1
print(f"Kept {n_out}/{n_in} records")
(Prefer the explicit form for clarity — the example above shows the structural pattern.)
import regex
from Bio import SeqIO
keep_pattern = regex.compile(r"^chr(1[0-9]|2[0-2]|[1-9]|X|Y|M)$")
def keep_chrom(rec, pat=keep_pattern):
return bool(pat.match(rec.id))
with open("primary.fasta", "w") as out:
SeqIO.write(r for r in SeqIO.parse("genome.fasta", "fasta") if keep_chrom(r)),
out, "fasta")
from Bio import SeqIO
from Bio.SeqUtils import gc_fraction
def gc_window(rec, lo=0.30, hi=0.70):
return lo <= gc_fraction(rec.seq) <= hi
SeqIO.write((r for r in SeqIO.parse("asm.fasta", "fasta") if gc_window(r)),
"asm_gc_filtered.fasta", "fasta")
def max_n(rec, max_frac=0.05):
s = str(rec.seq).upper()
if not s:
return False
return (s.count("N") / len(s)) <= max_frac
def min_mean_quality(rec, min_q=30):
q = rec.letter_annotations["phred_quality"]
return (sum(q) / len(q)) >= min_q
Useful for removing low-complexity reads that escape length filters:
import math
from collections import Counter
def entropy(s, k=4):
"""k-mer Shannon entropy; > ~2 bits usually means 'not junk' for k=4."""
if len(s) < k:
return 0.0
counts = Counter(s[i:i+k] for i in range(len(s) - k + 1))
total = sum(counts.values())
return -sum((c/total) * math.log2(c/total) for c in counts.values())
def complex_enough(rec, min_entropy=1.8, k=4):
return entropy(str(rec.seq).upper(), k=k) >= min_entropy
from functools import reduce
def keep(rec, preds):
return all(p(rec) for p in preds)
predicates = [lambda r: min_length(r, 1000), lambda r: max_n(r, 0.01), gc_window]
SeqIO.write((r for r in SeqIO.parse("in.fasta", "fasta") if keep(r, predicates)),
"out.fasta", "fasta")
def non_empty(rec):
return len(rec.seq) > 0
rec -> bool.Bio.SeqUtils.gc_fraction (excludes Ns) or normalize manually.^chr(\d+|X|Y|M)$ matches chr1 but not CHR1; decide and be explicit.SeqIO.write.AAAAAAAAAA...) has entropy ~0 and is dropped.| Need | Tool |
|---|---|
| Sequence filtering at scale | seqkit seq -m 500 -M 5000 in.fasta |
| Regex header subset | samtools view -b in.bam chr1 chr2 ... (for BAM) |
| Complexity filter | bbduk.sh entropy=0.5 (BBTools) |
| N-content filter | seqkit seq -g -G 0.05 (drop GC > 5% — actually means min GC, see docs) |
regex package: https://pypi.org/project/regex/ors-bioinformatics-sequence-fastq-quality-scores, ors-bioinformatics-sequence-paired-end-fastq.bio-filter-sequences (bioSkills-main/sequence-io/filter-sequences).Other skills in this category: