I ve to Write a Python program that prints a random DNA sequence in Fasta format.

That program should ask for the length of the sequence and suggest a reasonable sequence name.

The session should look something like:
> python randomdna.py
Length: 34

>MySequence
TGCGCATATTGTCTAACTATGGCTGTGGCCGGA
The output must be in valid Fasta format.
I am trying this way:

import random

>>> ''.join([random.choice('AGTC') for x in range(10)])
'GGTTTCGGTA'

>>> ''.join([random.choice('AGTC') for x in range(10)])
'GCGGGTCCGT'

but how to print the length of that string and a seq name with fasta symbol ">"?any idea?
thanks in advance.

Recommended Answers

All 6 Replies

>>> import random
>>> my_seq = ''.join([random.choice('AGTC') for x in range(10)])
>>> my_seq
'TATCCTTGTT'
>>> len(my_seq)
10
>>>

I'm not quite sure what you mean by "printing in FASTA format with the > "

Here" >"symbols indicates that this is a fasta file.
My output should look like:

length:10
>my seq
atcggctatg(randomly printed,10 ,if length 20,then it should print 20 base randomly)

Welcome to daniweb!
Can you wrap your codes in tags please. Also define what FASTA FORMAT is. We are from different background, and not all of us knows Bios and Logos!

Thanks!do not worry about fasta..I have to print 4 letters A,T,G,C several times randomly,output will be like this
length : (no of ATGC)
>file name
AGTC..BLA... BLA...(same number,defined by length) if length is 5 then it will print randomly 5 letters among ATGC.say,AGCTA.
Thanks!

Is this what your talking about?

import random
count = input("How long shall the sequence be?")
seq = ''.join([random.choice('AGTC') for x in range(count)])
print "Length:",count
print ">",seq

Thanks,it is!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.