Skip to content

Commit

Permalink
Merge pull request #230 from UC-Davis-molecular-computing/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
dave-doty authored Dec 1, 2022
2 parents fde69f6 + f664fd2 commit 370291c
Show file tree
Hide file tree
Showing 12 changed files with 202 additions and 180 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: pull_request

jobs:
docs:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
container:
image: unhumbleben/nupack:latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run_unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on: pull_request
jobs:
build:

runs-on: ubuntu-latest
runs-on: ubuntu-20.04
container:
image: unhumbleben/nupack:latest
strategy:
Expand Down
10 changes: 5 additions & 5 deletions examples/hamming_dist_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

def main():
domain_length = 15
# energy_constraint = dc.NearestNeighborEnergyConstraint(low_energy=-9.2, high_energy=-7)
numpy_constraints = [ # energy_constraint,
nc.RunsOfBasesConstraint(['C', 'G'], 4),
nc.RunsOfBasesConstraint(['A', 'T'], 4)
# energy_constraint = dc.NearestNeighborEnergyFilter(low_energy=-9.2, high_energy=-7)
numpy_filters = [ # energy_constraint,
nc.RunsOfBasesFilter(['C', 'G'], 4),
nc.RunsOfBasesFilter(['A', 'T'], 4)
]
domain_pool = nc.DomainPool(f'length-{domain_length} domains', domain_length,
numpy_constraints=numpy_constraints, replace_with_close_sequences=True)
numpy_filters=numpy_filters, replace_with_close_sequences=True)

random_seed = 0
strands = [nc.Strand([f'{i}' for i in range(1, 50)])]
Expand Down
30 changes: 15 additions & 15 deletions examples/many_strands_no_common_domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import nuad.constraints as nc # type: ignore
import nuad.vienna_nupack as nv # type: ignore
import nuad.search as ns # type: ignore
from nuad.constraints import NumpyConstraint
from nuad.constraints import NumpyFilter


def f(x: int | float) -> float:
Expand Down Expand Up @@ -76,17 +76,17 @@ def main() -> None:
parallel = False
# parallel = True

numpy_constraints: List[NumpyConstraint] = [
nc.NearestNeighborEnergyConstraint(-9.3, -9.0, 52.0),
# nc.BaseCountConstraint(base='G', high_count=1),
# nc.BaseEndConstraint(bases=('C', 'G')),
# nc.RunsOfBasesConstraint(['C', 'G'], 4),
# nc.RunsOfBasesConstraint(['A', 'T'], 4),
# nc.BaseEndConstraint(bases=('A', 'T')),
# nc.BaseEndConstraint(bases=('C', 'G'), distance_from_end=1),
# nc.BaseAtPositionConstraint(bases='T', position=3),
# nc.ForbiddenSubstringConstraint(['GGGG', 'CCCC']),
# nc.RestrictBasesConstraint(bases=['A', 'T', 'C']),
numpy_filters: List[NumpyFilter] = [
nc.NearestNeighborEnergyFilter(-9.3, -9.0, 52.0),
# nc.BaseCountFilter(base='G', high_count=1),
# nc.BaseEndFilter(bases=('C', 'G')),
# nc.RunsOfBasesFilter(['C', 'G'], 4),
# nc.RunsOfBasesFilter(['A', 'T'], 4),
# nc.BaseEndFilter(bases=('A', 'T')),
# nc.BaseEndFilter(bases=('C', 'G'), distance_from_end=1),
# nc.BaseAtPositionFilter(bases='T', position=3),
# nc.ForbiddenSubstringFilter(['GGGG', 'CCCC']),
# nc.RestrictBasesFilter(bases=['A', 'T', 'C']),
]

# def nupack_binding_energy_in_bounds(seq: str) -> bool:
Expand All @@ -95,18 +95,18 @@ def main() -> None:
# return -11 < energy < -9
#
# # list of functions:
# sequence_constraints: List[SequenceConstraint] = [
# sequence_filters: List[SequenceFilter] = [
# # nupack_binding_energy_in_bounds,
# ]

replace_with_close_sequences = True
# replace_with_close_sequences = False
domain_pool_10 = nc.DomainPool(f'length-10_domains', 10,
numpy_constraints=numpy_constraints,
numpy_filters=numpy_filters,
replace_with_close_sequences=replace_with_close_sequences,
)
domain_pool_11 = nc.DomainPool(f'length-11_domains', 11,
numpy_constraints=numpy_constraints,
numpy_filters=numpy_filters,
replace_with_close_sequences=replace_with_close_sequences,
)

Expand Down
12 changes: 6 additions & 6 deletions examples/sample_designer.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,18 @@ def main() -> None:
else:
design = initial_design

numpy_constraints = [
nc.NearestNeighborEnergyConstraint(-9.5, -9.0, 52.0),
nc.BaseCountConstraint(base='G', high_count=1),
nc.RunsOfBasesConstraint(['C', 'G'], 4),
nc.RunsOfBasesConstraint(['A', 'T'], 4),
numpy_filters = [
nc.NearestNeighborEnergyFilter(-9.5, -9.0, 52.0),
nc.BaseCountFilter(base='G', high_count=1),
nc.RunsOfBasesFilter(['C', 'G'], 4),
nc.RunsOfBasesFilter(['A', 'T'], 4),
]

lengths = [9, 10, 11, 12]
domain_pools = {
length:
nc.DomainPool(f'length-{length} domains', length,
numpy_constraints=numpy_constraints) for length in lengths
numpy_filters=numpy_filters) for length in lengths
}

for strand in [strand0, strand1]:
Expand Down
32 changes: 16 additions & 16 deletions examples/seesaw_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,30 @@
TOEHOLD_COMPLEMENT = f'{TOEHOLD_DOMAIN}{COMPLEMENT_SUFFIX}'

# Domain pools
forbidden_substring_constraints = [
nc.ForbiddenSubstringConstraint(['G' * 4, 'C' * 4]),
forbidden_substring_filters = [
nc.ForbiddenSubstringFilter(['G' * 4, 'C' * 4]),
]

non_sub_long_domain_constraints = [
nc.RestrictBasesConstraint(('A', 'C', 'T')),
*forbidden_substring_constraints
non_sub_long_domain_filters = [
nc.RestrictBasesFilter(('A', 'C', 'T')),
*forbidden_substring_filters
]
sub_long_domain_constraints: List[nc.NumpyConstraint] = [
nc.RestrictBasesConstraint(('A', 'C', 'T')),
sub_long_domain_filters: List[nc.NumpyFilter] = [
nc.RestrictBasesFilter(('A', 'C', 'T')),
]

if SUB_LONG_DOMAIN_LENGTH > 3:
sub_long_domain_constraints.extend(forbidden_substring_constraints)
sub_long_domain_filters.extend(forbidden_substring_filters)

SUB_LONG_DOMAIN_POOL: nc.DomainPool = nc.DomainPool('sub_long_domain_pool', SUB_LONG_DOMAIN_LENGTH,
numpy_constraints=sub_long_domain_constraints)
numpy_filters=sub_long_domain_filters)
NON_SUB_LONG_DOMAIN_POOL: nc.DomainPool = nc.DomainPool('non_sub_long_domain_pool',
NON_SUB_LONG_DOMAIN_LENGTH,
numpy_constraints=non_sub_long_domain_constraints)
numpy_filters=non_sub_long_domain_filters)

toehold_domain_contraints = [
nc.ForbiddenSubstringConstraint('G' * 4),
nc.ForbiddenSubstringConstraint('C' * 4)
nc.ForbiddenSubstringFilter('G' * 4),
nc.ForbiddenSubstringFilter('C' * 4)
]
TOEHOLD_DOMAIN_POOL: nc.DomainPool = nc.DomainPool('toehold_domain_pool', 5)

Expand Down Expand Up @@ -383,11 +383,11 @@ def reporter_base_strand(gate) -> nc.Strand:
strand_complexes=[f_waste_6_complex])


def four_g_constraint_evaluate(seqs: Tuple[str, ...], strand: Optional[nc.Strand]) -> Tuple[float, str]:
def four_g_constraint_evaluate(seqs: Tuple[str, ...], strand: Optional[nc.Strand]) -> nc.Result:
seq = seqs[0]
score = 1000 if 'GGGG' in seq else 0
excess = 1000 if 'GGGG' in seq else 0
violation_str = "" if 'GGGG' not in strand.sequence() else "** violation**"
return score, f"{strand.name}: {strand.sequence()}{violation_str}"
return nc.Result(excess=excess, summary=f"{strand.name}: {strand.sequence()}{violation_str}")


def four_g_constraint_summary(strand: nc.Strand):
Expand All @@ -408,8 +408,8 @@ def four_g_constraint_summary(strand: nc.Strand):
waste_2_5_complex_constraint,
reporter_6_complex_constraint,
f_waste_6_complex_constraint,
four_g_constraint,
]
constraints.append(four_g_constraint)

seesaw_design = nc.Design(strands=strands)

Expand Down
24 changes: 12 additions & 12 deletions examples/square_root_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@
ILLEGAL_SUBSTRINGS = ILLEGAL_SUBSTRINGS_FOUR + ILLEGAL_SUBSTRINGS_FIVE

# NumpyConstraints
three_letter_code_constraint = nc.RestrictBasesConstraint(('A', 'C', 'T'))
no_gggg_constraint = nc.ForbiddenSubstringConstraint(ILLEGAL_SUBSTRINGS_FOUR)
no_aaaaa_constraint = nc.ForbiddenSubstringConstraint(ILLEGAL_SUBSTRINGS_FIVE)
c_content_constraint = nc.BaseCountConstraint('C', floor(0.7 * SIGNAL_DOMAIN_LENGTH),
ceil(0.3 * SIGNAL_DOMAIN_LENGTH))
three_letter_code_constraint = nc.RestrictBasesFilter(('A', 'C', 'T'))
no_gggg_constraint = nc.ForbiddenSubstringFilter(ILLEGAL_SUBSTRINGS_FOUR)
no_aaaaa_constraint = nc.ForbiddenSubstringFilter(ILLEGAL_SUBSTRINGS_FIVE)
c_content_constraint = nc.BaseCountFilter('C', floor(0.7 * SIGNAL_DOMAIN_LENGTH),
ceil(0.3 * SIGNAL_DOMAIN_LENGTH))

# Domain pools
SUBDOMAIN_SS_POOL: nc.DomainPool = nc.DomainPool(f'SUBDOMAIN_SS_POOL',
SIGNAL_DOMAIN_LENGTH - EXTENDED_TOEHOLD_LENGTH)
SUBDOMAIN_S_POOL: nc.DomainPool = nc.DomainPool(f'SUBDOMAIN_S_POOL', EXTENDED_TOEHOLD_LENGTH)
TOEHOLD_DOMAIN_POOL: nc.DomainPool = nc.DomainPool(
name='TOEHOLD_DOMAIN_POOL', length=TOEHOLD_LENGTH, numpy_constraints=[three_letter_code_constraint])
name='TOEHOLD_DOMAIN_POOL', length=TOEHOLD_LENGTH, numpy_filters=[three_letter_code_constraint])

SIGNAL_DOMAIN_POOL: nc.DomainPool = nc.DomainPool(
name='SIGNAL_DOMAIN_POOL', length=SIGNAL_DOMAIN_LENGTH,
numpy_constraints=[three_letter_code_constraint, c_content_constraint, no_aaaaa_constraint,
no_gggg_constraint])
numpy_filters=[three_letter_code_constraint, c_content_constraint, no_aaaaa_constraint,
no_gggg_constraint])

# Alias
dc_complex_constraint = nc.nupack_complex_base_pair_probability_constraint
Expand Down Expand Up @@ -365,7 +365,7 @@ def base_difference_constraint(domains: Iterable[nc.Domain]) -> nc.DomainPairCon
"""

def evaluate(seqs: Tuple[str, ...], domain_pair: Optional[nc.DomainPair]) \
-> Tuple[float, str]:
-> nc.Result:
seq1, seq2 = seqs
if domain_pair is not None:
domain1, domain2 = domain_pair.domain1, domain_pair.domain2
Expand Down Expand Up @@ -401,7 +401,7 @@ def evaluate(seqs: Tuple[str, ...], domain_pair: Optional[nc.DomainPair]) \
f'\t{domain1}: {domain1.sequence}\n'
f'\t{domain2}: {domain2.sequence}\n')

return result, summary
return nc.Result(excess=result, summary=summary)

pairs = itertools.combinations(domains, 2)

Expand Down Expand Up @@ -430,15 +430,15 @@ def violated(seq: str):
return True
return False

def evaluate(seqs: Tuple[str, ...], strand: Optional[nc.Strand]) -> Tuple[float, str]:
def evaluate(seqs: Tuple[str, ...], strand: Optional[nc.Strand]) -> nc.Result:
seq = seqs[0]
if violated(seq):
violation_str = '** violation**'
score = 100
else:
violation_str = ''
score = 0
return score, f"{strand.name}: {strand.sequence()}{violation_str}"
return nc.Result(excess=score, summary=f"{strand.name}: {strand.sequence()}{violation_str}")

return nc.StrandConstraint(description="Strand Substring Constraint",
short_description="Strand Substring Constraint",
Expand Down
12 changes: 6 additions & 6 deletions examples/sst_canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ def create_design(width: int, height: int) -> nc.Design:
:return:
design with `width` x `height` canvas of SSTs
"""
numpy_constraints = [
nc.NearestNeighborEnergyConstraint(-9.3, -9.0, 52.0), # energies should all be "close"
nc.RunsOfBasesConstraint(['C', 'G'], 4), # forbid substrings of form {C,G}^4
nc.ForbiddenSubstringConstraint(['AAAAA', 'TTTTT']), # forbid 5 A's in a row or 5 T's in a row
numpy_filters = [
nc.NearestNeighborEnergyFilter(-9.3, -9.0, 52.0), # energies should all be "close"
nc.RunsOfBasesFilter(['C', 'G'], 4), # forbid substrings of form {C,G}^4
nc.ForbiddenSubstringFilter(['AAAAA', 'TTTTT']), # forbid 5 A's in a row or 5 T's in a row
]

domain_pool_10 = nc.DomainPool(f'length-10_domains', 10, numpy_constraints=numpy_constraints)
domain_pool_11 = nc.DomainPool(f'length-11_domains', 11, numpy_constraints=numpy_constraints)
domain_pool_10 = nc.DomainPool(f'length-10_domains', 10, numpy_filters=numpy_filters)
domain_pool_11 = nc.DomainPool(f'length-11_domains', 11, numpy_filters=numpy_filters)

design = nc.Design()

Expand Down
2 changes: 1 addition & 1 deletion nuad/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = '0.3.5' # version line; WARNING: do not remove or change this line or comment
version = '0.4.0' # version line; WARNING: do not remove or change this line or comment
Loading

0 comments on commit 370291c

Please sign in to comment.