<jupyter_start><jupyter_text>Generate your own DNA sequences **Required Information**- Length of Sequence- List of Nucleotides<jupyter_code># define the length of the sequence

length=10
# supply the list of nucleotides/bases

bases=['A','C','G','T']
print(length)
print(bases)<jupyter_output>['A', 'C', 'G', 'T']<jupyter_text>Generate a Sequence<jupyter_code># import random module
from random import choice<jupyter_output><empty_output><jupyter_text>Approach 1 : using the for loop<jupyter_code># creating an empty sequence
sequence=''

# randomly select a base and add it to the sequence (repeat 10 times)
for i in range(length):
    base=choice(bases)
    sequence+=base
    
print(sequence)<jupyter_output>GTTTAGGGGC<jupyter_text>Approach 2 : using a list comprehension<jupyter_code>sequence=[choice(bases) for i in range(length)]
print(sequence)
# convert the list to a string
sequence=''.join(sequence)
print(sequence)<jupyter_output>CAATGGGTTC<jupyter_text>Approach 3 : using a while loop<jupyter_code># create an empty list
sequence=''

while len(sequence)!=10:
    base=choice(bases)
    sequence+=base
print(sequence)<jupyter_output>GGCATTGATC<jupyter_text>Generate Multiple Sequences  Approach: Combine functions and loops<jupyter_code># import the random module
from random import choice
# create a function to generate a sequence
def generate_sequence(length=10):
    bases=['A','C','G','T']
    sequence=[choice(bases) for i in range(length)]
    sequence=''.join(sequence)
    return sequence
# scenario 1: generate sequences of the same length

length=10
number_of_sequences=5
sequences=[generate_sequence(length) for i in range(number_of_sequences)]
sequences
# scenario 2: generate sequences with different lengths
# user defined lengths
lengths=[10,5,6,5]
sequences=[generate_sequence(length) for length in lengths]
print(sequences)
len(sequences[0])
# computer generated lengths 
# numbers will be randomly generated by python
from random import choice
from random import randint
# define the number of sequences
number_of_sequences=5

# generate the lengths using randint
lengths=[randint(5,10) for i in range(number_of_sequences)]
lengths
sequences=[generate_sequence(length) for length in lengths]
sequences<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09774436090225563, 'fraction_numerical': 0.011499336576735958, 'mean_word_length': 7.225454545454546, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '326363', 'license': 'MIT', 'n_tokens_mistral': 729, 'n_tokens_neox': 689, 'n_words': 211, 'path': 'Session 8 Generate DNA sequences in Python.ipynb', 'repo_name': 'vappiah/Python-Programming-for-Biologists', 'size': '2261'}