473,387 Members | 1,529 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

New python user need help

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
3 1301
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
469 Expert 256MB
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
2,851 Expert Mod 2GB
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

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

Similar topics

5
by: Gary | last post by:
Hi- I've been searching the web for a while and I've been unable to find a way to access c data objects in python without using SWIG. I can do methods just fine but I can't access variables. ...
220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
36
by: Andrea Griffini | last post by:
I did it. I proposed python as the main language for our next CAD/CAM software because I think that it has all the potential needed for it. I'm not sure yet if the decision will get through, but...
8
by: Paul Cochrane | last post by:
Hi all, I've got an application that I'm writing that autogenerates python code which I then execute with exec(). I know that this is not the best way to run things, and I'm not 100% sure as to...
6
by: test | last post by:
Hi everyone, I'm creating a desktop Python application that requires web-based authentication for accessing additional application features. HTTP GET is really simple. HTTP POST is not (at...
112
by: mystilleef | last post by:
Hello, What is the Pythonic way of implementing getters and setters. I've heard people say the use of accessors is not Pythonic. But why? And what is the alternative? I refrain from using them...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.