nleroy917 / optipyzer

Multi-Species Codon Optimization Engine
https://optipyzer.com
Apache License 2.0
25 stars 6 forks source link

Optimizing from AA acid sequence returns NoneType Object #9

Closed cfreschlin closed 3 years ago

cfreschlin commented 3 years ago

Hi there, I'm trying to use Optipyzer for optimizing protein sequences with yeast codons. The program works perfectly until I switch the input sequence to amino acids, at which point I get the following error:

Traceback (most recent call last): File "/test.py", line 29, in optimized = optipyzer.optimize(seq,org_list=[org1,org2],weights=[1,2]) File "/anaconda3/lib/python3.8/site-packages/optipyzer/api.py", line 160, in optimize data = response.json() AttributeError: 'NoneType' object has no attribute 'json'

I ran the following code:

import optipyzer

# initalize API
optipyzer = optipyzer.api()

# search for e coli
results = optipyzer.search(name='Saccharomyces cerevisiae')
print(results)
org1 = results[0]
print(org1)

# search for campylbacter
results = optipyzer.search(name='Campylobacter')
org2 = results[0]

# pull codon usage for those organisms
codon_usage1 = optipyzer.pull_codons(org1)
codon_usage2 = optipyzer.pull_codons(org2)

# optimize a sequence to those organisms, weight campylobascter twice as much
seq = 'MFYKLILNGKTLKGETTTEAVDAYTAEKRF'
optimized = optipyzer.optimize(seq,org_list=[org1,org2],weights=[1,2])

Is there a setting I need to change for it to accept amino acid sequences?

Thanks! Chase

nleroy917 commented 3 years ago

Okay, I've been looking into this and haven't fully figured it out yet - but give me a few days and I will hopefully find the root of it and get back to you! Somethings going wrong with the optimization engine (that unfortunately, I am not the sole author of).

In the meantime make sure you are setting your seq_type to "protein" like so:

seq = 'MFYKLILNGKTLKGETTTEAVDAYTAEKRF'
optimized = optipyzer.optimize(seq,org_list=[org1,org2],weights=[1,2], seq_type="protein") # <--- Notice seq_type

I bumped the version to v0.24 on PyPi and should take care of error handling a little bit better so if you want you can upgrade using pip install optipyzer --upgrade.

Hopefully, it will still work with other sequences and species but the ones you are providing seem to break the code! I think this is an issue with the PyPi package since I was also able to optimize this sequence using the web interface just fine. In the meantime feel free to use the UI if you aren't using high-throughput workflows!

cfreschlin commented 3 years ago

Hi - thanks for the quick response. The update seems to work! I hadn't been designating protein as the sequence but was also running into an additional error. At random points (usually 200 to 400 sequences into the optimization) the code was failing. But the update seems to have fixed that. Thanks! - Chase

nleroy917 commented 3 years ago

Great! I need better documentation 😅 The whole app needs refactoring really since it's an older project of mine, but glad to hear it's working again!