Skip to content

Commit

Permalink
added random nucl sequence generator
Browse files Browse the repository at this point in the history
  • Loading branch information
rajanbit committed Apr 25, 2024
1 parent 5edf24a commit 8b95131
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/seqplotter/nucl.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,29 @@ def translate(self):
elif set(super().comp().keys()).issubset(["A", "T", "G", "C"])==False:
raise TypeError("Gene sequence contain ambiguous nucleotides")

# Function to generate random DNA sequence with length=l and gc_frequency=g
@classmethod
def generate_random_seq(cls, l:int, gc:float, count=1):
if count == 1:
seq = ""
nt = ["A", "T", "G", "C"]
for i in range(l):
if uniform(0.01, 1.0) < gc:
seq += nt[randint(2, 3)]
else:
seq += nt[randint(0, 1)]
cls("random_seq", seq)
else:
for c in range(count):
seq = ""
nt = ["A", "T", "G", "C"]
for i in range(l):
if uniform(0.01, 1.0) < gc:
seq += nt[randint(2, 3)]
else:
seq += nt[randint(0, 1)]
cls(f"random_seq{c+1}", seq)

class RNA(DNA):

# Constructor
Expand Down

0 comments on commit 8b95131

Please sign in to comment.