Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python SQL(ite)快速检索较大字符串(基因组)的多个子字符串_Python_Sql_Sqlite_Bioinformatics - Fatal编程技术网

Python SQL(ite)快速检索较大字符串(基因组)的多个子字符串

Python SQL(ite)快速检索较大字符串(基因组)的多个子字符串,python,sql,sqlite,bioinformatics,Python,Sql,Sqlite,Bioinformatics,我有一个sql数据库,由基因组、染色体和“有趣”区域(BED格式)组成。一个基因组(例如4GB)由+/-20条染色体组成,因此每条染色体串大约有200MB大。例如,基因组中的染色体由以下字符串组成: NNNNATCCAGGAGAATTACAT...ACCGGGAATTCCCGGNNNNN # 200 MB large 假设我有大约1.000.000个区域ATAC-seq峰,我只想得到3号染色体的100 bp序列。我的SQL查询如下所示: SELECT substr(Chr.Sequence,

我有一个sql数据库,由基因组、染色体和“有趣”区域(BED格式)组成。一个基因组(例如4GB)由+/-20条染色体组成,因此每条染色体串大约有200MB大。例如,基因组中的染色体由以下字符串组成:

NNNNATCCAGGAGAATTACAT...ACCGGGAATTCCCGGNNNNN # 200 MB large
假设我有大约1.000.000个区域ATAC-seq峰,我只想得到3号染色体的100 bp序列。我的SQL查询如下所示:

SELECT substr(Chr.Sequence, Bed.ChromStart + Bed.Peak - 50, 100) FROM Bed Bed
INNER JOIN Chromosome Chr ON Bed.ChromosomeId = Chr.ChromosomeId
WHERE Chr.Chromosome = 'chr3'
这种查找的问题是每次点击都会加载
Chr.Sequence
,导致ram使用量过大,查找速度非常慢。我“修复”这一问题的方法是只使用SQL数据库存储感兴趣位置的位置,然后使用
pyfaidx
快速从染色体中获取相应的序列


我想知道在SQL(ite)中是否可以进行快速查找,因为当前的解决方案对我来说有点特别

您可以将基因组字符串拆分为多个部分,并使用多处理同时搜索子字符串,以最大限度地减少单处理器的使用并加快搜索结果

import sys
import multiprocessing
from multiprocessing import Pool

def SplitGenomeString(start,length):
#where con in sqlconnection to database using as global variable
   cursorObj = con.cursor()


   cursorObj.execute('SELECT substr(Chr.Sequence,{},{}) FROM Chromosome 
                      Chr'.format(str(start),str(length))
   return cursorObj.fetchall()

def getSubSequence(s):
#Write your Queries according to your requirements for finding subsequence s




if __name__ == '__main__':
    length = SplitGenomeString(0,sys.maxint)
    cores = multiprocessing.cpu_count()

    #asumming the subsequence you want to check is 100
    subseq_len = 100

    for i in range(0,length,round(length/cores)):
        ls.append(SplitGenomeString(i,round(length/cores)))

    #this will also include the excluded parts because of splitting geneome string
    temp = []
    for i in range(len(ls) - 1):
        temp.append(ls[i][1 - subseq_len):] + ls[i+1][:subseq_len - 1])

    ls = ls + temp

    with Pool(cores) as p:
        p.map(getSubSequence,ls)
您可以在此链接中查看有关多处理的信息:


按要求编辑

索引概念在这种情况下可能会有所帮助。您是否在寻找优化查询或存储的方法?如果这是您使用序列的唯一方式,也许您可以将它们保存在块中?如果您只关心查询,那么您可以查看运行解释查询计划并分析结果:一个完整的SQL server应用程序(例如Postgres)很可能会自动优化加载行为,您不必担心这一点。使用explain查看在查询执行过程中如何处理。如果您只想使用bgzip和tabix分析bed文件
$bgzip example_sort.bed$tabix-p bed example_sort.bed.gz
bed文件就足以解决您的问题。如果一个序列跨越您已拆分基因组的位置,该怎么办?看起来你的代码出现了一些缩进问题。是的,这是可能的,然后你必须加入他们来检查,默认情况下,我正在拆分基因组,但它应该根据要检查的子字符串的长度进行拆分。假设您要将基因组拆分为四个部分,那么您必须使用多处理器检查4+3部分,其中3个部分是先前拆分的基因组的一部分,即从结束部分-1到结束部分-1的子字符串的大小下一个分裂基因组的部分,即从开始-1开始的子串的大小。我将很快编辑代码。谢谢你的答案+1,不过我更喜欢用fasta索引方法。