def parsePSL(filename): for pslObj in pslparser.read(open(filename)): strand = pslObj.strand chrom = pslObj.tName name = pslObj.qName chromStart = pslObj.tStart chromEnd = pslObj.tEnd blockCount = pslObj.blockCount blockSizes = ','.join([str(i) for i in pslObj.blockSizes]) blockStarts = ','.join([str(i - chromStart) \ for i in pslObj.tStarts]) thickStart = chromStart thickEnd = chromEnd writer = csv.writer(sys.stdout, dialect='excel-tab') writer.writerow((chrom, chromStart, chromEnd, name, 255, strand, thickStart, thickEnd, '0,0,0', blockCount, blockSizes, blockStarts))
def parse_psl(filename): '''Reads alignments from PSL format and create exon objects from each transcript. ''' for pslobj in pslparser.read(open(filename)): exons = [] for i in range(len(pslobj.tStarts)): start = pslobj.tStarts[i] end = start + pslobj.blockSizes[i] strand = pslobj.strand exon = Exon(pslobj.tName, start, end, strand) exons.append(exon) yield exons