File: validateSBML.php

package info (click to toggle)
libsbml 5.17.2%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 156,336 kB
  • sloc: cpp: 1,012,766; xml: 314,374; cs: 58,129; ansic: 54,053; python: 27,299; java: 27,152; makefile: 9,721; perl: 9,039; sh: 8,777; ruby: 4,760; php: 202; csh: 3
file content (86 lines) | stat: -rw-r--r-- 1,768 bytes parent folder | download | duplicates (6)
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
<?php
include("libSBML.php");

function printUsageAndExit() {
  echo "usage: validateSBML [-u] filename\n";
  echo "       -u : disable unit consistency check\n";
  exit(1);
}

function validateSBML($file, $enableUnitCheck) {

  echo "validating: $file\n";
  
  $reader = new SBMLReader();

  $doc = $reader->readSBMLFromFile($file);
  $log = $doc->getErrorLog();
  $numFatals = $log->getNumFailsWithSeverity(LIBSBML_SEV_FATAL);
  $numErrors = $log->getNumFailsWithSeverity(LIBSBML_SEV_ERROR);

  if ($numFatals + $numErrors > 0)  {
   $doc->printErrors();
   echo "Further consistency checking and validation aborted.\n";
   return FALSE;
  }

  $doc->setConsistencyChecks(LIBSBML_CAT_UNITS_CONSISTENCY, $enableUnitCheck);
  $failures = $doc->checkConsistency();
  $numFatals = $log->getNumFailsWithSeverity(LIBSBML_SEV_FATAL);
  $numErrors = $log->getNumFailsWithSeverity(LIBSBML_SEV_ERROR);

  if ($failures > 0) {
    echo "\n*** consistency check ***\n";
    $doc->printErrors();
  }  


  if ($numFatals + $numErrors > 0)  {
    return FALSE;
  }

  return True;
}


echo "\n\nValidateSBML\n";

if ($argc < 2) {
  printUsageAndExit();
}

$index = 1;
$file = $argv[1];
$enableUnitCheck = FALSE;

if ($file == "-u") {
$enableUnitCheck = TRUE;
$file = $argv[2];
$index = 2;
}

if ($file == "") {
  printUsageAndExit();
}

$numInvalid = 0;
$numFiles = 0;
for ($i = $index; $i < $argc; $i++) {

  $file = $argv[$index];

  $numFiles = $numFiles +1;

  if (!validateSBML($file, $enableUnitCheck))
    $numInvalid = $numInvalid + 1;

}

$numValid = $numFiles - $numInvalid;
echo "\nValidated $numFiles file(s), $numValid valid file(s), "; 
echo "$numInvalid invalid file(s)\n";
if (!$enableUnitCheck) {
    echo "  (Unit consistency checks skipped)\n";
}
echo "\n";
?>