Esempio n. 1
0
 def testLint5(self):
     if IGNORE_TEST:
         return
     model = """
 A -> B; 1
 B -> B + DUMMYMOLECULE;1
 A = 0
 B = 0
 DUMMYMOLECULE = 0
 """
     with open(TEST_OUT_PATH, 'w') as fd:
         try:
             result = sbmllint.lint(model_reference=model,
                                    file_out=fd,
                                    mass_balance_check="games",
                                    implicit_games=False,
                                    is_report=IS_REPORT)
         except exceptions.MissingTelluriumError:
             return
     self.assertTrue(result)
     with open(TEST_OUT_PATH, 'w') as fd:
         result = sbmllint.lint(model_reference=model,
                                file_out=fd,
                                mass_balance_check="games",
                                implicit_games=True,
                                is_report=IS_REPORT)
     self.assertFalse(result)
Esempio n. 2
0
 def get(config_fid=None):
     with open(TEST_OUT_PATH, 'w') as fd:
         result = sbmllint.lint(model_reference=cn.TEST_FILE4,
                                file_out=fd,
                                config_fid=config_fid,
                                is_report=IS_REPORT,
                                mass_balance_check=cn.MOIETY_ANALYSIS)
     return result
Esempio n. 3
0
 def testLint2(self):
     with open(TEST_OUT_PATH, 'w') as fd:
         result = sbmllint.lint(
             cn.TEST_FILE2,
             file_out=fd,
             mass_balance_check=sbmllint.STRUCTURED_NAMES)
     self.assertGreaterEqual(result.num_reactions, result.num_imbalances)
     with open(TEST_OUT_PATH, 'r') as fd:
         lines = fd.readlines()
     self.assertGreater(len(lines), 0)
Esempio n. 4
0
 def testLintWithXMLFileFid(self):
     if IGNORE_TEST:
         return
     fid = open(cn.TEST_FILE4, "r")
     with open(TEST_OUT_PATH, 'w') as fd:
         result = sbmllint.lint(model_reference=fid,
                                file_out=fd,
                                is_report=IS_REPORT,
                                mass_balance_check=cn.MOIETY_ANALYSIS)
     fid.close()
     self.assertGreater(len(result), 0)
Esempio n. 5
0
 def testLint5(self):
     model = """
 A -> B; 1
 B -> B + DUMMYIMPLICIT;1
 A = 0
 B = 0
 DUMMYIMPLICIT = 0
 """
     with open(TEST_OUT_PATH, 'w') as fd:
         result = sbmllint.lint(model,
                                file_out=fd,
                                mass_balance_check="games",
                                implicit_games=False)
     self.assertTrue(result)
     with open(TEST_OUT_PATH, 'w') as fd:
         result = sbmllint.lint(model,
                                file_out=fd,
                                mass_balance_check="games",
                                implicit_games=True)
     self.assertFalse(result)
Esempio n. 6
0
 def testLint2(self):
     if IGNORE_TEST:
         return
     with open(TEST_OUT_PATH, 'w') as fd:
         result = sbmllint.lint(model_reference=cn.TEST_FILE2,
                                file_out=fd,
                                is_report=True,
                                mass_balance_check=cn.MOIETY_ANALYSIS)
     self.assertGreaterEqual(result.num_reactions, result.num_imbalances)
     with open(TEST_OUT_PATH, 'r') as fd:
         lines = fd.readlines()
     self.assertGreater(len(lines), 0)
Esempio n. 7
0
 def testLint3(self):
     model = """
 2Glu + 2A_P_P_P -> 2Glu_P + 2A_P_P; 1
 Glu = 0
 A_P_P_P = 0
 Glu_P = 0
 A_P_P = 0
 """
     with open(TEST_OUT_PATH, 'w') as fd:
         result = sbmllint.lint(
             model,
             file_out=fd,
             mass_balance_check=sbmllint.STRUCTURED_NAMES)
     self.assertEqual(result.num_reactions, 1)
     self.assertEqual(result.num_imbalances, 0)
Esempio n. 8
0
 def testBIOMOD147_2(self):
     if IGNORE_TEST:
         return
     with open(TEST_OUT_PATH, 'w') as fd:
         result = sbmllint.lint(
             model_reference=TEST_147_SBML_FILE,
             config_fid=open(TEST_147_CFG_FILE2, "r"),
             file_out=fd,
             mass_balance_check=cn.MOIETY_ANALYSIS,
             implicit_games=False,
             is_report=IS_REPORT,
         )
     # Verify that exclicit declaration is decomposed
     # into moieties
     self.assertFalse("cytoplasm:" in result.report)
     self.assertFalse("nulceus:" in result.report)
Esempio n. 9
0
 def testLint3(self):
     if IGNORE_TEST:
         return
     model = """
 2Glu + 2A_P_P_P -> 2Glu_P + 2A_P_P; 1
 Glu = 0
 A_P_P_P = 0
 Glu_P = 0
 A_P_P = 0
 """
     with open(TEST_OUT_PATH, 'w') as fd:
         try:
             result = sbmllint.lint(model_reference=model,
                                    file_out=fd,
                                    is_report=IS_REPORT,
                                    mass_balance_check=cn.MOIETY_ANALYSIS)
         except exceptions.MissingTelluriumError:
             return
     self.assertEqual(result.num_reactions, 1)
     self.assertEqual(result.num_imbalances, 0)
Esempio n. 10
0
def main():
    parser = argparse.ArgumentParser(description='SBML XML file.')
    parser.add_argument('filename', type=str, help='SBML file')
    args = parser.parse_args()
    sbmllint.lint(args.filename, mass_balance_check=sbmllint.GAMES)
Esempio n. 11
0
def calcStats(initial=0, final=50, out_path=OUTPUT_PATH, 
    report_interval=50, report_progress=True, min_frc=-1,
    data_dir=cn.BIOMODELS_DIR):
  """
  Calculates statistics for structured names.
  :param int initial: Index of first model to process
  :param int final: Index of final model to process
  :param str out_path: Path to the output CSV file
  :param int report_interval: Number of files processed before
      a report is written
  :param bool report_progress: report file being processed
  :param float min_frc: Filter to select only those models
      that have at least the specified fraction of reactions
      balanced according to moiety_analysis
  """
  def writeDF(dfs):
    df_count = pd.concat(dfs)
    df_count[cn.NUM_BALANCED_REACTIONS] =  \
        df_count[cn.TOTAL_REACTIONS]  \
        - df_count[cn.NUM_IMBALANCED_REACTIONS]
    denom =  (df_count[cn.TOTAL_REACTIONS] 
        - df_count[cn.NUM_BOUNDARY_REACTIONS])
    denom = [np.nan if np.isclose(v, 0) else v for v in denom]
    df_count[cn.FRAC_BALANCED_REACTIONS] =  \
        1.0*df_count[cn.NUM_BALANCED_REACTIONS] / denom
    df_count[cn.FRAC_BOUNDARY_REACTIONS] =  \
        1.0*df_count[cn.NUM_BOUNDARY_REACTIONS] / (
        df_count[cn.TOTAL_REACTIONS])
    if min_frc < 0:
      df = df_count
    else:
      df = df_count[df_count[cn.FRAC_BALANCED_REACTIONS] > min_frc]
    df = df.sort_values(cn.FRAC_BALANCED_REACTIONS)
    df.to_csv(out_path, index=False)
  #
  dfs = []
  sbmliter = simple_sbml.modelIterator(initial=initial, final=final,
      data_dir=data_dir)
  for item in sbmliter:
    if report_progress:
      print("*Processing file %s, number %d"
           % (item.filename, item.number))
    simple = simple_sbml.SimpleSBML()
    try:
      simple.initialize(item.model)
    except:
      print("  Error in model number %d." % item.number)
      continue
    row = {cn.FILENAME: [item.filename], 
           cn.IS_STRUCTURED: [False], 
           cn.NUM_BOUNDARY_REACTIONS: [0],
           cn.TOTAL_REACTIONS: [0],
           cn.NUM_IMBALANCED_REACTIONS: [0],
           }
    for reaction in simple.reactions:
      if (len(reaction.reactants) == 0) or (len(reaction.products) == 0):
          row[cn.NUM_BOUNDARY_REACTIONS] =  \
              [row[cn.NUM_BOUNDARY_REACTIONS][0] + 1]
      molecules = util.uniqueify([m.molecule 
          for m in set(reaction.reactants).union(reaction.products)])
      if any([isStructuredName(m.name) for m in molecules]):
          row[cn.IS_STRUCTURED] = [True]
    try:
      mcr = sbmllint.lint(model_reference=item.model, is_report=False)
      row[cn.TOTAL_REACTIONS] = [mcr.num_reactions if mcr.num_reactions > 0 else np.nan]
      row[cn.NUM_IMBALANCED_REACTIONS] = [mcr.num_imbalances]
    except:
      row[cn.TOTAL_REACTIONS] = [None]
      row[cn.NUM_IMBALANCED_REACTIONS] = [0]
    dfs.append(pd.DataFrame(row))
    if item.number % report_interval == 0:
      writeDF(dfs)
  writeDF(dfs)