def create_hub(geo, email=None, upload=False, upload_dir=".", user=None, host=None): """ Create an UCSC track hub from a Geo object """ hub = Hub( hub=geo.gse, short_label=geo.gse, long_label="Hub for {0}".format(geo.gse), email=email) genomes_file = GenomesFile() trackdb = TrackDb() local_dir = geo.gse #hub.remote_fn = os.path.join(upload_dir, geo.gse, os.path.basename(hub.local_fn)) all_tracks = {} for sample in geo.samples.values(): genome = sample['genome'] all_tracks.setdefault(genome, []) name = re.sub('[^0-9a-zA-Z]+', '_',sample['name']) track = Track( name=name, url=os.path.join(HUB_URLBASE, geo.gse, genome, "{0}.bw".format(sample['gsm'])), tracktype='bigWig', short_label=sample['gsm'], long_label=name, color='128,128,0', maxHeightPixels='30:30:11', ) basename = os.path.basename(track.url) track.local_fn = os.path.join(local_dir, basename) track.remote_fn = os.path.join(upload_dir, geo.gse, genome, basename) all_tracks[genome].append(track) for build,tracks in all_tracks.items(): genome = Genome(build) trackdb.add_tracks(tracks) genome.add_trackdb(trackdb) genomes_file.add_genome(genome) hub.add_genomes_file(genomes_file) results = hub.render() if upload: for track in trackdb.tracks: upload_track(track=track, host=host, user=user) upload_hub(hub=hub, host=host, user=user)
class TestUpload(object): def setup(self): self.hub = Hub( hub='example_hub', short_label='example hub', long_label='an example hub for testing', email='*****@*****.**') self.genomes_file = GenomesFile() self.genome = Genome('dm3') self.trackdb = TrackDb() self.tracks = [ Track( name='track1', tracktype='bam', local_fn='data/track1.bam' ), Track( name='track2', tracktype='bigWig', local_fn='data/track2.bigwig', ), ] self.hub.add_genomes_file(self.genomes_file) self.genomes_file.add_genome(self.genome) self.genome.add_trackdb(self.trackdb) self.trackdb.add_tracks(self.tracks) @unittest.skipUnless(os.path.exists('data/track1.bam'), 'No test data') def test_upload(self): self.hub.remote_fn = os.path.join( 'uploaded_version', self.hub.remote_fn) self.hub.render() upload.upload_hub( 'localhost', None, self.hub, symlink=True, symlink_dir='staging', run_local=True,) for t, level in self.hub.leaves(Track): upload.upload_track( track=t, host='localhost', user=None, run_local=True) def test_render(self): trackdb = str(self.trackdb) # make sure some of the trackdb rendered correctly assert 'track track1' in trackdb assert 'bigDataUrl track1.bam' in trackdb
def setup(self): self.hub = Hub( hub='example_hub', short_label='example hub', long_label='an example hub for testing', email='*****@*****.**') self.genomes_file = GenomesFile() self.genome = Genome('dm3') self.trackdb = TrackDb() self.tracks = [ Track( name='track1', tracktype='bam', local_fn='data/track1.bam' ), Track( name='track2', tracktype='bigWig', local_fn='data/track2.bigwig', ), ] self.hub.add_genomes_file(self.genomes_file) self.genomes_file.add_genome(self.genome) self.genome.add_trackdb(self.trackdb) self.trackdb.add_tracks(self.tracks)
def setup(self): self.hub = Hub( hub='example_hub', short_label='example hub', long_label='an example hub for testing', email='*****@*****.**') self.genomes_file = GenomesFile() self.genome = Genome('dm3') self.trackdb = TrackDb() self.tracks = [ Track( name='track1', tracktype='bigBed', source=os.path.join(d, 'random-hg38-0.bigBed') ), Track( name='track2', tracktype='bigWig', source=os.path.join(d, 'sine-hg38-0.bedgraph.bw'), ), Track( name='track3', tracktype='bigWig', source=os.path.join(d, 'sine-hg38-1.bedgraph.bw'), filename='3.bw', ) ] self.hub.add_genomes_file(self.genomes_file) self.genomes_file.add_genome(self.genome) self.genome.add_trackdb(self.trackdb) self.trackdb.add_tracks(self.tracks)
class TestUpload(object): def setup(self): self.hub = Hub( hub='example_hub', short_label='example hub', long_label='an example hub for testing', email='*****@*****.**') self.genomes_file = GenomesFile() self.genome = Genome('dm3') self.trackdb = TrackDb() self.tracks = [ Track( name='track1', tracktype='bam', local_fn='data/track1.bam' ), Track( name='track2', tracktype='bigWig', local_fn='data/track2.bigwig', ), ] self.hub.add_genomes_file(self.genomes_file) self.genomes_file.add_genome(self.genome) self.genome.add_trackdb(self.trackdb) self.trackdb.add_tracks(self.tracks) def test_upload(self): self.hub.remote_fn = os.path.join( 'uploaded_version', self.hub.remote_fn) self.hub.render() upload.upload_hub( 'localhost', None, self.hub, symlink=True, symlink_dir='staging', run_local=True,) for t, level in self.hub.leaves(Track): upload.upload_track( track=t, host='localhost', user=None, run_local=True)
def setup(self): self.hub = Hub( hub="example_hub", short_label="example hub", long_label="an example hub for testing", email="*****@*****.**", ) self.genomes_file = GenomesFile() self.genome = Genome("dm3") self.trackdb = TrackDb() self.tracks = [Track(name="track1", tracktype="bam"), Track(name="track2", tracktype="bigWig")]
def setup(self): self.hub = Hub( hub='example_hub', short_label='example hub', long_label='an example hub for testing', email='*****@*****.**') self.genomes_file = GenomesFile() self.genome = Genome('dm3') self.trackdb = TrackDb() self.tracks = [ Track(name='track1', tracktype='bam'), Track(name='track2', tracktype='bigWig'), ]
if not args.long_label: args.long_label = args.short_label upload_dir = os.path.join("/zfs/Hubs", args.hub) URLBASE= os.path.join("http://sauron.ucsd.edu/Hubs", args.hub) GENOME = args.genome hub = Hub(hub=args.hub, short_label=args.short_label, long_label=args.long_label, email = args.email, ) genomes_file = GenomesFile() genome = Genome(GENOME) trackdb = TrackDb() genome.add_trackdb(trackdb) genomes_file.add_genome(genome) hub.add_genomes_file(genomes_file) hub.upload_fn = upload_dir files = args.files #logic for doing pos and neg as the same multi trackhub #process bw files first, do the rest with old logic bw_files = [track for track in files if track.endswith(".bw") or track.endswith(".bigWig")] remaining_files = [track for track in files if not (track.endswith(".bw") or track.endswith(".bigWig"))] key_func = lambda x: x.split(".")[:-2] for bw_group, files in groupby(sorted(bw_files, key=key_func), key_func): long_name = os.path.basename(bw_group[0])
class TestComponents(object): def setup(self): self.hub = Hub( hub='example_hub', short_label='example hub', long_label='an example hub for testing', email='*****@*****.**') self.genomes_file = GenomesFile() self.genome = Genome('dm3') self.trackdb = TrackDb() self.tracks = [ Track(name='track1', tracktype='bam'), Track(name='track2', tracktype='bigWig'), ] def CONNECT(self): """ Connect the components together. The default setup creates the objects but does not connect them. """ self.hub.add_genomes_file(self.genomes_file) self.genomes_file.add_genome(self.genome) self.genome.add_trackdb(self.trackdb) self.trackdb.add_tracks(self.tracks) def DISCONNECT(self): """ Re-run the setup, which results in unconnected components. Run CONNECT() to connect them up. """ self.setup() def test_self_connection(self): """ meta test: make sure the test class's connect/disconnect is working """ assert self.hub.genomes_file is None self.CONNECT() assert self.hub.genomes_file is self.genomes_file self.DISCONNECT() assert self.hub.genomes_file is None # Filenames --------------------------------------------------------------- def test_hub_fns(self): # Default unconnected assert self.hub.filename == 'example_hub.hub.txt' # Connecting components should not change hub self.CONNECT() assert self.hub.filename == 'example_hub.hub.txt' self.DISCONNECT() def test_genome_file_fns(self): with pytest.raises(AttributeError): getattr(self.genomes_file, 'url') # When unconnected, filenames should be None assert self.genomes_file.filename is None #...though you can set them manually self.genomes_file.filename = 'local.genomes' assert self.genomes_file.filename == 'local.genomes' self.genomes_file.filename = None self.CONNECT() assert self.genomes_file.filename == 'example_hub.genomes.txt' # when connected, overriding works self.genomes_file.filename = 'local.genomes' assert self.genomes_file.filename == 'local.genomes' self.genomes_file.filename = None # disconnecting brings it back to None self.DISCONNECT() assert self.genomes_file.filename is None # set the hub's local_dir; genomes_file should follow. self.CONNECT() # what happens if the hub's local FN is changed? self.hub.filename = 'localhub/hub.txt' assert self.genomes_file.filename == 'localhub/example_hub.genomes.txt' def test_trackdb_fns(self): # when unconnected, no defaults assert self.trackdb.filename is None self.CONNECT() assert self.trackdb.filename == 'dm3/trackDb.txt' # setting filename overrides self.trackdb.filename = 'mytrackdb.txt' assert self.trackdb.filename == 'mytrackdb.txt', self.trackdb.filename # genomes_file fn overrides self.trackdb.filename = None self.genomes_file.filename = 'anotherdir/genomes.txt' assert self.trackdb.filename == 'anotherdir/dm3/trackDb.txt' # reset parent hub and genomes file to get back to the default self.genomes_file.filename = None assert self.trackdb.filename == 'dm3/trackDb.txt' def test_track_fns(self): self.CONNECT() # local fns should still be None for track in self.tracks: assert track.source is None # filename is relative to the hub's filename assert self.tracks[0].filename == 'dm3/track1.bam' assert self.tracks[1].filename == 'dm3/track2.bigWig' # URL is relative to the trackDb assert self.tracks[0].url == 'track1.bam' def test_track_creation(self): track = Track(name='track0', tracktype='bam', source='t0.bam') assert track.source == 't0.bam'
if args.no_s3: URLBASE = os.path.join("https://s3-us-west-1.amazonaws.com/sauron-yeo/", args.hub) else: URLBASE = os.path.join("http://sauron.ucsd.edu/Hubs", args.hub) GENOME = args.genome hub = Hub(hub=args.hub, short_label=args.short_label, long_label=args.long_label, email=args.email, ) genomes_file = GenomesFile() genome = Genome(GENOME) trackdb = TrackDb() supertrack = SuperTrack(name=args.hub, short_label=args.hub, long_label=args.hub) genome.add_trackdb(trackdb) genomes_file.add_genome(genome) hub.add_genomes_file(genomes_file) hub.upload_fn = upload_dir files = args.files #logic for doing pos and neg as the same multi trackhub #process bw files first, do the rest with old logic bw_files = [track for track in files if track.endswith(".bw") or track.endswith(".bigWig")] remaining_files = [track for track in files if not (track.endswith(".bw") or track.endswith(".bigWig"))]
class TestComponents(object): def setup(self): self.hub = Hub( hub="example_hub", short_label="example hub", long_label="an example hub for testing", email="*****@*****.**", ) self.genomes_file = GenomesFile() self.genome = Genome("dm3") self.trackdb = TrackDb() self.tracks = [Track(name="track1", tracktype="bam"), Track(name="track2", tracktype="bigWig")] def CONNECT(self): """ Connect the components together. The default setup creates the objects but does not connect them. """ self.hub.add_genomes_file(self.genomes_file) self.genomes_file.add_genome(self.genome) self.genome.add_trackdb(self.trackdb) self.trackdb.add_tracks(self.tracks) def DISCONNECT(self): """ Re-run the setup, which results in unconnected components. Run CONNECT() to connect them up. """ self.setup() def test_self_connection(self): """ meta test: make sure the test class's connect/disconnect is working """ assert self.hub.genomes_file is None self.CONNECT() assert self.hub.genomes_file is self.genomes_file self.DISCONNECT() assert self.hub.genomes_file is None # Filenames --------------------------------------------------------------- def test_hub_fns(self): # Default unconnected assert self.hub.local_fn == "example_hub.hub.txt" assert self.hub.remote_fn == "example_hub.hub.txt" assert self.hub.url is None # Connecting components should not change hub self.CONNECT() assert self.hub.local_fn == "example_hub.hub.txt" assert self.hub.remote_fn == "example_hub.hub.txt" assert self.hub.url is None self.DISCONNECT() # set local/remote dir and fns should follow self.hub.local_dir = "/data/hubs" self.hub.remote_dir = "/remote/hubs" assert self.hub.local_fn == "/data/hubs/example_hub.hub.txt", self.hub.local_fn assert self.hub.remote_fn == "/remote/hubs/example_hub.hub.txt", self.hub.remote_fn # resetting them should not change self.hub.local_dir = None self.hub.remote_dir = None assert self.hub.local_fn == "example_hub.hub.txt" assert self.hub.remote_fn == "example_hub.hub.txt" # changing local_fn or remote_fn should stick -- and should override # any set local/remote dir self.hub.local_fn = "dummy.txt" self.hub.remote_fn = "remote.txt" self.hub.local_dir = "no_dir" self.hub.remote_dir = "remote_dir" assert self.hub.local_fn == "dummy.txt" assert self.hub.remote_fn == "remote.txt" def test_genome_file_fns(self): assert_raises(AttributeError, getattr, self.genomes_file, "url") # When unconnected, filenames should be None assert self.genomes_file.local_fn is None assert self.genomes_file.remote_fn is None # ...though you can set them manually self.genomes_file.local_fn = "local.genomes" assert self.genomes_file.local_fn == "local.genomes" self.genomes_file.local_fn = None self.CONNECT() assert self.genomes_file.local_fn == "example_hub.genomes.txt" # when connected, overriding works self.genomes_file.local_fn = "local.genomes" assert self.genomes_file.local_fn == "local.genomes" self.genomes_file.local_fn = None # disconnecting brings it back to None self.DISCONNECT() assert self.genomes_file.local_fn is None # set the hub's local_dir; genomes_file should follow. self.CONNECT() self.hub.local_dir = "local/" assert self.genomes_file.local_fn == "local/example_hub.genomes.txt" # what happens if the hub's local FN is changed? self.hub.local_fn = "localhub/hub.txt" assert self.genomes_file.local_fn == "localhub/example_hub.genomes.txt" def test_genome_fns(self): # should be easy -- filenames should raise attribute errors assert_raises(AttributeError, getattr, self.genome, "local_fn") assert_raises(AttributeError, getattr, self.genome, "remote_fn") assert_raises(AttributeError, getattr, self.genome, "url") def test_trackdb_fns(self): assert_raises(AttributeError, getattr, self.trackdb, "url") # when unconnected, no defaults assert self.trackdb.local_fn is None assert self.trackdb.remote_fn is None self.CONNECT() assert self.trackdb.local_fn == "dm3/trackDb.txt" assert self.trackdb.remote_fn == "dm3/trackDb.txt" # setting the local dir on the hub trickles down self.hub.local_dir = "localdir" assert self.trackdb.local_fn == "localdir/dm3/trackDb.txt" # setting local_fn overrides self.trackdb.local_fn = "mytrackdb.txt" assert self.trackdb.local_fn == "mytrackdb.txt", self.trackdb.local_fn # ...and back to None to reset self.trackdb.local_fn = None assert self.trackdb.local_fn == "localdir/dm3/trackDb.txt" # genomes_file fn overrides self.genomes_file.local_fn = "anotherdir/genomes.txt" assert self.trackdb.local_fn == "anotherdir/dm3/trackDb.txt" # reset parent hub and genomes file to get back to the default self.genomes_file.local_fn = None self.hub.local_dir = None assert self.trackdb.local_fn == "dm3/trackDb.txt" def test_track_fns(self): for track in self.tracks: assert track.local_fn is None assert track.remote_fn is None assert track.url is None self.CONNECT() # local fns should still be None for track in self.tracks: assert track.local_fn is None # remote_fn is relative to the hub's remote_fn assert self.tracks[0].remote_fn == "dm3/track1.bam" assert self.tracks[1].remote_fn == "dm3/track2.bigWig" self.hub.remote_fn = "/var/www/hubs/hub.txt" self.hub.url = "http://example.com/hubs/hub.txt" # URL is relative to the trackDb assert self.tracks[0].url == "track1.bam" def test_track_creation(self): track = Track(name="track0", tracktype="bam", local_fn="t0.bam") assert track.local_fn == "t0.bam"
class TestUpload(object): def setup(self): self.hub = Hub( hub='example_hub', short_label='example hub', long_label='an example hub for testing', email='*****@*****.**') self.genomes_file = GenomesFile() self.genome = Genome('dm3') self.trackdb = TrackDb() self.tracks = [ Track( name='track1', tracktype='bigBed', source=os.path.join(d, 'random-hg38-0.bigBed') ), Track( name='track2', tracktype='bigWig', source=os.path.join(d, 'sine-hg38-0.bedgraph.bw'), ), Track( name='track3', tracktype='bigWig', source=os.path.join(d, 'sine-hg38-1.bedgraph.bw'), filename='3.bw', ) ] self.hub.add_genomes_file(self.genomes_file) self.genomes_file.add_genome(self.genome) self.genome.add_trackdb(self.trackdb) self.trackdb.add_tracks(self.tracks) def test_staging(self): staging_dir, linknames = upload.stage_hub(self.hub) assert open(os.path.join(staging_dir, 'example_hub.genomes.txt')).read() == dedent( """\ genome dm3 trackDb dm3/trackDb.txt """) assert open(os.path.join(staging_dir, 'example_hub.hub.txt')).read() == dedent( """\ hub hub shortLabel example hub longLabel an example hub for testing genomesFile example_hub.genomes.txt email [email protected]""") #@unittest.skipUnless(os.path.exists('data/track1.bam'), 'No test data') def test_upload(self): d = tempfile.mkdtemp() print(d) upload.upload_hub( hub=self.hub, remote_dir=d, user=None, host=None, ) def test_render(self): trackdb = str(self.trackdb) # make sure some of the trackdb rendered correctly assert 'track track1' in trackdb assert 'bigDataUrl track1.bigBed' in trackdb assert 'bigDataUrl ../3.bw' in trackdb
class TestComponents(object): def setup(self): self.hub = Hub( hub='example_hub', short_label='example hub', long_label='an example hub for testing', email='*****@*****.**') self.genomes_file = GenomesFile() self.genome = Genome('dm3') self.trackdb = TrackDb() self.tracks = [ Track(name='track1', tracktype='bam'), Track(name='track2', tracktype='bigWig'), ] def CONNECT(self): self.hub.add_genomes_file(self.genomes_file) self.genomes_file.add_genome(self.genome) self.genome.add_trackdb(self.trackdb) self.trackdb.add_tracks(self.tracks) def DISCONNECT(self): self.setup() def test_self_connection(self): """ meta test: make sure the test class's connect/disconnect is working """ assert self.hub.genomes_file is None self.CONNECT() assert self.hub.genomes_file is self.genomes_file self.DISCONNECT() assert self.hub.genomes_file is None # Filenames --------------------------------------------------------------- def test_hub_fns(self): # Default unconnected assert self.hub.local_fn == 'example_hub.hub.txt' assert self.hub.remote_fn == 'example_hub.hub.txt' assert self.hub.url is None # Connecting components should not change hub self.CONNECT() assert self.hub.local_fn == 'example_hub.hub.txt' assert self.hub.remote_fn == 'example_hub.hub.txt' assert self.hub.url is None self.DISCONNECT() # set local/remote dir and fns should follow self.hub.local_dir = '/data/hubs' self.hub.remote_dir = '/remote/hubs' assert self.hub.local_fn == '/data/hubs/example_hub.hub.txt', \ self.hub.local_fn assert self.hub.remote_fn == '/remote/hubs/example_hub.hub.txt', \ self.hub.remote_fn # resetting them should not change self.hub.local_dir = None self.hub.remote_dir = None assert self.hub.local_fn == 'example_hub.hub.txt' assert self.hub.remote_fn == 'example_hub.hub.txt' # changing local_fn or remote_fn should stick -- and should override # any set local/remote dir self.hub.local_fn = 'dummy.txt' self.hub.remote_fn = 'remote.txt' self.hub.local_dir = 'no_dir' self.hub.remote_dir = 'remote_dir' assert self.hub.local_fn == 'dummy.txt' assert self.hub.remote_fn == 'remote.txt' def test_genome_file_fns(self): assert_raises(AttributeError, getattr, self.genomes_file, 'url') # When unconnected, filenames should be None assert self.genomes_file.local_fn is None assert self.genomes_file.remote_fn is None #...though you can set them manually self.genomes_file.local_fn = 'local.genomes' assert self.genomes_file.local_fn == 'local.genomes' self.genomes_file.local_fn = None self.CONNECT() assert self.genomes_file.local_fn == 'example_hub.genomes.txt' # when connected, overriding works self.genomes_file.local_fn = 'local.genomes' assert self.genomes_file.local_fn == 'local.genomes' self.genomes_file.local_fn = None # disconnecting brings it back to None self.DISCONNECT() assert self.genomes_file.local_fn is None # set the hub's local_dir; genomes_file should follow. self.CONNECT() self.hub.local_dir = 'local/' assert self.genomes_file.local_fn == 'local/example_hub.genomes.txt' # what happens if the hub's local FN is changed? self.hub.local_fn = 'localhub/hub.txt' assert self.genomes_file.local_fn == 'localhub/example_hub.genomes.txt' def test_genome_fns(self): # should be easy -- filenames should raise attribute errors assert_raises(AttributeError, getattr, self.genome, 'local_fn') assert_raises(AttributeError, getattr, self.genome, 'remote_fn') assert_raises(AttributeError, getattr, self.genome, 'url') def test_trackdb_fns(self): assert_raises(AttributeError, getattr, self.trackdb, 'url') # when unconnected, no defaults assert self.trackdb.local_fn is None assert self.trackdb.remote_fn is None self.CONNECT() assert self.trackdb.local_fn == 'dm3/trackDb.txt' assert self.trackdb.remote_fn == 'dm3/trackDb.txt' # setting the local dir on the hub trickles down self.hub.local_dir = 'localdir' assert self.trackdb.local_fn == 'localdir/dm3/trackDb.txt' # setting local_fn overrides self.trackdb.local_fn = 'mytrackdb.txt' assert self.trackdb.local_fn == 'mytrackdb.txt', self.trackdb.local_fn # ...and back to None to reset self.trackdb.local_fn = None assert self.trackdb.local_fn == 'localdir/dm3/trackDb.txt' # genomes_file fn overrides self.genomes_file.local_fn = 'anotherdir/genomes.txt' assert self.trackdb.local_fn == 'anotherdir/dm3/trackDb.txt' # reset parent hub and genomes file to get back to the default self.genomes_file.local_fn = None self.hub.local_dir = None assert self.trackdb.local_fn == 'dm3/trackDb.txt' def test_track_fns(self): for track in self.tracks: assert track.local_fn is None assert track.remote_fn is None assert track.url is None self.CONNECT() # local fns should still be None for track in self.tracks: assert track.local_fn is None assert self.tracks[0].remote_fn == 'dm3/track1.bam' assert self.tracks[1].remote_fn == 'dm3/track2.bigWig' self.hub.remote_fn = '/var/www/hubs/hub.txt' self.hub.url = 'http://example.com/hubs/hub.txt' print self.tracks[0].remote_fn print self.hub.remote_fn assert self.tracks[0].url == 'http://example.com/hubs/dm3/track1.bam' def test_track_creation(self): track = Track(name='track0', tracktype='bam', local_fn='t0.bam') assert track.local_fn == 't0.bam'
assert args.composite_track_name is not None, "please provide the composite track name" assert args.email is not None, "please provide your email" assert args.input_dir is not None, "please provide the path to the bigwig and bigbed files on your local computer" from trackhub import Hub, GenomesFile, Genome, TrackDb hub = Hub( hub='%s' % args.hub_name, short_label='%s' % args.hub_name, long_label='%s ChIP-seq hub' % args.hub_name, email='%s' % args.email) genomes_file = GenomesFile() genome = Genome('hg19') trackdb = TrackDb() # Bottom-up genome.add_trackdb(trackdb) genomes_file.add_genome(genome) hub.add_genomes_file(genomes_file) # make a composite track from trackhub import CompositeTrack composite = CompositeTrack( name="%s" % args.composite_track_name, short_label="%s" % args.composite_track_name, long_label=" %s ChIP-seq" % args.composite_track_name, tracktype="bigWig")
def files2viz(files_to_visualize): if DEBUG: print "Visualizing" print files_to_visualize from trackhub import Hub, GenomesFile, Genome, TrackDb, Track from trackhub.upload import upload_hub HUBHOST = 'http://cherry-vm45.stanford.edu' HUBDIR = 'trackhubs' USER = '******' URLBASE = os.path.join(HUBHOST, HUBDIR) EDWBASE = 'http://encodedcc.sdsc.edu/warehouse' GENOME = 'hg19' hub = Hub( hub='Selected_ENCODE_Tracks', short_label='Selected_ENCODE_Tracks_short', long_label='Selected_ENCODE_Tracks_long', email='*****@*****.**') genomes_file = GenomesFile() genome = Genome(GENOME) trackdb = TrackDb() for accession in files_to_visualize: file_obj = get_ENCODE(accession) if DEBUG: print file_obj if file_obj['file_format'] == 'bigWig': track = Track( name=accession, url=os.path.join(EDWBASE, str(file_obj['download_path'])), tracktype='bigWig', short_label=accession, long_label=accession, color='128,0,0', visibility='full') trackdb.add_tracks([track]) genome.add_trackdb(trackdb) genomes_file.add_genome(genome) hub.add_genomes_file(genomes_file) results=hub.render() if DEBUG: print hub print '...' print genomes_file print '...' print genome print '...' print trackdb #upload_hub(hub=hub, host=HUBHOST, user=USER) #doesn't seem to work import subprocess subprocess.call("cd .. && rsync -r trackhub [email protected]:/www/html/trackhubs", shell=True) import webbrowser hubfile = str(hub.hub) + '.hub.txt' UCSC_url = 'http://genome.ucsc.edu/cgi-bin/hgTracks?udcTimeout=1&db=hg19' + \ '&hubUrl=' + os.path.join(HUBHOST,HUBDIR,'trackhub',hubfile) # + \ #'&hsS_doLoadUrl=submit' + '&hgS_loadUrlName=' + os.path.join(HUBHOST,HUBDIR,'trackhub','session.txt') print UCSC_url webbrowser.open(UCSC_url)
def ENCSR2viz(experiments_to_visualize): if DEBUG: print "Visualizing" print experiments_to_visualize from trackhub import Hub, GenomesFile, Genome, TrackDb, Track from trackhub.upload import upload_hub HUBHOST = 'http://cherry-vm45.stanford.edu' HUBDIR = 'jseth/trackhubs' USER = '******' URLBASE = os.path.join(HUBHOST, HUBDIR) EDWBASE = 'http://encodedcc.sdsc.edu/warehouse' GENOME = 'hg19' hub = Hub( hub='ENCODE', short_label='ENCODE', long_label='ENCODE', email='*****@*****.**') genomes_file = GenomesFile() genome = Genome(GENOME) trackdb = TrackDb() for accession in experiments_to_visualize: experiment_obj = get_ENCODE(accession) if DEBUG: print experiment_obj for file_id in experiment_obj['files']: file_obj = get_ENCODE(file_id) if file_obj['file_format'] in ['bigWig', 'bigBed', 'broadPeak', 'narrowPeak']: if file_obj['file_format'] in ['bigWig']: track_type = 'bigWig' elif file_obj['file_format'] in ['bigBed', 'broadPeak', 'narrowPeak']: track_type = 'bigBed' track = Track( name=str(file_obj['accession']), url=os.path.join(EDWBASE, str(file_obj['download_path'])), tracktype=track_type, long_label=str(file_obj['accession']), short_label=str(file_obj['output_type']), color='128,0,0', visibility='dense', metadata='cell_type=primary') print file_obj['accession'] trackdb.add_tracks([track]) genome.add_trackdb(trackdb) genomes_file.add_genome(genome) hub.add_genomes_file(genomes_file) results=hub.render() if DEBUG: print hub print '...' print genomes_file print '...' print genome print '...' print trackdb #upload_hub(hub=hub, host=HUBHOST, user=USER) #doesn't seem to work import subprocess subprocess.call("cd .. && rsync -r trackhub [email protected]:/www/html/jseth/trackhubs", shell=True) import webbrowser hubfile = str(hub.hub) + '.hub.txt' UCSC_url = 'http://genome.ucsc.edu/cgi-bin/hgTracks?udcTimeout=1&db=hg19' + \ '&hubUrl=' + os.path.join(HUBHOST,HUBDIR,'trackhub',hubfile) # + \ #'&hsS_doLoadUrl=submit&hgS_loadUrlName=' + os.path.join(HUBHOST,HUBDIR,'trackhub','session.txt') print UCSC_url webbrowser.open(UCSC_url)