Closed:How to use cmd?
1
0
Entering edit mode
7.1 years ago
mrth ▴ 30

"Hello world", "...again",

I am using Python (2.7) and, with previous help from Biostars, created a class that parses a FASTA file in a dictionary output with this code:

class FastaFile(object):
    def __init__(self, path):
        self.path = path
        self._map = {}
        self.__fasta_iter()

    def __str__(self):
        return self._map.__str__()

    def __fasta_iter(self):
        fasta = open(self.path)
        fasta_iter = (x[1] for x in groupby(fasta, lambda line: line[0] == ">"))
        for header in fasta_iter:
            header = header.next()[1:9].strip()
            seq = "".join(s.strip() for s in fasta_iter.next())
            self._map[header] = seq

    def getitem(self, k):
        return self._map[k]

    def __iter__(self):
        for k in self._map:
            yield k, self._map[k]

cff = FastaFile("obs.fasta")

for sequence_id, sequence in cff:
    print sequence_id, sequence

What I would like to be able to do is have a user input a sequence identification number into the command line and the output given will be the sequence associated with that number. The problem is I don't know how!

I've been reading into raw_input and cmd on the python library website though not entirely sure how to begin as I find it difficult to read large paragraphs with no clear examples (dyslexic). I think cmd is what I should be using and I would like to use class as much as possible. Not entirely sure what the next step forward is. Any suggestions would be very helpful either useful code (me likey) or even links to websites with clear (maybe colourful) examples.

dictionary fasta sequences python command line • 162 views
ADD COMMENT
This thread is not open. No new answers may be added
Traffic: 1855 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6