[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7EF7H22V0778VXDZXHM5E57":3,"skill-same:01M7EF7H22V0778VXDZXHM5E57":100},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":30,"commitSha":31,"skillDirectory":32,"forksCount":14,"repositoryHtmlUrl":33,"repositoryHomepageUrl":33,"ownerHtmlUrl":34,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":35,"install":36,"resources":49},"01M7EF7H22V0778VXDZXHM5E57","bio-read-sequences",null,"Read biological sequence files (FASTA, FASTQ, GenBank, EMBL, ABI, SFF) with Biopython Bio.SeqIO, choosing between streaming, in-memory, and on-disk-indexed access. Use when parsing sequence files, iterating multi-record files, randomly accessing records by ID in large files, or maximizing parse throughput.","Mr-Nobody-Anonymous\u002FAll-skills","Mr-Nobody-Anonymous","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F184253119?v=4","01M7AEXFJHKTYQW5R0ZCQQTWFV","anonymous","01M7C00M3GQR4QKP9GZA42GFAK",0,"MIT","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fbiology\u002Fbio-read-sequences\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: bio-read-sequences\ndescription: Read biological sequence files (FASTA, FASTQ, GenBank, EMBL, ABI, SFF) with Biopython Bio.SeqIO, choosing between streaming, in-memory, and on-disk-indexed access. Use when parsing sequence files, iterating multi-record files, randomly accessing records by ID in large files, or maximizing parse throughput.\ntool_type: python\nprimary_tool: Bio.SeqIO\nsource: \"https:\u002F\u002Fgithub.com\u002FGPTomics\u002FbioSkills\"\nsource_repository: \"GPTomics\u002FbioSkills\"\nsource_path: \"sequence-io\u002Fread-sequences\u002FSKILL.md\"\nlicense: \"MIT\"\nimported_at: \"2026-09-20\"\n---\n\n## Version Compatibility\n\nReference examples tested with: BioPython 1.83+\n\nBefore using code patterns, verify installed versions match. If versions differ:\n- Python: `pip show biopython` then `help(module.function)` to check signatures\n\nIf code throws ImportError, AttributeError, or TypeError, introspect the installed\npackage and adapt the example to match the actual API rather than retrying.\n\n# Read Sequences\n\nRead biological sequence data from files using Biopython's Bio.SeqIO module.\n\n**\"Read sequences from a file\"** -> Parse a file into SeqRecord objects exposing id, sequence, and annotations.\n- Python: `SeqIO.parse()` \u002F `SeqIO.read()` (BioPython)\n- R: `readDNAStringSet()` \u002F `readAAStringSet()` (Biostrings)\n\n## The Governing Principle\n\nStream by default. `SeqIO.parse()` yields one record at a time and never holds the whole file in RAM, so it scales to any size. Reach for an in-memory or indexed structure only when the access pattern demands it: load all records (`to_dict`) only for small files needing random access; build an index (`index` \u002F `index_db`) for random access into large files. Never `list()` a huge file or `to_dict()` it - that defeats streaming and can exhaust memory.\n\n## Which Function to Use\n\n| Method | Returns | Memory model | Random access | Persists | Multi-file |\n|--------|---------|--------------|---------------|----------|------------|\n| `parse(handle, format)` | generator of SeqRecord | one record at a time | no | no | no |\n| `read(handle, format)` | one SeqRecord | one record | n\u002Fa | no | no |\n| `to_dict(records)` | real `dict` | ALL records in RAM | yes | no | feed combined iterators |\n| `index(filename, format)` | dict-like (read-only) | byte offsets only, re-parses on access | yes | no | no |\n| `index_db(idx_file, files, format)` | dict-like (read-only) | on-disk SQLite index | yes | yes | yes |\n\nDecision rule: `parse` for streaming; `read` for a known single-record file; `to_dict` when the file is small and random access by ID is needed; `index` for random access into one large file; `index_db` for files larger than RAM, many files indexed together, or an index reused across runs.\n\nBehavioral traps these methods hide:\n- `parse()` is a one-pass generator. It is NOT subscriptable (`parse(...)[3]` raises TypeError), and it EXHAUSTS SILENTLY: a second `for` loop over the same generator object yields nothing with no error. Re-call `parse()` for each pass, or `list()` it once if the file is small.\n- `read()` fails LOUDLY: zero records raise `ValueError: No records found in handle`; more than one raises `ValueError: More than one record found in handle`. Use it as an assertion that the file holds exactly one sequence.\n- `to_dict()`, `index()`, and `index_db()` all raise `ValueError` on a DUPLICATE id (`Duplicate key '...'`). Supply a `key_function` to derive unique keys when ids collide.\n- `index()` needs a FILENAME, not a handle (it must seek). It stores only byte offsets and re-parses the record from disk on every access, so it returns a fresh object each time and mutations do not persist. It is read-only (`__setitem__` raises NotImplementedError).\n- `index_db()` stores the offset index in an on-disk SQLite file. It PERSISTS across sessions (reopen later with just the index filename), and scales beyond RAM and across multiple files (pass a list of filenames). This is the right answer for data larger than memory.\n\nThe `alphabet=` argument still appears in some signatures for back-compatibility but is a no-op since BioPython 1.78; leave it `None`.\n\n## Required Import\n\n```python\nfrom Bio import SeqIO\n```\n\n## Reading Records\n\n### SeqIO.parse() - Stream Multiple Records\nReturns a one-pass iterator of SeqRecord objects. Always pass the format explicitly as the second argument.\n\n```python\nfor record in SeqIO.parse('sequences.fasta', 'fasta'):\n    print(record.id, len(record.seq))\n```\n\n### SeqIO.read() - Exactly One Record\nUse when the file must contain a single sequence; raises on zero or multiple records.\n\n```python\nrecord = SeqIO.read('single.fasta', 'fasta')\n```\n\n## Random Access\n\n### SeqIO.to_dict() - Small Files\nLoads every record into a dictionary keyed by id. Fast random access, but holds all records in RAM.\n\n```python\nrecords = SeqIO.to_dict(SeqIO.parse('sequences.fasta', 'fasta'))\nseq = records['sequence_id'].seq\n```\n\n### SeqIO.index() - One Large File\n\n**Goal:** Random access by id into a large file without loading every record into memory.\n\n**Approach:** Build an in-memory map of byte offsets keyed by id; each lookup re-parses one record from disk.\n\n**Reference (BioPython 1.83+):**\n```python\nrecords = SeqIO.index('large.fasta', 'fasta')\nseq = records['sequence_id'].seq\nrecords.close()\n```\n\nA `key_function` maps the id STRING to a custom key (note: `to_dict`'s key_function receives the whole record instead):\n```python\ndef get_accession(identifier):\n    return identifier.split('.')[0]  # drop the version suffix\n\nrecords = SeqIO.index('sequences.fasta', 'fasta', key_function=get_accession)\n```\n\n### SeqIO.index_db() - Huge \u002F Multiple Files\n\n**Goal:** Random access into data larger than RAM, or across many files, with the index reusable across runs.\n\n**Approach:** Persist the offset index in an on-disk SQLite database; reopen it later without re-parsing.\n\n**Reference (BioPython 1.83+):**\n```python\n# First call parses the file(s) and builds the SQLite index\nrecords = SeqIO.index_db('index.sqlite', 'large.fasta', 'fasta')\nseq = records['sequence_id'].seq\nrecords.close()\n\n# Later sessions reopen instantly with just the index filename\nrecords = SeqIO.index_db('index.sqlite')\n\n# Index multiple files as one database\nrecords = SeqIO.index_db('combined.sqlite', ['file1.fasta', 'file2.fasta'], 'fasta')\n```\n\n## High-Performance Parsing\n\nFor maximum throughput on large files, low-level parsers (SimpleFastaParser, FastqGeneralIterator) yield raw tuples and skip SeqRecord construction, so they run substantially faster than SeqIO.parse.\n\n### SimpleFastaParser\n\n**Goal:** Parse large FASTA files at maximum speed without SeqRecord overhead.\n\n**Approach:** Iterate `(title, sequence)` string tuples directly from the handle.\n\n**Reference (BioPython 1.83+):**\n```python\nfrom Bio.SeqIO.FastaIO import SimpleFastaParser\n\nwith open('large.fasta') as handle:\n    for title, sequence in SimpleFastaParser(handle):\n        if len(sequence) > 1000:\n            seq_id = title.split()[0]  # first whitespace token is the id\n```\n\n### FastqGeneralIterator\n\n**Goal:** Parse large FASTQ files at maximum speed.\n\n**Approach:** Iterate `(title, sequence, quality_string)` string tuples; decode quality manually if needed.\n\n**Reference (BioPython 1.83+):**\n```python\nfrom Bio.SeqIO.QualityIO import FastqGeneralIterator\n\nwith open('reads.fastq') as handle:\n    for title, sequence, quality in FastqGeneralIterator(handle):\n        avg_qual = sum(ord(c) - 33 for c in quality) \u002F len(quality)  # Phred+33\n```\n\n## SeqRecord Attributes\n\nAfter parsing, each record exposes:\n\n```python\nrecord.id          # first whitespace token of the header (string)\nrecord.name        # same first token (for FASTA, name == id)\nrecord.description # the ENTIRE header after '>', including the id token\nrecord.seq         # sequence data (Seq object; case-preserving)\nrecord.features    # list of SeqFeature objects (GenBank\u002FEMBL)\nrecord.annotations # dict of annotations (organism, molecule_type, ...)\nrecord.letter_annotations  # per-letter dict (e.g. 'phred_quality' list)\nrecord.dbxrefs     # database cross-references\n```\n\n### id vs name vs description - the first-space split\nA FASTA header `>FIRST rest of the line` parses to: `id` = `FIRST` (the first whitespace token), `name` = `FIRST` (same token), `description` = `FIRST rest of the line` (the WHOLE header after `>`, including the id). So `>seq1 some desc` gives id `seq1`, name `seq1`, description `seq1 some desc`. The id is therefore the leading word of the description, not a separate field - relevant when writing records back out.\n\n## Common Formats\n\n| Format | String | Typical Extension | Notes |\n|--------|--------|-------------------|-------|\n| FASTA | `'fasta'` | .fasta, .fa, .fna, .faa | Most common |\n| FASTA 2-line | `'fasta-2line'` | .fasta | One line per sequence (no wrapping) |\n| FASTQ | `'fastq'` | .fastq, .fq | Alias of fastq-sanger (Phred+33) |\n| FASTQ Solexa | `'fastq-solexa'` | .fastq | Old Solexa (Solexa+64, scores -5..62) |\n| FASTQ Illumina | `'fastq-illumina'` | .fastq | Illumina 1.3-1.7 (Phred+64) |\n| GenBank | `'genbank'` or `'gb'` | .gb, .gbk | With features\u002Fannotations |\n| EMBL | `'embl'` | .embl | European format with features |\n| Swiss-Prot | `'swiss'` | .dat | UniProt format |\n\nFASTQ quality encoding cannot be auto-detected reliably: the same quality line can be valid Phred+33 and Phred+64. Picking the wrong string can silently shift every score by 31. Confirm the encoding before parsing; see fastq-quality for the full encoding decision.\n\n## Specialized Formats\n\n| Format | String | Use Case |\n|--------|--------|----------|\n| ABI | `'abi'` | Sanger sequencing trace files (.ab1) |\n| ABI Trimmed | `'abi-trim'` | ABI with low-quality ends trimmed |\n| SFF | `'sff'` | 454\u002FIon Torrent flowgram data |\n| SFF Trimmed | `'sff-trim'` | SFF with adapter\u002Fquality trimming |\n| QUAL | `'qual'` | Quality scores file (pairs with FASTA) |\n| PDB SEQRES | `'pdb-seqres'` | Protein sequences from PDB SEQRES records |\n| PDB ATOM | `'pdb-atom'` | Sequences from ATOM records in PDB |\n| SnapGene | `'snapgene'` | SnapGene .dna files |\n\n### Reading ABI Trace Files\n```python\nrecord = SeqIO.read('sample.ab1', 'abi')\nqualities = record.letter_annotations['phred_quality']\nrecord_trimmed = SeqIO.read('sample.ab1', 'abi-trim')  # low-quality ends removed\n```\n\n### Reading 454\u002FIon Torrent SFF\n```python\nfor record in SeqIO.parse('reads.sff', 'sff'):\n    print(record.id, len(record.seq))\n```\n\n### Reading PDB Sequences\n```python\nfor record in SeqIO.parse('structure.pdb', 'pdb-seqres'):\n    print(record.id, record.seq)\n```\n\n## Alignment Formats (Read-Only)\n\n| Format | String | Notes |\n|--------|--------|-------|\n| PHYLIP | `'phylip'` | Interleaved; `'phylip-relaxed'` allows longer names |\n| Clustal | `'clustal'` | ClustalW output |\n| Stockholm | `'stockholm'` | Rfam\u002FPfam alignments |\n| NEXUS | `'nexus'` | PAUP\u002FMrBayes format |\n| MAF | `'maf'` | Multiple Alignment Format |\n\n## Code Patterns\n\n### Count Records Without Loading All\n```python\ncount = sum(1 for _ in SeqIO.parse('sequences.fasta', 'fasta'))\n```\n\n### Read GenBank with Features\n```python\nfor record in SeqIO.parse('sequence.gb', 'genbank'):\n    for feature in record.features:\n        if feature.type == 'CDS':\n            product = feature.qualifiers.get('product', ['Unknown'])[0]\n            cds_seq = feature.extract(record.seq)  # spliced feature sequence\n```\n\n### Access FASTQ Quality Scores\n```python\nfor record in SeqIO.parse('reads.fastq', 'fastq'):\n    qualities = record.letter_annotations['phred_quality']\n    avg_quality = sum(qualities) \u002F len(qualities)\n```\n\n### Read From a File Handle\n```python\nwith open('sequences.fasta') as handle:\n    for record in SeqIO.parse(handle, 'fasta'):\n        print(record.id)\n```\n\n## Common Errors\n\n| Symptom | Cause | Fix |\n|---------|-------|-----|\n| Second loop over a parser yields nothing, no error | `parse()` generator exhausted after the first pass | Re-call `parse()` per pass, or `list()` once for small files |\n| `TypeError: 'generator' object is not subscriptable` | Indexed\u002Fsliced a `parse()` result | Wrap in `list()`, or use `to_dict`\u002F`index` for keyed access |\n| `ValueError: More than one record found in handle` | `read()` on a multi-record file | Use `parse()` |\n| `ValueError: No records found in handle` | `read()` on an empty\u002Fzero-record file | Check the file and format string; use `parse()` if multi-record |\n| `ValueError: Duplicate key '...'` | `to_dict`\u002F`index`\u002F`index_db` hit a repeated id | Pass a `key_function` that derives unique keys |\n| Random access by id silently slow \u002F re-reads disk | `index()` re-parses each access; mutations don't persist | Expected; cache needed records, or use `to_dict` for small files |\n| MemoryError \u002F process killed on a huge file | `list()` or `to_dict()` loaded everything into RAM | Stream with `parse()`; use `index_db()` for random access |\n| `ValueError: unknown format` | Misspelled format string | Use a lowercase string from the format tables |\n| `ValueError`\u002F`AssertionError` naming the LOCUS line | GenBank parser reads fixed LOCUS columns (molecule type ~44-54, topology ~55-63); ICE\u002FSnapGene\u002FEnsembl\u002Fassembler LOCUS lines violate the spec | Biologically valid content can still fail the strict column parse; fix the LOCUS columns or re-export from a spec-compliant writer |\n| FASTQ scores all off by ~31 with no error | Wrong FASTQ variant string (Phred+33 vs +64 overlap) | Confirm encoding; see fastq-quality |\n| `AttributeError` referencing `.alphabet` | Code assumes pre-1.78 alphabet API | Drop alphabet usage; molecule type lives in `annotations['molecule_type']` |\n\n## Related Skills\n\n- write-sequences - Write parsed sequences to new files\n- filter-sequences - Filter sequences by criteria after reading\n- format-conversion - Convert between formats (GenBank->FASTA silently drops annotations)\n- compressed-files - Read gzip\u002Fbzip2\u002FBGZF compressed files; only BGZF supports indexed random access\n- fastq-quality - FASTQ encoding (Phred vs Solexa) and offset selection\n- sequence-manipulation\u002Fseq-objects - Work with parsed SeqRecord and Seq objects\n- database-access\u002Fentrez-fetch - Fetch sequences from NCBI instead of local files\n- alignment-files\u002Fsam-bam-basics - For SAM\u002FBAM\u002FCRAM alignment files, use samtools\u002Fpysam\n","## Version Compatibility\n\nReference examples tested with: BioPython 1.83+\n\nBefore using code patterns, verify installed versions match. If versions differ:\n- Python: `pip show biopython` then `help(module.function)` to check signatures\n\nIf code throws ImportError, AttributeError, or TypeError, introspect the installed\npackage and adapt the example to match the actual API rather than retrying.\n\n# Read Sequences\n\nRead biological sequence data from files using Biopython's Bio.SeqIO module.\n\n**\"Read sequences from a file\"** -> Parse a file into SeqRecord objects exposing id, sequence, and annotations.\n- Python: `SeqIO.parse()` \u002F `SeqIO.read()` (BioPython)\n- R: `readDNAStringSet()` \u002F `readAAStringSet()` (Biostrings)\n\n## The Governing Principle\n\nStream by default. `SeqIO.parse()` yields one record at a time and never holds the whole file in RAM, so it scales to any size. Reach for an in-memory or indexed structure only when the access pattern demands it: load all records (`to_dict`) only for small files needing random access; build an index (`index` \u002F `index_db`) for random access into large files. Never `list()` a huge file or `to_dict()` it - that defeats streaming and can exhaust memory.\n\n## Which Function to Use\n\n| Method | Returns | Memory model | Random access | Persists | Multi-file |\n|--------|---------|--------------|---------------|----------|------------|\n| `parse(handle, format)` | generator of SeqRecord | one record at a time | no | no | no |\n| `read(handle, format)` | one SeqRecord | one record | n\u002Fa | no | no |\n| `to_dict(records)` | real `dict` | ALL records in RAM | yes | no | feed combined iterators |\n| `index(filename, format)` | dict-like (read-only) | byte offsets only, re-parses on access | yes | no | no |\n| `index_db(idx_file, files, format)` | dict-like (read-only) | on-disk SQLite index | yes | yes | yes |\n\nDecision rule: `parse` for streaming; `read` for a known single-record file; `to_dict` when the file is small and random access by ID is needed; `index` for random access into one large file; `index_db` for files larger than RAM, many files indexed together, or an index reused across runs.\n\nBehavioral traps these methods hide:\n- `parse()` is a one-pass generator. It is NOT subscriptable (`parse(...)[3]` raises TypeError), and it EXHAUSTS SILENTLY: a second `for` loop over the same generator object yields nothing with no error. Re-call `parse()` for each pass, or `list()` it once if the file is small.\n- `read()` fails LOUDLY: zero records raise `ValueError: No records found in handle`; more than one raises `ValueError: More than one record found in handle`. Use it as an assertion that the file holds exactly one sequence.\n- `to_dict()`, `index()`, and `index_db()` all raise `ValueError` on a DUPLICATE id (`Duplicate key '...'`). Supply a `key_function` to derive unique keys when ids collide.\n- `index()` needs a FILENAME, not a handle (it must seek). It stores only byte offsets and re-parses the record from disk on every access, so it returns a fresh object each time and mutations do not persist. It is read-only (`__setitem__` raises NotImplementedError).\n- `index_db()` stores the offset index in an on-disk SQLite file. It PERSISTS across sessions (reopen later with just the index filename), and scales beyond RAM and across multiple files (pass a list of filenames). This is the right answer for data larger than memory.\n\nThe `alphabet=` argument still appears in some signatures for back-compatibility but is a no-op since BioPython 1.78; leave it `None`.\n\n## Required Import\n\n```python\nfrom Bio import SeqIO\n```\n\n## Reading Records\n\n### SeqIO.parse() - Stream Multiple Records\nReturns a one-pass iterator of SeqRecord objects. Always pass the format explicitly as the second argument.\n\n```python\nfor record in SeqIO.parse('sequences.fasta', 'fasta'):\n    print(record.id, len(record.seq))\n```\n\n### SeqIO.read() - Exactly One Record\nUse when the file must contain a single sequence; raises on zero or multiple records.\n\n```python\nrecord = SeqIO.read('single.fasta', 'fasta')\n```\n\n## Random Access\n\n### SeqIO.to_dict() - Small Files\nLoads every record into a dictionary keyed by id. Fast random access, but holds all records in RAM.\n\n```python\nrecords = SeqIO.to_dict(SeqIO.parse('sequences.fasta', 'fasta'))\nseq = records['sequence_id'].seq\n```\n\n### SeqIO.index() - One Large File\n\n**Goal:** Random access by id into a large file without loading every record into memory.\n\n**Approach:** Build an in-memory map of byte offsets keyed by id; each lookup re-parses one record from disk.\n\n**Reference (BioPython 1.83+):**\n```python\nrecords = SeqIO.index('large.fasta', 'fasta')\nseq = records['sequence_id'].seq\nrecords.close()\n```\n\nA `key_function` maps the id STRING to a custom key (note: `to_dict`'s key_function receives the whole record instead):\n```python\ndef get_accession(identifier):\n    return identifier.split('.')[0]  # drop the version suffix\n\nrecords = SeqIO.index('sequences.fasta', 'fasta', key_function=get_accession)\n```\n\n### SeqIO.index_db() - Huge \u002F Multiple Files\n\n**Goal:** Random access into data larger than RAM, or across many files, with the index reusable across runs.\n\n**Approach:** Persist the offset index in an on-disk SQLite database; reopen it later without re-parsing.\n\n**Reference (BioPython 1.83+):**\n```python\n# First call parses the file(s) and builds the SQLite index\nrecords = SeqIO.index_db('index.sqlite', 'large.fasta', 'fasta')\nseq = records['sequence_id'].seq\nrecords.close()\n\n# Later sessions reopen instantly with just the index filename\nrecords = SeqIO.index_db('index.sqlite')\n\n# Index multiple files as one database\nrecords = SeqIO.index_db('combined.sqlite', ['file1.fasta', 'file2.fasta'], 'fasta')\n```\n\n## High-Performance Parsing\n\nFor maximum throughput on large files, low-level parsers (SimpleFastaParser, FastqGeneralIterator) yield raw tuples and skip SeqRecord construction, so they run substantially faster than SeqIO.parse.\n\n### SimpleFastaParser\n\n**Goal:** Parse large FASTA files at maximum speed without SeqRecord overhead.\n\n**Approach:** Iterate `(title, sequence)` string tuples directly from the handle.\n\n**Reference (BioPython 1.83+):**\n```python\nfrom Bio.SeqIO.FastaIO import SimpleFastaParser\n\nwith open('large.fasta') as handle:\n    for title, sequence in SimpleFastaParser(handle):\n        if len(sequence) > 1000:\n            seq_id = title.split()[0]  # first whitespace token is the id\n```\n\n### FastqGeneralIterator\n\n**Goal:** Parse large FASTQ files at maximum speed.\n\n**Approach:** Iterate `(title, sequence, quality_string)` string tuples; decode quality manually if needed.\n\n**Reference (BioPython 1.83+):**\n```python\nfrom Bio.SeqIO.QualityIO import FastqGeneralIterator\n\nwith open('reads.fastq') as handle:\n    for title, sequence, quality in FastqGeneralIterator(handle):\n        avg_qual = sum(ord(c) - 33 for c in quality) \u002F len(quality)  # Phred+33\n```\n\n## SeqRecord Attributes\n\nAfter parsing, each record exposes:\n\n```python\nrecord.id          # first whitespace token of the header (string)\nrecord.name        # same first token (for FASTA, name == id)\nrecord.description # the ENTIRE header after '>', including the id token\nrecord.seq         # sequence data (Seq object; case-preserving)\nrecord.features    # list of SeqFeature objects (GenBank\u002FEMBL)\nrecord.annotations # dict of annotations (organism, molecule_type, ...)\nrecord.letter_annotations  # per-letter dict (e.g. 'phred_quality' list)\nrecord.dbxrefs     # database cross-references\n```\n\n### id vs name vs description - the first-space split\nA FASTA header `>FIRST rest of the line` parses to: `id` = `FIRST` (the first whitespace token), `name` = `FIRST` (same token), `description` = `FIRST rest of the line` (the WHOLE header after `>`, including the id). So `>seq1 some desc` gives id `seq1`, name `seq1`, description `seq1 some desc`. The id is therefore the leading word of the description, not a separate field - relevant when writing records back out.\n\n## Common Formats\n\n| Format | String | Typical Extension | Notes |\n|--------|--------|-------------------|-------|\n| FASTA | `'fasta'` | .fasta, .fa, .fna, .faa | Most common |\n| FASTA 2-line | `'fasta-2line'` | .fasta | One line per sequence (no wrapping) |\n| FASTQ | `'fastq'` | .fastq, .fq | Alias of fastq-sanger (Phred+33) |\n| FASTQ Solexa | `'fastq-solexa'` | .fastq | Old Solexa (Solexa+64, scores -5..62) |\n| FASTQ Illumina | `'fastq-illumina'` | .fastq | Illumina 1.3-1.7 (Phred+64) |\n| GenBank | `'genbank'` or `'gb'` | .gb, .gbk | With features\u002Fannotations |\n| EMBL | `'embl'` | .embl | European format with features |\n| Swiss-Prot | `'swiss'` | .dat | UniProt format |\n\nFASTQ quality encoding cannot be auto-detected reliably: the same quality line can be valid Phred+33 and Phred+64. Picking the wrong string can silently shift every score by 31. Confirm the encoding before parsing; see fastq-quality for the full encoding decision.\n\n## Specialized Formats\n\n| Format | String | Use Case |\n|--------|--------|----------|\n| ABI | `'abi'` | Sanger sequencing trace files (.ab1) |\n| ABI Trimmed | `'abi-trim'` | ABI with low-quality ends trimmed |\n| SFF | `'sff'` | 454\u002FIon Torrent flowgram data |\n| SFF Trimmed | `'sff-trim'` | SFF with adapter\u002Fquality trimming |\n| QUAL | `'qual'` | Quality scores file (pairs with FASTA) |\n| PDB SEQRES | `'pdb-seqres'` | Protein sequences from PDB SEQRES records |\n| PDB ATOM | `'pdb-atom'` | Sequences from ATOM records in PDB |\n| SnapGene | `'snapgene'` | SnapGene .dna files |\n\n### Reading ABI Trace Files\n```python\nrecord = SeqIO.read('sample.ab1', 'abi')\nqualities = record.letter_annotations['phred_quality']\nrecord_trimmed = SeqIO.read('sample.ab1', 'abi-trim')  # low-quality ends removed\n```\n\n### Reading 454\u002FIon Torrent SFF\n```python\nfor record in SeqIO.parse('reads.sff', 'sff'):\n    print(record.id, len(record.seq))\n```\n\n### Reading PDB Sequences\n```python\nfor record in SeqIO.parse('structure.pdb', 'pdb-seqres'):\n    print(record.id, record.seq)\n```\n\n## Alignment Formats (Read-Only)\n\n| Format | String | Notes |\n|--------|--------|-------|\n| PHYLIP | `'phylip'` | Interleaved; `'phylip-relaxed'` allows longer names |\n| Clustal | `'clustal'` | ClustalW output |\n| Stockholm | `'stockholm'` | Rfam\u002FPfam alignments |\n| NEXUS | `'nexus'` | PAUP\u002FMrBayes format |\n| MAF | `'maf'` | Multiple Alignment Format |\n\n## Code Patterns\n\n### Count Records Without Loading All\n```python\ncount = sum(1 for _ in SeqIO.parse('sequences.fasta', 'fasta'))\n```\n\n### Read GenBank with Features\n```python\nfor record in SeqIO.parse('sequence.gb', 'genbank'):\n    for feature in record.features:\n        if feature.type == 'CDS':\n            product = feature.qualifiers.get('product', ['Unknown'])[0]\n            cds_seq = feature.extract(record.seq)  # spliced feature sequence\n```\n\n### Access FASTQ Quality Scores\n```python\nfor record in SeqIO.parse('reads.fastq', 'fastq'):\n    qualities = record.letter_annotations['phred_quality']\n    avg_quality = sum(qualities) \u002F len(qualities)\n```\n\n### Read From a File Handle\n```python\nwith open('sequences.fasta') as handle:\n    for record in SeqIO.parse(handle, 'fasta'):\n        print(record.id)\n```\n\n## Common Errors\n\n| Symptom | Cause | Fix |\n|---------|-------|-----|\n| Second loop over a parser yields nothing, no error | `parse()` generator exhausted after the first pass | Re-call `parse()` per pass, or `list()` once for small files |\n| `TypeError: 'generator' object is not subscriptable` | Indexed\u002Fsliced a `parse()` result | Wrap in `list()`, or use `to_dict`\u002F`index` for keyed access |\n| `ValueError: More than one record found in handle` | `read()` on a multi-record file | Use `parse()` |\n| `ValueError: No records found in handle` | `read()` on an empty\u002Fzero-record file | Check the file and format string; use `parse()` if multi-record |\n| `ValueError: Duplicate key '...'` | `to_dict`\u002F`index`\u002F`index_db` hit a repeated id | Pass a `key_function` that derives unique keys |\n| Random access by id silently slow \u002F re-reads disk | `index()` re-parses each access; mutations don't persist | Expected; cache needed records, or use `to_dict` for small files |\n| MemoryError \u002F process killed on a huge file | `list()` or `to_dict()` loaded everything into RAM | Stream with `parse()`; use `index_db()` for random access |\n| `ValueError: unknown format` | Misspelled format string | Use a lowercase string from the format tables |\n| `ValueError`\u002F`AssertionError` naming the LOCUS line | GenBank parser reads fixed LOCUS columns (molecule type ~44-54, topology ~55-63); ICE\u002FSnapGene\u002FEnsembl\u002Fassembler LOCUS lines violate the spec | Biologically valid content can still fail the strict column parse; fix the LOCUS columns or re-export from a spec-compliant writer |\n| FASTQ scores all off by ~31 with no error | Wrong FASTQ variant string (Phred+33 vs +64 overlap) | Confirm encoding; see fastq-quality |\n| `AttributeError` referencing `.alphabet` | Code assumes pre-1.78 alphabet API | Drop alphabet usage; molecule type lives in `annotations['molecule_type']` |\n\n## Related Skills\n\n- write-sequences - Write parsed sequences to new files\n- filter-sequences - Filter sequences by criteria after reading\n- format-conversion - Convert between formats (GenBank->FASTA silently drops annotations)\n- compressed-files - Read gzip\u002Fbzip2\u002FBGZF compressed files; only BGZF supports indexed random access\n- fastq-quality - FASTQ encoding (Phred vs Solexa) and offset selection\n- sequence-manipulation\u002Fseq-objects - Work with parsed SeqRecord and Seq objects\n- database-access\u002Fentrez-fetch - Fetch sequences from NCBI instead of local files\n- alignment-files\u002Fsam-bam-basics - For SAM\u002FBAM\u002FCRAM alignment files, use samtools\u002Fpysam\n",{"name":5,"source":24,"license":15,"tool_type":25,"description":7,"imported_at":26,"source_path":27,"primary_tool":28,"source_repository":29},"https:\u002F\u002Fgithub.com\u002FGPTomics\u002FbioSkills","python","2026-09-20","sequence-io\u002Fread-sequences\u002FSKILL.md","Bio.SeqIO","GPTomics\u002FbioSkills","main","2d1750717747097b602acf30bd09a7cbd4b4c6ea","awesome_skills\u002Fbiology\u002Fbio-read-sequences","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous","2026-11-09 11:45:36",{"source":8,"skillName":5,"commands":37,"prompt":47,"zipAvailable":48},[38,41,44],{"tool":39,"command":40},"npx","npx skills add Mr-Nobody-Anonymous\u002FAll-skills --skill bio-read-sequences",{"tool":42,"command":43},"bunx","bunx skills add Mr-Nobody-Anonymous\u002FAll-skills --skill bio-read-sequences",{"tool":45,"command":46},"pnpm","pnpm dlx skills add Mr-Nobody-Anonymous\u002FAll-skills --skill bio-read-sequences","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fbiology\u002Fbio-read-sequences\u002FSKILL.md",true,[50,56,60,64,68,72,78,82,86,90,96],{"path":51,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":54,"sourceHtmlUrl":55},"examples\u002Faccess_patterns.py","SCRIPT","脚本",1512,"https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fbiology\u002Fbio-read-sequences\u002Fexamples\u002Faccess_patterns.py",{"path":57,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":58,"sourceHtmlUrl":59},"examples\u002Fbasic_parsing.py",932,"https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fbiology\u002Fbio-read-sequences\u002Fexamples\u002Fbasic_parsing.py",{"path":61,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":62,"sourceHtmlUrl":63},"examples\u002Ffastq_quality.py",939,"https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fbiology\u002Fbio-read-sequences\u002Fexamples\u002Ffastq_quality.py",{"path":65,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":66,"sourceHtmlUrl":67},"examples\u002Fgenbank_features.py",855,"https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fbiology\u002Fbio-read-sequences\u002Fexamples\u002Fgenbank_features.py",{"path":69,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":70,"sourceHtmlUrl":71},"examples\u002Frandom_access.py",1018,"https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fbiology\u002Fbio-read-sequences\u002Fexamples\u002Frandom_access.py",{"path":73,"resourceType":74,"resourceTypeDesc":75,"sizeBytes":76,"sourceHtmlUrl":77},"examples\u002Fsample.fasta","OTHER","其他",277,"https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fbiology\u002Fbio-read-sequences\u002Fexamples\u002Fsample.fasta",{"path":79,"resourceType":74,"resourceTypeDesc":75,"sizeBytes":80,"sourceHtmlUrl":81},"examples\u002Fsample.fastq",415,"https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fbiology\u002Fbio-read-sequences\u002Fexamples\u002Fsample.fastq",{"path":83,"resourceType":74,"resourceTypeDesc":75,"sizeBytes":84,"sourceHtmlUrl":85},"examples\u002Fsample.gb",882,"https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fbiology\u002Fbio-read-sequences\u002Fexamples\u002Fsample.gb",{"path":87,"resourceType":74,"resourceTypeDesc":75,"sizeBytes":88,"sourceHtmlUrl":89},"examples\u002Fsingle.fasta",106,"https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fbiology\u002Fbio-read-sequences\u002Fexamples\u002Fsingle.fasta",{"path":91,"resourceType":92,"resourceTypeDesc":93,"sizeBytes":94,"sourceHtmlUrl":95},"tests.json","REFERENCE","参考文档",2694,"https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fbiology\u002Fbio-read-sequences\u002Ftests.json",{"path":97,"resourceType":92,"resourceTypeDesc":93,"sizeBytes":98,"sourceHtmlUrl":99},"usage-guide.md",3488,"https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fbiology\u002Fbio-read-sequences\u002Fusage-guide.md",[101,109,116,123,130,137],{"skillNo":102,"name":103,"nameZh":6,"description":104,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":105,"categories":106,"keywords":107,"publishedAt":108},"01M7FFFZPC2025JQQHPHDX154J","dei-assessment","Assess diversity, equity, and inclusion with metrics. TRIGGERS - Use when user needs help with dei-assessment related tasks.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fdei-assessment\u002FSKILL.md",[],[],"2026-11-16 10:05:34",{"skillNo":110,"name":111,"nameZh":6,"description":112,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":113,"categories":114,"keywords":115,"publishedAt":108},"01M7FFFWN8H4WA7A6Y398QKB6J","dei-action-plan","Create DEI action plans with goals and initiatives. TRIGGERS - Use when user needs help with dei-action-plan related tasks.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fdei-action-plan\u002FSKILL.md",[],[],{"skillNo":117,"name":118,"nameZh":6,"description":119,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":120,"categories":121,"keywords":122,"publishedAt":108},"01M7FFFSHTM0QZRVZ2NRJTJ0PY","culture-fit-assessment","Design culture add assessment processes. TRIGGERS - Use when user needs help with culture-fit-assessment related tasks.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fculture-fit-assessment\u002FSKILL.md",[],[],{"skillNo":124,"name":125,"nameZh":6,"description":126,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":127,"categories":128,"keywords":129,"publishedAt":108},"01M7FFFMA12RKEQA38KHJSXXPS","cowork-to-code-bridge","Use an already-installed, independently verified cowork-to-code bridge to run narrowly approved actions on the user's own macOS, Linux, or WSL2 machine through a local file queue.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fcowork-to-code-bridge\u002FSKILL.md",[],[],{"skillNo":131,"name":132,"nameZh":6,"description":133,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":134,"categories":135,"keywords":136,"publishedAt":108},"01M7FFFH1F6M8YRGW5V487GH1K","counter-offer-response","Draft counter-offer responses for retention. TRIGGERS - Use when user needs help with counter-offer-response related tasks.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fcounter-offer-response\u002FSKILL.md",[],[],{"skillNo":138,"name":139,"nameZh":6,"description":140,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":141,"categories":142,"keywords":143,"publishedAt":108},"01M7FFFDGEHV8Y7J9N40HZXW52","continuous-feedback-system","Design continuous feedback systems. TRIGGERS - Use when user needs help with continuous-feedback-system related tasks.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fcontinuous-feedback-system\u002FSKILL.md",[],[]]