def __init__(self, vals=True, strands=True, anchor=None, valDType='float64'): assert(vals!=True or anchor!=None) if anchor==None: numElements = len(vals) anchor = [10, 10 + numElements] else: numElements = anchor[1] - anchor[0] vals = self._createList(vals, getRandValList(numElements), valDType) strands = self._createList(strands, getRandStrandList(numElements), 'bool8') #print (vals, strands, anchor) TrackView.__init__(self, GenomeRegion('TestGenome', 'chr21', anchor[0], anchor[1]), None, None, vals, strands, None, None, None, 'crop', False)
def __init__(self, vals=True, strands=True, anchor=None, valDType='float64'): assert (vals != True or anchor is not None) if anchor is None: numElements = len(vals) anchor = [10, 10 + numElements] else: numElements = anchor[1] - anchor[0] vals = self._createList(vals, getRandValList(numElements), valDType) strands = self._createList(strands, getRandStrandList(numElements), 'bool8') #print (vals, strands, anchor) TrackView.__init__( self, GenomeRegion('TestGenome', 'chr21', anchor[0], anchor[1]), None, None, vals, strands, None, None, None, 'crop', False)
def __init__(self, segments=None, starts=True, ends=True, vals=True, strands=False, ids=False, edges=False, weights=False, \ extras=False, anchor=None, numElements=None, valDType='float64', borderHandling='crop', allowOverlaps=False): if type(starts) != bool and ends == True: ends = False if type(ends) != bool and starts == True: starts = False assert not (starts==False and ends==False) assert segments!=False and segments!=True assert starts!=None and ends!=None and vals!=None and strands!=None assert segments==None or (starts==True and ends==True) assert not (isIter(weights) and not isIter(edges)) assert (any( type(x) not in [bool,type(None)] for x in [segments,starts,ends,vals,strands,ids,edges,weights,extras]) and numElements==None) \ or numElements!=None #assert(( (type(segments)!=bool or type(starts)!=bool or type(ends)!=bool or \ # type(vals)!=bool or type(strands)!=bool) and numElements==None )\ # or numElements!=None) # if anchor==None: anchor = [10,1000] if segments != None: starts = [] ends = [] for seg in segments: starts.append(seg[0]) ends.append(seg[1]) if isIter(edges): maxNumEdges = self._findMaxNumEls(edges) edges = self._appendEmptyToEnd(edges, '', maxNumEdges) if isIter(weights): weights = self._appendEmptyToEnd(weights, numpy.nan, maxNumEdges) [starts, ends, vals, strands, ids, edges, weights] + ([x for x in extras.values()] if isinstance(extras, dict) else []) for list in [starts, ends, vals, strands, ids, edges, weights] + ([x for x in extras.values()] if isinstance(extras, dict) else []): if type(list) != bool and numElements == None: numElements = len(list) assert(type(list) == bool or len(list) == numElements) for coordList in [starts, ends]: if type(coordList) != bool: for j in range(len(coordList)): coordList[j] += anchor[0] randSegmentLists = getRandSegments(numElements, anchor[0], anchor[1]) starts = self._createList(starts, randSegmentLists[0], 'int32') ends = self._createList(ends, randSegmentLists[1], 'int32') vals = self._createList(vals, getRandValList(numElements, valDType), valDType) strands = self._createList(strands, getRandStrandList(numElements), 'bool8') randIds, randEdges, randWeights = getRandGraphLists(numElements) ids = self._createList(ids, randIds, randIds.dtype) edges = self._createList(edges, randEdges, randEdges.dtype) weights = self._createList(weights, randWeights, 'float64') if weights is not None and len(weights.shape) == 1: weights = weights.reshape(weights.shape + (0,)) extras = self._createExtraLists(extras, 'S', numElements) if starts == None: if ends[0] != 0: ends = numpy.append([anchor[0]], ends) if vals != None: vals = numpy.append([nan], vals) if strands != None: strands = numpy.append([True], strands) if ends[-1] != anchor[1]: ends[-1] = anchor[1] # print (starts, ends, vals, strands, anchor) TrackView.__init__(self, GenomeRegion('TestGenome', 'chr21', anchor[0], anchor[1]), starts, ends, vals, \ strands, ids, edges, weights, borderHandling, allowOverlaps, extraLists=extras)
def __init__(self, segments=None, starts=True, ends=True, vals=False, strands=False, ids=False, edges=False, weights=False, extras=False, anchor=None, numElements=None, valDType='float64', borderHandling='crop', allowOverlaps=False): if type(starts) != bool and ends == True: ends = False if type(ends) != bool and starts == True: starts = False assert not (starts == False and ends == False) assert segments != False and segments != True assert starts is not None and ends is not None and vals is not None and strands is not None assert segments is None or (starts == True and ends == True) assert not (isIter(weights) and not isIter(edges)) assert (any( type(x) not in [bool,type(None)] for x in [segments,starts,ends,vals,strands,ids,edges,weights,extras]) and numElements==None) \ or numElements is not None #assert(( (type(segments)!=bool or type(starts)!=bool or type(ends)!=bool or \ # type(vals)!=bool or type(strands)!=bool) and numElements==None )\ # or numElements!=None) # if anchor is None: anchor = [10, 1000] if segments is not None: starts = [] ends = [] for seg in segments: starts.append(seg[0]) ends.append(seg[1]) if isIter(edges): maxNumEdges = self._findMaxNumEls(edges) edges = self._appendEmptyToEnd(edges, '', maxNumEdges) if isIter(weights): weights = self._appendEmptyToEnd(weights, numpy.nan, maxNumEdges) [starts, ends, vals, strands, ids, edges, weights ] + ([x for x in extras.values()] if isinstance(extras, dict) else []) for list in [starts, ends, vals, strands, ids, edges, weights] + ( [x for x in extras.values()] if isinstance(extras, dict) else []): if type(list) != bool and numElements is None: numElements = len(list) assert (type(list) == bool or len(list) == numElements) for coordList in [starts, ends]: if type(coordList) != bool: for j in range(len(coordList)): coordList[j] += anchor[0] randSegmentLists = getRandSegments(numElements, anchor[0], anchor[1]) starts = self._createList(starts, randSegmentLists[0], 'int32') ends = self._createList(ends, randSegmentLists[1], 'int32') vals = self._createList(vals, getRandValList(numElements, valDType), valDType) strands = self._createList(strands, getRandStrandList(numElements), 'bool8') randIds, randEdges, randWeights = getRandGraphLists(numElements) ids = self._createList(ids, randIds, randIds.dtype) edges = self._createList(edges, randEdges, randEdges.dtype) weights = self._createList(weights, randWeights, 'float64') if weights is not None and len(weights.shape) == 1: weights = weights.reshape(weights.shape + (0, )) extras = self._createExtraLists(extras, 'S', numElements) if starts is None: if ends[0] != 0: ends = numpy.append([anchor[0]], ends) if vals is not None: vals = numpy.append([nan], vals) if strands is not None: strands = numpy.append([True], strands) if ends[-1] != anchor[1]: ends[-1] = anchor[1] # print (starts, ends, vals, strands, anchor) TrackView.__init__(self, GenomeRegion('TestGenome', 'chr21', anchor[0], anchor[1]), starts, ends, vals, \ strands, ids, edges, weights, borderHandling, allowOverlaps, extraLists=extras)