跳转到主要内容

Python包,用于快速从UCSC下载基因组。

项目描述

Supported Python Versions Pypi project Pypi total project downloads

Python包,用于快速从UCSC网站下载和处理基因组。

如何安装此包?

像往常一样,只需使用pip下载即可

pip install ucsc_genomes_downloader

获取COVID-19基因组

要下载COVID19基因组,只需运行

from ucsc_genomes_downloader import Genome
covid = Genome("wuhCor1")

genome = covid["NC_045512v2"]

使用示例

简单地实例化一个新的基因组

要下载并加载指定基因组组装的染色体到内存中,可以使用以下代码片段

from ucsc_genomes_downloader import Genome
hg19 = Genome(assembly="hg19")

下载选定的染色体

如果您想选择要下载的染色体子集,可以使用“chromosomes”属性

from ucsc_genomes_downloader import Genome
hg19 = Genome("hg19", chromosomes=["chr1", "chr2"])

获取间隙区域

该方法返回一个类似bed的DataFrame,包含仅存在n或N个核苷酸的区域。

all_gaps = hg19.gaps() # Returns gaps (region formed of Ns) for all chromosomes
# Returns gaps for chromosome chrM
chrM_gaps = hg19.gaps(chromosomes=["chrM"])

获取填充区域

该方法返回一个类似bed的DataFrame,包含没有未知核苷酸存在的区域,基本上是间隙方法的补集。

all_filled = hg19.filled() # Returns filled for all chromosomes
# Returns filled for chromosome chrM
chrM_filled = hg19.filled(chromosomes=["chrM"])

删除基因组缓存

要删除包括染色体和元数据的基因组缓存,可以使用delete方法

hg19.delete()

基因组对象表示

当打印时,基因组对象具有可读的表示。这允许您按如下方式打印基因组对象列表

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
# ]

获取特定的bed文件序列

给定一个类似bed的pandas DataFrame,您可以使用bed_to_sequence方法获取加载组装的相应基因组序列

my_bed = pd.read_csv("path/to/my/file.bed", sep="\t")
sequences = hg19.bed_to_sequence(my_bed)

属性

基因组对象具有以下属性

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

实用工具

检索可用基因组的列表

您可以通过以下方法从UCSC网站获取可用基因组的完整列表:

from ucsc_genomes_downloader.utils import get_available_genomes
all_genomes = get_available_genomes()

镶嵌bed文件

创建给定大小的类似于pandas dataframes的bed文件镶嵌。

可用的对齐方式是左侧、右侧或居中。

from ucsc_genomes_downloader.utils import tessellate_bed
import pandas as pd

my_bed = pd.read_csv("path/to/my/file.bed", sep="\t")
tessellated = tessellate_bed(
    my_bed,
    window_size=200,
    alignment="left"
)

扩展bed文件区域

使用选择的对齐方式扩展给定bed格式dataframe。

可用的对齐方式是左侧、右侧或居中。

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"
)

摆动bed文件区域

通过摆动初始区域生成基于给定bed文件的新区域。

from ucsc_genomes_downloader.utils import wiggle_bed_regions
import pandas as pd

my_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 region
    wiggles=10, # Number of wiggled samples to introduce
    seed=42 # Random seed for reproducibility
)

项目详情


下载文件

下载您平台上的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分布

ucsc_genomes_downloader-1.1.26.tar.gz (13.4 kB 查看哈希值)

上传时间

由以下提供支持