def get_activation(sequences, concentrations, params): model = nu.Model(material='dna', celsius=params['temperature'], sodium=params['sodium'], magnesium=params['magnesium']) # Define strands and sequences probeF = nu.Strand(sequences['probeF'], name='probeF') probeQ = nu.Strand(sequences['probeQ'], name='probeQ') sink = nu.Strand(sequences['sink'], name='sink') sinkC = nu.Strand(sequences['sinkC'], name='sinkC') non_mut_target = nu.Strand(sequences['non_mut_target'], name='non_mut_target') mut_target = nu.Strand(sequences['mut_target'], name='mut_target') # Define 3 tubes: one without target (initial), one with mutated target (mut), and one with non-mutated target (non_mut) initial_state = nu.Tube(strands={ probeF: concentrations['probeF'], probeQ: concentrations['probeQ'], sink: concentrations['sink'], sinkC: concentrations['sinkC'] }, complexes=nu.SetSpec( max_size=2, include=[[probeF, probeQ, sink, sinkC]]), name='initial_state') mut_state = nu.Tube(strands={ probeF: concentrations['probeF'], probeQ: concentrations['probeQ'], sink: concentrations['sink'], sinkC: concentrations['sinkC'], mut_target: concentrations['mut_target'] }, complexes=nu.SetSpec( max_size=2, include=[[probeF, probeQ, sink, sinkC, mut_target]]), name='mut_state') non_mut_state = nu.Tube(strands={ probeF: concentrations['probeF'], probeQ: concentrations['probeQ'], sink: concentrations['sink'], sinkC: concentrations['sinkC'], non_mut_target: concentrations['non_mut_target'] }, complexes=nu.SetSpec(max_size=2, include=[[ probeF, probeQ, sink, sinkC, non_mut_target ]]), name='non_mut_state') # Compute proportion of probe which is active in each tube result = nu.tube_analysis(tubes=[initial_state, mut_state, non_mut_state], compute=['pairs', 'mfe'], model=model) initial_activation = parse_nupack_output(result, 'initial_state', concentrations) mut_activation = parse_nupack_output(result, 'mut_state', concentrations) non_mut_activation = parse_nupack_output(result, 'non_mut_state', concentrations) return initial_activation, mut_activation, non_mut_activation
def test_stack_energy(): mod = nu.Model() pairs = 'AT CG GC TA GT TG'.split() pairs = 'AT CG GC TA'.split() s = '' for i in pairs: for j in pairs: seqs = [i[0] + j[0], j[1] + i[1]] s += '%d ' % int(100*mod.loop_energy(seqs)) s += '\n' return s
def basic( ths: str, rbs: str = "AGAGGAGA", const_rna: Optional[Collection[str]] = None, max_size: int = 3, n_samples: int = 100, celsius: float = 37.0, filename: str = "output.txt", nupack_v: int = 4, ) -> None: """Basic test against miRNAs from the H**o sapiens miRBase which saves results as text. You can also set file ending to .csv for a spreadsheet.""" if nupack_v == 4: model = nupack.Model(celsius=celsius) elif nupack_v == 3: model = nupack.Model(ensemble="some-nupack3", material="rna95-nupack3", celsius=celsius) else: raise ValueError( f"only NUPACK versions supported allowed, not 'nupack_v={nupack_v}'" ) fasta = FASTA.fromspecies("H**o sapiens") t = autoconfig( ths=ths, rbs=rbs, triggers=fasta.seqs, set_size=1, names=fasta.IDs, const_rna=const_rna, model=model, ) results = t.run(max_size, n_samples=n_samples) with open(filename, "w", encoding="utf-8-sig") as f: if filename.endswith(".csv"): f.write(results.to_csv()) else: f.write(results.prettify())
def autoconfig( ths: str, rbs: str, triggers: Collection[str], set_size: int = 1, const_rna: Optional[Iterable[str]] = None, names: Optional[Collection[str]] = None, model: nupack.Model = nupack.Model(), ) -> ToeholdTest: """ Quick configuration of ToeholdTests, assuming every RNA has the same concentration. Args: ths (str): the toehold switch rbs (str): the ribosome binding site whose position in the ths will be autodetected triggers (list): an array-like of the triggers to test the ths against set_size (int, optional): how many triggers to test against the ths at a time. Defaults to 1. const_rna (list, optional): a list of any constant RNAs. Defaults to []. names (list, optional): the names of each trigger. Defaults to []. model (nupack.Model, optional): the physical model to use. Defaults to nupack.Model(). Returns: a fully configured ToeholdTest instance """ rbs_location = find_rbs(ths, rbs) trigger_sets = combs(triggers, set_size) conc_sets = np.full(trigger_sets.shape, 1, dtype=np.float64) t = ToeholdTest( ths={ths: 1}, rbs_location=rbs_location, trigger_sets=trigger_sets, conc_sets=conc_sets, const_rna={rna: 1 for rna in const_rna}, model=model, ) if len(names) > 0: assert len(names) == len( triggers ), "each name must match to a corresponding trigger. Set to [] otherwise." names = combs(names, set_size) t.names = names return t
import numpy as np import pandas as pd import nupack # configure nupack model NUPACK_MODEL = nupack.Model( material=snakemake.config.get('nupack_material', 'dna'), ensemble=snakemake.config.get('nupack_ensemble', 'stacking'), celsius=snakemake.config.get('nupack_celsius', 74.5), sodium=snakemake.config.get('nupack_sodium', 0.39), magnesium=snakemake.config.get('nupack_magnesium', 0.0), ) def main(): # load probe data df = pd.read_csv(snakemake.input[0], sep='\t', header=None) df.columns = [ 'chrom', 'start', 'stop', 'seq', 'Tm', 'on_target_score', 'off_target_score', 'repeat' ] # compute prob value for each sequence df['prob'] = df['seq'].apply(prob)
def test_loop_energy(): em = nu.Model(ensemble='some-nupack3', material='rna95-nupack3') assert abs(em.beta - 1.6225317071110157) < 1e-8 assert em.hairpin_energy('AAAAT') == 4.1
def test_structure_energy(): model = nu.Model(ensemble='some-nupack3', material='rna95-nupack3') assert model.structure_energy('CCCCTTTGGGG', '((((...))))') == -4.6 assert model.structure_energy('GGAAACC', '.(...).') == 3.3 assert abs(nu.Model(ensemble='stacking', material='rna95-nupack3').structure_energy('GGAAACC', '.(...).') - 2.7239996321033035) < 1e-8