Pymeta API

Pymeta API提供基于PythonMeta的在线meta分析远程调用服务,此文档为调用方法说明。

环境:服务器端(Requests,curl等)
方法:POST
URL:https://www.pymeta.com/api (注意地址不能以“/”结尾!)
端口:80
数据格式:application/json
提交参数:authkey, datatype, model, effect, algorithm, figtype, studies
authkey授权码[type:string]。
  • "<test@test.com>X#09FW.LKD,C2n_sOK%IKC$ERk": 测试用授权码,有性能限制,功能同正式授权码
  • 正式授权码请向项目组申请(Email:dephew@126.com)
datatype 数据类型[type:string],可选值: "CATE", "CONT"
  • "CATE": 二分类数据
  • "CONT": 连续型数据
model 效应模型[type:string],可选值: "Fixed", "Random"
  • "Fixed": 固定效应模型
  • "Random": 随机效应模型
effect 效应量[type:string],可选值: "OR", "RR", "RD", "MD", "SMD"
  • "OR": 比值比(二分类数据)
  • "RR": 率比(二分类数据)
  • "RD": 率差(二分类数据)
  • "MD": 均值差或加权均差(连续型数据)
  • "SMD": 标准均差(连续型数据)
algorithm 算法[type:string],可选值: "IV", "MH", "Peto"
  • "IV": 倒方差法(适合两种数据类型的全部效应量计算)
  • "MH": Mantel-Haenszel法(适合二分类数据)
  • "Peto": Peto法,效应值为OR时可选
figtype 图像类型[type:string],可选值: "None", "Forest", "Funnel","Forest,Funnel"
  • "None": 不返回图像结果
  • "Forest": 返回森林图
  • "Funnel": 返回漏斗图
  • "Forest,Funnel": 返回森林图和漏斗图
studies待分析数据[type:list]。
二分类数据:studyID, 干预events, 干预number, 对照events, 对照number 如:
["Fang 2015, 15, 40, 24, 37",
"Gong 2012, 10, 40, 18, 35",
"Liu 2015, 30, 50, 40, 50",
"Long 2012, 19, 40, 26, 40",
"Pan 2015a, 57, 100, 68, 100",
"Wang 2001, 13, 18, 17, 18",
"Wang 2003, 7, 86, 15, 86"]

连续型数据:studyID, 干预mean, 干预SD, 干预number, 对照mean, 对照SD, 对照number 如:
["Atmaca 2005, 20.9, 6.0, 15, 27.4, 8.5, 14",
"Guo 2014, 12.8, 5.2, 51, 11.9, 5.3, 51",
"Liu 2010, 23.38, 5.86, 35, 24.32, 5.43, 35",
"Wang 2012, 15.67, 8.78, 43, 18.67, 9.87, 43",
"Xu 2002, 15.49, 7.16, 50, 21.72, 8.07, 50",
"Zhao 2012, 12.8, 5.7, 40, 13.0, 5.2, 40"]
完整的提交json数据示例 二分类数据:
{
"authkey":"<test@test.com>X#09FW.LKD,C2n_sOK%IKC$ERk",
"datatype":"CATE",
"model":"Fixed",
"effect":"RR",
"algorithm":"MH",
"figtype":"Forest,Funnel",
"studies":[
"Fang 2015, 15, 40, 24, 37",
"Gong 2012, 10, 40, 18, 35",
"Liu 2015, 30, 50, 40, 50",
"Long 2012, 19, 40, 26, 40",
"Pan 2015a, 57, 100, 68, 100",
"Wang 2001, 13, 18, 17, 18",
"Wang 2003, 7, 86, 15, 86"
]
}

连续型数据:
{
"authkey":"<test@test.com>X#09FW.LKD,C2n_sOK%IKC$ERk",
"datatype":"CONT",
"model":"Fixed",
"effect":"MD",
"algorithm":"IV",
"figtype":"Forest,Funnel",
"studies":[
"Atmaca 2005, 20.9, 6.0, 15, 27.4, 8.5, 14",
"Guo 2014, 12.8, 5.2, 51, 11.9, 5.3, 51",
"Liu 2010, 23.38, 5.86, 35, 24.32, 5.43, 35",
"Wang 2012, 15.67, 8.78, 43, 18.67, 9.87, 43",
"Xu 2002, 15.49, 7.16, 50, 21.72, 8.07, 50",
"Zhao 2012, 12.8, 5.7, 40, 13.0, 5.2, 40"
]
}
API调用代码示例 Python:
import requests
import json

#API网址
url_str = "https://www.pymeta.com/api" #注意地址不能以“/”结尾!

#设置meta分析参数和数据
data_dict = {}
data_dict["authkey"] = "<test@test.com>X#09FW.LKD,C2n_sOK%IKC$ERk"
data_dict["datatype"] = "CATE"
data_dict["model"] = "Fixed"
data_dict["effect"] = "RR"
data_dict["algorithm"] = "MH"
data_dict["figtype"] = "Forest,Funnel"
data_dict["studies"] = [
    "Fang 2015, 15, 40, 24, 37",
    "Gong 2012, 10, 40, 18, 35",
    "Liu 2015, 30, 50, 40, 50",
    "Long 2012, 19, 40, 26, 40",
    "Pan 2015a, 57, 100, 68, 100",
    "Wang 2001, 13, 18, 17, 18",
    "Wang 2003, 7, 86, 15, 86"]
data_json = json.dumps(data_dict) #将dict对象转换为json数据

#发送请求
recv_json = requests.post(url_str,data_json)

#返回并处理结果
print(recv_json.text)



php:
<?php
$data = array();
$data["authkey"] = "<test@test.com>X#09FW.LKD,C2n_sOK%IKC\$ERk";
$data["datatype"] = "CATE";
$data["model"] = "Fixed";
$data["effect"] = "RR";
$data["algorithm"] = "MH";
$data["figtype"] = "Forest,Funnel";
$data["studies"] = array(
"Fang 2015, 15, 40, 24, 37",
"Gong 2012, 10, 40, 18, 35",
"Liu 2015, 30, 50, 40, 50",
"Long 2012, 19, 40, 26, 40",
"Pan 2015a, 57, 100, 68, 100",
"Wang 2001, 13, 18, 17, 18",
"Wang 2003, 7, 86, 15, 86");

$data_string = json_encode($data);

$ch = curl_init('https://www.pymeta.com/api'); //注意地址不能以“/”结尾!
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);

$result = curl_exec($ch);
echo $result;
?>


正常返回结果示例 说明:
  • 结果数据为json格式;
  • “results”数据依次定义为:studyID,病例数,效应量,CI低值,CI高值,权重(%);
  • 图像结果链接$apihost$为本站域名或IP地址(https://www.pymeta.com);
  • 图像结果仅在本站暂时保存,可能随时被清理,请即时下载到本地备份。
  • {
    "effect":"RR",
    "algorithm":"MH",
    "model":"Fixed",
    "results":[
    ["Fang2015",77,0.58,0.36,0.92,11.87],
    ["Gong2012",75,0.49,0.26,0.91,9.14],
    ["Liu2015",100,0.75,0.58,0.98,19.04],
    ["Long2012",80,0.73,0.49,1.09,12.37],
    ["Pan2015a",200,0.84,0.67,1.04,32.36],
    ["Wang2001",36,0.76,0.56,1.04,8.09],
    ["Wang2003",172,0.47,0.20,1.09,7.14],
    ["Total",740,0.71,0.62,0.82,100]
    ],
    "overall":{
    "studynum":7,
    "totalsamples":740,
    "z":4.85,
    "p":"0.000"
    },
    "heterogeneity":{
    "Q":5.69,
    "p":"0.461",
    "I2":"0%"
    }
    "plots":[
    {"forest":"$apihost$/temp/dhy_sohu_com/forest_1613304991860.png"},
    {"funnel":"$apihost$/temp/dhy_sohu_com/funnel_1613304992000.png"}
    ]
    }

    错误返回结果示例 说明:API以json格式返回错误结果,以下为常见错误类型。
    {
    "error":"Not Found"
    }

    {
    "error":"数据获取或解析错误,请检查数据类型和数据格式。"
    }

    {
    "error":"Meta分析执行错误,请检查数据类型、算法和数据格式。"
    }

    {
    "error":"Busy:提交频繁,请稍后再试(60 s)。"
    }

    {
    "error":"授权码错误。"
    }

    {
    "error":"数据类型参数可选:'CONT', 'CATE'。"
    }

    ©Pymeta.com