我有这段读取PSL文件的代码。为了清楚起见,我在下面粘贴了整个内容,但我现在真正关注的是readPSLpairs方法(它在最底层)。现在,我只是尝试让该方法打印psl文件的前20行,但由于某种原因,它没有...我没有收到错误消息或其他任何东西--但是程序是空白的。我遗漏了什么?谢谢。
import sys
class PSLreader :
'''
Class to provide reading of a file containing psl alignments
formatted sequences:
object instantiation:
myPSLreader = PSLreader(<file name>):
object attributes:
fname: the initial file name
methods:
readPSL() : reads psl file, yielding those alignments that are within the first or last
1000 nt
readPSLpairs() : yields psl pairs that support a circular hypothesis
Author: David Bernick
Date: May 12, 2013
'''
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编辑:所以我试着引用main,如下所示:
def main():
new_psl = PSLreader(fname)
new_psl.readPSLpairs()#creating class objects
new_psl.output()
main()但这仍然不能使代码工作...错误状态为"NameError:全局名称'fname‘未定义“
发布于 2014-05-24 05:49:16
首先,readPSLpairs函数中的check i>20意味着程序将只打印第20行之后的行。如果您的文件只有20行(或者少于20行满足readPSL中的约束条件),那么就可以解释您的问题了。我会检查有多少行通过了readPSL (形式为if condition: continue)的检查;尝试在readPSL中放置一些打印语句。
另外,如果这是您的整个程序,那么您没有任何main方法来实际运行它;请确保您的代码实际上正在运行某些东西!
https://stackoverflow.com/questions/23838693
复制相似问题