Biopython
≈ 7 min read
Names in other languages
No names in other languages are held for this entry yet.
Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.
Biopython is an open-source collection of non-commercial Python modules for computational biology and bioinformatics. It makes robust and well-tested code easily accessible to researchers. Python is an object-oriented programming language and is a suitable choice for automation of common tasks. The availability of reusable libraries saves development time and lets researchers focus on addressing scientific questions. Biopython is constantly updated and maintained by a large team of volunteers across the globe. Biopython contains parsers for diverse bioinformatic sequence, alignment, and structure formats. Sequence formats include FASTA, FASTQ, GenBank, and EMBL. Alignment formats include Clustal, BLAST, PHYLIP, and NEXUS. Structural formats include the PDB, which contains the 3D atomic coordinates of the macromolecules. It has provisions to access information from biological databases like NCBI, Expasy, PBD, and BioSQL. This can be used in scripts or incorporated into their software. Biopython contains a standard sequence class, sequence alignment, and motif analysis tools. It also has clustering algorithms, a module for structural biology, and a module for phylogenetics analysis.
Biopython is an open-source collection of non-commercial Python modules for computational biology and bioinformatics. It makes robust and well-tested code easily accessible to researchers. Python is an object-oriented programming language and is a suitable choice for automation of common tasks. The availability of reusable libraries saves development time and lets researchers focus on addressing scientific questions. Biopython is constantly updated and maintained by a large team of volunteers across the globe. Biopython contains parsers for diverse bioinformatic sequence, alignment, and structure formats. Sequence formats include FASTA, FASTQ, GenBank, and EMBL. Alignment formats include Clustal, BLAST, PHYLIP, and NEXUS. Structural formats include the PDB, which contains the 3D atomic coordinates of the macromolecules. It has provisions to access information from biological databases like NCBI, Expasy, PBD, and BioSQL. This can be used in scripts or incorporated into their software. Biopython contains a standard sequence class, sequence alignment, and motif analysis tools. It also has clustering algorithms, a module for structural biology, and a module for phylogenetics analysis. >>> # 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. >>> from Bio import 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 >>> # This script creates a DNA sequence and performs some typical manipulations >>> from Bio.Seq import 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') >>> # The script reads a GenBank file to extract and print the sequence’s name and description. It then accesses and displays detailed information about a specific annotated feature (e.g., a gene) within the sequence. >>> from Bio import SeqIO >>> seq_record = SeqIO.read("sequence.gb", "genbank") >>> # Access metadata >>> print(seq_record.name) >>> print(seq_record.description) 'NC_005816' 'Yersinia pestis biovar Microtus str. 91001 plasmid pPCP1, complete sequence' >>> # Access features list and example feature at index 14 if available >>> if len(seq_record.features) > 14: ... print(seq_record.features[14]) ... else: ... print("Feature index 14 not available") type: CDS location: [6115:6421](+) qualifiers: Key: codon_start, Value: ['1'] Key: inference, Value: ['COORDINATES: similar to AA sequence:RefSeq:WP_002221218.1'] Key: locus_tag, Value: ['YP_RS22235'] Key: note, Value: ['Derived by automated computational analysis using gene prediction method: Protein Homology.'] Key: old_locus_tag, Value: ['pPCP07', 'YP_pPCP07'] Key: product, Value: ['hypothetical protein'] Key: protein_id, Value: ['WP_002221218.1'] Key: transl_table, Value: ['11'] Key: translation, Value: ['MSKTKSGRHRLSKTDKRLLAALVVAGYEERTARDLIQKHVYTLTQADLRHLVSEISNGVGQSQAYDAIYQAR >>> # This code fetches nucleotide sequence records from the NCBI database for specified accession IDs, reads the GenBank-formatted data and prints the first two lines. The output can also be written to a file. >>> from Bio import Entrez >>> Entrez.email = "example@example.com" >>> record_ids = ["NM_000546.6", "NM_001354689.3"] >>> for record_id in record_ids: ... with Entrez.efetch(db="nucleotide", id=record_id, rettype="gb", retmode="text") as handle: ... line_count = 0 ... for line in handle: ... print(line.rstrip()) ... line_count += 1 ... if line_count == 2: # Print only first 2 lines of the record ... break LOCUS NM_000546 2512 bp mRNA linear PRI 12-JUN-2025 DEFINITION Homo sapiens tumor protein p53 (TP53), transcript variant 1, mRNA. LOCUS NM_001354689 3251 bp mRNA linear PRI 12-JUN-2025 DEFINITION Homo sapiens Raf-1 proto-oncogene, serine/threonine kinase (RAF1) >>> # 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. >>> from Bio.PDB import 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] ==References==
Text derived from https://en.wikipedia.org/w/index.php?oldid=1361406744 under CC BY-SA 4.0; modifications have been made.