Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

A package for mapping biological data onto protein PDB structures

Project Description


Biostructmap is a Python tool for mapping sequence-aligned data (such as location of polymorphisms) onto a protein structure.

Additionally, biostructmap allows for the incorporation of residue spatial-proximity into sliding-window calculations, and can be used to incorporate protein structure information into genetic tests of selection pressure.

Table of Contents

Getting Started

Usage Examples

Calculate proportion of polymorphic residues within a radius

A simple usage case may be identification of regions of the protein with a high percentage of polymorphic residues. If we are perhaps interested in antibody-antigen interaction, 15 Angstrom is a reasonable radius over which to average over.

import biostructmap

# Initialise structure object
structure = biostructmap.Structure('1zrl.pdb', 'test_pdb_name')

# The location of known polymorphisms relative to the PDB sequence (we are not
# providing a reference sequence for this example), for each chain.
data = {('A',): [200, 276, 300, 480, 367, 349]}

# Map polymorphism data using a radius of 15 Angstrom. Results are returned
# in a new object.
results =, method='snps', ref=None, radius=15)

# Use the results object to write data to a local PDB file, with data saved
# in the B-factor column

Calculation of average hydrophobicity for all surface exposed residues

A slighly more complicated usage case may be the calculation of an average amino acid propensity scale, such as the Kyte & Doolittle index of hydrophobicity. Additionally, if we are solely interested in surface exposed residues, we may wish to restrict analysis to only residues with a relative solvent accessibility greater than 0.2.

import biostructmap

# Initialise structure object
structure = biostructmap.Structure('1zrl.pdb', 'test_pdb_name')

# For this method, the data parameter is a string which represents the amino
# acid propensity scale we wish to use. Note the use of the optional rsa_range
# parameter to restrict to surface exposed residues.
results ='kd', method='aa_scale', ref=None, radius=15,
                    rsa_range=(0.2, 1.0))

# Use the results object to write data to a local PDB file, with data saved
# in the B-factor column

Calculation of Tajima’s D using protein structural information

We can also use the biostructmap package to calculate a modified Tajima’s D value which incorporates protein structural information — essentially using a 3D sliding window instead of the standard 2D sliding window often applied over a protein sequence.

import biostructmap

# Initialise structure object
structure = biostructmap.Structure('1zrl.pdb', 'test_pdb_name')

# Read in multiple sequence alignment data
msa_data = biostructmap.SequenceAlignment('seq_align.fsa')
data = {('A',): msa_data}

# Reference seq might be the first sequence in the multiple sequence alignment
reference_seq = {'A': str(msa_data[0].seq)}

results =, method='tajimasd', ref=reference_seq,
                    radius=15, map_to_dna=True)


Result can be easily viewed in PyMol using the spectrum command.

From the Pymol command line:

load my_pdb_file_name_here

as surface

#Select all residues with a mapped data value. Can change the default 'no-value'
#option when writing to pdb b factor using biostructmap if needed.
select nonzeros, b < 0 | b > 0

color white

spectrum b, selection=nonzeros

#Make a publication quality image. May need to center molecule and perhaps
#adjust image size to your requirements.
set ray_opaque_background, off
ray 2400, 2400
cmd.png('output_file_name.png', dpi=300)


Installing the biostructmap package requires both an install of the main package, as well as optional install of a few external binaries (NCBI BLAST+, Exonerate and DSSP).


To install the BLAST+ package, visit the NCBI BLAST+ site and follow the links to download and install a local copy of the BLAST+ application.

BLAST+ is not required, but is recommended. If BLAST+ is not installed, a fallback pairwise alignment is performed using BioPython.pairwise2, and the user should indicate that BLAST+ is not installed by including:

import biostructmap

biostructmap.seqtools.LOCAL_BLAST = False


To install DSSP, visit the DSSP website and follow the instructions for install. Alternatively, users of recent Ubuntu or Debian distributions will find that DSSP is available as part of these distributions. To check if DSSP is currently installed under Linux, try running:

dssp --version || mkdssp --version

At least one of these should return version 2.x.x

If DSSP is not installed, you can try installing dssp using your local package manager. For example, on Ubuntu:

sudo apt-get install dssp

If this fails you will have to install DSSP from the source code provided here.

DSPP is not strictly required, but any analysis that involves calculation of secondary structure or solvent accessibility will raise an exception if DSSP is not installed.


To install Exonerate, visit the Exonerate website and follow the instructions to install Exonerate on your system. Alternatively, Exonerate is available through the default Ubuntu repositories:

sudo apt-get install exonerate

Note that Exonerate is only required if performing calculation of Tajima’s D over a protein structure using a multiple sequence alignment - it is used to align a genomic sequence to a protein coding region. If this functionality is not required, then biostructmap can be installed and run without Exonerate, although some of the tests will fail.

If Exonerate is not installed, a fallback pairwise alignment is performed using BioPython.pairwise2, and the user should indicate that Exonerate is not installed by including:

import biostructmap

biostructmap.seqtools.LOCAL_EXONERATE = False


Before install biostructmap it is recommended to install Numpy using your Python package manager of choice (eg pip or conda). If you are using the Anaconda distribution of Python, then Numpy should be installed already. If not, or if you are using a virtual environment:

conda install numpy


pip install numpy


To install the biostructmap package, it is first recommended that you make sure all tests pass in your environment.

From the root package directory, run:

python test

If these tests pass, you can then install the package (or just skip straight to this step if you’re feeling lucky):

python install

Running the tests

From the root package directory run:

python test

or alternatively


These tests should cover most of the biostructmap functionality, with several tests reliant on additional packages such as NCBI BLAST+ or DSSP, which should be installed alongside biostructmap.

biostructmap was developed for Python 3+, but also supports Python 2.7. Please contact us if any compatibility issues are observed with older versions of Python.


Please read CONTRIBUTING.rst for details on our code of conduct, and the process for submitting pull requests to us.


We use SemVer for versioning. For the versions available, see the tags on this repository.


See also the list of contributors who participated in this project.


This project is licensed under the MIT License - see the LICENSE.txt file for details


  • Paul Ramsland, Jack Richards and Vashti Irani for various suggestions and support.
v0.2.3, 2017-10-26 – Add scipy distance calculation back in as an option if scipy present.
  • Added scipy distance calculation back. Numpy implementation was a memory hog, so will use scipy if present.
v0.2.2, 2017-10-24 – Remove Scipy dependency and refactor calls to DSSP
  • Removed SciPy dependency, which simplifies install process.
  • DSSP is only called if it is required, for example when there is a need to calculate secondary structure or solvent accessibility.
  • Also removed redundant methods for writing output data to file.
  • Updated README to reflect optional requirements for BLAST+, Exonerate and DSSP.

v0.2.1post1, 2017-10-24 – Include CHANGES.txt in distributed files (oops!)

v0.2.1, 2017-10-24 – Minor changes to documentation and distribution

v0.2.0, 2017-10-24 – Major update, first release since making biostructmap public.
  • Added features: * Additional genetic tests (Watterson’s theta, nucleotide diversity) * Added multi-chain support. This allows mapping of data from different chains. * Some code refactoring was performed. map method is now available from the Structure class, not each individual Chain.
  • Data requirements altered slightly. Each data object should be associated with a particular set of structure chains e.g. {(‘A’, ‘B’): data_1, (‘C’,): data_2}
  • Reference sequences should be provided for each chain: {‘A’: seq_1, ‘B’: seq_1, ‘C’: seq_2}

v0.1.1, 2016-02-24 – Some bug fixes

v0.1.0, 2016-02-12 – Initial Release

Release History

Release History

This version
History Node


History Node


History Node


History Node


Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
biostructmap-0.2.3.tar.gz (32.0 kB) Copy SHA256 Checksum SHA256 Source Oct 26, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting