Python Forum
Guidance in Creating random output for a variable.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Guidance in Creating random output for a variable.
#1
Hi - This thread is not for problem solving but for giving tools into creating a code for a certain idea (tried to find a solution in certain threads in the forum but to no avail)

so here it is:
I have the current RNA codons, in which the keys stands for the RNA codon and the values stands for the amino acid it translated to. I shall call this dictionary "genetic_code"
genetic_code = {"UUU":"F", "UUC":"F", "UUA":"L", "UUG":"L", "UCU":"S", "UCC":"s", "UCA":"S", "UCG":"S", "UAU":"Y", "UAC":"Y", "UAA":"STOP", "UAG":"STOP", "UGU":"C", "UGC":"C", "UGA":"STOP", "UGG":"W", "CUU":"L", "CUC":"L", "CUA":"L", "CUG":"L", "CCU":"P", "CCC":"P", "CCA":"P", "CCG":"P", "CAU":"H", "CAC":"H", "CAA":"Q", "CAG":"Q", "CGU":"R", "CGC":"R", "CGA":"R", "CGG":"R", "AUU":"I", "AUC":"I", "AUA":"I", "AUG":"M", "ACU":"T", "ACC":"T", "ACA":"T", "ACG":"T", "AAU":"N", "AAC":"N", "AAA":"K", "AAG":"K", "AGU":"S", "AGC":"S", "AGA":"R", "AGG":"R", "GUU":"V", "GUC":"V", "GUA":"V", "GUG":"V", "GCU":"A", "GCC":"A", "GCA":"A", "GCG":"A", "GAU":"D", "GAC":"D", "GAA":"E", "GAG":"E", "GGU":"G", "GGC":"G", "GGA":"G", "GGG":"G",}
Now, i want to create a new variable (that shall be named "RNA_seq" ).
in this variable, i want to write a code that will pick me 3 random keys from "genetic_code" dictionary, excluding the keys with the value of "STOP". output example:
RNA_seq = ["ACU", "CGU", "CGA"] 
all the possible random keys besides the keys that has "STOP" value

i am sorry if i am not clear enough - still at the start of the road.
many thanks
Reply
#2
import random genetic_code = {"UUU":"F", "UUC":"F", "UUA":"L", "UUG":"L", "UCU":"S", "UCC":"s", "UCA":"S", "UCG":"S", "UAU":"Y", "UAC":"Y", "UAA":"STOP", "UAG":"STOP", "UGU":"C", "UGC":"C", "UGA":"STOP", "UGG":"W", "CUU":"L", "CUC":"L", "CUA":"L", "CUG":"L", "CCU":"P", "CCC":"P", "CCA":"P", "CCG":"P", "CAU":"H", "CAC":"H", "CAA":"Q", "CAG":"Q", "CGU":"R", "CGC":"R", "CGA":"R", "CGG":"R", "AUU":"I", "AUC":"I", "AUA":"I", "AUG":"M", "ACU":"T", "ACC":"T", "ACA":"T", "ACG":"T", "AAU":"N", "AAC":"N", "AAA":"K", "AAG":"K", "AGU":"S", "AGC":"S", "AGA":"R", "AGG":"R", "GUU":"V", "GUC":"V", "GUA":"V", "GUG":"V", "GCU":"A", "GCC":"A", "GCA":"A", "GCG":"A", "GAU":"D", "GAC":"D", "GAA":"E", "GAG":"E", "GGU":"G", "GGC":"G", "GGA":"G", "GGG":"G", } def get_3_random_keys_no_stop_values(input_dict): while True: choices = random.sample(input_dict.keys(), k=3) if 'STOP' not in [input_dict[value] for value in choices]: return choices print(get_3_random_keys_no_stop_values(genetic_code))
Output:
['GGA', 'ACG', 'GAC']
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  creating arbitrary local variable names Skaperen 9 2,947 Sep-07-2024, 12:12 AM
Last Post: Skaperen
  Unexpected output while using random.randint with def terickson2367 1 1,679 Oct-24-2023, 05:56 AM
Last Post: buran
  Whys is asterisk and random variable necessary in these functions? rrowhe4d 5 3,375 Aug-05-2022, 07:53 AM
Last Post: Gribouillis
  How to combine two output in one variable? ilknurg 2 2,488 Aug-01-2022, 09:31 AM
Last Post: Gribouillis
  Os command output in variable shows wrong value paulo79 2 2,907 Apr-09-2022, 03:48 PM
Last Post: ndc85430
  Command output to Variable ironclaw 1 7,640 Aug-26-2021, 06:55 PM
Last Post: bowlofred
  Your Guidance caslor 1 3,406 Mar-28-2021, 09:34 PM
Last Post: Larz60+
  Getting a GET request output text into a variable to work with it. LeoT 2 6,812 Feb-24-2021, 02:05 PM
Last Post: LeoT
  [split] Creating a variable as a function DPaul 23 12,431 Sep-07-2020, 05:20 PM
Last Post: DPaul
  Creating a variable as a function JarredAwesome 4 4,480 Sep-06-2020, 05:08 AM
Last Post: buran

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.