Package: ucsc-genomic-api
UCSC-Genomic-REST-Api-WrapperAn open-source python package licensed under the MIT license, the package represents a python Api wrapper on the UCSC genomic database, which makes it much easier for researchers to access and query the database with an elegant and human readable ApiAbout The PackageProject ProposalFeaturesExpressive ApiEasy to useCan be extendedCan be reused.No boilerplateInstallationInstall ucsc with pippipinstallucsc-genomic-apiDocumentationQuick Introduction for busy developersThere are 6 primary classes in the package:fromucsc.apiimportHub,Genome,Track,TrackSchema,Chromosome,SequenceEach class has the following primary method:# check documentation for required and optional parametersclassName.get()# Returns list of objects of the classclassName.find()# Find object by nameclassName.findBy()# Find object by a specified attributeclassName.exists()# Check to see if an object existsThen you can access the attributes of the object using . notationclassName.attributeName# Returns attribute nameUsage guideList of available hubs as python objectsfromucsc.apiimportHubhubList=Hub.get()Find hub by name, the function will return the result as an object or throws a not found exceptionfromucsc.apiimportHubhub=Hub.find('ALFA Hub')Find hub by given attribute, the function will return the result as an object or throws a not found exceptionfromucsc.apiimportHubhub=Hub.findBy('hubName','ALFA Hub')Get all genomes from specified hub objectfromucsc.apiimportHubhub=Hub.find('ALFA Hub')print(hub.genomes)# prints the list of all genomes in the given hubGet all genomes from all UCSC Databasefromucsc.apiimportGenomegenomesList=Genome.get()Find genome by name, the function will return the result as an object or throws a not found exceptionfromucsc.apiimportGenomegenome=Genome.find('ALFA Genome')Find genome by given attribute, the function will return the result as an object or throws a not found exceptionfromucsc.apiimportGenomegenome=Genome.findBy('genomeName','ALFA Genome')Check if genome exists in a UCSC databasefromucsc.apiimportGenomeGenome.exists('hg38')List the available tracks of the genome objectfromucsc.apiimportGenomegenome=Genome.find('ALFA Genome')tracks=genome.tracksFind a specific track in a genome by name, the return type is an object of trackfromucsc.apiimportTracktrack=Track.find('hg38','knownGene')Or using a Genome objectfromucsc.apiimportGenomegenome.findTrack('knownGene')Find a specific track using a specific attribute, the return type is an object of trackfromucsc.apiimportTracktrack=Track.findBy('hg38','longLabel','ClinGen curation ')Or using a Genome objectfromucsc.apiimportGenomegenome.findTrackBy('longLabel','knownGene')Check if track exists in a genomefromucsc.apiimportTrackTrack.exists('hg38','knownGene')Or using a Genome objectfromucsc.apiimportGenomegenome.isTrackExists('longLabel')List the schema of specified track from given genomefromucsc.apiimportTracktrack=Track.find('hg38','knownGene')trackSchema=track.schema('hg38')Get track data depends on the parameter you will pass to the trackData function, listed below the possible parameter for each use casefromucsc.apiimportTracktrack=Track.find('hg38','knownGene')# or you can get the track using the findBy method# Get track data for specified track in UCSC database genometrack.trackData(genome='hg38',track='gold',maxItemsOutput=100)# Get track data for specified track and chromosome in UCSC database genometrack.trackData(genome='hg38',track='gold',chrom='chrM')# Get track data for specified track, chromosome and start,end coordinates in UCSC database genometrack.trackData(genome='hg38',track='gold',chrom='chr1',start=47000,end=48000)# Get track data for specified track in an assembly hub genome -hubUrl='http://hgdownload.soe.ucsc.edu/hubs/mouseStrains/hub.txt'track.trackData(genome='CAST_EiJ',track='assembly',hubUrl=hubUrl)# Get track data for specified track and chromosome in an assembly hub genomehubUrl='http://hgdownload.soe.ucsc.edu/hubs/mouseStrains/hub.txt'track.trackData(genome='CAST_EiJ',track='assembly',chrom='chr1',hubUrl=hubUrl)# Get track data for specified track in a track hub -hubUrl='http://hgdownload.soe.ucsc.edu/hubs/mouseStrains/hub.txt'track.trackData(genome='CAST_EiJ',track='ensGene',hubUrl=hubUrl)# Get track data for specified track and chromosome in a track hubhubUrl='http://hgdownload.soe.ucsc.edu/hubs/mouseStrains/hub.txt'track.trackData(genome='CAST_EiJ',track='ensGene',chrom='chr1',hubUrl=hubUrl)# Download track data for specified track, chromosome with start and end limits in an assembly hub genome -hubUrl='http://hgdownload.soe.ucsc.edu/hubs/mouseStrains/hub.txt'track.downloadData(genome='CAST_EiJ',track='ensGene',chrom='chr1',hubUrl=hubUrl,start=4321,end=5678)# Download track data for specified track in a UCSC database genometrack.downloadData(genome='galGal6',track='gc5BaseBw',maxItemsOutput=100)List chromosomes from UCSC database genomefromucsc.apiimportChromosomechromosomes=Chromosome.get(genome='hg38')List chromosomes from specified track in UCSC database genomefromucsc.apiimportChromosomechromosomes=Chromosome.get(genome='hg38',track='knownGene')# orfromucsc.apiimportTrack,Genometrack=Track.find('hg38','knownGene')genome=Genome.find('ALFA Genome')chromosomes=Chromosome.get(genome,track)List chromosomes from assembly hub genomefromucsc.apiimportChromosomechromosomes=Chromosome.get(hub='ALFA Hub')List chromosomes from specified track in assembly hub genome # Deprected!fromucsc.apiimportChromosomechromosomes=Chromosome.get('hg38','ALFA Hub','knownGene')Find Specific chromosomefromucsc.apiimportChromosomechromosome=Chromosome.find(genome)Find DNA sequenceThe get method in Sequence class accepts multiple parameter, which depends on how do you want to retrieve the sequence objectfromucsc.apiimportSequence# Get DNA sequence from specified chromosome in UCSC database genome -sequence=Sequence.get(genome='hg38',chrom='chrM')print(sequence.dna)# Get DNA sequence from specified chromosome and start,end coordinates in UCSC database genome -sequence=Sequence.get(genome='hg38',chrom='chrM',start=4321,end=5678)print(sequence.dna)# Get DNA sequence from a track hub where 'genome' is a UCSC database -hubUrl='http://hgdownload.soe.ucsc.edu/hubs/mouseStrains/hub.txt';sequence=Sequence.get(genome='mm10',chrom='chrM',hubUrl=hubUrl,start=4321,end=5678)print(sequence.dna)