Amherst College I.T. I.T. home. Amherst College.
I.T. home.
ATS > Software > Scientific Programming with Python > Bioinformatics

Scientific Programming with Python

Part 4: Bioinformatics

Previous: Newton’s Laws of Motion

Current: Bioinformatics

Next: Simulating a Magnet


Biopython provides a number of tools useful for studying genetic sequencing.

Topics


Installing Biopython

Biopython is available through the Anaconda distribution, but is not installed by default.


The Conda Installer

Anaconda provides a wide variety of scientific packages, and has its own installer or package manager, called conda, which lets you install many more (see the complete list).

Generally speaking, if you are installing specialized software that may depend on a lot of other software, it’s a good idea to first create a conda environment, which will isolate these packages and even let you use different versions of python (e.g. because a package hasn’t been updated for newer versions).

Procedure 1: Setting Up a Conda Environment

Working with Conda requires using a shell, a command-line interpreter that is available on both Macs and Windows;

  1. Launch a shell:
    • On Windows: Menu Start> Anaconda3 > Anaconda PowerShell Prompt.
    • On Macs: Navigate to the folder Applications and then the folder Utilities, and open the application Terminal.

    A window will appear with a text prompt that looks something like:

    (base) ~ username$

    If (base) appears, it represents a conda default environment, i.e. the one created by Anaconda.

    Commands are typed after the $, always followed by pressing the key return (Macs) or Enter (Windows) to submit them for execution.

  2. Create a conda environment by typing, for example:
  3. conda create -n biopython

    Conda will provide some setup information and then ask if you want to Proceed ([y]/n)?; type y.

  4. Activate this environment, for example:
  5. conda activate biopython

    Your prompt will now show this environment at its beginning, for example:

    (biopython) ~ username$

  6. Install other packages into this environment, for example:
  7. conda install biopython

    Again, Conda will provide some setup information and then ask if you want to Proceed ([y]/n)?; type y.

  8. Test that the package is available by running Python and loading one of its modules, for example:
  9. python
    import Bio

    If the package is properly installed, there will be no response. Type exit() or ctrl-D to leave Python.

  10. Also any other packages you might need, e.g. matplotlib
  11. conda install matplotlib

  12. To use a new environment with Spyder:
    1. Install Spyder components in the environment:
    2. conda install spyder-kernels=2.5

      The version assignment seen here will install the appropriate version of this package for version 5 of Spyder, which is provided with the 2025 version of Anaconda.

    3. Quit Spyder if it’s open.
    4. Open Spyder.
    5. Menu python > Preferences….
    6. In the dialog Preferences, in the left-side list, choose Python interpretor:

    7. In the section Python Interpreter, click on the button Use the following Python interpreter:.
    8. In the menu of possible interpreters, all of your environments will be listed (note they will all be in a subfolder named envs). Select the option for your new environment, e.g. /opt/anaconda3/envs/biopython/bin/python.
    9. Click on the button OK to both apply these changes and close the dialog.
    10. In the pane iPython Console, in the upper right corner, menu ꠵ Options > Restart kernel.
    11. Test that the environment and package(s) you just installed are available in Spyder by loading one of its modules, e.g.:
    12. import Bio

      If the environment and package(s) are properly installed, there will be no response.

  13. To return to the base environment in the shell, deactivate the current environment, for example:
  14. conda deactivate biopython

Now you can start up Spyder and import Biopython in IPython:

import biopython as bp

For today, we’ll follow this tutorial.


Previous:
Newton’s Laws of Motion

Scientific Programming with Python:
Bioinformatics

Next:
Simulating a Magnet

Top of Page  | Using IT DocumentationIT Home  |  IT Site Map  |  Search IT