Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,39 +12,30 @@ 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 |
Entrez.email = "your_email@example.com"
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
gene_id = record["IdList"][0]
|
| 25 |
-
|
| 26 |
-
# 2. 获取核苷酸 ID
|
| 27 |
-
# 核心修复点:使用 "refseq[filter] AND RNA[filter]"
|
| 28 |
-
# 这会同时命中 NM_ (mRNA) 和 NR_ (ncRNA),且排除掉染色体大片段
|
| 29 |
-
link_handle = Entrez.elink(
|
| 30 |
-
dbfrom="gene",
|
| 31 |
-
db="nucleotide",
|
| 32 |
-
id=gene_id,
|
| 33 |
-
term="refseq[filter] AND RNA[filter]"
|
| 34 |
-
)
|
| 35 |
-
link_record = Entrez.read(link_handle)
|
| 36 |
-
|
| 37 |
-
# 检查是否有返回结果,防止 list index out of range
|
| 38 |
-
if not link_record[0]["LinkSetDb"]:
|
| 39 |
-
return {"error": f"基因 {gene_symbol} 找不到标准的 RefSeq 转录本"}
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
nucl_id = link_record[0]["LinkSetDb"][0]["Link"][0]["Id"]
|
| 42 |
|
| 43 |
-
# 3. 下载
|
| 44 |
handle = Entrez.efetch(db="nucleotide", id=nucl_id, rettype="gb", retmode="text")
|
| 45 |
seq_record = SeqIO.read(handle, "genbank")
|
| 46 |
|
| 47 |
-
#
|
| 48 |
junctions = []
|
| 49 |
current_pos = 0
|
| 50 |
for feature in seq_record.features:
|
|
@@ -54,7 +45,7 @@ def get_ready_for_primers(gene_symbol, species="human"):
|
|
| 54 |
junctions.append(int(current_pos))
|
| 55 |
|
| 56 |
if junctions:
|
| 57 |
-
junctions.pop()
|
| 58 |
|
| 59 |
return {
|
| 60 |
"symbol": gene_symbol,
|
|
@@ -63,8 +54,7 @@ def get_ready_for_primers(gene_symbol, species="human"):
|
|
| 63 |
"junctions": junctions
|
| 64 |
}
|
| 65 |
except Exception as e:
|
| 66 |
-
|
| 67 |
-
return {"error": f"获取 {gene_symbol} 失败: {str(e)}"}
|
| 68 |
|
| 69 |
def design_qpcr_primers(gene_data):
|
| 70 |
"""设计qPCR引物,包含失败重试机制"""
|
|
|
|
| 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 |
+
# 1. 搜索基因并获取 NCBI 内部 ID
|
| 19 |
+
search_term = f"{gene_symbol}[Gene Name] AND {species}[Organism]"
|
| 20 |
+
handle = Entrez.esearch(db="gene", term=search_term)
|
| 21 |
+
record = Entrez.read(handle)
|
| 22 |
+
if not record["IdList"]:
|
| 23 |
+
return {"error": "未找到该基因"}
|
| 24 |
+
gene_id = record["IdList"][0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
# 2. 获取该基因关联的 NM_ 编号
|
| 27 |
+
link_handle = Entrez.elink(dbfrom="gene", db="nucleotide", id=gene_id, term="srcdb_refseq[prop] AND mRNA[filter]")
|
| 28 |
+
link_record = Entrez.read(link_handle)
|
| 29 |
+
|
| 30 |
+
try:
|
| 31 |
+
# 获取第一个关联的核苷酸 UID
|
| 32 |
nucl_id = link_record[0]["LinkSetDb"][0]["Link"][0]["Id"]
|
| 33 |
|
| 34 |
+
# 3. 下载完整的 GenBank 格式数据
|
| 35 |
handle = Entrez.efetch(db="nucleotide", id=nucl_id, rettype="gb", retmode="text")
|
| 36 |
seq_record = SeqIO.read(handle, "genbank")
|
| 37 |
|
| 38 |
+
# 提取外显子分界点
|
| 39 |
junctions = []
|
| 40 |
current_pos = 0
|
| 41 |
for feature in seq_record.features:
|
|
|
|
| 45 |
junctions.append(int(current_pos))
|
| 46 |
|
| 47 |
if junctions:
|
| 48 |
+
junctions.pop() # 移除最后一个边界
|
| 49 |
|
| 50 |
return {
|
| 51 |
"symbol": gene_symbol,
|
|
|
|
| 54 |
"junctions": junctions
|
| 55 |
}
|
| 56 |
except Exception as e:
|
| 57 |
+
return {"error": f"获取基因信息失败: {str(e)}"}
|
|
|
|
| 58 |
|
| 59 |
def design_qpcr_primers(gene_data):
|
| 60 |
"""设计qPCR引物,包含失败重试机制"""
|