Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,31 +10,38 @@ import time
|
|
| 10 |
|
| 11 |
app = Flask(__name__)
|
| 12 |
ssl._create_default_https_context = ssl._create_unverified_context
|
|
|
|
| 13 |
def get_ready_for_primers(gene_symbol, species="human"):
|
| 14 |
-
"""获取基因序列和外显子交界点信息"""
|
| 15 |
Entrez.email = "your_email@example.com"
|
| 16 |
|
| 17 |
-
# 1. 搜索基因并获取 NCBI 内部 ID
|
| 18 |
-
search_term = f"{gene_symbol}[Gene Name] AND {species}[Organism]"
|
| 19 |
-
handle = Entrez.esearch(db="gene", term=search_term)
|
| 20 |
-
record = Entrez.read(handle)
|
| 21 |
-
if not record["IdList"]:
|
| 22 |
-
return {"error": "未找到该基因"}
|
| 23 |
-
gene_id = record["IdList"][0]
|
| 24 |
-
|
| 25 |
-
# 2. 获取该基因关联的 NM_ 编号
|
| 26 |
-
link_handle = Entrez.elink(dbfrom="gene", db="nucleotide", id=gene_id, term="srcdb_refseq[prop] AND mRNA[filter]")
|
| 27 |
-
link_record = Entrez.read(link_handle)
|
| 28 |
-
|
| 29 |
try:
|
| 30 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
nucl_id = link_record[0]["LinkSetDb"][0]["Link"][0]["Id"]
|
| 32 |
|
| 33 |
-
#
|
| 34 |
handle = Entrez.efetch(db="nucleotide", id=nucl_id, rettype="gb", retmode="text")
|
| 35 |
seq_record = SeqIO.read(handle, "genbank")
|
| 36 |
|
| 37 |
-
# 提取外显子
|
| 38 |
junctions = []
|
| 39 |
current_pos = 0
|
| 40 |
for feature in seq_record.features:
|
|
@@ -44,7 +51,7 @@ def get_ready_for_primers(gene_symbol, species="human"):
|
|
| 44 |
junctions.append(int(current_pos))
|
| 45 |
|
| 46 |
if junctions:
|
| 47 |
-
junctions.pop()
|
| 48 |
|
| 49 |
return {
|
| 50 |
"symbol": gene_symbol,
|
|
@@ -53,7 +60,7 @@ def get_ready_for_primers(gene_symbol, species="human"):
|
|
| 53 |
"junctions": junctions
|
| 54 |
}
|
| 55 |
except Exception as e:
|
| 56 |
-
return {"error": f"获取基因信息失败: {str(e)}"}
|
| 57 |
|
| 58 |
def design_qpcr_primers(gene_data):
|
| 59 |
"""设计qPCR引物,包含失败重试机制"""
|
|
|
|
| 10 |
|
| 11 |
app = Flask(__name__)
|
| 12 |
ssl._create_default_https_context = ssl._create_unverified_context
|
| 13 |
+
|
| 14 |
def get_ready_for_primers(gene_symbol, species="human"):
|
| 15 |
+
"""获取基因序列和外显子交界点信息(增强报错处理版)"""
|
| 16 |
Entrez.email = "your_email@example.com"
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
try:
|
| 19 |
+
# 1. 搜索基因
|
| 20 |
+
search_term = f"{gene_symbol}[Gene Name] AND {species}[Organism] AND alive[prop]"
|
| 21 |
+
handle = Entrez.esearch(db="gene", term=search_term)
|
| 22 |
+
record = Entrez.read(handle)
|
| 23 |
+
if not record["IdList"]:
|
| 24 |
+
return {"error": f"在 {species} 中未找到基因符号: {gene_symbol}"}
|
| 25 |
+
gene_id = record["IdList"][0]
|
| 26 |
+
|
| 27 |
+
# 2. 尝试获取关联的 RefSeq mRNA (NM_)
|
| 28 |
+
# 增加多种筛选条件以提高匹配率
|
| 29 |
+
link_handle = Entrez.elink(dbfrom="gene", db="nucleotide", id=gene_id,
|
| 30 |
+
term="srcdb_refseq[prop] AND mRNA[filter]")
|
| 31 |
+
link_record = Entrez.read(link_handle)
|
| 32 |
+
|
| 33 |
+
# 检查是否有跳转结果
|
| 34 |
+
if not link_record[0]["LinkSetDb"]:
|
| 35 |
+
return {"error": f"基因 {gene_symbol} (ID: {gene_id}) 暂无已证实的 RefSeq mRNA 序列 (NM_),无法进行 qPCR 引物设计。"}
|
| 36 |
+
|
| 37 |
+
# 3. 提取核苷酸 ID
|
| 38 |
nucl_id = link_record[0]["LinkSetDb"][0]["Link"][0]["Id"]
|
| 39 |
|
| 40 |
+
# 4. 下载 GenBank 数据
|
| 41 |
handle = Entrez.efetch(db="nucleotide", id=nucl_id, rettype="gb", retmode="text")
|
| 42 |
seq_record = SeqIO.read(handle, "genbank")
|
| 43 |
|
| 44 |
+
# 提取外显子(此处逻辑保持不变)
|
| 45 |
junctions = []
|
| 46 |
current_pos = 0
|
| 47 |
for feature in seq_record.features:
|
|
|
|
| 51 |
junctions.append(int(current_pos))
|
| 52 |
|
| 53 |
if junctions:
|
| 54 |
+
junctions.pop()
|
| 55 |
|
| 56 |
return {
|
| 57 |
"symbol": gene_symbol,
|
|
|
|
| 60 |
"junctions": junctions
|
| 61 |
}
|
| 62 |
except Exception as e:
|
| 63 |
+
return {"error": f"获取基因 {gene_symbol} 信息失败: {str(e)}"}
|
| 64 |
|
| 65 |
def design_qpcr_primers(gene_data):
|
| 66 |
"""设计qPCR引物,包含失败重试机制"""
|