(Working in R studio) I am trying to generate a DNA sequence in FASTA format where each base has equal probability of being randomly selected. Specifically I need to write it as a function. Here is what I have so far:
#Define length of sequence
length=100
#supply list of nucleotides
bases=["A","G","C","T"]
print(bases)
#Generate a sequence
from random import choice
#create empty sequence
sequence=""
#randomly select base and add to sequence(repeat 100 times for length=100)
for i in range(length):
base=choice(bases)
sequence+=base
print(sequence)
#create function to generate sequences
def getsequences(length):
sequence=""
for count in range(length):
sequence+=choice(bases)
return sequence
getsequences(length)
#where "getsequences" is the function name
This seems to work (if you spot an error please let me know), however now I need to create a text file where I can story this sequence data. Any ideas?