New python user need help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • drjekil
    New Member
    • Apr 2008
    • 5

    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
    TGCGCATATTGTCTA ACTATGGCTGTGGCC GGA
    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:",c ount
    print ">",seq

    But its only printing "34"

    any idea?
    Thanks in advance
  • drjekil
    New Member
    • Apr 2008
    • 5

    #2
    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",cou nt
    print ">my seq " ,
    print seq

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

    How i can break this line?

    Comment

    • boxfish
      Recognized Expert Contributor
      • Mar 2008
      • 469

      #3
      Originally posted by drjekil
      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
      Code:
      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
      Code:
      count = input("Length: ")
      Then you can just get rid of the line
      Code:
      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.

      Comment

      • bvdet
        Recognized Expert Specialist
        • Oct 2006
        • 2851

        #4
        Originally posted by drjekil
        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",cou nt
        print ">my seq " ,
        print seq

        I am getting output like this:
        Length:34 <function count at 0xb7ebe80c>
        >my seq GTGTCATTGGGCTTT CGTCTTTCATACCAG GCCC
        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:[code=Python]print ">my seq\n%s" % seq[/code]
        OR drop the comma.

        Comment

        Working...