# BioShell Python library¶

BioShell 3.0 comes also with Python bindings i.e. BioShell classes can be also used as Python modules. Let’s consider the following C++ program that reads a PDB file and writes a FASTA sequence for every chain:

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 #include #include #include int main(const int argc, const char *argv[]) { using namespace core::data::io; // Pdb and create_fasta_string lives there Pdb reader(argv[1], is_not_alternative, true); core::data::structural::Structure_SP strctr = (reader.create_structure(0)); // Iterate over all chains for (int ic = 0; ic < strctr->count_chains(); ++ic) std::cout << "> " << strctr->code() << (*strctr)[ic]->id() << "\n" // --- e.g. prints "> 2gb1 A" << (*strctr)[ic]->create_sequence()->sequence << "\n"; // --- prints the sequence itself } 

The same program written in Pyton looks much simpler. It calls nearly the same BioShell C++ objects as the one above, but due to simplicity of Python, the script is a bit shorter:

  1 2 3 4 5 6 7 8 9 10 11 import sys sys.path.append('../../../../../bin/') from pybioshell.core.data.io import find_pdb for pdb_fname in sys.argv[1:] : structure = find_pdb(pdb_fname, "./").create_structure(0) for ic in range(structure.count_chains()) : chain = structure[ic] print(">",structure.code(), chain.id()) print(chain.create_sequence().sequence) 

PyBioShell How-to