def _buildTestTrees(self): # inputTree splitOnA splitOnB pairwise (A vs B) # / \ | / \ / \ # A B C D E t1_t2 t1_t3 # | / \ / \ /\ /\ / \ / \ # C D E A B A B A B Q R Q R # | | | | / \ | | | | | | | | # t1 t2 t3 t1 D E C t2 C t3 t1 t2 t1 t2 # | | | | # t2 t3 t1 t1 self.t1 = SingleTrackTS(Track(['t1']), {'field 1': 'value 1'}) self.t2 = SingleTrackTS(Track(['t2']), { 'field 1': 'value 2', 'field 2': '6' }) self.t3 = SingleTrackTS(Track(['t3']), { 'field 1': 'value 2', 'field 3': 'None' }) self.inputTree = TrackStructureV2() self.inputTree['A'] = TrackStructureV2() self.inputTree['A']['C'] = self.t1 self.inputTree['B'] = TrackStructureV2() self.inputTree['B']['D'] = self.t2 self.inputTree['B']['E'] = self.t3 # correct result of the input tree splitted on node A self.splittedOnNodeA = TrackStructureV2() self.splittedOnNodeA['C'] = TrackStructureV2() self.splittedOnNodeA['C']['A'] = self.t1 self.splittedOnNodeA['C']['B'] = TrackStructureV2() self.splittedOnNodeA['C']['B']['D'] = self.t2 self.splittedOnNodeA['C']['B']['E'] = self.t3 # correct result of the input tree splitted on node B self.splittedOnNodeB = TrackStructureV2() self.splittedOnNodeB['D'] = TrackStructureV2() self.splittedOnNodeB['D']['A'] = TrackStructureV2() self.splittedOnNodeB['D']['A']['C'] = self.t1 self.splittedOnNodeB['D']['B'] = self.t2 self.splittedOnNodeB['E'] = TrackStructureV2() self.splittedOnNodeB['E']['A'] = TrackStructureV2() self.splittedOnNodeB['E']['A']['C'] = self.t1 self.splittedOnNodeB['E']['B'] = self.t3 self.pairwiseCombinations = TrackStructureV2() self.pairwiseCombinations["['t1']_['t2']"] = TrackStructureV2() self.pairwiseCombinations["['t1']_['t2']"]['query'] = self.t1 self.pairwiseCombinations["['t1']_['t2']"]['reference'] = self.t2 self.pairwiseCombinations["['t1']_['t3']"] = TrackStructureV2() self.pairwiseCombinations["['t1']_['t3']"]['query'] = self.t1 self.pairwiseCombinations["['t1']_['t3']"]['reference'] = self.t3 self.flatTrackStructure = FlatTracksTS() self.flatTrackStructure['A'] = self.t1 self.flatTrackStructure['B'] = self.t2 self.flatTrackStructure['C'] = self.t3
def setUp(self): stsRef1 = SingleTrackTS(Mock(spec=Track), dict(title="trackA")) ts1 = FlatTracksTS() ts1["reference"] = stsRef1 ts1.result = 0.5 ts1["query"] = Mock(spec=SingleTrackTS) stsRef2 = SingleTrackTS(Mock(spec=Track), dict(title="trackB")) ts2 = FlatTracksTS() ts2["reference"] = stsRef2 ts2.result = 1.2 ts2["query"] = Mock(spec=SingleTrackTS) self.resultTS = TrackStructureV2() self.resultTS['0'] = ts1 self.resultTS['1'] = ts2
def setUp(self): genomeAnchor = [0, 101] self.bins = [ GenomeRegion('TestGenome', 'chr21', 0, 50), GenomeRegion('TestGenome', 'chr21', 50, 101) ] self.ts = defaultdict(TrackStructureV2) allSegmentSetNoOverlap = [[[10, 20]], [[5, 10], [25, 50], [55, 70], [75, 80], [90, 95]], [[5, 15], [20, 30], [45, 55], [75, 80]], [[0, 20], [60, 65], [85, 100]]] allSegmentSetOverlap = [[[10, 25]], [[5, 10], [20, 50], [55, 70], [75, 80], [90, 95]], [[5, 20], [15, 30], [45, 55], [75, 80]], [[0, 20], [60, 65], [85, 100]]] excludedSegments = [[45, 55], [70, 75]] for allowOverlaps, allSegmentSet in \ zip([False, True], [allSegmentSetNoOverlap, allSegmentSetOverlap]): for i, segmentSet in enumerate(allSegmentSet): track = SampleTrack( SampleTV(segments=segmentSet, anchor=genomeAnchor, allowOverlaps=allowOverlaps)) track.getUniqueKey = MagicMock(return_value=i) self.ts[allowOverlaps]['dummy' + str(i)] = SingleTrackTS( track, {}) track = SampleTrack( SampleTV(segments=[], anchor=genomeAnchor, allowOverlaps=allowOverlaps)) track.getUniqueKey = MagicMock(return_value=i + 1) self.ts[allowOverlaps]['emptyTrack'] = SingleTrackTS(track, {}) exclusionTrack = SampleTrack( SampleTV(segments=excludedSegments, anchor=genomeAnchor, allowOverlaps=False)) self.exclusionTs = SingleTrackTS(exclusionTrack, {})
def getFlatTracksTS(genome, guiSelectedGSuite): ts = FlatTracksTS() gsuite = getGSuiteFromGalaxyTN(guiSelectedGSuite) for gsTrack in gsuite.allTracks(): assert gsTrack.trackName is not None, "Gstrack name is None %s" % gsTrack track = PlainTrack(gsTrack.trackName) metadata = OrderedDict(title=gsTrack.title, genome=str(genome)) metadata.update(gsTrack.attributes) assert track is not None assert metadata is not None ts[gsTrack.title] = SingleTrackTS(track, metadata) return ts
def setUp(self): """ Create a fake trackstructure containing empty tracks, this is only used to ensure the randomization pool knows there should be 3 input tracks. """ genomeAnchor = [0, 101] self.amountTracks = 3 self.region = GenomeRegion('TestGenome', 'chr21', genomeAnchor[0], genomeAnchor[1]) self.ts = TrackStructureV2() for i, segmentSet in enumerate([[]] * self.amountTracks): track = SampleTrack( SampleTV(segments=segmentSet, anchor=genomeAnchor)) track.getUniqueKey = MagicMock(return_value=i) self.ts[str(i)] = SingleTrackTS(track, {}) self.shufflePool = ShuffleElementsBetweenTracksPool( self.ts, self.region, None)
def getSingleTrackTS(genome, guiSelectedTrack, title='Dummy'): trackName = ExternalTrackManager.getPreProcessedTrackFromGalaxyTN(genome, guiSelectedTrack) return SingleTrackTS(PlainTrack(trackName), {'title': title})
def create_track(file_name, trackName): from gtrackcore.core.Api import importFile importFile(file_name, genome="hg18", trackName=trackName) t = PlainTrack([trackName]) single_track_ts = SingleTrackTS(t, {"title": trackName}) return single_track_ts
from gold.track.TrackStructure import FlatTracksTS, SingleTrackTS, TrackStructureV2 class MockTrack(Track): def __new__(cls, *args): return object.__new__(cls) def __init__(self, name): object.__init__(self) self.trackName = [ name ] #because needed by hash in makeTreeSegregatedByCategory self.trackTitle = name q = SingleTrackTS(MockTrack('t1'), OrderedDict(title='t1', cat='q')) flat = FlatTracksTS() flat['t2'] = SingleTrackTS(MockTrack('t2'), OrderedDict(title='t2', cat='C1')) flat['t3'] = SingleTrackTS(MockTrack('t3'), OrderedDict(title='t3', cat='C1')) flat['t4'] = SingleTrackTS(MockTrack('t4'), OrderedDict(title='t4', cat='C2')) r = flat.getSplittedByCategoryTS('cat') orig = TrackStructureV2() orig['q'] = q orig['r'] = r def allInOne(): print 'Orig: ', orig