示例#1
0
 def test_keep_existing_reaction_id(self):
     message = reaction_pb2.Reaction()
     message.reaction_id = 'foo'
     message.provenance.record_created.time.value = '11 am'
     updates.update_reaction(message)
     self.assertEqual(message.reaction_id, 'foo')
     self.assertLen(message.provenance.record_modified, 0)
示例#2
0
 def test_keep_existing_reaction_id(self):
     message = reaction_pb2.Reaction()
     message.reaction_id = 'ord-c0bbd41f095a44a78b6221135961d809'
     message.provenance.record_created.time.value = '2020-01-01'
     updates.update_reaction(message)
     self.assertEqual(message.reaction_id,
                      'ord-c0bbd41f095a44a78b6221135961d809')
     self.assertLen(message.provenance.record_modified, 0)
示例#3
0
 def test_with_no_updates(self):
     message = reaction_pb2.Reaction()
     message.provenance.record_created.time.value = '2020-05-08'
     message.reaction_id = 'ord-c0bbd41f095a44a78b6221135961d809'
     copied = reaction_pb2.Reaction()
     copied.CopyFrom(message)
     updates.update_reaction(copied)
     self.assertEqual(copied, message)
示例#4
0
 def test_with_resolve_names(self):
     reaction = reaction_pb2.Reaction()
     component = reaction.inputs['ethylamine'].components.add()
     component.identifiers.add(type='NAME', value='ethylamine')
     updates.update_reaction(reaction)
     self.assertLen(component.identifiers, 2)
     self.assertEqual(component.identifiers[1].value, 'CCN')
     self.assertEqual(component.identifiers[1].type,
                      reaction_pb2.CompoundIdentifier.IdentifierType.SMILES)
     self.assertRegex(component.identifiers[1].details, 'NAME resolved')
示例#5
0
 def test_with_resolve_names(self):
     reaction = reaction_pb2.Reaction()
     component = reaction.inputs['ethylamine'].components.add()
     component.identifiers.add(type='NAME', value='ethylamine')
     updates.update_reaction(reaction)
     self.assertLen(component.identifiers, 2)
     self.assertEqual(
         component.identifiers[1],
         reaction_pb2.CompoundIdentifier(
             type='SMILES', value='CCN',
             details='NAME resolved by PubChem'))
示例#6
0
def main(argv):
    del argv  # Only used by app.run().
    inputs = sorted(_get_inputs())
    if not inputs:
        logging.info('nothing to do')
        return  # Nothing to do.
    datasets = {}
    for file_status in inputs:
        datasets[file_status.filename] = message_helpers.load_message(
            file_status.filename, dataset_pb2.Dataset)
    if FLAGS.validate:
        validations.validate_datasets(datasets, FLAGS.write_errors)
    if not FLAGS.update:
        logging.info('nothing else to do; use --update for more')
        return  # Nothing else to do.
    for dataset in datasets.values():
        for reaction in dataset.reactions:
            updates.update_reaction(reaction)
        # Offload large Data values.
        data_filenames = data_storage.extract_data(dataset,
                                                   FLAGS.root,
                                                   min_size=FLAGS.min_size,
                                                   max_size=FLAGS.max_size)
        if data_filenames:
            args = ['git', 'add'] + data_filenames
            logging.info('Running command: %s', ' '.join(args))
            subprocess.run(args, check=True)
    combined = _combine_datasets(datasets)
    # Final validation to make sure we didn't break anything.
    validations.validate_datasets({'_COMBINED': combined}, FLAGS.write_errors)
    if FLAGS.output:
        output_filename = FLAGS.output
    else:
        _, suffix = os.path.splitext(inputs[0].filename)
        output_filename = os.path.join(
            FLAGS.root,
            message_helpers.id_filename(f'{combined.dataset_id}{suffix}'))
    os.makedirs(os.path.dirname(output_filename), exist_ok=True)
    if FLAGS.cleanup:
        cleanup(inputs, output_filename)
    logging.info('writing combined Dataset to %s', output_filename)
    message_helpers.write_message(combined, output_filename)
示例#7
0
 def test_add_reaction_id(self):
     message = reaction_pb2.Reaction()
     updates.update_reaction(message)
     self.assertNotEmpty(message.reaction_id)
     self.assertLen(message.provenance.record_modified, 1)
示例#8
0
 def test_with_updates_simple(self):
     message = reaction_pb2.Reaction()
     updates.update_reaction(message)
     self.assertNotEqual(message, reaction_pb2.Reaction())
     self.assertLen(message.provenance.record_modified, 1)