0

i'm a biologist and been making a few scripts to help me deal with a lot of files. Recently I developed one and I'm having troubles. It is a script to parse some files I have, to make a xls sheet. The problem is, when I use the OO approach the program just won't work. Here it is:

from linecache import getline

class Parser:
    def __init__(self , pth='' , prot=''):
        self.pth = pth
        self.failed = ''
        self.prot_name = prot

    def sumParser(self , f):
        l_info = getline(f , 6)
        l_info = l_info.replace(':' , '')
        l_info = l_info.replace('plot' , '')
        l_info = l_info.replace('+' , '')
        l_info = l_info.replace('core' , '')
        l_info = l_info.replace('allow' , '')
        l_info = l_info.replace('gener' , '')
        l_info = l_info.replace('disall' , '')
        l_info = l_info.replace('*' , '')
        l_info = l_info.replace('Ramachandran' , '')
        l_info = l_info.replace('|' , '')
        l_info = l_info.replace('%' , '')
        l_info= " ".join(l_info.split())
        l_info = l_info.replace(' ', ';')
        return l_info

    def setProt(self, prot):
        self.prot_name = prot

    def setPth(self , pth):
        self.pth = pth

    def Open(self):
        self.f = open(self.pth)
        self.f2 = open('presheet.prst' , 'w')



    def Parser(self):
        for line in self.f:

            model_name = line[0:line.find('.p')]
            L = " ".join(line.split())
            L = L.replace(' ', ';')
            self.f2.write(L+';')
            L = self.sumParser(model_name+'.sum') + '\n'
            self.f2.write(L)   

    def Close(self):
        self.__f.close()
        self.__f2.close()

The inputs for the file are: one file, the .sum,(whose 6th line is where the info I want is) and the other that is the 'pdop.pdop', which is on the following format:

GH4p.B9990001.pdb   -134134  -111111  1.00000
GH4p.B9990002.pdb   -134134  -111111  1.00000
GH4p.B9990003.pdb   -134134  -111111  1.00000
GH4p.B9990004.pdb   -134134  -111111  1.00000
GH4p.B9990005.pdb   -134134  -111111  1.00000

Except that on the actual file there are 100 entries. What I want(and was able without OO) is to merge both files into one(using ';' to join the words) for me to put it all on a xls sheet. The rest is done and working. I can parse it with a script, using no OO, but when I put everything into a class it just wont work! I don't know anything I could do, I read this code more than 30 times, and can't see the solution(maybe because of the tests for college).

EDIT: Sorry for not being too clear!

OO stands for Object Oriented, and it means I'm using classes to do the job, but not sure if I was doing it right, learned all bymyself.

It doesn't outputs any exception, it just doesn't work right!!

The code to run this is simple, 3 lines:

parser = Parser('pdop.pdop')
parser.Open()
parser.Parse('GH4p')

This is it. I was going to add it on the more complex program, but wont do it if it is not working, right?

Another info... the expected output:

GH4p.B99900001.pdb;123123123;123123123;123123123;1.000;91;4;4;1(example!)
4

0 回答 0