Content
Summary
This lesson covers the tools and Python methods for retrieving and processing genomic data, specifically focusing on genome browsers like Gbrowse and JBrowse, and parsing FASTA and GFF files. It details the workflow for extracting coding sequences (CDS) from specific transcripts, handling strand orientation, and translating DNA to protein.
Intuition
To work with genomic data in Python, you first need to understand how data is stored and accessed. Genome browsers like Gbrowse and JBrowse help visualize this data, with Gbrowse supporting scalable exports and JBrowse offering faster, asynchronous loading. In Python, we use dictionaries to map chromosome names to their nucleotide sequences for rapid lookup. When processing annotations from GFF files, we must carefully filter for specific transcripts and handle coordinate systems correctly, remembering that GFF uses 1-based indexing while Python uses 0-based indexing. Finally, strand orientation dictates whether we need to reverse complement sequences before translation.
Derivation
- Genomic data is visualized using tools like Gbrowse (scalable export) or JBrowse (asynchronous loading, PNG export only).
- FASTA files are parsed using Bio.SeqIO, creating a Python dictionary where chromosome names (keys) map to nucleotide sequences (values).
- GFF files are parsed line-by-line, skipping comment lines starting with '#'.
- Valid GFF lines are split into nine fields; entries are filtered for 'CDS' sequence type and a specific transcript ID.
- Start and stop positions are converted from strings to integers immediately to allow numerical operations.
- For negative strand genes, the list of exon coordinates is sorted in reverse order.
- CDS sequences are extracted using 0-based indexing by subtracting 1 from the 1-based GFF start position.
- For negative strand genes, reverse complements of extracted CDS segments are generated.
- All CDS segments are concatenated into a single ORF string.
- The ORF is transcribed to RNA and translated to protein using Bio.Seq methods.
Worked example
You have a GFF file entry for a CDS on the negative strand: chromosome 'chr2L', start 100, stop 200, strand '-'. How do you extract the sequence from a Python genome dictionary genome where keys are chromosome names and values are strings?
- Identify the strand is '-', so you must handle reverse complementation later.
- Convert start and stop from strings to integers: start=100, stop=200.
- Adjust for 0-based indexing: start_index = 100 - 1 = 99.
- Extract the sequence segment: segment = genome['chr2L'][99:200].
- Generate the reverse complement of the segment because the strand is negative.
- Concatenate this segment with others if part of a larger transcript.
Answer Extract genome['chr2L'][99:200], then take its reverse complement.
Common mistakes
- Using a gene ID instead of a transcript ID, which can result in multiple lines being printed due to multiple transcripts per gene.
- Failing to convert GFF start and stop positions from strings to integers, causing errors in numerical operations.
- Attempting to parse GFF lines containing hash symbols, which fail because they lack the expected tab-separated column structure.
- Ignoring the 1-based indexing of GFF files, leading to off-by-one errors when slicing Python sequences.
- Forgetting to reverse complement sequences for genes on the negative strand.