| 1007 | |
| 1008 | |
| 1009 | void OMSFileLoad::loadConsensusFeatures_(ConsensusMap& consensus) |
| 1010 | { |
| 1011 | if (!db_->tableExists("FEAT_FeatureHandle")) return; |
| 1012 | |
| 1013 | // start with top-level features only: |
| 1014 | SQLite::Statement query_feat(*db_, "SELECT * FROM FEAT_BaseFeature LEFT JOIN FEAT_FeatureHandle ON id = feature_id ORDER BY id ASC"); |
| 1015 | // prepare sub-queries (optional - corresponding tables may not be present): |
| 1016 | SQLite::Statement query_meta(*db_, ""); |
| 1017 | SQLite::Statement query_match(*db_, ""); |
| 1018 | prepareQueriesBaseFeature_(query_meta, query_match); |
| 1019 | SQLite::Statement query_ratio(*db_, ""); |
| 1020 | if (db_->tableExists("FEAT_ConsensusRatio")) |
| 1021 | { |
| 1022 | query_ratio = SQLite::Statement(*db_, "SELECT * FROM FEAT_ConsensusRatio WHERE feature_id = :id " \ |
| 1023 | "ORDER BY ratio_index DESC"); |
| 1024 | } |
| 1025 | |
| 1026 | while (query_feat.executeStep()) |
| 1027 | { |
| 1028 | if (query_feat.getColumn("subordinate_of").isNull()) // ConsensusFeature |
| 1029 | { |
| 1030 | int id = query_feat.getColumn("id").getInt(); |
| 1031 | ConsensusFeature feature(makeBaseFeature_(id, query_feat, query_meta, query_match)); |
| 1032 | consensus.push_back(feature); |
| 1033 | if (!isEmpty_(query_ratio)) |
| 1034 | { |
| 1035 | query_ratio.bind(":id", id); |
| 1036 | while (query_ratio.executeStep()) |
| 1037 | { |
| 1038 | Size ratio_index = query_ratio.getColumn("ratio_index").getUInt(); |
| 1039 | // first row should have max. hull index (sorted descending): |
| 1040 | if (feature.getRatios().size() <= ratio_index) |
| 1041 | { |
| 1042 | feature.getRatios().resize(ratio_index + 1); |
| 1043 | } |
| 1044 | ConsensusFeature::Ratio& ratio = feature.getRatios()[ratio_index]; |
| 1045 | ratio.ratio_value_ = query_ratio.getColumn("ratio_value").getDouble(); |
| 1046 | ratio.denominator_ref_ = query_ratio.getColumn("denominator_ref").getString(); |
| 1047 | ratio.numerator_ref_ = query_ratio.getColumn("numerator_ref").getString(); |
| 1048 | ratio.description_ = ListUtils::create<String>(query_ratio.getColumn("description").getString()); |
| 1049 | } |
| 1050 | query_ratio.reset(); // get ready for new executeStep() |
| 1051 | } |
| 1052 | } |
| 1053 | else // FeatureHandle |
| 1054 | { |
| 1055 | BaseFeature feature(makeBaseFeature_(-1, query_feat, query_meta, query_match)); |
| 1056 | UInt64 map_index = query_feat.getColumn("map_index").getInt64(); |
| 1057 | FeatureHandle handle(map_index, feature); |
| 1058 | consensus.back().insert(handle); |
| 1059 | } |
| 1060 | } |
| 1061 | } |
| 1062 | |
| 1063 | |
| 1064 | void OMSFileLoad::loadConsensusColumnHeaders_(ConsensusMap& consensus) |