def test_that_constraints_in_records_are_accounted_for(): sequence = "ATACGTCTCTAG" rec = sequence_to_biopython_record(sequence) annotate_record(rec, label="@cds") from genedom import BUILTIN_STANDARDS emma = BUILTIN_STANDARDS["EMMA"] p7 = emma.domesticators["p7"] result = p7.domesticate(rec) seq_after = str( result.record_after[len(p7.left_flank):-len(p7.right_flank)].seq) assert translate(seq_after) == translate(sequence)
def test_AvoidRareCodons_as_constraint(): numpy.random.seed(123) sequence = "ATG" "TTT" "ATA" "CCA" "CTT" "TAG" problem = DnaOptimizationProblem( sequence=sequence, constraints=[EnforceTranslation(), AvoidRareCodons(0.11, "e_coli")], ) assert problem.all_constraints_pass() assert problem.sequence_edits_as_array().sum() == 4 assert translate(problem.sequence) == translate(sequence)
def test_EnforceTranslation_bacterial_valine(): table_name = "Bacterial" protein = "LLTMMVTTTTVMVL" protein_sequence = reverse_translate(protein, table=table_name) for first_codon_before, first_codon_after in [ ("ATG", "ATG"), # methionine stays the only methionine codon ("GTG", "GTG"), # valine-start-codon stays the only valine-start-codon ]: sequence = first_codon_before + protein_sequence cds_constraint = EnforceTranslation( genetic_table="Bacterial", start_codon="keep" ) problem = DnaOptimizationProblem( sequence=sequence, constraints=[cds_constraint], objectives=[EnforceChanges()], logger=None, ) assert problem.constraints[0].translation == "MLLTMMVTTTTVMVL" problem.optimize() protein_after = translate( problem.sequence, table_name, assume_start_codon=True ) assert protein_after == "M" + protein assert problem.sequence[:3] == first_codon_after
def test_AvoidRareCodons_as_constraint_reversed(): numpy.random.seed(123) sequence = "ATG" "TTT" "ATA" "CCA" "CTT" "TAG" rev_sequence = reverse_complement(sequence) location = (0, len(sequence), -1) problem = DnaOptimizationProblem( sequence=rev_sequence, constraints=[ EnforceTranslation(location=location), AvoidRareCodons(0.11, "e_coli", location=location), ], ) assert problem.all_constraints_pass() assert problem.sequence_edits_as_array().sum() == 4 new_sequence = reverse_complement(problem.sequence) assert translate(new_sequence) == translate(sequence)
def test_AvoidStopCodons(): numpy.random.seed(123) problem = DnaOptimizationProblem( sequence="".join(["ATT", "TAG", "GCC", "TGA", "ATC", "TAA"]), constraints=[AvoidStopCodons()], logger=None, ) assert not problem.all_constraints_pass() problem.resolve_constraints() assert problem.all_constraints_pass() assert "*" not in translate(problem.sequence)
def test_maximal_protein_sequence_change(): np.random.seed(123) protein = dc.random_protein_sequence(200) sequence = dc.reverse_translate(protein) problem = dc.DnaOptimizationProblem( sequence=sequence, constraints=[dc.EnforceTranslation()], objectives=[dc.EnforceChanges()], ) problem.resolve_constraints() problem.optimize() assert problem.number_of_edits() == 238 assert dc.translate(problem.sequence) == protein