Skip to content

Commit 744fd79

Browse files
committed
parse features now works
1 parent df8634a commit 744fd79

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

genbank/genbank.php

+19-18
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ function process(){
142142

143143
$features = $this->retrieveSections("FEATURES", $sectionsRaw);
144144
$parsed_features_arr = $this->parseFeatures($features);
145+
print_r($parsed_features_arr);exit;
145146

146147
//get the source section
147148
$source = $this->retrieveSections("SOURCE", $sectionsRaw);
@@ -232,33 +233,33 @@ function process(){
232233
* http://www.insdc.org/documents/feature-table
233234
*/
234235
function parseFeatures($feature_arr){
235-
$rm = array();
236+
237+
$out = array();
236238
//get a copy of the features array
237239
$features = $this->getFeatures();
238240
$feat_keys = array_keys($features);
239241
foreach($feature_arr as $feat){
240242
$feature_raw = utf8_encode(trim($feat['value']));
241-
echo "\n\n".$feature_raw."\n\n";
242243

243244
$arr = explode("\n", $feature_raw);
244-
print_r($arr);exit;
245-
if(strlen($feature_raw)){
246-
//remove multiple spaces and newlines
247-
$feature_raw = preg_replace('/\s\s*/', ' ', $feature_raw);
248-
//now construct a regex for every section
249-
$regex_string = "(.*)";
250-
$regex_groups = array();
251-
foreach($feat_keys as $aKey){
252-
if(strpos($feature_raw, $aKey)){
253-
$regex_string .= "\s+".$aKey."\s+(.*)";
254-
$regex_groups[] = $aKey;
255-
}
256-
}//foreach
257-
$regex = "/".$regex_string."/";
258-
echo "\n".$feature_raw."\n".$regex."\n";exit;
245+
$count = 0;
246+
foreach($arr as $aLine){
247+
$p1 = "/^\s{5}(\S+)\s+(.*)/";
248+
$p2 = "/^\s{20,}(.*)/";
249+
preg_match($p1, $aLine, $m1);
250+
preg_match($p2, $aLine, $m2);
251+
if(count($m1)){
252+
$out[$count] = array('type'=> $m1[1], 'value'=>$m1[2]);
253+
$count ++;
254+
continue;
255+
}
256+
if(count($m2)){
257+
$value = $out[$count-1]['value'];
258+
$out[$count-1]['value'] = $value.PHP_EOL.$m2[1];
259+
}
259260
}
260261
}
261-
return $rm;
262+
return $out;
262263
}
263264

264265
/**

0 commit comments

Comments
 (0)