2.1. bcforms package

2.1.1. Submodules

2.1.2. bcforms.__main__ module

bcforms command line interface

Author

Jonathan Karr <karr@mssm.edu>

Date

2019-06-25

Copyright

2019, Karr Lab

License

MIT

class bcforms.__main__.App(label=None, **kw)[source]

Bases: cement.core.foundation.App

Command line application

class Meta[source]

Bases: object

base_controller = 'base'[source]
handlers = [<class 'bcforms.__main__.BaseController'>, <class 'bcforms.__main__.ValidateController'>, <class 'bcforms.__main__.GetFormulaController'>, <class 'bcforms.__main__.GetMolWtController'>, <class 'bcforms.__main__.GetChargeController'>][source]
label = 'bcforms'[source]
class bcforms.__main__.BaseController(*args, **kw)[source]

Bases: cement.ext.ext_argparse.ArgparseController

Base controller for command line application

class Meta[source]

Bases: object

arguments = [(['-v', '--version'], {'action': 'version', 'version': '0.0.2'})][source]
description = 'bcforms'[source]
help = 'bcforms'[source]
label = 'base'[source]
class bcforms.__main__.GetChargeController(*args, **kw)[source]

Bases: cement.ext.ext_argparse.ArgparseController

Calculate the total charge of a BcForm

Example:

bcforms get-charge 'abc_a + abc_b' '{abc_a:+1, abc_b:-1}'
class Meta[source]

Bases: object

arguments = [(['form'], {'type': <class 'str'>, 'help': 'input BcForm'}), (['subunit_charges'], {'type': <class 'str'>, 'help': 'dictionary of subunit charge'})][source]
description = 'Calculate the total charge of a BcForm'[source]
help = 'Calculate the total charge of a BcForm'[source]
label = 'get-charge'[source]
stacked_on = 'base'[source]
stacked_type = 'nested'[source]
class bcforms.__main__.GetFormulaController(*args, **kw)[source]

Bases: cement.ext.ext_argparse.ArgparseController

Calculate the chemical formula of a BcForm

Example:

bcforms get-formula 'abc_a + abc_b' '{abc_a:C5H10O, abc_b:C3H5O}'
class Meta[source]

Bases: object

arguments = [(['form'], {'type': <class 'str'>, 'help': 'input BcForm'}), (['subunit_formulas'], {'type': <class 'str'>, 'help': 'dictionary of subunit formulas'})][source]
description = 'Calculate the chemical formula of a BcForm'[source]
help = 'Calculate the chemical formula of a BcForm'[source]
label = 'get-formula'[source]
stacked_on = 'base'[source]
stacked_type = 'nested'[source]
class bcforms.__main__.GetMolWtController(*args, **kw)[source]

Bases: cement.ext.ext_argparse.ArgparseController

Calculate the molecular weight of a BcForm

Example

bcforms get-molwt ‘abc_a + abc_b’ ‘{abc_a:86, abc_b:57}’

class Meta[source]

Bases: object

arguments = [(['form'], {'type': <class 'str'>, 'help': 'input BcForm'}), (['subunit_mol_wts'], {'type': <class 'str'>, 'help': 'dictionary of subunit molecular weights'})][source]
description = 'Calculate the molecular weight of a BcForm'[source]
help = 'Calculate the molecular weight of a BcForm'[source]
label = 'get-molwt'[source]
stacked_on = 'base'[source]
stacked_type = 'nested'[source]
class bcforms.__main__.ValidateController(*args, **kw)[source]

Bases: cement.ext.ext_argparse.ArgparseController

Validate a biopolymer form

Example:

bcforms validate 'abc_a + abc_b'
class Meta[source]

Bases: object

arguments = [(['form'], {'type': <class 'str'>, 'help': 'BcForm to validate'})][source]
description = 'Validate a biocomplex form'[source]
help = 'Validate a biocomplex form'[source]
label = 'validate'[source]
stacked_on = 'base'[source]
stacked_type = 'nested'[source]
bcforms.__main__.main()[source]

2.1.3. bcforms.core module

BcForms

Author

Mike Zheng <xzheng20@colby.edu>

Author

Jonathan Karr <karr@mssm.edu>

Date

2019-06-25

Copyright

2019, Karr Lab

License

MIT

class bcforms.core.Atom(subunit, element, position, monomer, charge=0, subunit_idx=None, component_type=None)[source]

Bases: object

Atom in a crosslink

subunit[source]

id of subunit

Type

str

subunit_idx[source]

index of the subunit for homomers

Type

int

element[source]

code of the element

Type

str

position[source]

SMILES position of the atom within the compound

Type

int

monomer[source]

index of parent monomer

Type

int

charge[source]

charge of the atom

Type

int

component_type[source]

type of component the atom belongs to: either ‘monomer’ or ‘backbone’

Type

str

__str__()[source]

Generate a string representation

Returns

string representation

Return type

str

property charge[source]

Get the charge of the atom

Returns

charge

Return type

int

property component_type[source]

Get the type of component the atom belongs to

Returns

component type

Return type

str

property element[source]

Get the element of the atom

Returns

element

Return type

str

is_equal(other)[source]

Check if two atoms are semantically equal (belong to the same subunit/monomer and have the same element, position, and charge)

Parameters

other (Atom) – another atom

Returns

True, if the atoms are semantically equal

Return type

bool

property monomer[source]

Get the position in the subunit of the monomer that the atom belongs to

Returns

monomer position

Return type

int

property position[source]

Get the position of the atom in the compound

Returns

position

Return type

int

property subunit[source]

Get the subunit that the atom belongs to

Returns

subunit

Return type

str

property subunit_idx[source]

Get the index of the homomer of the subunit that the atom belongs to

Returns

subunit_idx or None

Return type

int

class bcforms.core.BcForm(subunits=None, crosslinks=None)[source]

Bases: object

A form of a macromolecular complex

subunits[source]

subunit composition of the complex

Type

list of Subunit

crosslinks in the complex

Type

list Crosslink

__str__()[source]

Generate a string representation

Returns

string representation of complex

Return type

str

clean()[source]

Clean up the subunits and the crosslinks

For example, convert 1 * a + 1 * a to 2 * a

property crosslinks[source]

Get the crosslinks

Returns

crosslinks

Return type

list of Crosslink

export(format='smiles', options=[])[source]

Export the structure to string

Parameters
  • format (str, optional) – export format

  • options (list, optional) – export options

Returns

exported string representation of the structure

Return type

str

file = <_io.TextIOWrapper name='/root/project/bcforms/grammar.lark' mode='r' encoding='UTF-8'>[source]
from_set(subunits)[source]

Set the subunits from a list of subunits

Note: this method does not support crosslinks

Parameters

subunits

(list): list representation of a complex. For example:

[
    {'id': 'ABC_A', 'stoichiometry': 2},
    {'id': 'ABC_B', 'stoichiometry': 3},
]

Returns

this complex

Return type

BcForm

Raises
  • ValueError – subunit has no ‘id’ key

  • ValueError – subunit has no ‘stoichiometry’ key

from_str(string)[source]

Set a complex from a string representation

Parameters

string (str) – string representation of a complex

Returns

structured BcForm representation of the string

Return type

BcForm

get_charge(subunit_charges=None)[source]

Get the total charge

  • If user wants to calculate charge of nested BcForm, where some subunits are BcForm objects, then the subunit BcForms must be able to calculate its own charge through structure

Parameters

subunit_formulas (dict or None) – dictionary of subunit ids and charges

Returns

the total charge of the BcForm

Return type

int

Raises
  • ValueError – subunit_charges does not include all subunits

  • ValueError – Not all subunits have defined charge

get_formula(subunit_formulas=None)[source]

Get the empirical formula

  • If user wants to calculate formula of nested BcForm, where some subunits are BcForm objects, then the subunit BcForms must be able to calculate its own formula through structure

Parameters

subunit_formulas (dict or None) – dictionary of subunit ids and empirical formulas

Returns

the empirical formula of the BcForm

Return type

EmpiricalFormula

Raises
  • ValueError – subunit formulas does not include all subunits

  • ValueError – Not all subunits have defined formula

get_genomic_image(seq_features=None, width=1200, cols=2, nt_per_track=80, **kwargs)[source]

Get a genomic visualization of the BpForm

Parameters
  • seq_features (dict) –

    list of features each represented by a dictionary with three keys

    • label (str): description of the type of feature

    • color (str): color

    • positions (list of list of int): list of position ranges of the type of feature

  • width (int, optional) – width

  • cols (int, optional) – number of columns of polymers

  • nt_per_track (int, optional) – number of nucleotides per track

The method also accepts the same arguments as

bpforms.util.gen_genomic_viz.

Returns

SVG image

Return type

str

get_mol_wt(subunit_mol_wts=None)[source]

Get the molecular weight

  • If user wants to calculate molecular weight of nested BcForm, where some subunits are BcForm objects, then the subunit BcForms must be able to calculate its own molecular weight through structure

Parameters

subunit_formulas (dict or None) – dictionary of subunit ids and molecular weights

Returns

the molecular weight of the BcForm

Return type

float

Raises
  • ValueError – subunit_mol_wts does not include all subunits

  • ValueError – Not all subunits have defined molecular weight

get_structure()[source]

Get an Open Babel molecule of the structure

Returns

Open Babel molecule of the structure

Return type

openbabel.OBMol

get_subunit_attribute(subunit_id, attribute)[source]

Set attribute (stoichiometry, structure) of subunit by id

Parameters
  • subunit_id (str) – id of subunit

  • attribute (str) – attribute to set

Returns

int for stoichiometry, bpforms.BpForm, openbabel.OBMol, or None for structure

Raises
  • ValueError – No Subunit with subunit_id

  • ValueError – Invalid attribute

is_equal(other)[source]

Check if two complexes are semantically equal (same subunits and crosslinks)

Parameters

other (BcForm) – another complex

Returns

True, if the complexes are semantically equal

Return type

bool

set_subunit_attribute(subunit_id, attribute, value)[source]

Set attribute (stoichiometry, structure) of subunit by id

Parameters
  • subunit_id (str) – id of subunit

  • attribute (str) – attribute to set

  • value (int for stoichiometry, bpforms.BpForm, openbabel.OBMol, or None for structure) – value

Raises
  • ValueError – No Subunit with subunit_id

  • ValueError – Invalid attribute

property subunits[source]

Get the subunits

Returns

subunits

Return type

list of Subunit or BcForm

validate()[source]

Check if the BcForm is valid

  • Check if the crosslinking subunit is in the subunit list and if the subunit_idx is valid

Returns

list of errors, if any

Return type

list of str

Bases: abc.ABC

Abstract class of a crosslink between subunits

abstract __str__()[source]

Generate a string representation

Returns

string representation

Return type

str

abstract get_l_bond_atoms()[source]

Get the left bond atoms

Returns

left bond atoms

Return type

list of Atom

abstract get_l_displaced_atoms()[source]

Get the left displaced atoms

Returns

left displaced atoms

Return type

list of Atom

abstract get_order()[source]

Get the order

Returns

order

Return type

BondOrder

abstract get_r_bond_atoms()[source]

Get the right bond atoms

Returns

right bond atoms

Return type

list of Atom

abstract get_r_displaced_atoms()[source]

Get the right displaced atoms

Returns

right displaced atoms

Return type

list of Atom

abstract get_stereo()[source]

Get the stereochemistry

Returns

stereochemistry

Return type

BondStereo

is_equal(other)[source]

Check if two crosslinks are semantically equal (have the same bond atoms)

Parameters

other (Crosslink) – another crosslink

Returns

True, if the crosslinks are semantically equal

Return type

bool

Bases: bcforms.core.Crosslink

A crosslink between subunits defined inline

l_bond_atoms[source]

atoms from the left subunit that bond with the right subunit

Type

list of Atom

r_bond_atoms[source]

atoms from the right subunit that bond with the left subunit

Type

list of Atom

l_displaced_atoms[source]

atoms from the left subunit displaced by the crosslink

Type

list of Atom

r_displaced_atoms[source]

atoms from the right subunit displaced by the crosslink

Type

list of Atom

order[source]

order

Type

BondOrder

stereo[source]

stereochemistry

Type

BondStereo

comments[source]

comments

Type

str

__str__()[source]

Generate a string representation

Returns

string representation

Return type

str

property comments[source]

Get comments

Returns

comments

Return type

str

get_l_bond_atoms()[source]

Get the left bond atoms

Returns

left bond atoms

Return type

list of Atom

get_l_displaced_atoms()[source]

Get the left displaced atoms

Returns

left displaced atoms

Return type

list of Atom

get_order()[source]

Get the order

Returns

order

Return type

BondOrder

get_r_bond_atoms()[source]

Get the right bond atoms

Returns

right bond atoms

Return type

list of Atom

get_r_displaced_atoms()[source]

Get the right displaced atoms

Returns

right displaced atoms

Return type

list of Atom

get_stereo()[source]

Get the stereochemistry

Returns

stereochemistry

Return type

BondStereo

property l_bond_atoms[source]

Get the left bond atoms

Returns

left bond atoms

Return type

list of Atom

property l_displaced_atoms[source]

Get the left displaced atoms

Returns

left displaced atoms

Return type

list of Atom

property order[source]

Get the order

Returns

order

Return type

BondOrder

property r_bond_atoms[source]

Get the right bond atoms

Returns

right bond atoms

Return type

list of Atom

property r_displaced_atoms[source]

Get the right displaced atoms

Returns

right displaced atoms

Return type

list of Atom

property stereo[source]

Get the stereochemistry

Returns

stereochemistry

Return type

BondStereo

Bases: bcforms.core.Crosslink

A pre-defined crosslink between subunits

type[source]

type of the pre-defined crosslink

Type

str

l_subunit[source]

name of the left subunit

Type

str

l_subunit_idx[source]

index of the left subunit, optional if only one copy of the subunit

Type

int, optional

l_monomer[source]

index of the monomer from the left subunit

Type

int

r_subunit[source]

name of the left subunit

Type

str

r_subunit_idx[source]

index of the left subunit, optional if only one copy of the subunit

Type

int, optional

r_monomer[source]

index of the monomer from the right subunit

Type

int

detailed information about the abstracted crosslink

Type

tuple

lark grammar parser used to parse atom strings

Type

lark.Lark

class ParseTreeTransformer(visit_tokens=False)[source]

Bases: lark.visitors.Transformer

atom_charge(*args)[source]
atom_element(*args)[source]
atom_position(*args)[source]
start(*args)[source]
__str__()[source]

Generate a string representation

Returns

string representation

Return type

str

get_details()[source]

Get the full details of the crosslink in a dictionary

Returns

detailed information of the crosslink

Return type

dict

Raises

KeyError – Unknown abstracted crosslink type

get_l_bond_atoms()[source]

Get the left bond atoms

Returns

left bond atoms

Return type

list of Atom

get_l_displaced_atoms()[source]

Get the left displaced atoms

Returns

left displaced atoms

Return type

list of Atom

get_order()[source]

Get the order

Returns

order

Return type

BondOrder

get_r_bond_atoms()[source]

Get the right bond atoms

Returns

right bond atoms

Return type

list of Atom

get_r_displaced_atoms()[source]

Get the right displaced atoms

Returns

right displaced atoms

Return type

list of Atom

get_stereo()[source]

Get the stereochemistry

Returns

stereochemistry

Return type

BondStereo

property l_monomer[source]

Get the index of the left monomer in the crosslink

Returns

index of the left monomer

Return type

int

property l_subunit[source]

Get the name of the left subunit in the crosslink

Returns

name of the left subunit

Return type

str

property l_subunit_idx[source]

Get the index of the left subunit in the crosslink

Returns

index of the left subunit

Return type

int

property r_monomer[source]

Get the index of the right monomer in the crosslink

Returns

index of the right monomer

Return type

int

property r_subunit[source]

Get the name of the right subunit in the crosslink

Returns

name of the right subunit

Return type

str

property r_subunit_idx[source]

Get the index of the right subunit in the crosslink

Returns

index of the right subunit

Return type

int

property type[source]

Get the type of the abstracted crosslink

Returns

type of the crosslink

Return type

str

class bcforms.core.Subunit(id, stoichiometry, structure=None, formula=None, mol_wt=None, charge=None)[source]

Bases: object

Subunit in a BcForm macromolecular complex

id[source]

id of the subunit

Type

str

stoichiometry[source]

stoichiometry of the subunit

Type

int

structure[source]

structure of the subunit

Type

bpforms.BpForm or openbabel.OBMol, optional

formula[source]

formula of the subunit

Type

EmpiricalFormula, optional

mol_wt[source]

molecular weight of the subunit

Type

float, optional

charge[source]

charge of the subunit

Type

int, optional

property charge[source]

Get the charge of the subunit

Returns

charge of the subunit

Return type

int or None

export(format='smiles', options=[])[source]

Export the structure to string

Parameters
  • format (str, optional) – export format

  • options (list, optional) – export options

Returns

exported string representation of the structure

Return type

str

property formula[source]

Get the empirical formula of the subunit

Returns

formula of the subunit

Return type

EmpiricalFormula or None

get_charge(charge=None)[source]

Get the total charge

Parameters

charge (int or None) – Subunit charge per copy

Returns

the total charge of the Subunit

Return type

int or None

get_formula(formula=None)[source]

Get the empirical formula

Parameters

formula (EmpiricalFormula or None) – Subunit empirical formula per copy

Returns

the empirical formula of the Subunit

Return type

EmpiricalFormula or None

get_mol_wt(mol_wt=None)[source]

Get the molecular weight

Parameters

mol_wt (float or None) – Subunit molecular weight per copy

Returns

the molecular weight of the Subunit

Return type

float or None

get_structure()[source]

Get an Open Babel molecule of the structure

Returns

  • openbabel.OBMol: Open Babel molecule of the structure

  • dict of obj:dict: dictionary which maps subunit_idx to

    atom_maps

Return type

tuple

Raises

ValueError – Subunit structure is None

property id[source]

Get the id of the subunit

Returns

id of the subunit

Return type

str

is_equal(other)[source]

Check if two Subunits are semantically equal

  • Check id and stoichiometry; do not check structure yet

Parameters

other (Subunit) – another Subunit

Returns

True, if the Subunits are semantically equal

Return type

bool

property mol_wt[source]

Get the molecular weight of the subunit

Returns

molecular weight of the subunit

Return type

float or None

property stoichiometry[source]

Get the stoichiometry of the subunit

Returns

stoichiometry of the subunit

Return type

int

property structure[source]

Get the structure of the subunit

Returns

structure of the subunit

Return type

bpforms.BpForm or openbabel.OBMol or None

Generate an image of a crosslink

Parameters
  • xlink_name (str) – name of xlink

  • include_all_hydrogens (bool, optional) – if True, show all hydrogens

  • remove_hydrogens (bool, optional) – if True, remove all hydrogens

  • show_atom_nums (bool, optional) – if True, show atom numbers

  • l_color (int, optional) – color of left monomer

  • r_color (int, optional) – color of right monomer

  • bond_color (int, optional) – color of crosslinking bond

  • width (int, optional) – width

  • height (int, optional) – height

  • atom_label_font_size (float, optional) – relative font size of atom labels

  • image_format (str, optional) – format of image

  • include_xml_header (bool, optional) – if True, include XML header for SVG image

Returns

image

Return type

object

Raises
  • KeyError – Unknown crosslink id

  • ValueError – Unknown monomer alphabet

bcforms.core.get_hydrogen_atom(parent_atom, bonding_hydrogens, i_monomer)[source]

Get a hydrogen atom attached to a parent atom :param parent_atom: parent atom :type parent_atom: openbabel.OBAtom :param bonding_hydrogens: hydrogens that have already been gotten :type bonding_hydrogens: list :param i_monomer: index of parent monomer in sequence :type i_monomer: int

Returns

hydrogen atom

Return type

openbabel.OBAtom

bcforms.core.parse_yaml(path)[source]

Read a YAML file

Parameters

path (str) – path to YAML file which defines alphabet

Returns

content of file

Return type

object

2.1.4. bcforms.rest module

REST JSON API

Author

Mike Zheng <xzheng20@colby.edu>

Author

Jonathan Karr <karr@mssm.edu>

Date

2019-07-03

Copyright

2019, Karr Lab

License

MIT

class bcforms.rest.Bcform(api=None, *args, **kwargs)[source]

Bases: flask_restplus.resource.Resource

endpoint = 'bcform_bcform'[source]
mediatypes()[source]
methods = {'POST'}[source]
post()[source]
class bcforms.rest.CrosslinkResource(api=None, *args, **kwargs)[source]

Bases: flask_restplus.resource.Resource

Get crosslinks

endpoint = 'crosslink_crosslink_resource'[source]
get()[source]

Get crosslinks

Returns

dictionary representation of all crosslinks

Return type

dict

mediatypes()[source]
methods = {'GET'}[source]
class bcforms.rest.PrefixMiddleware(app, prefix='')[source]

Bases: object

Get an alphabet

Returns

dictionary representation of crosslinks

Return type

dict

2.1.5. Module contents