By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,957 Members | 2,038 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,957 IT Pros & Developers. It's quick & easy.

New python user need help

P: 5
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
import sys
from string import *
count = input("34")
seq = ''.join([random.choice('AGTC') for x in range(count)])
print "Length:",count
print ">",seq

But its only printing "34"

any idea?
Thanks in advance
Nov 15 '08 #1
Share this Question
Share on Google+
3 Replies


P: 5
Almost solved this problem...
import random
import sys
from string import*
a=random.choice('AGTC')
seq = ''.join([random.choice('AGTC') for x in range(34)])
print "Length:34",count
print ">my seq " ,
print seq

I am getting output like this:
Length:34 <function count at 0xb7ebe80c>
>my seq GTGTCATTGGGCTTTCGTCTTTCATACCAGGCCC
But i want this way:
length:34
>my seq
atggg.bla..bla...attac

How i can break this line?
Nov 15 '08 #2

boxfish
Expert 100+
P: 469
But its only printing "34"
When it says 34, try typing in 34 and pressing enter. It is asking what number to put into count.
The line
Expand|Select|Wrap|Line Numbers
  1. count = input("34")
prints out 34 and waits for the user to enter a number, then puts that number into count. It would make more sense to say
Expand|Select|Wrap|Line Numbers
  1. count = input("Length: ")
Then you can just get rid of the line
Expand|Select|Wrap|Line Numbers
  1. print "Length:",count
Ah, I just saw your new post. The code you posted at first is much better than what you have now.
By the way, it would be helpful if you used code tags around your code. Put [CODE] before the code and [/CODE] after it, so it shows up in a code box and the indentation isn't wrecked. Thanks.
I hope this is helpful.
Nov 15 '08 #3

bvdet
Expert Mod 2.5K+
P: 2,851
Almost solved this problem...
import random
import sys
from string import*
a=random.choice('AGTC')
seq = ''.join([random.choice('AGTC') for x in range(34)])
print "Length:34",count
print ">my seq " ,
print seq

I am getting output like this:
Length:34 <function count at 0xb7ebe80c>
>my seq GTGTCATTGGGCTTTCGTCTTTCATACCAGGCCC
But i want this way:
length:34
>my seq
atggg.bla..bla...attac

How i can break this line?
You almost have it. Either this:
Expand|Select|Wrap|Line Numbers
  1. print ">my seq\n%s" % seq
OR drop the comma.
Nov 15 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.