FazBrowse Wikipedia Viewer | Main Page |
Search Wikipedia:
|
Viewing: https://en.wikipedia.org/wiki/BioPython

Biopython

Contents
    Sequences
    Sequence annotation
    Population genetics
    Wrappers for command line tools
See also
References

"},"released":{"wt":"{{Start date and age|df=yes|2002|12|17}}"},"latest release version":{"wt":"v1.87"},"latest release date":{"wt":"{{Start date and age|2026|03|30}}"},"programming language":{"wt":"[[Python (programming language)|Python]], [[C (programming language)|C]]"},"platform":{"wt":"[[Cross platform]]"},"genre":{"wt":"[[Bioinformatics]]"},"license":{"wt":"[[BSD licenses#3-clause license (\"BSD License 2.0\", \"Revised BSD License\", \"New BSD License\", or \"Modified BSD License\")|BSD 3-clause license]]"},"website":{"wt":"{{Official URL}}"},"repo":{"wt":"{{wikidata|property|reference|edit|P1324}}"}},"i":0}}]}'>
Biopython
Original authorsChapman B, Chang J
Release17 December 2002;23 years ago (2002-12-17)
https://github.com/biopython/biopython.github.io 
This article is part of a series on
Python
Python logo
>>> # The code reads a GenBank file record-by-record to efficiently handle large sequence files without exhausting memory. It converts each sequence record into FASTA format and writes it to a new output file. >>> fromBioimport SeqIO >>> # Reading sequences from a GenBank file and writing to a FASTA file >>> input_file = "sequence_1.gb" >>> output_file = "converted_sequences.fasta" >>> # Using iterator to read large file without loading all into memory >>> with open(output_file, "w") as out_handle: ... for record in SeqIO.parse(input_file, "genbank"): ... # Each record is a SeqRecord populated with metadata ... print(f"Processing record: {record.id} - {record.description}") ... SeqIO.write(record, out_handle, "fasta") # Convert and write to FASTA

Sequences

edit

A core concept in Biopython is the biological sequence, and this is represented by the Seq class. A Biopython Seq object is similar to a Python string in many respects: it supports the Python slice notation, can be concatenated with other sequences and is immutable. This object includes both general string-like and biological sequence-specific methods. It is best to store information about the biological type (DNA, RNA, protein) separately from the sequence, rather than using an explicit alphabet argument.

>> # This script creates a DNA sequence and performs some typical manipulations\n\n>>> from Bio.Seq import Seq\n>>> dna_sequence = Seq(\"AGGCTTCTCGTA\")\n>>> print(dna_sequence)\nSeq('AGGCTTCTCGTA')\n\n>>> print(dna_sequence[2:7])\nSeq('GCTTC')\n\n>>> print(dna_sequence.reverse_complement())\nSeq('TACGAGAAGCCT')\n\n>>> rna_sequence = dna_sequence.transcribe()\n>>> print(rna_sequence)\nSeq('AGGCUUCUCGUA')\n\n>>> print(rna_sequence.back_transcribe())\nSeq('AGGCTTCTCGTA')\n\n>>> print(rna_sequence.translate())\nSeq('RLLV')\n"}}'>>>> # This script creates a DNA sequence and performs some typical manipulations >>> fromBio.Seqimport Seq >>> dna_sequence = Seq("AGGCTTCTCGTA") >>> print(dna_sequence) Seq('AGGCTTCTCGTA') >>> print(dna_sequence[2:7]) Seq('GCTTC') >>> print(dna_sequence.reverse_complement()) Seq('TACGAGAAGCCT') >>> rna_sequence = dna_sequence.transcribe() >>> print(rna_sequence) Seq('AGGCUUCUCGUA') >>> print(rna_sequence.back_transcribe()) Seq('AGGCTTCTCGTA') >>> print(rna_sequence.translate()) Seq('RLLV')

Sequence annotation

edit

The SeqRecord class describes sequences, along with information such as name, description and features in the form of SeqFeature objects. Each SeqFeature object specifies the type of the feature and its location. Feature types can be ‘gene’, ‘CDS’ (coding sequence), ‘repeat_region’, ‘mobile_element’ or others, and the position of features in the sequence can be exact or approximate.

>>> # This script parses a PDB file to print the first model’s chain IDs and extract coordinates of atoms in the 100th residue of each chain. It demonstrates navigating protein structure hierarchy and accessing specific residue data. >>> fromBio.PDBimport PDBParser >>> # Parse the PDB file >>> parser = PDBParser(QUIET=True) >>> structure = parser.get_structure("2yox", "2yox.pdb") >>> # Iterate over models >>> for model in structure: >>> print(f"Model ID: {model.id}") >>> # Iterate over chains in the model >>> for chain in model: ... print(f" Chain ID: {chain.id}") >>> # Check if residue 100 exists in this chain >>> if 100 in chain: ... residue = chain[100] ... print(f" Coordinates of atoms in residue 100:") ... # Print coordinates of each atom in residue 100 ... for atom in residue: ... print(atom.coord) ... else: ... print(" Residue 100 not found in this chain.") ... break Model ID: 0 Chain ID: A Coordinates of atoms in residue 100: [ 9.837 18.218 81.24 ] [ 9.644 18.809 79.938] [ 8.772 20.066 80.01 ] [ 7.572 19.996 80.27 ] [ 9.07 17.788 78.962] [ 8.989 18.261 77.529] [10.352 18.647 76.938] [11.281 17.832 76.922] [10.486 19.917 76.503] Chain ID: B Coordinates of atoms in residue 100: [23.712 13.531 36.955] [23.197 12.95 35.746] [23.961 11.693 35.339] [25.138 11.757 34.935] [23.183 13.97 34.623] [22.49 13.49 33.361] [21.022 13.13 33.571] [20.22 13.96 34.039] [20.66 11.867 33.253]

Population genetics

edit

The Bio.PopGen module adds support to Biopython for Genepop, a software package for statistical analysis of population genetics. This allows for analyses of Hardy–Weinberg equilibrium, linkage disequilibrium and other features of a population's allele frequencies.

This module can also carry out population genetic simulations using coalescent theory with the fastsimcoal2 program.

Wrappers for command line tools

edit

Biopython previously included command-line wrappers for tools such as BLAST, Clustal, EMBOSS, and SAMtools. This option allowed users to run external tool commands from within the code using specialized Biopython classes.

However, Bio.Application modules and their wrappers have deprecated and will be removed in future Biopython releases. The main reason for this is the high maintenance burden of updating them with the evolving external tools.

The recommended approach is to directly construct and execute command-line tool commands using Python’s built-in subprocess module. This method provides flexibility and removes the dependency on the Biopython wrappers. subprocess is a native Python module useful for running external commands, programs, and capturing their output.

See also

edit

References

edit
"Introduction — Biopython 1.85 documentation". biopython.org. Retrieved 15 August 2025.
  • 1 2 Knight, R; Maxwell, P; Birmingham, A; Carnes, J; Caporaso, J. G.; Easton, B. C.; Eaton, M; Hamady, M; Lindsay, H; Liu, Z; Lozupone, C; McDonald, D; Robeson, M; Sammut, R; Smit, S; Wakefield, M. J.; Widmann, J; Wikman, S; Wilson, S; Ying, H; Huttley, G. A. (2007). "Py Cogent: A toolkit for making sense from sequence". Genome Biology. 8 (8): R171. doi:10.1186/gb-2007-8-8-r171. PMC 2375001. PMID 17708774.
  • ↑ "Biopython". GitHub.
  • ↑ Talevich, Eric; Invergo, Brandon M; Cock, Peter JA; Chapman, Brad A (21 August 2012). "Bio.Phylo: A unified toolkit for processing, analyzing and visualizing phylogenetic trees in Biopython". BMC Bioinformatics. 13 (209): 209. doi:10.1186/1471-2105-13-209. PMC 3468381. PMID 22909249.
  • ↑ Hamelryck, Thomas; Manderick, Bernard (10 May 2003). "PDB file parser and structure class implemented in Python". Bioinformatics. 19 (17): 2308–2310. doi:10.1093/bioinformatics/btg299. PMID 14630660.
  • ↑ Excoffier, Laurent; Foll, Matthieu (1 March 2011). "fastsimcoal: a continuous-time coalescent simulator of genomic diversity under arbitrarily complex evolutionary scenarios". Bioinformatics. 27 (9): 1332–1334. doi:10.1093/bioinformatics/btr124. PMID 21398675.
  • ↑

  • View original on Wikipedia | Back | FazBrowse Home