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
bcforms.__main__.
BaseController
(*args, **kw)[source]¶ Bases:
cement.ext.ext_argparse.ArgparseController
Base controller for command line application
-
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
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
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}’
3.1.3. bcforms._version module¶
3.1.4. 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
-
component_type
[source]¶ type of component the atom belongs to: either ‘monomer’ or ‘backbone’
- 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
-
__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
-
export
(format='smiles', options=[])[source]¶ Export the structure to string
- Parameters
format (
str
, optional) – export formatoptions (
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
- 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
-
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
orNone
) – 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
orNone
) – 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 featurecolor (
str
): colorpositions (
list
oflist
ofint
): list of position ranges of the type of feature
width (
int
, optional) – widthcols (
int
, optional) – number of columns of polymersnt_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
orNone
) – 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 subunitattribute (
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 subunitattribute (
str
) – attribute to setvalue (
int
for stoichiometry,bpforms.BpForm
,openbabel.OBMol
, or None for structure) – value
- Raises
ValueError – No Subunit with subunit_id
ValueError – Invalid attribute
-
-
class
bcforms.core.
Crosslink
[source]¶ 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
ofAtom
-
abstract
get_l_displaced_atoms
()[source]¶ Get the left displaced atoms
- Returns
left displaced atoms
- Return type
list
ofAtom
-
abstract
get_r_bond_atoms
()[source]¶ Get the right bond atoms
- Returns
right bond atoms
- Return type
list
ofAtom
-
abstract
get_r_displaced_atoms
()[source]¶ Get the right displaced atoms
- Returns
right displaced atoms
- Return type
list
ofAtom
-
abstract
-
class
bcforms.core.
InlineCrosslink
(l_bond_atoms=None, r_bond_atoms=None, l_displaced_atoms=None, r_displaced_atoms=None, order=<BondOrder.single: 1>, stereo=None, comments=None)[source]¶ 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
ofAtom
-
r_bond_atoms
[source]¶ atoms from the right subunit that bond with the left subunit
- Type
list
ofAtom
-
r_displaced_atoms
[source]¶ atoms from the right subunit displaced by the crosslink
- Type
list
ofAtom
-
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
ofAtom
-
get_l_displaced_atoms
()[source]¶ Get the left displaced atoms
- Returns
left displaced atoms
- Return type
list
ofAtom
-
get_r_bond_atoms
()[source]¶ Get the right bond atoms
- Returns
right bond atoms
- Return type
list
ofAtom
-
get_r_displaced_atoms
()[source]¶ Get the right displaced atoms
- Returns
right displaced atoms
- Return type
list
ofAtom
-
property
l_bond_atoms
[source] Get the left bond atoms
- Returns
left bond atoms
- Return type
list
ofAtom
-
property
l_displaced_atoms
[source] Get the left displaced atoms
- Returns
left displaced atoms
- Return type
list
ofAtom
-
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
ofAtom
-
property
r_displaced_atoms
[source] Get the right displaced atoms
- Returns
right displaced atoms
- Return type
list
ofAtom
-
property
stereo
[source] Get the stereochemistry
- Returns
stereochemistry
- Return type
BondStereo
-
-
class
bcforms.core.
OntologyCrosslink
(type, l_subunit, l_monomer, r_subunit, r_monomer, l_subunit_idx=None, r_subunit_idx=None)[source]¶ Bases:
bcforms.core.Crosslink
A pre-defined crosslink between subunits
-
l_subunit_idx
[source]¶ index of the left subunit, optional if only one copy of the subunit
- Type
int
, optional
-
r_subunit_idx
[source]¶ index of the left subunit, optional if only one copy of the subunit
- Type
int
, optional
-
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
ofAtom
-
get_l_displaced_atoms
()[source]¶ Get the left displaced atoms
- Returns
left displaced atoms
- Return type
list
ofAtom
-
get_r_bond_atoms
()[source]¶ Get the right bond atoms
- Returns
right bond atoms
- Return type
list
ofAtom
-
get_r_displaced_atoms
()[source]¶ Get the right displaced atoms
- Returns
right displaced atoms
- Return type
list
ofAtom
-
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
-
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 formatoptions (
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
orNone
) – 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
orNone
) – 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
orNone
) – 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 structuredict
of obj:dict: dictionary which mapssubunit_idx
toatom_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
oropenbabel.OBMol
or None
-
property
-
bcforms.core.
draw_xlink
(xlink_name, include_all_hydrogens=False, remove_hydrogens=True, show_atom_nums=False, l_color=59982, r_color=44527, bond_color=15352320, width=300, height=200, atom_label_font_size=0.6, image_format='png', include_xml_header=False)[source]¶ Generate an image of a crosslink
- Parameters
xlink_name (
str
) – name of xlinkinclude_all_hydrogens (
bool
, optional) – ifTrue
, show all hydrogensremove_hydrogens (
bool
, optional) – ifTrue
, remove all hydrogensshow_atom_nums (
bool
, optional) – ifTrue
, show atom numbersl_color (
int
, optional) – color of left monomerr_color (
int
, optional) – color of right monomerbond_color (
int
, optional) – color of crosslinking bondwidth (
int
, optional) – widthheight (
int
, optional) – heightatom_label_font_size (
float
, optional) – relative font size of atom labelsimage_format (
str
, optional) – format of imageinclude_xml_header (
bool
, optional) – ifTrue
, 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
3.1.5. 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