def _composeDataLine(self, ge, hbColumns, dataLineCount, lastGE): cols = [] for hbColName in hbColumns: if hbColName == 'start': cols.append(self._formatStart(ge.start)) elif hbColName == 'end': cols.append(self._formatEnd(ge.end)) elif hbColName == 'strand': cols.append(getStringFromStrand(ge.strand)) elif hbColName == 'val': cols.append(self._formatValue(ge.val)) elif hbColName == 'edges': cols.append(self._formatEdges(ge.edges, ge.weights)) elif hbColName == 'weights': pass else: cols.append(self._formatPhraseWithCorrectChrUsage(str(getattr(ge, hbColName)), \ useUrlEncoding=True, notAllowedChars='#\t')) if self._headerDict['fixed-size data lines']: assert len(cols) == 1 return cols[0] + (os.linesep if (dataLineCount * len(cols[0])) % 60 < len(cols[0]) \ or lastGE else '') else: return '\t'.join(cols) + os.linesep
def _composeDataLine(self, ge, hbColumns, dataLineCount, lastGE): cols = [] for hbColName in hbColumns: if hbColName == 'start': cols.append( self._formatStart(ge.start) ) elif hbColName == 'end': cols.append( self._formatEnd(ge.end) ) elif hbColName == 'strand': cols.append( getStringFromStrand(ge.strand) ) elif hbColName == 'val': cols.append( self._formatValue(ge.val) ) elif hbColName == 'edges': cols.append( self._formatEdges(ge.edges, ge.weights) ) elif hbColName == 'weights': pass else: cols.append(self._formatPhraseWithCorrectChrUsage(str(getattr(ge, hbColName)), \ useUrlEncoding=True, notAllowedChars='#\t')) if self._headerDict['fixed-size data lines']: assert len(cols) == 1 return cols[0] + (os.linesep if (dataLineCount * len(cols[0])) % 60 < len(cols[0]) \ or lastGE else '') else: return '\t'.join(cols) + os.linesep
def _compose(self, out): trackName = self._geSource.getTrackName() if trackName is not None: name = ':'.join(self._geSource.getTrackName()).replace(' ', '_') print >> out, 'track' + ' name=' + name numCols = self._findNumCols() bedColumnsList = list(self._bedColumnsDict.iteritems()) for ge in self._geSource: cols = [''] * numCols for i in range(numCols): colNames, colInfo = bedColumnsList[i] for colName in (colNames if type(colNames) == tuple else (colNames, )): try: value = getattr(ge, colName) except AttributeError: value = None if colName == 'end': value = self._handleEnd(ge, value) elif colName == 'val': value = self._handleVal(value) elif colName == 'strand': value = getStringFromStrand(value) if isinstance(value, str) and colName not in ('name', 'id'): if '|' in value or any('|' in getattr(ge, col) \ for col in colInfo.checkExtra if hasattr(ge,col)): cols[i] = colInfo.defaultVal else: cols[i] = value else: cols[ i] = value if value is not None else colInfo.defaultVal if colName == 'id' and value is not None: break print >> out, '\t'.join([str(x) for x in cols])
def _compose(self, out): print >>out, '##gff-version 3' gffColumnsList = list(self._gffColumnsDict.iteritems()) numCols = 9 for ge in self._geSource: cols = [''] * numCols for i in range(numCols): colName, colInfo = gffColumnsList[i] try: value = getattr(ge, colName) except AttributeError: value = None if colName == 'source': if value is not None and '\t' in value: #from old source memmaps value = '.' if colName == 'start': value = value + 1 elif colName == 'val': try: value = self._commonFormatNumberVal(value) except: value = '.' elif colName == 'strand': value = getStringFromStrand(value) elif colName == 'attributes': if value is None: attrs = '' if ge.id is not None: attrs += 'ID=%s;' % quote(ge.id, safe=' |') if hasattr(ge, 'name'): attrs += 'Name=%s;' % quote(ge.name, safe=' |') if attrs != '': value = attrs cols[i] = value if value is not None else colInfo.defaultVal print >>out, '\t'.join([str(x) for x in cols])
def _compose(self, out): print >> out, '##gff-version 3' gffColumnsList = list(self._gffColumnsDict.iteritems()) numCols = 9 for ge in self._geSource: cols = [''] * numCols for i in range(numCols): colName, colInfo = gffColumnsList[i] try: value = getattr(ge, colName) except AttributeError: value = None if colName == 'source': if value is not None and '\t' in value: #from old source memmaps value = '.' if colName == 'start': value = value + 1 elif colName == 'val': try: value = self._commonFormatNumberVal(value) except: value = '.' elif colName == 'strand': value = getStringFromStrand(value) elif colName == 'attributes': if value is None: attrs = '' if ge.id is not None: attrs += 'ID=%s;' % quote(ge.id, safe=' |') if hasattr(ge, 'name'): attrs += 'Name=%s;' % quote(ge.name, safe=' |') if attrs != '': value = attrs cols[i] = value if value is not None else colInfo.defaultVal print >> out, '\t'.join([str(x) for x in cols])
def _compose(self, out): trackName = self._geSource.getTrackName() if trackName is not None: name = ":".join(self._geSource.getTrackName()).replace(" ", "_") print >> out, "track" + " name=" + name numCols = self._findNumCols() bedColumnsList = list(self._bedColumnsDict.iteritems()) for ge in self._geSource: cols = [""] * numCols for i in range(numCols): colNames, colInfo = bedColumnsList[i] for colName in colNames if type(colNames) == tuple else (colNames,): try: value = getattr(ge, colName) except AttributeError: value = None if colName == "end": value = self._handleEnd(ge, value) elif colName == "val": value = self._handleVal(value) elif colName == "strand": value = getStringFromStrand(value) if isinstance(value, str) and colName not in ("name", "id"): if "|" in value or any( "|" in getattr(ge, col) for col in colInfo.checkExtra if hasattr(ge, col) ): cols[i] = colInfo.defaultVal else: cols[i] = value else: cols[i] = value if value is not None else colInfo.defaultVal if colName == "id" and value is not None: break print >> out, "\t".join([str(x) for x in cols])
def _compose(self, out): trackName = self._geSource.getTrackName() if trackName is not None: name = ':'.join(self._geSource.getTrackName()).replace(' ','_') print >>out, 'track' + ' name=' + name numCols = self._findNumCols() bedColumnsList = list(self._bedColumnsDict.iteritems()) for ge in self._geSource: cols = ['']*numCols for i in range(numCols): colNames, colInfo = bedColumnsList[i] for colName in (colNames if type(colNames) == tuple else (colNames,)): try: value = getattr(ge, colName) except AttributeError: value = None if colName == 'end': value = self._handleEnd(ge, value) elif colName == 'val': value = self._handleVal(value) elif colName == 'strand': value = getStringFromStrand(value) if isinstance(value, str) and colName not in ('name', 'id'): if '|' in value or any('|' in getattr(ge, col) \ for col in colInfo.checkExtra if hasattr(ge,col)): cols[i] = colInfo.defaultVal else: cols[i] = value else: cols[i] = value if value is not None else colInfo.defaultVal if colName == 'id' and value is not None: break print >>out, '\t'.join([str(x) for x in cols])