-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload.php
More file actions
156 lines (100 loc) · 3.4 KB
/
upload.php
File metadata and controls
156 lines (100 loc) · 3.4 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
function cors() {
header("Access-Control-Allow-Origin: *");
// Allow from any origin
if (isset($_SERVER['HTTP_ORIGIN'])) {
// Decide if the origin in $_SERVER['HTTP_ORIGIN'] is one
// you want to allow, and if so:
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400'); // cache for 1 day
}
}
// echo "This is files\r\n";
// echo $_FILES;
// echo "\r\n filename name \r\n";
// echo $_FILES["file"]["name"];
// echo "\r\n filename name \r\n";
// echo $_FILES["file"]
// echo "\r\n temp name \r\n";
// echo $_FILES["file"]["tmp_name"];
// echo "\r\n error \r\n";
// echo $_FILES["file"]["error"]
// echo "That was files";
// $inipath = php_ini_loaded_file();
// if ($inipath) {
// echo 'Loaded php.ini: ' . $inipath;
// } else {
// echo 'A php.ini file is not loaded';
// }
// Setup directory to store uploads
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["file"]["name"]);
$tree_file = $target_dir . basename($_FILES["tree"]["name"]);
$returnArray = array();
// Pattern to check if line is a header
$headerPattern = "/^>.*/";
$seq = '';
$seqCount = 0;
$string_name = (string)$target_file;
// Upload file
$moved = move_uploaded_file($_FILES["file"]["tmp_name"], $target_file );
if( $moved ) {
} else {
echo "Not uploaded because of error #".$_FILES["file"]["error"];
}
if ($_FILES["tree"]["name"]){
$moved = move_uploaded_file($_FILES["tree"]["tmp_name"], $tree_file );
}
$file = fopen($target_file, 'rb');
while (($line = fgets($file)) !== false){
// Clean up any instances of repeating pipe symbols
$line = str_replace("||", "|", $line);
// If we are at an identifier
if (preg_match($headerPattern, $line)){
if ($seq != ''){
$returnArray[$seqCount]['seq'] = $seq;
$seq = '';
$seqCount +=1;
}
$lineArray = preg_split("/[\s,|_\/]+/", $line);
$type = substr($lineArray[0], 1);
$id = "";
$id_name = "";
// Add the type (NCBI or UniProt) back into the array as the actual letter code
if ($type == "XP" || $type == "XM" || $type == "XR" || $type == "WP" || $type == "NP" || $type == "NC" || $type == "NG" || $type == "NM" || $type == "NR") {
$id = $type . "_" . $lineArray[1];
} elseif ($type == "gi") {
$id = $type . "|" . $lineArray[1];
} elseif ($type == "pdb" || $type == "sp" || $type == "tr" ){
$id = $lineArray[1];
$uniprotArray = preg_split("/[\s,\/]+/", $line);
$uniProtstring = print_r($uniprotArray[0], true);
$idArray = preg_split("/[\s,|]+/", $uniProtstring);
for ($i = 2; $i < count($idArray); $i++) {
$id_name = $id_name . "_" . $idArray[$i];
}
$id_name = ltrim($id_name,"_");
// $id_name = $idArray[1] . "_" . $idArray[2];
// $id_name = $uniProtstring;
} else {
$id = $type;
$type = "";
}
// Prepare the array for returning
$returnArray[] = array('originalHeader' => $line, 'type' => $type ,'id' => $id, 'id_name' => $id_name);
}
else {
// Add all of the lines of the sequence to the sequence object
$seq .= str_replace(array("\r\n", "\n\r", "\n", "\r"), '', $line);
}
}
// Create object to return
$returnArray[$seqCount]['seq'] = $seq;
$file = fopen($tree_file, 'rb');
while (($line = fgets($file)) !== false){
$returnArray[$seqCount + 1]['tree'] = $line;
}
$jsonData = json_encode($returnArray);
echo $jsonData;
?>