Hello i tried doing this problem from ROSALIND but when i put the example rna sequence (AUGGCCAUGGCGCCCAGAACUGAGAUCAAUAGUACCCGUAUUAACGGGUGA) it produced me the wrong output "['M', 'M', 'N', 'I']" instead of the suggested "MAMAPRTEINSTRING".I tried to modify the code but still not it did not give me the desired output.I would like some help if someone can.
Here is my code:
**dna_seq = input("PLace your RNA sequence here(it must not exceed 1kb):")
list = []
for x in range (0,len(dna_seq),3):
if dna_seq[x:x+3] == "AUG":
list.append("M")
elif dna_seq[x:x+3] == ("UUU" or "UUC"):
list.append("F")
elif dna_seq[x:x+3] == ("UUA" or "UUG" or "CUU" or "CUC" or "CUA" or "CUG"):
list.append("L")
elif dna_seq[x:x+3] == ("AUU" or "AUC" or "AUA"):
list.append("I")
elif dna_seq[x:x+3] == ("GUA" or "GUG" or "GUC" or "GUU"):
list.append("V")
elif dna_seq[x:x+3] == ("UCA" or "UCU" or "UCG" or "UCC"):
list.append("S")
elif dna_seq[x:x+3] == ("CCU" or "CCA" or "CCC" or "CCG" or "AGU" or "AGC"):
list.append("P")
elif dna_seq[x:x+3] == ("ACA" or "ACU" or "ACG" or "ACC"):
list.append("T")
elif dna_seq[x:x+3] == ("GCU" or "GCA" or "GCG" or "GCC"):
list.append("A")
elif dna_seq[x:x+3] == ("UAU" or "UAC"):
list.append("Y")
elif dna_seq[x:x+3] == ("UAA" or "UAG" or "UGA"):
list.append("STOP")
elif dna_seq[x:x+3] == ("CAU" or "CAC"):
list.append("H")
elif dna_seq[x:x+3] == ("CAA" or "CAG"):
list.append("Q")
elif dna_seq[x:x+3] == ("AAU" or"AAC"):
list.append("N")
elif dna_seq[x:x+3] == ("AAA" or "AAG"):
list.append("K")
elif dna_seq[x:x+3] == ("GAU" or "GAC"):
list.append("D")
elif dna_seq[x:x+3] == ("GAA" or "GAG"):
list.append("E")
elif dna_seq[x:x+3] == ("UGU" or "UGC"):
list.append("C")
elif dna_seq[x:x+3] == ("UGG"):
list.append("W")
elif dna_seq[x:x+3] == ("CGA" or "CGG" or "CGC" or "CGU" or "AGA" or "AGG"):
list.append("R")
elif dna_seq[x:x+3] == ("GGU" or "GGC" or "GGA" or "GGG"):
list.append("G")
print(list)**
Thanks for your time!
The statement ("CAU" or "CAC") evaluates to "CAU".:
>>> ("CAU" or "CAC")
'CAU'
Thus your elif statements will only ever check the first codon in the list. You can fix this by rewriting your statements to this format:
elif dna_seq[x:x+3] == "CAU" or dna_seq[x:x+3] "CAC":
But much better would be to make a dictionary where your codons are the keys and the values are the amino acids corresponding to that codon. Then build your protein sequence by getting the value of a codon from the dictionary and add it your list.
Finally, don't name a variable in python list. It overwrites the built in function list().
Related
Is there a way to condense the following code to remove the pylint too many statements error. All this code is contained within a single function: -
selection = input("Enter 1, 2, 3, 4 or 5 to start: \n")
if selection == "1":
print("\nYou have selected "+"'"+question_data[0][0]+"', let's begin!")
for key in science:
print("--------------------------------------------------------\n")
print(key)
for i in science_choices[num_question-1]:
print("")
print(i)
choice = input("Enter you answer (A, B or C): \n").upper()
answers.append(choice)
correct_answers += check_correct_answer(science.get(key), choice)
num_question += 1
player_score(correct_answers, answers)
elif selection == "2":
...................................................
elif selection == "3":
...................................................
elif selection == "4":
...................................................
elif selection == "5":
...................................................
else:
print("\nYou entered an incorrect value.Please try again.\n")
start_new_quiz()
the program works as is but it's for a college assignment and I would prefer not to submit with pylint errors.
One obvious way is to create a function for each selection:
selection = input("Enter 1, 2, 3, 4 or 5 to start: \n")
if selection == "1":
treat_one()
elif selection == "2":
...................................................
elif selection == "3":
...................................................
elif selection == "4":
...................................................
elif selection == "5":
...................................................
else:
print("\nYou entered an incorrect value.Please try again.\n")
start_new_quiz()
def treat_one():
print("\nYou have selected "+"'"+question_data[0][0]+"', let's begin!")
for key in science:
print("--------------------------------------------------------\n")
print(key)
for i in science_choices[num_question-1]:
print("")
print(i)
choice = input("Enter you answer (A, B or C): \n").upper()
answers.append(choice)
correct_answers += check_correct_answer(science.get(key), choice)
num_question += 1
player_score(correct_answers, answers)
You could also create a dictionary:
functions_to_use = {
"1": treat_one,
...
}
function = functions_to_use.get(selection)
if function is None:
print("\nYou entered an incorrect value.Please try again.\n")
else:
function()
Of if you want to over-engineer it, use getattr:
function = getattr("treat_{selection}", error)
function()
def error():
print("\nYou entered an incorrect value.Please try again.\n")
So I am trying to make this continue from get_burger_choice to get_burger price to where it would flow and finish the program. I am trying to write this program to where I could get the type of burger then the price from get_burger_price. Heres the problem, I do not know how to intergrate it towards doing that. I am completely stuck after the part where it says "no" at the end part of get_burger_choice to where I can transition to get_burger_price
Here is the code that I used : the part highlighted is where Im having trouble transitioning:I would like it to where if the user says no, it would ask if they would like to see the price, and it would transition towards get_burger_price
def get_burger_choice():
SIZE = 3
burgers = ["Cheesy", "Regular", "Veggie" ]
search = True
while search == True:
index = 0
found = False
print("What type of burger would you like?")
searchValue = input()
while found == False and index <= SIZE - 1:
if burgers[index].lower()==searchValue.lower():
found = True
else:
index = index + 1
if found:
print("That is on our menu")
else:
print("That is not in our menu")
print("Do you want see another burger? yes/no: ")
tryagain = input()
if tryagain.lower() =='no':
print("Would you like to see the price? yes or no: ")
if
def price_burger(burger_choice, burger_price):
if burger_price == 'cheesy':
burger_price = 3.00
elif burger_choice == 'regular':
burger_price = 2.00
elif burger_choice == 'veggie':
burger_price = 2.00
else:
print("we do not have that, sorry")
return burger_price
def total_price(burger_price, burger_choice=None):
print("The burger cost $", burger_price)
def closing(burger_choice):
if burger_choice == 'cheesy':
print("Nice selection, This is our best!")
else:
print("enjoy!")
def main(burger_price = 0):
choice = "yes"
while choice != "no":
burger_choice = get_burger_choice()
burger_price = price_burger(burger_choice,burger_price)
total_price(burger_price)
closing(burger_choice)
choice = input("\nWould you like to try again? yes or no: ")
main()
I'm not sure if I'm barking up the wrong tree but I wanted to create a function to check if an account exists based on all optional parameters so it can be used to pull data depending on whatever you'd like to check on.
Basically the query should be:
where loginName = p1 or loginName = p2 or loginName = p3 but with the paramters all being optional, however at least one will be provided.
This is what I tried so far:
public async Task<bool> CheckAccountExistsAsync(string loginName = "", string authenticatorId = "", string eId = "")
{
if (string.IsNullOrWhiteSpace(loginName) && string.IsNullOrWhiteSpace(authenticatorId) && string.IsNullOrWhiteSpace(eId))
throw new InvalidOperationException("You must pass at least one parameter");
return await _context.Accounts.AnyAsync(a =>
(string.IsNullOrWhiteSpace(loginName) || a.LoginName == loginName)
|| (string.IsNullOrWhiteSpace(authenticatorId) || a.AuthenticatorId == authenticatorId)
|| (string.IsNullOrWhiteSpace(eId) || a.EmployeeId == eId));
}
Problem with this approach is that if I just pass the loginName, then the query is as follows with the condition completely omitted.:
SELECT CASE
WHEN EXISTS (
SELECT 1
FROM [Accounts] AS [a]) THEN CAST(1 AS bit)
ELSE CAST(0 AS bit)
END
I'm sure I'm missing something, is there a better approach?
What you are using is applicable for optional and expressions, e.g.
return await _context.Accounts.AnyAsync(a =>
(string.IsNullOrWhiteSpace(loginName) || a.LoginName == loginName)
&& (string.IsNullOrWhiteSpace(authenticatorId) || a.AuthenticatorId == authenticatorId)
&& (string.IsNullOrWhiteSpace(eId) || a.EmployeeId == eId));
For optional or you have to use optional and sub conditions and add additional check for all optional parameters missing, e.g.
return await _context.Accounts.AnyAsync(a =>
(string.IsNullOrWhiteSpace(loginName)
&& string.IsNullOrWhiteSpace(authenticatorId)
&& string.IsNullOrWhiteSpace(eId))
|| (!string.IsNullOrWhiteSpace(loginName) && a.LoginName == loginName)
|| (!string.IsNullOrWhiteSpace(authenticatorId) && a.AuthenticatorId == authenticatorId)
|| (!string.IsNullOrWhiteSpace(eId) && a.EmployeeId == eId));
I already have the 'ROLE_ADMIN', 'ROLE_SUPERUSER', 'ROLE_USER' roles set up and they are working perfectly. Now, I need to give access to 3 particular users to a certain page (with user names: admin1, admin2, admin3).
I tried the controller-centric approach, as follow...
import grails.plugin.springsecurity.annotation.Secured
#Secured(["authentication.name == 'admin1'", "authentication.name == 'admin2'", "authentication.name == 'admin3'"])
def transferMoney() {...}
But that only gave access to the first user, the admin1, the rest 2 didn't have the access.
Then I tried to give access from static mapping...
grails.plugin.springsecurity.interceptUrlMap = [
'/hostAdmin/account/transferMoney': ["authentication.name == 'admin1'", "authentication.name == 'admin2'", "authentication.name == 'admin3'"]
]
or
grails.plugin.springsecurity.controllerAnnotations.staticRules = [
[pattern: '/hostAdmin/account/transferMoney', access: ["authentication.name == 'admin1'", "authentication.name == 'admin2'", "authentication.name == 'admin3'"]]
]
But both of them had no effect, the /hostAdmin/account/transferMoney page was open to ALL.
Can someone please help me? I really have to figure out how to give access to these 3 users only. Thank you in advance!
The solution was actually pretty simple ^_^
I went with the controller-centric approach. And both of these solutions worked....
#Secured(["authentication.name == 'admin1' || authentication.name == 'admin2' || authentication.name == 'admin3'"])
or
#Secured(closure = {
assert request
assert ctx
authentication.name == 'admin1' || authentication.name == 'admin2' || authentication.name == 'admin3'
})
Hope someone finds this helpful :)
I would like to find all objects which have a year value which starts with 20... so I would like to search for 20*, where * is a wild card.
I tries something like
'match_phrase_prefix': { 'year': { 'query': '20*', 'max_expansions': 50}}
but I guess this only works for strings. How would I do this for integers?
EDIT: I found a solution... its not pretty but it works
year_query = '20'
if len(str(year_query)) < 4:
try:
low_year, high_year = extend_year(int(year_query))
filter_list.append({"range": {"year": {"gte": low_year, "lte": high_year}}})
except ValueError:
print "Not a valid input for year"
pass
else:
for year in year_query.split(','):
if '-' in year:
year_range = year.split('-')
high_year = year_range[1].strip()
if len(high_year) < 4:
low_year, high_year = extend_year(high_year)
try:
filter_list.append({"range" : {"year" : {"gte" : int(year_range[0].strip()),"lte" : int(high_year),"format": "yyyy"}}})
except ValueError:
print "Not a valid input for year"
pass
else:
try:
filter_list.append({ "match": {"year": int(year.strip()) }})
except ValueError:
print "Not a valid input for year"
pass
with the function
def extend_year(input_year):
length = len(str(input_year))
if length == 4:
return input_year, 0
elif length == 3:
return input_year*10, int(str(input_year) + '9')
elif length == 2:
return input_year*100, int(str(input_year) + '99')
elif length == 1:
return input_year*1000, int(str(input_year) + '999')
elif length == 0:
return 0, 9999
else:
return input_year, 0
if anybody can come up with a better solution please let me know
This should work
'range': { 'year': { 'gte': 2000, 'max_expansions': 50}}