Repository navigation
Core Calculators & Biophysics
The Core Calculators & Biophysics module forms the computational backbone of BioLabCalc. It provides high-precision biophysical calculations, sequence manipulation algorithms, robust unit parsing, and experimental quality-control (QC) reporting. Designed for molecular biology laboratories, genomic core facilities, and automated analytical pipelines, this engine guarantees physical mass balance, isotopic fidelity, and reproducibility across bench experiments.
BioLabCalc implements rigorous, residue-level molecular weight calculations for deoxyribonucleic acid (DNA), ribonucleic acid (RNA), and polypeptides. In high-resolution mass spectrometry (LC-MS) and biochemical stoichiometry, confusing average isotopic mass with monoisotopic mass introduces significant mass errors (
The molecular weight of a biological polymer is governed by the summation of its constituent monomeric residue masses plus terminal modifications:
where:
-
$n_i$ is the count of residue species$i$ . -
$MW_{\text{residue}, i}$ is the molecular weight of the nucleotide or amino acid monophosphate residue as incorporated within the chain (accounting for the condensation loss of$\text{H}_2\text{O}$ ). -
$\Delta MW_{\text{termini}}$ represents terminal groups (e.g., 5'-phosphorylation, caps, 3'-modifications, peptide N- and C-termini). -
$\Delta MW_{\text{backbone}}$ represents internucleotide or backbone alterations (e.g., phosphorothioate linkages).
Standard single-stranded DNA (ssDNA) synthesized via solid-phase phosphoramidite chemistry terminates with a 5'-hydroxyl (
| Base | Residue | Average MW (g/mol) | Monoisotopic MW (g/mol) | Chemical Formula (in-chain) |
|---|---|---|---|---|
| A | 2'-deoxyadenosine-5'-monophosphate | $\text{C}{10}\text{H}{12}\text{N}_5\text{O}_5\text{P}$ | ||
| C | 2'-deoxycytidine-5'-monophosphate | $\text{C}{9}\text{H}{12}\text{N}_3\text{O}_6\text{P}$ | ||
| G | 2'-deoxyguanosine-5'-monophosphate | $\text{C}{10}\text{H}{12}\text{N}_5\text{O}_6\text{P}$ | ||
| T | 2'-deoxythymidine-5'-monophosphate | $\text{C}{10}\text{H}{13}\text{N}_2\text{O}_7\text{P}$ |
| 5' Terminal Chemistry |
|
|
Description |
|---|---|---|---|
Hydroxyl (hydroxyl) |
Standard synthetic oligo (5'-OH, 3'-OH) | ||
Monophosphate (monophosphate) |
Phosphorylated oligo / restriction fragment | ||
Triphosphate (triphosphate) |
Initiated enzymatic transcript | ||
Circular (circular=True) |
Closed circular plasmid DNA (no free ends) |
When double_stranded=True, BioLabCalc generates the complementary Watson-Crick reverse strand, calculates both single-strand weights independently with terminal state symmetry, and sums them:
Ribonucleic acid exhibits greater structural complexity at its termini and internucleotide linkages. BioLabCalc natively models in vitro transcription (IVT) products, synthetic oligonucleotides, cap analogs, and phosphorothioate backbones.
| Base | Residue | Average MW (g/mol) | Monoisotopic MW (g/mol) | Chemical Formula (in-chain) |
|---|---|---|---|---|
| A | Adenosine-5'-monophosphate | $\text{C}{10}\text{H}{12}\text{N}_5\text{O}_6\text{P}$ | ||
| C | Cytidine-5'-monophosphate | $\text{C}{9}\text{H}{12}\text{N}_3\text{O}_7\text{P}$ | ||
| G | Guanosine-5'-monophosphate | $\text{C}{10}\text{H}{12}\text{N}_5\text{O}_7\text{P}$ | ||
| U | Uridine-5'-monophosphate | $\text{C}{9}\text{H}{11}\text{N}_2\text{O}_8\text{P}$ |
-
5' Modifications:
-
Triphosphate (
triphosphate): Standard IVT initiation ($\text{pppNp}\dots$ ),$+239.94\text{ Da}$ relative to 5'-hydroxyl ($+177.98\text{ Da}$ net). -
Monophosphate (
monophosphate): Processed or 5'-monophosphorylated RNA,$+79.98\text{ Da}$ relative to 5'-hydroxyl. -
Hydroxyl (
hydroxyl): Synthetic RNA, base net adjustment of$-61.96\text{ Da}$ . -
Cap0 (
$\text{m}^7\text{GpppN}$ ): Clean eukaryotic cap structure,$+749.24\text{ Da}$ relative to 5'-hydroxyl. -
Cap1 (
$\text{m}^7\text{GpppN}_{2'\text{-O-Me}}$ ): Clean mammalian Cap1 with 2'-O-methylated first base,$+763.26\text{ Da}$ relative to 5'-hydroxyl.
-
Triphosphate (
-
3' Modifications:
-
Hydroxyl (
hydroxyl): Standard canonical terminus ($0.0\text{ Da}$ ). -
Monophosphate (
monophosphate):$+79.98\text{ Da}$ . -
Diphosphate (
diphosphate):$+159.96\text{ Da}$ . -
Triphosphate (
triphosphate):$+239.94\text{ Da}$ . -
Cyclic Phosphate (
cyclic_phosphate):$2',3'\text{-cyclic phosphate}$ resulting from ribozyme cleavage or RNase A digestion,$+61.96\text{ Da}$ .
-
Hydroxyl (
-
Phosphorothioate (PS) Backbone:
- Each phosphorothioate internucleotide linkage replaces a non-bridging oxygen atom (
$15.9994\text{ Da}$ ) with a sulfur atom ($32.065\text{ Da}$ ). -
$\Delta MW_{\text{avg}} = +16.066\text{ Da}$ per linkage;$\Delta MW_{\text{mono}} = +15.9772\text{ Da}$ per linkage. - For fully phosphorothioated RNA,
$N_{\text{linkages}} = L - 1$ .
- Each phosphorothioate internucleotide linkage replaces a non-bridging oxygen atom (
BioLabCalc calculates polypeptide molecular weights based on the 20 standard amino acid residues, including peptide bond condensation and disulfide bond oxidation states.
where
| AA | 1-Letter | Name | Avg Residue MW (g/mol) | Monoisotopic MW (g/mol) | Side Chain Polarity |
|---|---|---|---|---|---|
| Ala | A | Alanine | Non-polar, aliphatic | ||
| Arg | R | Arginine | Positively charged (basic) | ||
| Asn | N | Asparagine | Polar, uncharged | ||
| Asp | D | Aspartate | Negatively charged (acidic) | ||
| Cys | C | Cysteine | Polar, thiol-containing | ||
| Glu | E | Glutamate | Negatively charged (acidic) | ||
| Gln | Q | Glutamine | Polar, uncharged | ||
| Gly | G | Glycine | Non-polar, achiral | ||
| His | H | Histidine | Positively charged (aromatic) | ||
| Ile | I | Isoleucine | Non-polar, branched aliphatic | ||
| Leu | L | Leucine | Non-polar, branched aliphatic | ||
| Lys | K | Lysine | Positively charged (basic) | ||
| Met | M | Methionine | Non-polar, thioether | ||
| Phe | F | Phenylalanine | Non-polar, aromatic | ||
| Pro | P | Proline | Non-polar, cyclic imino | ||
| Ser | S | Serine | Polar, hydroxyl | ||
| Thr | T | Threonine | Polar, hydroxyl | ||
| Trp | W | Tryptophan | Non-polar, aromatic indole | ||
| Tyr | Y | Tyrosine | Polar, aromatic phenol | ||
| Val | V | Valine | Non-polar, branched aliphatic |
When cysteines oxidize into cystines (
To preserve physical mass balance, BioLabCalc clamps the count of oxidized cysteines so it cannot exceed the actual number of cysteine residues present in the sequence (
Each formed disulfide bond subtracts
Laboratory nucleic acid manipulation frequently requires switching between physical mass, molar amount, concentration, and molecular copy number.
Mass (g)
β² β
m = nΒ·MW β β n = m / MW
β βΌ
Moles (mol)
β² β
N = nΒ·N_Aβ β n = N / N_A
β βΌ
Copy Number (N)
-
Mass-to-Moles Conversion:
$$n = \frac{m}{MW}$$ where$n$ is in moles ($\text{mol}$ ),$m$ is in grams ($\text{g}$ ), and$MW$ is in$\text{g/mol}$ . -
Moles-to-Mass Conversion:
$$m = n \cdot MW$$ -
Mass to Copy Number:
$$N = \left( \frac{m}{MW} \right) \cdot N_A$$ where$N_A = 6.02214076 \times 10^{23}\text{ molecules/mol}$ (Avogadro's constant, CODATA 2018). -
Copy Number to Mass:
$$m = \frac{N \cdot MW}{N_A}$$ -
Concentration to Molarity:
$$\text{Molarity } (M) = \frac{\text{Mass Concentration (g/L)}}{MW} = \frac{\text{Concentration (ng/\mu L)} \times 10^{-3}}{MW}$$
All stoichiometry solvers enforce strict physical bounds:
- Validates
$MW > 0$ acrossmass_to_copy_number()andconcentration_to_molarity()(as well asmass_to_moles()andmoles_to_mass()), raisingValueErrorto prevent division-by-zero errors. - Validates that
target_unit.lower()exists inMASS_TO_GRAMSincopy_number_to_mass(), raisingValueErrorfor unknown target units.
BioLabCalc features dynamic unit auto-ranging. Outputs are scaled to standard biological orders of magnitude to avoid truncation or scientific notation errors:
| Base Unit | Scale Range | Display Unit | Scaling Factor |
|---|---|---|---|
| Molar ( |
|||
| Mass ( |
|||
BioLabCalc contains a specialized sequence-processing pipeline designed to clean, validate, translate, and compute biophysical properties of raw FASTA sequences.
The clean_sequence function automatically:
- Strips FASTA definition lines starting with
>. - Removes all numbers, tabs, spaces, and carriage returns.
- Removes termination asterisks (
*) in nucleotide inputs. - Normalizes all remaining characters to uppercase.
The validate_sequence function validates strings against strict IUPAC degenerate alphabets:
-
DNA:
[ACGTNRYWSKMBDHV]+ -
RNA:
[ACGUNRYWSKMBDHV]+ -
Protein:
[ACDEFGHIKLMNPQRSTVWY*]+
To support primer design, degenerate probe synthesis, and enzyme cleavage recognition sites, BioLabCalc supports the full IUPAC degenerate base code and provides exact reverse-complementation:
| IUPAC Code | Meaning | Bases Represented | DNA Complement | RNA Complement |
|---|---|---|---|---|
| A | Adenine | A | T | U |
| C | Cytosine | C | G | G |
| G | Guanine | G | C | C |
| T | Thymine (DNA) | T | A | A |
| U | Uracil (RNA) | U | A | A |
| R | Purine | A or G | Y (pYrimidine) | Y |
| Y | Pyrimidine | C or T/U | R (puRine) | R |
| S | Strong interaction | C or G | S (G or C) | S |
| W | Weak interaction | A or T/U | W (T/U or A) | W |
| K | Keto | G or T/U | M (aMino) | M |
| M | Amino | A or C | K (Keto) | K |
| B | Not A | C, G, or T/U | V (Not T/U) | V |
| D | Not C | A, G, or T/U | H (Not G) | H |
| H | Not G | A, C, or T/U | D (Not C) | D |
| V | Not T/U | A, C, or G | B (Not A) | B |
| N | Any nucleotide | A, C, G, or T/U | N | N |
The in silico translation utility converts DNA sequences to amino acid chains across 6 possible reading frames:
-
Forward Frames:
$+1$ ,$+2$ ,$+3$ . -
Reverse Complement Frames:
$-1$ ,$-2$ ,$-3$ . -
Termination Control (
to_stop=True): Halts translation immediately upon reaching the first stop codon (*), mirroring in vivo ribosomal termination.
BioLabCalc features UnitParser, a static class that parses arbitrary human-written string representations into strictly normalized float values.
UnitParser uses regex pattern matching to decouple magnitude from units:
r"^([+-]?[0-9]*\.?[0-9]+(?:[eE][+-]?[0-9]+)?)([a-zA-ZΒ΅/]*)$"Inputs such as "500 uL", "0.5 mL", "1.25e-3 L", "25 mM", "10 Β΅M", "1.5 ug", or "100 ng/ul" are normalized into consistent base metrics.
| Physical Dimension | Method | Default Target | Supported Units |
|---|---|---|---|
| Volume | parse_volume |
l, liter, ml, milliliter, ul, Β΅l, microliter, nl, nanoliter, pl
|
|
| Molar Concentration | parse_concentration |
m, molar, mm, millimolar, um, Β΅m, micromolar, nm, pm, fm
|
|
| Mass Concentration | parse_concentration |
mg/ml, ug/ul, Β΅g/Β΅l, g/l, ug/ml, Β΅g/ml, ng/ul, ng/ml
|
|
| Mass | parse_mass |
g, gram, mg, milligram, ug, Β΅g, microgram, ng, nanogram, pg, fg
|
|
| Moles | parse_moles |
mol, mole, mmol, umol, Β΅mol, nmol, nanomole, pmol, fmol, amol
|
Scientific reproducibility requires traceability. BioLabCalc includes an integrated electronic lab session manager (LabReport) that records replicate measurements, evaluates Quality Control (QC) status against specifications, computes sample statistics, and outputs publication-grade reports.
Each measurement recorded by add_record encapsulates experimental metadata:
-
sample_id: Sample identifier. -
parameter: Assay or parameter measured (e.g.,$A_{260}$ , Yield, Purity, MW). -
value: Observed numeric value. -
unit: Physical measurement unit. -
target_or_expected: Theoretical or specification target. -
tolerance_pct: Acceptable percentage deviation ($\pm%$ ). -
percent_deviation:$$\text{Deviation (%)} = \frac{\text{Value} - \text{Target}}{\text{Target}} \times 100$$ -
status: Automated status assignment:-
PASS:$|\text{Deviation}| \le \text{tolerance_pct}$ -
FLAG:$\text{tolerance_pct} < |\text{Deviation}| \le 1.5 \times \text{tolerance_pct}$ -
FAIL:$|\text{Deviation}| > 1.5 \times \text{tolerance_pct}$
-
When multiple experimental replicates ((sample_id, parameter) pair, calculate_statistics() computes summary statistics:
-
Sample Mean (
$\bar{x}$ ):$$\bar{x} = \frac{1}{N} \sum_{i=1}^{N} x_i$$ -
Sample Standard Deviation (
$s$ ):$$s = \sqrt{\frac{1}{N - 1} \sum_{i=1}^{N} (x_i - \bar{x})^2}$$ -
Coefficient of Variation (
$%CV$ ):$$%CV = \left( \frac{s}{\bar{x}} \right) \times 100$$ -
Range:
$$[\min(x_1, \dots, x_N), \max(x_1, \dots, x_N)]$$
The report session can be exported to multiple formats:
-
Markdown (
to_markdown): Formatted tables and replicate summaries suitable for GitHub wikis or static documentation. -
Excel (
to_excel): Professional multi-section spreadsheet styled withopenpyxl. Includes embedded dynamic formulas for percent deviation, automated soft color-coding for QC statuses (green for PASS, yellow for FLAG, red for FAIL), and auto-fitted column dimensions. -
CSV (
to_csv): Tidy-data tabular format compatible with R, Python (pandas), or LIMS databases. -
JSON (
to_json): Structured hierarchical schema suitable for ELN REST APIs.
from biolabcalc.molecular_weight import (
calculate_dna_mw,
calculate_rna_mw,
calculate_protein_mw,
mass_to_moles,
moles_to_mass,
mass_to_copy_number,
copy_number_to_mass,
concentration_to_molarity,
)
# 1. dsDNA Molecular Weight (100 bp duplex with 5'-phosphate)
dna_res = calculate_dna_mw(
seq="ATGCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATC",
double_stranded=True,
end_5="monophosphate",
)
print(f"dsDNA Average MW: {dna_res.average_mw:.2f} Da")
print(f"dsDNA Monoisotopic MW: {dna_res.monoisotopic_mw:.4f} Da")
print(f"Duplex GC Content: {dna_res.gc_content:.2f}%")
# 2. Synthetic Modified mRNA (Cap1, fully phosphorothioate-linked)
rna_res = calculate_rna_mw(
seq="AUGGUGAGCAAGGGCGAGGAGCUGUUCACCGGG",
end_5="cap1",
end_3="hydroxyl",
backbone="phosphorothioate",
)
print(f"mRNA Average MW: {rna_res.average_mw:.2f} Da")
print(f"Backbone: {rna_res.backbone}")
# 3. Protein with Disulfide Bonds
prot_res = calculate_protein_mw(
seq="MKWVTFISLLFLFSSAYSRGVFRRDTHKSEIAHRFKDLGEEHFKGLVLIAFSQYLQQCPFDEHVKLVNELTEFAKTCVADESHAGCEKSLHTLFGDELCKVASLRETYGDMADCCEKQEPERNECFLSHKDDSPDLPKLKPDPNTLCDEFKADEKKFWGKYLYEIARRHPYFYAPELLYYANKYNGVFQECCQAEDKGACLLPKIETMREKVLASSARQRLRCASIQKFGERALKAWSVARLSQKFPKAEFVEVTKLVTDLTKVHKECCHGDLLECADDRADLAKYICDNQDTISSKLKECCDKPLLEKSHCIAEVEKDAIPENLPPLTADFAEDKDVCKNYQEAKDAFLGSFLYEYSRRHPEYAVSVLLRLAKEYEATLEECCAKDDPHACYSTVFDKLKHLVDEPQNLIKQNCDQFEKLGEYGFQNALIVRYTRKVPQVSTPTLVEVSRSLGKVGTRCCTKPESERMPCTEDYLSLILNRLCVLHEKTPVSEKVTKCCTESLVNRRPCFSALTPDETYVPKAFDEKLFTFHADICTLPDTEKQIKKQTALVELLKHKPKATEEQLKTVMENFVAFVDKCCAADDKEACFAVEGPKLVVSTQTALA",
oxidized_cysteines=34, # Human Serum Albumin: 17 disulfide bonds
)
print(f"Protein MW: {prot_res.average_mw:.2f} Da")
# 4. Stoichiometry and Copy Number Calculations
val, unit = mass_to_moles(mass_val=2.5, mass_unit="ug", mw=dna_res.average_mw)
print(f"2.5 Β΅g dsDNA = {val:.3f} {unit}")
copies = mass_to_copy_number(mass_val=10.0, mass_unit="ng", mw=dna_res.average_mw)
print(f"10 ng dsDNA = {copies:.3e} copies")
mass_needed = copy_number_to_mass(copies=1e9, mw=dna_res.average_mw, target_unit="ng")
print(f"10^9 copies requires {mass_needed:.4f} ng")from biolabcalc.seq_utils import (
clean_sequence,
validate_sequence,
reverse_complement,
translate_dna,
calculate_gc_content,
)
raw_fasta = """
>ENA|A00001|A00001.1 Synthetic cloning vector pBR322
TTCTCATGTT TGACAGCTTA TCATCGATAA GCTTTAATGC GGTAGTTTAT
CACAGTTAAA TTGCTAACGC AGTCAGGCAC CGTGTATGAA ATCTAACAAT
"""
clean_dna = clean_sequence(raw_fasta)
assert validate_sequence(clean_dna, seq_type="dna")
rc_dna = reverse_complement(clean_dna, seq_type="dna")
gc = calculate_gc_content(clean_dna)
# Translate forward frame 1 to first stop codon
peptide = translate_dna(clean_dna, frame=1, to_stop=True)
print(f"Peptide (Frame +1): {peptide}")from biolabcalc.lab_report import LabReport
report = LabReport(
title="Plasmid Prep Quality Control",
experimenter="Dr. J. Watson",
project="pUC19 Core Validation",
objective="Quantify yield, replicate consistency, and optical purity.",
)
# Record replicate concentration measurements
report.add_record(sample_id="Plasmid_P1", parameter="Concentration", value=152.4, unit="ng/uL", target=150.0, tolerance_pct=10.0)
report.add_record(sample_id="Plasmid_P1", parameter="Concentration", value=148.9, unit="ng/uL", target=150.0, tolerance_pct=10.0)
report.add_record(sample_id="Plasmid_P1", parameter="Concentration", value=151.0, unit="ng/uL", target=150.0, tolerance_pct=10.0)
# Record purity ratios
report.add_record(sample_id="Plasmid_P1", parameter="A260/A280", value=1.86, unit="ratio", target=1.80, tolerance_pct=5.0)
report.add_record(sample_id="Plasmid_P1", parameter="A260/A230", value=2.15, unit="ratio", target=2.10, tolerance_pct=10.0)
report.add_conclusion("Sample Plasmid_P1 meets all purity and concentration release specifications.")
# Export multi-format reports
report.to_markdown("pUC19_QC_Report.md")
report.to_excel("pUC19_QC_Report.xlsx")
report.to_csv("pUC19_QC_Report.csv")BioLabCalc exposes CLI commands for direct terminal execution:
# DNA single strand
biolabcalc mw -s "ATGCGATCGATCGATCGATC" -t dna
# dsDNA duplex with monophosphate 5' ends
biolabcalc mw -s "ATGCGATCGATCGATCGATC" -t dsdna --end5 monophosphate
# RNA transcript with 5'-triphosphate
biolabcalc mw -s "AUGCGAUCGAUCGAUCGAUC" -t rna --end5 triphosphate
# Protein sequence
biolabcalc mw -s "MKWVTFISLLFLFSSAYSRG" -t protein# Initialize a new report session and add a record
biolabcalc report add --sample "Sample_A" --param "Concentration" --val 245.8 --unit "ng/uL" --target 250.0 --tol 5.0
# Export active report session to Markdown or Excel
biolabcalc report export --format excel --out "Experiment_Run_101.xlsx"
biolabcalc report export --format md --out "Experiment_Run_101.md"BioLabCalc Documentation Wiki | Licensed under the MIT License | GitHub Repository Research Use Only (RUO). Not intended for clinical or diagnostic procedures.
- Core Calculators & Stoichiometry
- Solution Prep & Spectroscopy
- Buffers & Precipitation
- Protein Quantification & Assays
- Fluorophores & Dye Labeling
- Molecular Cloning & Assembly
- Plasmid Engineering & Workbench
- PCR Kinetics & Primer Design
- In Vitro Transcription (IVT)
- Western Blotting Suite
- Bacterial Growth & Kinetics
- ELN System Architecture
- SOP & Protocol Management
- Instrument Data Parsers
- Inventory & Freezer LIMS
- Local RAG Knowledge Engine
- GxP Compliance & Audit Trails