static rc_t get_tbl_schema_info(VTable const *const tbl, unsigned const bsz, char buffer[]) { KMetadata const *meta; rc_t rc = VTableOpenMetadataRead(tbl, &meta); buffer[0] = '\0'; if (rc == 0) rc = get_schema_info(meta, bsz, buffer); KMetadataRelease(meta); return rc; }
rc_t copy_table_meta ( const VTable *src_table, VTable *dst_table, const char * excluded_nodes, const bool show_meta, const bool schema_updated ) { const KMetadata *src_meta; rc_t rc; if ( src_table == NULL || dst_table == NULL ) return RC( rcExe, rcNoTarg, rcCopying, rcParam, rcNull ); /* it is OK if excluded_nodes is NULL */ rc = VTableOpenMetadataRead ( src_table, & src_meta ); DISP_RC( rc, "copy_table_meta:VTableOpenMetadataRead() failed" ); if ( rc == 0 ) { rc = copy_back_revisions ( src_meta, dst_table, show_meta ); if ( rc == 0 ) { KMetadata *dst_meta; rc = VTableOpenMetadataUpdate ( dst_table, & dst_meta ); DISP_RC( rc, "copy_table_meta:VTableOpenMetadataUpdate() failed" ); if ( rc == 0 ) { if ( show_meta ) KOutMsg( "+++copy current metadata\n" ); rc = copy_stray_metadata ( src_meta, dst_meta, excluded_nodes, show_meta ); if ( show_meta ) KOutMsg( "+++end of copy current metadata\n" ); /* enter a attribute "vdb-copy" under '/SOFTWARE/update' *if the schema was updated ! */ if ( rc == 0 && schema_updated ) rc = enter_schema_update( dst_meta, show_meta ); /* enter a unconditional node under '/SOFTWARE/Copy' <%TIMESTAMP%> <Application date="%DATE%" name="vdb-copy" vers="%VERSION%"/> </%TIMESTAMP%> */ if ( rc == 0 ) rc = enter_vdbcopy_node( dst_meta, show_meta ); KMetadataRelease ( dst_meta ); } } KMetadataRelease ( src_meta ); } return rc; }
rc_t AlignRefTableCursor(const VTable* table, const VCursor *native_curs, const VCursor** ref_cursor,const VTable **reftbl) { rc_t rc = 0; char ref_tbl_name[512] = "REFERENCE"; const KMetadata* meta; const VCursor *curs; if( (rc = VTableOpenMetadataRead(table, &meta)) == 0 ) { const KMDataNode* node; if( (rc = KMetadataOpenNodeRead(meta, &node, "CONFIG/REF_TABLE")) == 0 ) { size_t sz; rc = KMDataNodeReadCString(node, ref_tbl_name, sizeof(ref_tbl_name), &sz); ref_tbl_name[sz] = '\0'; KMDataNodeRelease(node); } KMetadataRelease(meta); } rc = VCursorLinkedCursorGet(native_curs,ref_tbl_name,&curs); if(rc != 0){ const VDatabase *db; const VTable *tbl; /* get at the parent database */ rc = VTableOpenParentRead ( table, & db ); if(rc != 0) return rc; /* open the table */ rc = VDatabaseOpenTableRead ( db, &tbl, ref_tbl_name); VDatabaseRelease ( db ); if(rc != 0) return rc; /* create a cursor */ rc = VTableCreateCachedCursorRead(tbl, &curs,256*1024*1024); if(reftbl){ *reftbl = tbl; } else { VTableRelease(tbl); } if(rc != 0) return rc; rc = VCursorPermitPostOpenAdd( curs ); if(rc != 0) return rc; rc = VCursorOpen( curs ); if(rc != 0) return rc; if(native_curs){ rc = VCursorLinkedCursorSet(native_curs,ref_tbl_name,curs); } if(rc != 0) return rc; } else { VCursorAddRef(curs); } *ref_cursor = curs; return 0; }
static rc_t extract_spotgroups( VNamelist * spotgroups, input_files * ifs, bool from_stats ) { rc_t rc = 0; uint32_t i; for ( i = 0; i < ifs->database_count && rc == 0; ++i ) { input_database * id = VectorGet( &ifs->dbs, i ); if ( id != NULL ) { if ( from_stats ) { const VTable * tab; rc = VDatabaseOpenTableRead( id->db, &tab, "SEQUENCE" ); if ( rc != 0 ) (void)PLOGERR( klogErr, ( klogErr, rc, "cannot open table SEQUENCE in '$(t)'", "t=%s", id->path ) ); else { const KMetadata * meta; rc = VTableOpenMetadataRead( tab, &meta ); if ( rc != 0 ) (void)PLOGERR( klogErr, ( klogErr, rc, "cannot open metadata from '$(t)'", "t=%s", id->path ) ); else { if ( from_stats ) rc = extract_spotgroups_from_stats( spotgroups, id, meta ); KMetadataRelease( meta ); } VTableRelease( tab ); } } else { const KMetadata * meta; rc = VDatabaseOpenMetadataRead( id->db, &meta ); /* do not report if metadata cannot be found, because this would produce an error message when a database has no metadata at all */ if ( rc == 0 ) { rc = extract_spotgroups_from_bam_hdr( spotgroups, id, meta ); KMetadataRelease( meta ); } } } } return rc; }
static rc_t vdb_info_tab( vdb_info_data * data, VSchema * schema, const VDBManager *mgr ) { const VTable * tab; rc_t rc = VDBManagerOpenTableRead( mgr, &tab, schema, "%s", data->acc ); if ( rc == 0 ) { const KMetadata * meta = NULL; data->s_platform = get_platform( tab ); data->seq_rows = get_rowcount( tab ); rc = VTableOpenMetadataRead ( tab, &meta ); if ( rc == 0 ) { get_meta_info( data, meta ); KMetadataRelease ( meta ); } VTableRelease( tab ); } return rc; }
static int AccessionType(VDBManager const *const mgr, unsigned const N, char const accession[], rc_t *const rc) { char scheme[1024]; bool isOdd = false; scheme[0] = '\0'; { KMetadata const *meta = NULL; { VDatabase const *db = NULL; *rc = VDBManagerOpenDBRead(mgr, &db, NULL, "%.*s", (int)N, accession); if (db) { *rc = VDatabaseOpenMetadataRead(db, &meta); VDatabaseRelease(db); } else { VTable const *tbl = NULL; *rc = VDBManagerOpenTableRead(mgr, &tbl, NULL, "%.*s", (int)N, accession); if (tbl) { *rc = VTableOpenMetadataRead(tbl, &meta); VTableRelease(tbl); } else { isOdd = true; *rc = VDBManagerOpenTableRead(mgr, &tbl, NULL, "ncbi-acc:%.*s?vdb-ctx=refseq", (int)N, accession); if (tbl) { *rc = VTableOpenMetadataRead(tbl, &meta); VTableRelease(tbl); } } } } if (meta) { KMDataNode const *node = NULL; *rc = KMetadataOpenNodeRead(meta, &node, "schema"); KMetadataRelease(meta); if (node) { size_t sz = 0; *rc = KMDataNodeReadAttr(node, "name", scheme, sizeof(scheme) - 1, &sz); KMDataNodeRelease(node); scheme[sz] = '\0'; while (sz) { --sz; if (scheme[sz] == '#') { scheme[sz] = '\0'; break; } } } } } if (strcmp(scheme, "NCBI:WGS:db:contig") == 0) return refSeqType_WGS; if (strcmp(scheme, "NCBI:refseq:tbl:reference") == 0) return isOdd ? refSeqType_RefSeq_odd : refSeqType_RefSeq; return 0; }
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; }
/* OpenRead * open an existing table * * "tbl" [ OUT ] - return parameter for table * * "spec" [ IN ] - NUL terminated UTF-8 string giving path * to table. */ static rc_t CC SRAMgrVOpenAltTableRead ( const SRAMgr *self, const SRATable **rslt, const char *altname, const char *spec, va_list args ) { rc_t rc; if ( rslt == NULL ) rc = RC ( rcSRA, rcTable, rcOpening, rcParam, rcNull ); else { if ( self == NULL ) rc = RC ( rcSRA, rcMgr, rcAccessing, rcSelf, rcNull ); else if ( spec == NULL ) rc = RC ( rcSRA, rcTable, rcOpening, rcName, rcNull ); else if ( spec [ 0 ] == 0 ) rc = RC ( rcSRA, rcTable, rcOpening, rcName, rcEmpty ); else { char path [ 4096 ]; rc = ResolveTablePath ( self, path, sizeof path, spec, args ); if ( rc == 0 ) { SRATable *tbl = calloc ( 1, sizeof *tbl ); if ( tbl == NULL ) rc = RC ( rcSRA, rcTable, rcConstructing, rcMemory, rcExhausted ); else { VSchema *schema = NULL; rc = VDBManagerMakeSRASchema(self -> vmgr, & schema); if ( rc == 0 ) { rc = VDBManagerOpenTableRead ( self -> vmgr, & tbl -> vtbl, schema, path ); if ( rc != 0 && GetRCObject ( rc ) == rcTable && GetRCState ( rc ) == rcIncorrect ) { const VDatabase *db; rc_t rc2 = VDBManagerOpenDBRead ( self -> vmgr, & db, schema, path ); if ( rc2 == 0 ) { rc2 = VDatabaseOpenTableRead ( db, & tbl -> vtbl, altname ); if ( rc2 == 0 ) rc = 0; VDatabaseRelease ( db ); } } VSchemaRelease(schema); if ( rc == 0 ) { rc = VTableOpenMetadataRead ( tbl -> vtbl, & tbl -> meta ); if ( rc == 0 ) { rc = KMetadataVersion ( tbl -> meta, & tbl -> metavers ); if ( rc == 0 ) { rc = VTableCreateCursorRead ( tbl -> vtbl, & tbl -> curs ); if ( rc == 0 ) { tbl -> mgr = SRAMgrAttach ( self ); tbl -> mode = self -> mode; tbl -> read_only = true; KRefcountInit ( & tbl -> refcount, 1, "SRATable", "OpenTableRead", path ); rc = SRATableFillOut ( tbl, false ); if ( rc == 0 ) { * rslt = tbl; return 0; } } } } } } SRATableWhack ( tbl ); } } } * rslt = NULL; } return rc; }