Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python打印语句不返回PSL数据_Python_Bioinformatics - Fatal编程技术网

Python打印语句不返回PSL数据

Python打印语句不返回PSL数据,python,bioinformatics,Python,Bioinformatics,我有一个代码,它生成了一个非常精巧的打印语句。这是我的密码: import sys class PSLreader : def __init__ (self, fname='EEV14-Cb.filtered.psl'): '''contructor: saves attribute fname ''' self.fname = fname def doOpen (self): if self.fname is '':

我有一个代码,它生成了一个非常精巧的打印语句。这是我的密码:

import sys
class PSLreader :

    def __init__ (self, fname='EEV14-Cb.filtered.psl'):
        '''contructor: saves attribute fname '''

        self.fname = fname

    def doOpen (self):
        if self.fname is '':
            return sys.stdin
        else:
            return open(self.fname)

    def readPSL (self):
        '''
        using filename given in init, returns each filtered psl records
        that contain alignments that are within the terminal 1000nt of
        the target. Incomplete psl records are discarded.
        If filename was not provided, stdin is used.

        This method selects for alignments that could may be part of a
        circle.

        Illumina pairs aligned to the top strand would have read1(+) and read2(-).
        For the bottoms trand, read1(-) and read2(+).

        For potential circularity,
        these are the conditions that can support circularity:
        read1(+) near the 3' terminus
        read1(-) near the 5' terminus
        read2(-) near the 5' terminus
        read2(+) near the 3' terminus

        so...
        any read(+) near the 3', or
        any read(-) near the 5'

        '''

        nearEnd = 1000   # this constant determines "near the end"
        with self.doOpen() as fileH:

            for line in fileH:
                pslList = line.split()
                if len(pslList) < 17:
                    continue
                tSize = int(pslList[14])
                tStart = int(pslList[15])
                strand = str(pslList[8])

                if strand.startswith('+') and (tSize - tStart > nearEnd):
                    continue
                elif strand.startswith('-') and (tStart > nearEnd):
                    continue

                yield line

    def readPSLpairs (self):
        i = 0
        for psl in self.readPSL():
            if i>20:
                print(psl.split())
                i+=1
            else: 
                break

fileH = ("EEV14-Cb.filtered.psl")
new_psl = PSLreader(fileH)
print (new_psl.readPSLpairs())
它仍然不起作用,但那是因为我总是在某个地方遇到语法问题

编辑2:我将代码更改为此,这导致了一个错误:

new_psl = PSLreader("EEV14-Cb.filtered.psl")
gen = new_psl.readPSLpairs()            
for line in gen:
    print (new_psl.readPSLpairs())
错误为:“TypeError:“非类型”对象不可编辑”

编辑3:

new_psl = PSLreader("EEV14-Cb.filtered.psl")
gen = new_psl.readPSLpairs()            
for line in gen:
     print line

当出现语法错误时,“打印行”中的“行”将突出显示。

readPSL将创建一个由readPSLpairs使用的对象,该对象不会产生或返回任何内容,因此打印输出是正确的

代码的最后两行应该如下所示

for line in gen:
    print line

它将允许您查看您询问的前20行。

但是,我仍然不确定为什么无法获取psl文件的前20行。我的意思是,这就是readPSLpairs的目的…我不知道你在readPSLpairs中想做什么。该方法将读取一行并由于“中断”退出循环。我错过什么了吗?你说的“放弃”可能不是“放弃”?这将得到前20行。当我将“break”改为“yield”时,我得到的输出是“”,这有点奇怪……这是正确的。要打印出这些行,您需要遍历它:gen=new_psl.readPSLpairs(),然后迭代:对于gen中的行:
for line in gen:
    print line