static rc_t bam_header(const VDatabase* db) { rc_t rc = 0; const char path[] = "BAM_HEADER"; const KMetadata* meta = NULL; const KMDataNode* node = NULL; char* buffer = NULL; assert(db); if (rc == 0) { rc = VDatabaseOpenMetadataRead(db, &meta); DISP_RC(rc, "while calling VDatabaseOpenMetadataRead"); } if (rc == 0) { rc = KMetadataOpenNodeRead(meta, &node, "%s", path); if (GetRCState(rc) == rcNotFound) { rc = 0; } else { DISP_RC2(rc, path, "while calling KMetadataOpenNodeRead"); if (rc == 0) { int i = 0; size_t bsize = 0; size_t size = 1024; for (i = 0; i < 2; ++i) { free(buffer); bsize = size + 1; buffer = malloc(bsize); if (buffer == NULL) { rc = RC(rcExe, rcStorage, rcAllocating, rcMemory, rcExhausted); } else { rc = KMDataNodeReadCString(node, buffer, bsize, &size); if (rc == 0) { break; } else if (i == 0 && GetRCObject(rc) == (enum RCObject)rcBuffer && GetRCState (rc) == rcInsufficient) { rc = 0; } } DISP_RC2(rc, path, "while calling KMDataNodeReadCString"); } } } } if (rc == 0 && buffer) { OUTMSG(("BAM_HEADER: {\n%s}\n\n", buffer)); } DESTRUCT(KMDataNode, node); DESTRUCT(KMetadata, meta); free(buffer); return rc; }
static rc_t align_info(const Params* prm) { rc_t rc = 0; const VDatabase* db = NULL; const VDBManager* mgr = NULL; const KDBManager *kmgr = NULL; VSchema* schema = NULL; bool is_db = false; if (prm == NULL) { return RC(rcExe, rcQuery, rcExecuting, rcParam, rcNull); } if (rc == 0) { rc = VDBManagerMakeRead(&mgr, NULL); DISP_RC(rc, "while calling VDBManagerMakeRead"); } if (rc == 0) { rc = VDBManagerOpenKDBManagerRead(mgr, &kmgr); DISP_RC(rc, "while calling VDBManagerOpenKDBManagerRead"); } if (rc == 0) { rc = VDBManagerMakeSRASchema(mgr, &schema); DISP_RC(rc, "while calling VDBManagerMakeSRASchema"); } if (rc == 0) { /* const char path[] = "/panfs/pan1/trace_work/scratch/XXX000013"; */ rc = VDBManagerOpenDBRead(mgr, &db, schema, prm->dbPath); if (rc == 0) { is_db = true; } else if (rc == SILENT_RC(rcDB, rcMgr, rcOpening, rcDatabase, rcIncorrect)) { PLOGMSG(klogWarn, (klogWarn, "'$(path)' is not a database", "path=%s", prm->dbPath)); rc = 0; } else { PLOGERR(klogErr, (klogErr, rc, "$(path)", "path=%s", prm->dbPath)); } } if (is_db) { if (rc == 0) { if (prm->paramRef) { const VDBDependencies* dep = NULL; uint32_t count = 0; int i = 0; rc = VDatabaseListDependencies(db, &dep, false); DISP_RC2(rc, prm->dbPath, "while calling VDatabaseListDependencies"); if (rc == 0) { rc = VDBDependenciesCount(dep, &count); DISP_RC2(rc, prm->dbPath, "while calling VDBDependenciesCount"); } for (i = 0; i < count && rc == 0; ++i) { bool circular = false; const char* name = NULL; const char* path = NULL; const char* remote = NULL; bool local = false; const char* seqId = NULL; rc = VDBDependenciesCircular(dep, &circular, i); if (rc != 0) { DISP_RC2(rc, prm->dbPath, "while calling VDBDependenciesCircular"); break; } rc = VDBDependenciesName(dep, &name, i); if (rc != 0) { DISP_RC2(rc, prm->dbPath, "while calling VDBDependenciesName"); break; } rc = VDBDependenciesPath(dep, &path, i); if (rc != 0) { DISP_RC2(rc, prm->dbPath, "while calling VDBDependenciesPath"); break; } rc = VDBDependenciesLocal(dep, &local, i); if (rc != 0) { DISP_RC2(rc, prm->dbPath, "while calling VDBDependenciesLocal"); break; } rc = VDBDependenciesSeqId(dep, &seqId, i); if (rc != 0) { DISP_RC2(rc, prm->dbPath, "while calling VDBDependenciesSeqId"); break; } rc = VDBDependenciesPathRemote(dep, &remote, i); if (rc != 0) { DISP_RC2(rc, prm->dbPath, "while calling VDBDependenciesRemote"); break; } OUTMSG(("%s,%s,%s,%s", seqId, name, (circular ? "true" : "false"), (local ? "local" : "remote"))); if (path && path[0]) { OUTMSG((":%s", path)); } else if (remote && remote[0]) { OUTMSG(("::%s", remote)); } OUTMSG(("\n")); } DESTRUCT(VDBDependencies, dep); } if (prm->paramBamHeader) { rc_t rc3 = bam_header(db); if (rc3 != 0 && rc == 0) { rc = rc3; } } if (prm->paramQuality) { rc_t rc3 = qual_stats(prm, db); if (rc3 != 0 && rc == 0) { rc = rc3; } } } } DESTRUCT(VSchema, schema); DESTRUCT(KDBManager, kmgr); DESTRUCT(VDBManager, mgr); DESTRUCT(VDatabase, db); return rc; }
static rc_t qual_stats(const Params* prm, const VDatabase* db) { rc_t rc = 0; const char tblName[] = "SEQUENCE"; const VTable* tbl = NULL; const KMetadata* meta = NULL; const KMDataNode* node = NULL; assert(prm && db); if (rc == 0) { rc = VDatabaseOpenTableRead(db, &tbl, tblName); DISP_RC2(rc, tblName, "while calling VDatabaseOpenTableRead"); } if (rc == 0) { rc = VTableOpenMetadataRead(tbl, &meta); DISP_RC2(rc, tblName, "while calling VTableOpenMetadataRead"); } if (rc == 0) { bool found = false; const char path[] = "STATS/QUALITY"; rc = KMetadataOpenNodeRead(meta, &node, path); if (rc == 0) { found = true; } else if (GetRCState(rc) == rcNotFound) { rc = 0; } DISP_RC2(rc, path, "while calling KMetadataOpenNodeRead"); if (found) { uint32_t i = 0; int nbr = 0; uint32_t count = 0; KNamelist* names = NULL; int* quals = NULL; if (rc == 0) { rc = KMDataNodeListChild(node, &names); DISP_RC2(rc, path, "while calling KMDataNodeListChild"); } if (rc == 0) { rc = KNamelistCount(names, &count); DISP_RC2(rc, path, "while calling KNamelistCount"); if (rc == 0 && count > 0) { quals = calloc(count, sizeof *quals); if (quals == NULL) { rc = RC(rcExe, rcStorage, rcAllocating, rcMemory, rcExhausted); } } } for (i = 0; i < count && rc == 0; ++i) { /* uint64_t u = 0; const KMDataNode* n = NULL; */ const char* nodeName = NULL; const char* name = NULL; rc = KNamelistGet(names, i, &nodeName); DISP_RC2(rc, path, "while calling KNamelistGet"); if (rc) { break; } name = nodeName; /* rc = KMDataNodeOpenNodeRead(node, &n, name); DISP_RC(rc, name); if (rc == 0) { rc = KMDataNodeReadAsU64(n, &u); DISP_RC(rc, name); } */ if (rc == 0) { char* c = strchr(name, '_'); if (c != NULL && *(c + 1) != '\0') { name = c + 1; if (sscanf(name, "%d", &quals[i]) != 1) { rc = RC(rcExe, rcNode, rcParsing, rcName, rcUnexpected); PLOGERR(klogInt, (klogInt, rc, "$(name)", "name=%s", nodeName)); } } /* OUTMSG(("QUALITY %s %lu\n", name, u)); */ } /* DESTRUCT(KMDataNode, n); */ } if (rc == 0 && count > 0) { ksort(quals, count, sizeof *quals, sort_callback, NULL); } if (rc == 0) { OUTMSG(("%s", prm->dbPath)); } for (i = 0, nbr = 0; i < count && rc == 0; ++i, ++nbr) { uint64_t u = 0; char name[64]; const KMDataNode* n = NULL; sprintf(name, "PHRED_%d", quals[i]); rc = KMDataNodeOpenNodeRead(node, &n, name); DISP_RC(rc, name); if (rc == 0) { rc = KMDataNodeReadAsU64(n, &u); DISP_RC(rc, name); if (rc == 0) { while (nbr < quals[i]) { OUTMSG(("\t0")); ++nbr; } OUTMSG(("\t%lu", u)); /* OUTMSG(("QUALITY %d %lu\n", quals[i], u)); */ } } DESTRUCT(KMDataNode, n); } while (rc == 0 && nbr <= 40) { OUTMSG(("\t0")); nbr++; } if (rc == 0) { OUTMSG(("\n")); } DESTRUCT(KNamelist, names); } } DESTRUCT(KMDataNode, node); DESTRUCT(KMetadata, meta); DESTRUCT(VTable, tbl); return rc; }