Edinburgh-Genome-Foundry / DnaChisel

:pencil2: A versatile DNA sequence optimizer
https://edinburgh-genome-foundry.github.io/DnaChisel/
MIT License
213 stars 38 forks source link

Error! The optimized sequence is not consist with the original one in protein level. #3

Closed y9c closed 6 years ago

y9c commented 6 years ago

test code

from dnachisel import *
from Bio.Seq import Seq
from Bio.Alphabet import generic_dna

# DEFINE THE OPTIMIZATION PROBLEM
problem = DnaOptimizationProblem(
    sequence=random_dna_sequence(900),
    constraints=[AvoidPattern(enzyme="BsaI"),
                 EnforceGCContent(mini=0.3, maxi=0.7, window=50)],
    objectives=[CodonOptimize(species='e_coli', location=(0, 3))]
)
# SOLVE THE CONSTRAINTS, OPTIMIZE WITH RESPECT TO THE OBJECTIVE
problem.resolve_constraints()
problem.optimize()
# PRINT SUMMARIES TO CHECK THAT CONSTRAINTS PASS
print(problem.constraints_text_summary())
print(problem.objectives_text_summary())
print(problem.sequence_before)
print(problem.sequence)
print("---------------------------------")
temp1 = str(
    Seq(problem.sequence_before, generic_dna).translate(
        table="Standard",
        stop_symbol="*",
        to_stop=False,
        cds=False,
        gap=None,
    )
)
temp2 = str(
    Seq(problem.sequence, generic_dna).translate(
        table="Standard",
        stop_symbol="*",
        to_stop=False,
        cds=False,
        gap=None,
    )
)
print(temp2 == temp1)
print("---------------------------------")
y9c commented 6 years ago

btw, the code in readme is of bugs...

Zulko commented 6 years ago

Just CodonOptimize as an objective is not enough to conserve translation, you also need to have EnforceTranslation in your constraints:

constraints=[
    EnforceTranslation(),
    AvoidPattern(enzyme="BsaI"),
    EnforceGCContent(mini=0.3, maxi=0.7, window=50)
]

It works, I just checked.

Thanks for the notification regarding the readme, I'll have a look.

Zulko commented 6 years ago

Indeed the readme code was full of bugs, I fixed them, thanks for that.

y9c commented 6 years ago

It works fine now. Thank you @Zulko