Package: ucsc-genomes-downloader
Python package to quickly download and process genomes from the UCSC website.How do I install this package?As usual, just download it using pip:pipinstallucsc_genomes_downloaderGetting COVID-19 GenomeTo download the COVID19 genome just run:fromucsc_genomes_downloaderimportGenomecovid=Genome("wuhCor1")genome=covid["NC_045512v2"]Usage examplesSimply instantiate a new genomeTo download and load into memory the chromosomes of a given genomic assembly
you can use the following code snippet:fromucsc_genomes_downloaderimportGenomehg19=Genome(assembly="hg19")Downloading selected chromosomesIf you want to select a subset of chromosomes to be downloaded
you can use the attribute “chromosomes”:fromucsc_genomes_downloaderimportGenomehg19=Genome("hg19",chromosomes=["chr1","chr2"])Getting gaps regionsThe method returns a DataFrame in bed-like format
that contains the regions where only n or N nucleotides
are present.all_gaps=hg19.gaps()# Returns gaps (region formed of Ns) for all chromosomes# Returns gaps for chromosome chrMchrM_gaps=hg19.gaps(chromosomes=["chrM"])Getting filled regionsThe method returns a DataFrame in bed-like format
that contains the regions where no unknown nucleotides
are present, basically the complementary
of the gaps method.all_filled=hg19.filled()# Returns filled for all chromosomes# Returns filled for chromosome chrMchrM_filled=hg19.filled(chromosomes=["chrM"])Removing genome’s cacheTo delete the cache of the genome, including chromosomes
and metadata you can use the delete method:hg19.delete()Genome objects representationWhen printed, a Genome object has a human-readable representation.
This allows you to print lists of Genome objects as follows:print([hg19,hg38,mm10])# >>> [#    Human, Homo sapiens, hg19, 2009-02-28, 25 chromosomes,#    Human, Homo sapiens, hg38, 2013-12-29, 25 chromosomes,#    Mouse, Mus musculus, mm10, 2011-12-29, 22 chromosomes# ]Obtaining a given bed file sequencesGiven a pandas DataFrame in bed-like format, you can obtain
the corresponding genomic sequences for the loaded assembly
using the bed_to_sequence method:my_bed=pd.read_csv("path/to/my/file.bed",sep="\t")sequences=hg19.bed_to_sequence(my_bed)PropertiesA Genome object has the following properties:hg19.assembly# Returns "hg19"hg19.date# Returns "2009-02-28" as datetime objecthg19.organism# Returns "Human"hg19.scientific_name# Returns "Homo sapiens"hg19.description# Returns the brief description as provided from UCSChg19.path# Returns path where genome is cachedUtilitiesRetrieving a list of the available genomesYou can get a complete list of the genomes available
from the UCSC website with the following method:fromucsc_genomes_downloader.utilsimportget_available_genomesall_genomes=get_available_genomes()Tessellating bed filesCreate a tessellation of a given size of a given bed-like pandas dataframe.Available alignments are to the left, right or center.fromucsc_genomes_downloader.utilsimporttessellate_bedimportpandasaspdmy_bed=pd.read_csv("path/to/my/file.bed",sep="\t")tessellated=tessellate_bed(my_bed,window_size=200,alignment="left")Expand bed files regionsExpand a given dataframe in bed-like format using selected alignment.Available alignments are to the left, right or center.fromucsc_genomes_downloader.utilsimportexpand_bed_regionsimportpandasaspdmy_bed=pd.read_csv("path/to/my/file.bed",sep="\t")expanded=expand_bed_regions(my_bed,window_size=1000,alignment="left")Wiggle bed files regionsGenerate new bed regions based on a given bed file by wiggling the
initial regions.fromucsc_genomes_downloader.utilsimportwiggle_bed_regionsimportpandasaspdmy_bed=pd.read_csv("path/to/my/file.bed",sep="\t")expanded=wiggle_bed_regions(my_bed,max_wiggle_size=100,# Maximum amount to wiggle regionwiggles=10,# Number of wiggled samples to introduceseed=42# Random seed for reproducibility)