Python package to quickly download genomes from the UCSC.
Project description
Python package to quickly download and work with genomes from the UCSC.
How do I install this package?
As usual, just download it using pip:
pip install ucsc_genomes_downloader
Tests Coverage
Since some software handling coverages sometime get slightly different results, here’s three of them:
Usage examples
Simply instanziate a new genome
To download and load into memory the chromosomes of a given genomic assembly you can use the following code snippet:
from ucsc_genomes_downloader import Genome
hg19 = Genome(assembly="hg19")
Downloading selected chromosomes
If you want to select a subset of chromosomes to be downloaded you can use the attribute “chromosomes”:
from ucsc_genomes_downloader import Genome
hg19 = Genome("hg19", chromosomes=["chr1", "chr2"])
Getting gaps regions
The method return 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 chrM
chrM_gaps = hg19.gaps(chromosomes=["chrM"])
Getting filled regions
The method return a DataFrame in bed-like format that contains the regions where no unknown nucleotide is present, basically the complementary of the gaps method.
all_filled = hg19.filled() # Returns filled for all chromosomes
# Returns filled for chromosome chrM
chrM_filled = hg19.filled(chromosomes=["chrM"])
Removing genome’s cache
To delete the cache of genome, including chromosomes and metadata you can use the delete method:
hg19.delete()
Genome objects representation
When 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 sequences
Given a pandas DataFrame in bed-like format, you can obtain the curresponding 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)
Properties
A Genome object has the following properties:
hg19.assembly # Returns "hg19"
hg19.date # Returns "2009-02-28" as datetime object
hg19.organism # Returns "Human"
hg19.scientific_name # Returns "Homo sapiens"
hg19.description # Returns the brief description as provided from UCSC
hg19.path # Returns path where genome is cached
Utilities
Retrieving a list of the available genomes
You can get a complete list of the genomes available from the UCSC website with the following method:
from ucsc_genomes_downloader.utils import get_available_genomes
all_genomes = get_available_genomes()
Tasselizing bed files
Create a tasselization of a given size of a given bed-like pandas dataframe.
Available alignment are to the left, right or center.
from ucsc_genomes_downloader.utils import tasselize_bed
import pandas as pd
my_bed = pd.read_csv("path/to/my/file.bed", sep="\t")
tasselized = tasselize_bed(
my_bed,
window_size=200,
alignment="left"
)
Expand bed files regions
Expand a given dataframe in bed-like format using selected alignment.
Available alignment are to the left, right or center.
from ucsc_genomes_downloader.utils import expand_bed_regions
import pandas as pd
my_bed = pd.read_csv("path/to/my/file.bed", sep="\t")
expanded = expand_bed_regions(
my_bed,
window_size=1000,
alignment="left"
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for ucsc_genomes_downloader-1.1.8.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54e44dfa3a12bf955da0032f6d482fc5a1a07ec65cdc8a3ed3423078d1621727 |
|
MD5 | e01cfa2bd70df97eceefb8f81afbaebe |
|
BLAKE2b-256 | efae751a02b0b80a5f6cd456e989cc11dfbf78ea37217c237b67d3b85b226e1b |