-
Notifications
You must be signed in to change notification settings - Fork 1
/
figure5.php
104 lines (67 loc) · 2.66 KB
/
figure5.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
$client = new \GuzzleHttp\Client;
$search_term = 'human lymphoblastoid cell lines proliferation';
$response = $client->request('GET', 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi', [
'query' => [
'db' => 'pubmed',
'term' => $search_term,
'retmode' => 'json',
]
]);
$response = json_decode($response->getBody(), true);
$count = $response['esearchresult']['count'];
$retmax = 200;
$num_loops = ceil($count/$retmax);
$retstart = 0;
$cnt = 0;
for($i = 0; $i < $num_loops; $i++){
$response = $client->request('GET', 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi', [
'query' => [
'db' => 'pubmed',
'term' => $search_term,
'retmode' => 'json',
'retmax' => $retmax,
'retstart' => $retmax*$i
]
]);
$response = json_decode($response->getBody(), true);
$idlist_arr = $response['esearchresult']['idlist'];
$idlist = implode(',', $idlist_arr);
$response = $client->request('GET', 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi', [
'query' => [
'db' => 'pubmed',
'id' => $idlist,
'rettype'=> 'abstract',
'retmode' => 'XML',
]
]);
$xml = simplexml_load_string($response->getBody());
$json = json_encode($xml);
$array = json_decode($json,TRUE);
if(isset($array['PubmedArticle'])) $articles = $array['PubmedArticle'];
else $articles = [$array['MedlineCitation']];
$output_dir = base_path()."/bio_data/morpheome";
$cnt0 = 0;
foreach($articles as $article){
$abstract_txt = "";
$pmid = $article['MedlineCitation']['PMID'];
if(isset($article['MedlineCitation']['Article']['Abstract'])){
$abstract = $article['MedlineCitation']['Article']['Abstract']['AbstractText'];
}
else{
$abstract = '';
}
if(is_array($abstract)){
array_walk_recursive($abstract, function ($item, $key) use(&$abstract_txt){
$abstract_txt = $abstract_txt . $item;
});
}
else{
$abstract_txt = $abstract;
}
if ( ($handle1 = fopen($output_dir."/all_patient_abstracts.csv", "a") ) !== FALSE) {
fputcsv($handle1, [$pmid, $abstract_txt]);
}
fclose($handle1);
}
?>