@@ -1191,6 +1191,121 @@ macro_rules! build_table_column_slice_mut_getter {
1191
1191
} ;
1192
1192
}
1193
1193
1194
+ macro_rules! delegate_table_view_api {
1195
+ ( ) => {
1196
+ delegate:: delegate! {
1197
+ to self . views {
1198
+ /// Get reference to the [``EdgeTable``](crate::EdgeTable).
1199
+ pub fn edges( & self ) -> & crate :: EdgeTable ;
1200
+ /// Get reference to the [``IndividualTable``](crate::IndividualTable).
1201
+ pub fn individuals( & self ) -> & crate :: IndividualTable ;
1202
+ /// Get reference to the [``MigrationTable``](crate::MigrationTable).
1203
+ pub fn migrations( & self ) -> & crate :: MigrationTable ;
1204
+ /// Get reference to the [``MutationTable``](crate::MutationTable).
1205
+ pub fn mutations( & self ) -> & crate :: MutationTable ;
1206
+ /// Get reference to the [``NodeTable``](crate::NodeTable).
1207
+ pub fn nodes( & self ) -> & crate :: NodeTable ;
1208
+ /// Get reference to the [``PopulationTable``](crate::PopulationTable).
1209
+ pub fn populations( & self ) -> & crate :: PopulationTable ;
1210
+ /// Get reference to the [``SiteTable``](crate::SiteTable).
1211
+ pub fn sites( & self ) -> & crate :: SiteTable ;
1212
+
1213
+ #[ cfg( feature = "provenance" ) ]
1214
+ #[ cfg_attr( doc_cfg, doc( cfg( feature = "provenance" ) ) ) ]
1215
+ /// Get reference to the [``ProvenanceTable``](crate::provenance::ProvenanceTable)
1216
+ pub fn provenances( & self ) -> & crate :: provenance:: ProvenanceTable ;
1217
+
1218
+ /// Return an iterator over the individuals.
1219
+ pub fn individuals_iter( & self ) -> impl Iterator <Item = crate :: IndividualTableRow > + ' _;
1220
+ /// Return an iterator over the nodes.
1221
+ pub fn nodes_iter( & self ) -> impl Iterator <Item = crate :: NodeTableRow > + ' _;
1222
+ /// Return an iterator over the edges.
1223
+ pub fn edges_iter( & self ) -> impl Iterator <Item = crate :: EdgeTableRow > + ' _;
1224
+ /// Return an iterator over the migrations.
1225
+ pub fn migrations_iter( & self ) -> impl Iterator <Item = crate :: MigrationTableRow > + ' _;
1226
+ /// Return an iterator over the mutations.
1227
+ pub fn mutations_iter( & self ) -> impl Iterator <Item = crate :: MutationTableRow > + ' _;
1228
+ /// Return an iterator over the populations.
1229
+ pub fn populations_iter( & self ) -> impl Iterator <Item = crate :: PopulationTableRow > + ' _;
1230
+ /// Return an iterator over the sites.
1231
+ pub fn sites_iter( & self ) -> impl Iterator <Item = crate :: SiteTableRow > + ' _;
1232
+
1233
+ #[ cfg( feature = "provenance" ) ]
1234
+ #[ cfg_attr( doc_cfg, doc( cfg( feature = "provenance" ) ) ) ]
1235
+ /// Return an iterator over provenances
1236
+ pub fn provenances_iter( & self , ) -> impl Iterator <Item = crate :: provenance:: ProvenanceTableRow > + ' _;
1237
+
1238
+ /// Obtain a vector containing the indexes ("ids")
1239
+ /// of all nodes for which [`crate::TSK_NODE_IS_SAMPLE`]
1240
+ /// is `true`.
1241
+ ///
1242
+ /// The provided implementation dispatches to
1243
+ /// [`crate::NodeTable::samples_as_vector`].
1244
+ pub fn samples_as_vector( & self ) -> Vec <crate :: NodeId >;
1245
+
1246
+ /// Obtain a vector containing the indexes ("ids") of all nodes
1247
+ /// satisfying a certain criterion.
1248
+ ///
1249
+ /// The provided implementation dispatches to
1250
+ /// [`crate::NodeTable::create_node_id_vector`].
1251
+ ///
1252
+ /// # Parameters
1253
+ ///
1254
+ /// * `f`: a function. The function is passed the current table
1255
+ /// collection and each [`crate::node_table::NodeTableRow`].
1256
+ /// If `f` returns `true`, the index of that row is included
1257
+ /// in the return value.
1258
+ ///
1259
+ /// # Examples
1260
+ ///
1261
+ /// Get all nodes with time > 0.0:
1262
+ ///
1263
+ /// ```
1264
+ /// use tskit::bindings::tsk_id_t;
1265
+ ///
1266
+ /// let mut tables = tskit::TableCollection::new(100.).unwrap();
1267
+ /// tables
1268
+ /// .add_node(tskit::TSK_NODE_IS_SAMPLE, 0.0, tskit::PopulationId::NULL,
1269
+ /// tskit::IndividualId::NULL)
1270
+ /// .unwrap();
1271
+ /// tables
1272
+ /// .add_node(tskit::TSK_NODE_IS_SAMPLE, 1.0, tskit::PopulationId::NULL,
1273
+ /// tskit::IndividualId::NULL)
1274
+ /// .unwrap();
1275
+ /// let samples = tables.create_node_id_vector(
1276
+ /// |row: &tskit::NodeTableRow| row.time > 0.,
1277
+ /// );
1278
+ /// assert_eq!(samples[0], 1);
1279
+ ///
1280
+ /// // Get all nodes that have a mutation:
1281
+ ///
1282
+ /// // fn node_has_mutation(
1283
+ /// // // dyn trait here means this
1284
+ /// // // will work with TreeSequence, too.
1285
+ /// // tables_type: &dyn std::ops::Deref<Target=tskit::table_views::TableViews>,
1286
+ /// // row: &tskit::NodeTableRow,
1287
+ /// // ) -> bool {
1288
+ /// // for mrow in tables_type.mutations_iter() {
1289
+ /// // if mrow.node == row.id {
1290
+ /// // return true;
1291
+ /// // }
1292
+ /// // }
1293
+ /// // false
1294
+ /// // }
1295
+ ///
1296
+ /// // // Get all nodes that have a mutation:
1297
+ ///
1298
+ /// // tables.add_mutation(0, 0, tskit::MutationId::NULL, 0.0, None).unwrap();
1299
+ /// // let samples_with_mut = tables.create_node_id_vector(
1300
+ /// // |row: &tskit::NodeTableRow| node_has_mutation(&tables, row));
1301
+ /// // assert_eq!(samples_with_mut[0], 0);
1302
+ /// ```
1303
+ pub fn create_node_id_vector( & self , f: impl FnMut ( & crate :: NodeTableRow ) -> bool ) -> Vec <crate :: NodeId >;
1304
+ }
1305
+ }
1306
+ } ;
1307
+ }
1308
+
1194
1309
#[ cfg( test) ]
1195
1310
mod test {
1196
1311
use crate :: error:: TskitError ;
0 commit comments