0

Working on a proprietary Bioinformatics software that manipulate domain objects, I have to enhance the API so that external parties can access (CRUD) data stored in the internal DB.

The data are grouped by type (such as molecule, oligo and enzyme) and within each, there can be subsets (molecule::protein, molecule::dna, etc) which are nest-able.

Since each data type has different attributes, we are using formatted query string (similar to widely-used entrez format) to specify the search criteria. Example of the code will be as follow:

IMoleculePersistenceService svc = PersistenceFactory::GetMoleculeService();

// IMoleculePersistenceService::search( <search-string>, <subset> );
IMolecule[] searchResult = svc.search( "Foo[Name] OR 128[Length]", "molecule::protein" );


My question is:

Assuming the users have corresponding domain knowledge to understand biology-related hierarchy. Will it be better to have the search function accept prototype object instead of the formatted-string ?

IMoleculePersistenceService svc = PersistenceFactory::GetMoleculeService();

IMoleculeTemplate searchPrototype = svc.GetSearchPrototype();
searchPrototype.SetName( "Foo" );
searchPrototype.SetLength( 128 );

IMolecule[] searchResult = svc.search( searchPrototype, "molecule::protein" );
IMolecule[] searchResult2 = svc.search( svc.GetSearchPrototype( <parameters> ), "molecule::protein" );


Pros:
-easier to visualize/understand
-compatible with query-string if prototype can be serialized into (formatted) string automatically.
Cons:
-not flexible as the criteria combination is fixed (either AND, OR).

YeenFei
  • 3,180
  • 18
  • 26

1 Answers1

0

The service should accept only a "prototype". Parsing of a string to a prototype is a feature of its own and does not directly belong to the service. I'd promote the prototype-based one by e.g. first showing examples with it in the HowTo, and mention the parsing capability only later.

In C# land, there's the IQueryable interface -- have a look at the answers to this question. The prototypes very much look like Expressions, but this could be too generic for the needs at hand.

Also, returning an array might not be the best option, because this fixes the implementation to using arrays. Again in C#, there's IEnumerable, but I'd like to see some simple SearchResult class providing the capability of generating/returning the result array, and therefore allowing you internal changes and optimizations.

Community
  • 1
  • 1
Stefan Hanke
  • 3,458
  • 2
  • 30
  • 34