-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfigure4.php
66 lines (42 loc) · 1.88 KB
/
figure4.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
<?php
$servername = "localhost";
$username = "root";
$password = "";
$db = "morpheome";
try {
$conn = new PDO("mysql:host=$servername;dbname=".$db, $username, $password,
[PDO::MYSQL_ATTR_LOCAL_INFILE => true]);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
$table = 'gene_disease';
$field = 'disease_type';
$diseases = ['cancer','infection','alzheimer','cardiovascular','diabetes','obesity','depression','inflammation','osteoporosis','hypertension','stroke'];
ini_set('memory_limit','1G');
$insert_db_table = 'gene_disease_copy';
$query = 'SELECT aliases.* FROM aliases left join '.$insert_db_table.' on aliases.gene_id='.$insert_db_table.'.gene_id where type = "NCBI_official_symbol" and '.$insert_db_table.'.gene_id is null';
$sth = $conn->prepare($query);
$sth->execute();
/* Fetch all of the values in form of a numeric array */
$result = $sth->fetchAll();
$ids = [];
foreach($diseases as $disease){
foreach($result as $row){
$ids[] = $row['name'];
// searches PubMed for co-occurrence of gene name and disease name;
$query2 = 'SELECT count(*) as publication_count FROM publications WHERE match(abstract) against("+'.str_replace(["-", "@"], ["", ""],$row['name']).' +'.$disease.'" IN BOOLEAN MODE);';
$sth2 = $conn->prepare($query2);
$sth2->execute();
/* Fetch all of the values in form of a numeric array */
$result2 = $sth2->fetchAll();
$query3 = 'INSERT into '.$insert_db_table.' (gene_id,alias_id,disease_type,publication_count) values ("'.$row['gene_id'].'",'.$row['id'].', "'.$disease.'", "'.$result2[0]['publication_count'].'")';
$sth3 = $conn->prepare($query3);
$sth3->execute();
}
}
$conn = null;
?>