3.1. bcforms package

3.1.1. Submodules

3.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.1'})][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 ex:

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 ex:

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 ex:

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 ex:

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]

3.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
charge[source]

Get the charge of the atom

Returns:charge
Return type:int
component_type[source]

Get the type of component the atom belongs to

Returns:component type
Return type:str
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
monomer[source]

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

Returns:monomer position
Return type:int
position[source]

Get the position of the atom in the compound

Returns:position
Return type:int
subunit[source]

Get the subunit that the atom belongs to

Returns:subunit
Return type:str
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

crosslinks[source]

Get the crosslinks

Returns:crosslinks
Return type:list of Crosslink
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, from_structure=False)[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
  • from_structure (bool) – True if calculate molecular weight from subunit structure
Returns:

the total charge of the BcForm

Return type:

int

Raises:

ValueError – subunit_charges does not include all subunits

get_formula(subunit_formulas=None, from_structure=False)[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
  • from_structure (bool) – True if calculate formula from subunit structure
Returns:

the empirical formula of the BcForm

Return type:

EmpiricalFormula

Raises:

ValueError – subunit formulas does not include all subunits

get_mol_wt(subunit_mol_wts=None, from_structure=False)[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
  • from_structure (bool) – True if calculate molecular weight from subunit structure
Returns:

the molecular weight of the BcForm

Return type:

float

Raises:

ValueError – subunit_mol_wts does not include all subunits

get_structure()[source]

Get an OpenBabel molecule of the structure

Returns:OpenBabel 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
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: object

A crosslink between subunits

left_bond_atoms[source]

atoms from the left subunit that bond with the right subunit

Type:list of Atom
right_bond_atoms[source]

atoms from the right subunit that bond with the left subunit

Type:list of Atom
left_displaced_atoms[source]

atoms from the left subunit displaced by the crosslink

Type:list of Atom
right_displaced_atoms[source]

atoms from the right subunit displaced by the crosslink

Type:list of Atom
__str__()[source]

Generate a string representation

Returns:string representation
Return type:str
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
left_bond_atoms[source]

Get the left bond atoms

Returns:left bond atoms
Return type:list of Atom
left_displaced_atoms[source]

Get the left displaced atoms

Returns:left displaced atoms
Return type:list of Atom
right_bond_atoms[source]

Get the right bond atoms

Returns:right bond atoms
Return type:list of Atom
right_displaced_atoms[source]

Get the right displaced atoms

Returns:right displaced atoms
Return type:list of Atom
class bcforms.core.Subunit(id, stoichiometry, structure=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
get_charge(charge=None, from_structure=False)[source]

Get the total charge

Parameters:
  • charge (int or None) – Subunit charge per copy
  • from_structure (bool) – True if calculate formula from subunit structure
Returns:

the total charge of the Subunit

Return type:

int

Raises:

ValueError – Attempting to get total charge from structure but structure is None

get_formula(formula=None, from_structure=False)[source]

Get the empirical formula

Parameters:
  • formula (EmpiricalFormula or None) – Subunit empirical formula per copy
  • from_structure (bool) – True if calculate formula from subunit structure
Returns:

the empirical formula of the Subunit

Return type:

EmpiricalFormula

Raises:

ValueError – Attempting to get formula from structure but structure is None

get_mol_wt(mol_wt=None, from_structure=False)[source]

Get the molecular weight

Parameters:
  • mol_wt (float or None) – Subunit molecular weight per copy
  • from_structure (bool) – True if calculate formula from subunit structure
Returns:

the molecular weight of the Subunit

Return type:

float

Raises:

ValueError – Attempting to get molecular weight from structure but structure is None

get_structure()[source]

Get an OpenBabel molecule of the structure

Returns:OpenBabel molecule of the structure dict of obj:dict: dictionary which maps subunit_idx to
atom_maps
Return type:openbabel.OBMol
Raises:ValueError – Subunit structure is None
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
stoichiometry[source]

Get the stoichiometry of the subunit

Returns:stoichiometry of the subunit
Return type:int
structure[source]

Get the structure of the subunit

Returns:structure of the subunit
Return type:bpforms.BpForm or openbabel.OBMol or None
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

3.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.PrefixMiddleware(app, prefix='')[source]

Bases: object

3.1.5. Module contents