Skip to content

Commit

Permalink
When opening a store, also decide the default read version if only sq…
Browse files Browse the repository at this point in the history
…Read_normal is set.
  • Loading branch information
brianwalenz committed Sep 5, 2020
1 parent 8da1b99 commit 7ccc151
Showing 1 changed file with 44 additions and 16 deletions.
60 changes: 44 additions & 16 deletions src/stores/sqStoreConstructor.C
Original file line number Diff line number Diff line change
Expand Up @@ -39,38 +39,66 @@ sqStore::sqStore_loadMetadata(void) {
AS_UTL_loadFile(_storePath, '/', "libraries", _libraries, _librariesAlloc);
AS_UTL_loadFile(_storePath, '/', "reads", _meta, _readsAlloc);

// If the user hasn't set a default version (by calling
// sqRead_setDefaultVersion() before a sqStore object is constructed),
// pick the plausible most recent version.

if (sqRead_defaultVersion == sqRead_unset) {
if (sqStore_getNumReads(sqRead_raw) > 0) sqRead_defaultVersion = sqRead_raw;
if (sqStore_getNumReads(sqRead_raw | sqRead_trimmed) > 0) sqRead_defaultVersion = sqRead_raw | sqRead_trimmed;
if (sqStore_getNumReads(sqRead_corrected) > 0) sqRead_defaultVersion = sqRead_corrected;
if (sqStore_getNumReads(sqRead_corrected | sqRead_trimmed) > 0) sqRead_defaultVersion = sqRead_corrected | sqRead_trimmed;
}
// If the user hasn't set a default version, or has only requested
// uncompressed reads, pick the plausible most recent version then add
// that to the default.
//
// Otherwise, the user HAS requested a default. If this isn't requesting
// 'raw' or 'corrected' (so, e.g., only requesting the latest 'trimmed'
// reads), decide which of 'raw' or 'corrected' is the most recent.

if ((sqRead_defaultVersion == sqRead_normal) ||
(sqRead_defaultVersion == sqRead_unset)) {
sqRead_which mr; // "Most Recent"

// Otherwise, if neither raw or corrected reads were specified, decide
// which one is the most recent. This is for when the user only asks
// for 'trimmed' reads, not caring if they are raw or corrected.
if (sqStore_getNumReads(sqRead_raw) > 0) mr = sqRead_raw;
if (sqStore_getNumReads(sqRead_raw | sqRead_trimmed) > 0) mr = sqRead_raw | sqRead_trimmed;
if (sqStore_getNumReads(sqRead_corrected) > 0) mr = sqRead_corrected;
if (sqStore_getNumReads(sqRead_corrected | sqRead_trimmed) > 0) mr = sqRead_corrected | sqRead_trimmed;

sqRead_defaultVersion |= mr;
}

else if (((sqRead_defaultVersion & sqRead_raw) == sqRead_unset) &&
((sqRead_defaultVersion & sqRead_corrected) == sqRead_unset)) {
if (sqStore_getNumReads(sqRead_corrected) > 0) sqRead_defaultVersion |= sqRead_corrected;
else if (sqStore_getNumReads(sqRead_raw) > 0) sqRead_defaultVersion |= sqRead_raw;
}

// The store itself can now insist that 'compressed' reads be used by default.
// If the store is set to return compressed reads by default and the user
// didn't explicitly say to use uncompressed reads, enable compression.

if (((sqRead_defaultVersion & sqRead_normal) == sqRead_unset) &&
(fileExists(sqStore_path(), '/', "homopolymerCompression") == true)) {
sqRead_defaultVersion &= ~sqRead_normal;
sqRead_defaultVersion |= sqRead_compressed;
}

// Default version MUST be set now.
// The default version MUST be set now:
// - either raw or corrected is set, but not both.
// - at most one of normal or compressed is set (but if neither is set, it's treated as 'normal').

bool validMode = true;

if (sqRead_defaultIsNot(sqRead_raw) &&
sqRead_defaultIsNot(sqRead_corrected)) {
fprintf(stderr, "sqStore_loadMetadata()-- At least one of 'raw' or 'corrected' must be specified.\n");
validMode = false;
}

if (sqRead_defaultIs(sqRead_raw) &&
sqRead_defaultIs(sqRead_corrected)) {
fprintf(stderr, "sqStore_loadMetadata()-- Cannot read both 'raw' and 'corrected' reads at the same time.\n");
validMode = false;
}

if (sqRead_defaultIs(sqRead_normal) &&
sqRead_defaultIs(sqRead_compressed)) {
fprintf(stderr, "sqStore_loadMetadata()-- Cannot read both 'normal' and 'compressed' reads at the same time.\n");
validMode = false;
}

assert(sqRead_defaultVersion != sqRead_unset);
assert(validMode == true);

// We can maybe, eventually, be clever and load these on-demand.
// For now, load all the metadata.
Expand Down

0 comments on commit 7ccc151

Please sign in to comment.