to_sort += ['algorithm', 'peaks'] sort_order = ' '.join([i + '=+' for i in to_sort]) composite = CompositeTrack( name=hub_config['hub']['name'] + 'composite', short_label='ChIP-seq composite', long_label='ChIP-seq composite', dimensions=dimensions_from_subgroups(subgroups), filterComposite=filter_composite_from_subgroups(subgroups), sortOrder=sort_order, tracktype='bigWig') signal_view = ViewTrack(name='signalviewtrack', view='signal', visibility='full', tracktype='bigWig', short_label='signal', long_label='signal') peaks_view = ViewTrack(name='peaksviewtrack', view='peaks', visibility='dense', tracktype='bigBed', short_label='peaks', long_label='peaks') supplemental_view = ViewTrack(name='suppviewtrack', view='supplemental', visibility='full', tracktype='bigBed', short_label='Supplemental',
to_sort += [sg.name for sg in subgroups if sg.name not in to_sort] sort_order = ' '.join([i + '=+' for i in to_sort]) composite = CompositeTrack( name=hub_config['hub']['name'] + 'composite', short_label='rnaseq composite', long_label='rnaseq composite', dimensions=dimensions_from_subgroups(subgroups), filterComposite=filter_composite_from_subgroups(subgroups), sortOrder=sort_order, tracktype='bigWig') # ASSUMPTION: stranded bigwigs pos_signal_view = ViewTrack(name='possignalviewtrack', view='possignal', visibility='full', tracktype='bigWig', short_label='pos strand', long_label='positive strand signal') neg_signal_view = ViewTrack(name='negsignalviewtrack', view='negsignal', visibility='full', tracktype='bigWig', short_label='neg strand', long_label='negative strand signal') supplemental_view = ViewTrack(name='suppviewtrack', view='supplementalview', visibility='full', tracktype='bigBed', short_label='Supplemental', long_label='Supplemental')
sample_dir = config['sample_dir'] samples = df[df.columns[0]] composite = CompositeTrack( name=hub_config['hub']['name'] + 'composite', short_label='rnaseq composite', long_label='rnaseq composite', dimensions=dimensions_from_subgroups(subgroups), filterComposite=filter_composite_from_subgroups(subgroups), sortOrder=sort_order, tracktype='bigWig') # ASSUMPTION: stranded bigwigs sense_signal_view = ViewTrack(name='sensesignalviewtrack', view='sensesignal', visibility='full', tracktype='bigWig', short_label='sense strand', long_label='sense strand signal') antisense_signal_view = ViewTrack(name='antisensesignalviewtrack', view='antisensesignal', visibility='full', tracktype='bigWig', short_label='antisense strand', long_label='antisense strand signal') supplemental_view = ViewTrack(name='suppviewtrack', view='supplementalview', visibility='full', tracktype='bigBed', short_label='Supplemental', long_label='Supplemental')
def main(): parser = argparse.ArgumentParser( description='Make trackhubs for UCSC browser using bigBed files. \ Outputs to CURRENT DIRECTORY.') parser.add_argument('inputdir', metavar='INDIR', help='Directory containing bigBed files .bb ending') parser.add_argument('outdir', metavar='OUTDIR', help='Directory for staging files') parser.add_argument('--quiet', '-q', action='store_true', help='Suppress some print statements') parser.add_argument('--render', '-r', action='store_true', help='Render file to current dir') parser.add_argument('--upload', '-u', action='store_true', help='Upload file to webserver') parser.add_argument('--mm9', '-m', action='store_true', help='Switch from mm10 to mm9') parser.add_argument('--has_strand', '-s', action='store_true', help='Bed has strand (changes from 5 columns to 6)') parser.add_argument('--suffix', '-S', metavar="trackhub label suffix", default="", help='Suffix to label, for example H3K4me1') args = parser.parse_args() # store command line arguments for reproducibility CMD_INPUTS = ' '.join(['python'] + sys.argv) # easy printing later # store argparse inputs for reproducibility / debugging purposes args_dic = vars(args) ARG_INPUTS = ['%s=%s' % (key, val) for key, val in args_dic.iteritems()] # ARG_INPUTS = ['%s=%s' % (key, val) for key, val in args_dic.items()] ARG_INPUTS = ' '.join(ARG_INPUTS) # Print arguments supplied by user if not args.quiet: print('Command line inputs:') print(CMD_INPUTS) print('Argparse variables:') print(ARG_INPUTS) # define constants (hard coded) if args.mm9: genobuild = "mm9" else: genobuild = "mm10" jsuffix = "%s_%s" % (genobuild, args.suffix) print("Assigning prefix: %s" % jsuffix) # dirname: motevo_from_peaks/H3K4me1_peaks dirname = "motevo_from_peaks/%s_peaks/motevo_motifs_%s" % (args.suffix, jsuffix) hubname = "motevo_motifs_%s" % jsuffix shortlab = "motevo_%s" % jsuffix longlab = "Motevo motifs %s" % jsuffix email = "*****@*****.**" # url = "http://upnaepc2.epfl.ch" url = "http://upnaesrv1.epfl.ch" assay = "bigbed" jvis = "dense" # bigbed options loaded into ViewTrack jspectrum = "on" scoremax = 1000 scoremin = 500 # define URLs url_main = "%s/%s" % (url, dirname) url_base = "%s/%s/data" % (url, dirname) # upload_main = "~/Sites/%s" % dirname # upload_base = "~/Sites/%s/data" % dirname upload_main = "%s" % hubname upload_base = "%s/data" % hubname if not args.has_strand: ftype = "bigBed 5" else: ftype = "bigBed 6" # host = "circadian.epfl.ch" # user = "******" host = "upnaesrv1.epfl.ch" user = "******" # define constants genomebuild = genobuild files_dic = get_files_from_dir(args.inputdir, ext=".bb") samples_dic = {} for sample in files_dic.keys(): samples_dic[sample] = sample # init hub genomes file genome trackdb # Make my hub hub = Hub(hub=hubname, short_label=shortlab, long_label=longlab, email=email) # url = "%s/%s" % (url, dirname)) hub.url = os.path.join(url_main, "%s.hub.txt" % hub.hub) genomes_file = GenomesFile() genome = Genome(genomebuild) trackdb = TrackDb() # add remote fn # hub.remote_fn = os.path.join(upload_main, "hub.txt") # genomes_file.remote_fn = os.path.join(upload_main, "genomes.txt") hub.remote_fn = upload_main genomes_file.remote_fn = upload_main trackdb.remote_fn = os.path.join(upload_main, genomebuild, "trackDb.txt") hub.add_genomes_file(genomes_file) genome.add_trackdb(trackdb) genomes_file.add_genome(genome) # init composite composite = CompositeTrack(name=hubname, short_label=shortlab, long_label=longlab, tracktype=ftype) # make subgroups subgroups = [ SubGroupDefinition(name="sample", label="sample", mapping=samples_dic), ] composite.add_subgroups(subgroups) # make viewTrack, a hierarchy containing my files, for example view = ViewTrack( name="%sViewTrack" % assay, view="%s" % assay, visibility=jvis, tracktype=ftype, short_label="%s" % assay, long_label="%s assay" % assay, # big bed labels spectrum=jspectrum, scoreMin=scoremin, scoreMax=scoremax) composite.add_view(view) # make track for sample, wfs in files_dic.iteritems(): for wf in wfs: sampname = os.path.basename(wf) bname = sampname.split(".")[0] track = Track(name=bname, tracktype=ftype, url=os.path.join(url_base, "%s" % sampname), local_fn=os.path.abspath(wf), remote_fn=os.path.join(upload_base, "%s" % sampname), visibility=jvis, shortLabel=bname, longLabel=bname, spectrum=jspectrum, scoreMin=scoremin, scoreMax=scoremax, subgroups={"sample": sample}) view.add_tracks(track) trackdb.add_tracks(composite) print('Track looks like this:') print(trackdb) if args.render: # print('Rendering to %s' % hub.local_fn) # results = hub.render() # upload_hub(hub=hub, host='localhost', remote_dir='example_grouping_hub') stage_hub(hub, staging=args.outdir) if args.upload: print('Uploading to [email protected]') # for track in trackdb.tracks: # upload_track(track = track, host = host, user = user) upload_hub(hub=hub, host=host, user=user, remote_dir="/data/web/sites/motevo_from_peaks") print('Subgroups:') for sg in subgroups: print(sg) print("Staging to path: %s" % args.outdir)
def composite_track(self): """ Create a composite track ready to be added to a trackhub.TrackDb instance. """ bigwigs = [i for i in self.tracks if i.type_ == 'bigwig'] bigbeds = [i for i in self.tracks if i.type_ == 'bigbed'] # Build the HTML docs last_section = self.reference_section() html_string = utils.reST_to_html( self.metadata['study'].get('description', '') + '\n' + last_section) sanitized_label = utils.sanitize(self.label, strict=True) # Composite track to hold all subtracks for the study composite = CompositeTrack( name=sanitized_label, short_label=self.study['short_label'], long_label=self.study['long_label'], tracktype='bigBed', # Add all the documentation html_string=html_string) # If there are any bigWigs defined for this study, make a new "signal" # subtrack in the composite and then add the bigWigs to it. # # Uses the sanitized label for the study to ensure uniqueness among # tracks. # def _add_tracks(data_list, view, default_tracktype): for data_obj in data_list: kwargs = data_obj.obj.get('trackinfo', {}) kwargs = dict((k, str(v)) for k, v in kwargs.items()) kwargs.setdefault('tracktype', default_tracktype) view.add_tracks( Track(name=sanitized_label + utils.sanitize(data_obj.label), short_label=data_obj.label, long_label=data_obj.obj['long_label'], local_fn=data_obj.processed, **kwargs)) if len(bigwigs) > 0: signal_view = ViewTrack( name=sanitized_label + 'signalviewtrack', view=sanitized_label + 'signalview', short_label=self.label + ' signal view', long_label=self.label + ' signal view', visibility='full', maxHeightPixels='100:25:8', autoScale='off', tracktype='bigWig', ) composite.add_view(signal_view) _add_tracks(bigwigs, signal_view, 'bigWig') # Same thing with bigBeds if len(bigbeds) > 0: bed_view = ViewTrack( name=sanitized_label + 'bedviewtrack', view=sanitized_label + 'bed_view', short_label=self.label + ' bed view', long_label=self.label + ' bed view', visibility='dense', ) composite.add_view(bed_view) _add_tracks(bigbeds, bed_view, 'bigBed 9') return composite
return '0,0,0' hub, genomes_file, genome, trackdb = default_hub(**config['trackhub']['hub']) hub.remote_fn = config['trackhub']['upload']['remote_fn'] sample_composite = CompositeTrack(name='samplespecific', short_label='Samples', long_label='Individual samples', tracktype='bigWig') sample_signal_view = ViewTrack(name='samplesignalview', view='samplesignal', visibility='full', tracktype='bigWig', viewLimits='0:150000', maxHeightPixels='15:50:127', short_label='Sample Signal', long_label='Sample-level Signal') sample_bed_view = ViewTrack(name='samplebedview', view='samplebed', visibility='dense', tracktype='bigBed', short_label='Sample Region', long_label='Sample-level regions') bait_composite = CompositeTrack(name='baitspecific', short_label='Baits', long_label='Bait level', tracktype='bigBed')
dragAndDrop='subtracks', visibility='full', viewLimits='1:10', autoScale='off', maxHeightPixels='100:30:10', priority=1 ) ####################### #make the tracks and add to the appropriate groups during loo chipseq_bwfiles = [f for f in os.listdir(datadir+'/chip/processed/bw/') if f.endswith('.bw')] chipseq_bbfiles = [b for b in os.listdir(datadir+'/chip/processed/bb/') if b.endswith('.bb')] signal_view = ViewTrack( name = 'Chipseq_signal', view = 'Signal', visibility = 'full', tracktype = 'bigWig', short_label = 'signal') bed_view = ViewTrack( name = 'Chipseq_bed', view = 'Bed', visibility = 'dense', tracktype = 'bigBed', short_label = 'peaks') comp.add_view(signal_view) comp.add_view(bed_view) for f in chipseq_bwfiles: name, rep = get_name_and_rep(f) bname = os.path.basename(f)
short_label = 'signal') <<<<<<< HEAD bed_view = ViewTrack( ======= chip_bed_view = ViewTrack( >>>>>>> e33a5d89c0f5d75afae01dde9452063e2287f8d6 name = 'Chipseq_bed', view = 'Bed', visibility = 'dense', tracktype = 'bigBed', short_label = 'peaks') <<<<<<< HEAD rna_view = ViewTrack( name = 'RNAseq_signal', view = 'RNA', visibility = 'full', tracktype = 'bigWig', short_label = 'Rnaseq_signal') comp_chip.add_view(signal_view) comp_chip.add_view(bed_view) comp_rna.add_view(rna_view) ======= #rna_signal_view = ViewTrack( # name = 'RNAseq_signal', # view = 'Signal', # visibility = 'full', # tracktype = 'bigwig', # short_label = 'signal') # comp.add_view(chip_signal_view)
args.composite_track_name, tracktype="bigWig") # After the composite track has been created, we can incrementally add additional parameters. # This is same method can be used for all classes derived from Track CompositeTrack, ViewTrack # and of course Track itself: composite.add_params(dragAndDrop='subtracks', visibility='full') # The next part of the hierarchy is a ViewTrack object. Both ViewTrack and CompositeTrack are subclasses of the more generic Track class, # so they act in much the same way. This should look familiar, but a notable difference is the addition of the view kwarg from trackhub import ViewTrack bed_view = ViewTrack(name="bedViewTrack", view="Bed", visibility="squish", tracktype="bigBed 3", short_label="beds", long_label="Beds") signal_view = ViewTrack(name="signalViewTrack", view="Signal", visibility="full", tracktype="bigWig 0 10000", short_label="signal", long_label="Signal") # Add these new view tracks to composite: composite.add_view(bed_view) composite.add_view(signal_view)
viewLimits='1:10', autoScale='off', maxHeightPixels='100:30:10', priority=1) ####################### #make the tracks and add to the appropriate groups during loo chipseq_bwfiles = [ f for f in os.listdir(datadir + '/chip/processed/bw/') if f.endswith('.bw') ] chipseq_bbfiles = [ b for b in os.listdir(datadir + '/chip/processed/bb/') if b.endswith('.bb') ] signal_view = ViewTrack(name='Chipseq_signal', view='Signal', visibility='full', tracktype='bigWig', short_label='signal') bed_view = ViewTrack(name='Chipseq_bed', view='Bed', visibility='dense', tracktype='bigBed', short_label='peaks') comp.add_view(signal_view) comp.add_view(bed_view) for f in chipseq_bwfiles: name, rep = get_name_and_rep(f) bname = os.path.basename(f) col = maps[name] track = Track(name='%s_%s_signal' % (name, rep),