Skip to content

Commit 61aeabf

Browse files
committed
fix #520: put chromosome metadata into provenance also
1 parent 2066ab6 commit 61aeabf

3 files changed

Lines changed: 30 additions & 5 deletions

File tree

VERSIONS

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ Note that not every commit will be logged here; that is what the Github commit h
77

88
development head (in the master branch):
99
add recipe 16.11, life-long monogamous mating
10-
add the ability to suppress the header line of a LogFile, with a new [logical$ header = T] parameter to createLogFile() (#516), and adding [Nl$ header = NULL] for setFilePath()
11-
add [string$ sex = "*"] parameter to initializeRecombinationRateFromFile(), passed through to initializeRecombinationRate(); fixing an oversight
10+
add the ability to suppress the header line of a LogFile, with a new [logical$ header = T] parameter to createLogFile() (#516), and adding [Nl$ header = NULL] for setFilePath() (#516)
11+
add [string$ sex = "*"] parameter to initializeRecombinationRateFromFile(), passed through to initializeRecombinationRate(); fixing an oversight (#524)
12+
write "chromosomes" and "this_chromosome" keys out to provenance as well as metadata (#520)
1213

1314

1415
version 5.0 (Eidos version 4.0):

core/species.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6657,7 +6657,7 @@ void Species::WriteTreeSequenceMetadata(tsk_table_collection_t *p_tables, EidosD
66576657
handle_error("tsk_node_table_set_metadata_schema", ret);
66586658
}
66596659

6660-
void Species::WriteProvenanceTable(tsk_table_collection_t *p_tables, bool p_use_newlines, bool p_include_model)
6660+
void Species::WriteProvenanceTable(tsk_table_collection_t *p_tables, bool p_use_newlines, bool p_include_model, slim_chromosome_index_t p_chromosome_index)
66616661
{
66626662
int ret = 0;
66636663
time_t timer;
@@ -6771,6 +6771,30 @@ void Species::WriteProvenanceTable(tsk_table_collection_t *p_tables, bool p_use_
67716771
j["parameters"]["separate_sexes"] = sex_enabled_ ? true : false;
67726772
j["parameters"]["nucleotide_based"] = nucleotide_based_ ? true : false;
67736773

6774+
j["parameters"]["chromosomes"] = nlohmann::json::array();
6775+
for (Chromosome *chromosome : chromosomes_)
6776+
{
6777+
nlohmann::json chromosome_info;
6778+
6779+
chromosome_info["index"] = chromosome->Index();
6780+
chromosome_info["id"] = chromosome->ID();
6781+
chromosome_info["symbol"] = chromosome->Symbol();
6782+
if (chromosome->Name().length() > 0)
6783+
chromosome_info["name"] = chromosome->Name();
6784+
chromosome_info["type"] = StringForChromosomeType(chromosome->Type());
6785+
6786+
j["parameters"]["chromosomes"].push_back(chromosome_info);
6787+
6788+
if (p_chromosome_index == chromosome->Index()) // true for the chromosome being written
6789+
{
6790+
// write out all the same information again in a key called "this_chromosome"; this way the
6791+
// user can trivially get the info for the chromosome represented by the file; note that a
6792+
// no-genetics model will have a chromosomes key with an empty array, and no this_chromosome,
6793+
// but a no-genetics model can't write a tree sequence anyway, so that is moot.
6794+
j["parameters"]["this_chromosome"] = chromosome_info;
6795+
}
6796+
}
6797+
67746798
if (p_include_model)
67756799
j["parameters"]["model"] = scriptString; // made model optional in file_version 0.4
67766800
j["parameters"]["model_hash"] = scriptHashString; // added model_hash in file_version 0.4
@@ -7451,7 +7475,7 @@ void Species::WriteTreeSequence(std::string &p_recording_tree_path, bool p_simpl
74517475

74527476
// Add a row to the Provenance table to record current state; text format does not allow newlines in the entry,
74537477
// so we don't prettyprint the JSON when going to text, as a quick fix that avoids quoting the newlines etc.
7454-
WriteProvenanceTable(&output_tables, /* p_use_newlines */ true, p_include_model);
7478+
WriteProvenanceTable(&output_tables, /* p_use_newlines */ true, p_include_model, chromosome->Index());
74557479

74567480
// Add top-level metadata and metadata schema
74577481
WriteTreeSequenceMetadata(&output_tables, p_metadata_dict, chromosome->Index());

core/species.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ class Species : public EidosDictionaryUnretained
556556
void AddLiveIndividualsToIndividualsTable(tsk_table_collection_t *p_tables, INDIVIDUALS_HASH *p_individuals_hash);
557557
void FixAliveIndividuals(tsk_table_collection_t *p_tables);
558558
void WritePopulationTable(tsk_table_collection_t *p_tables);
559-
void WriteProvenanceTable(tsk_table_collection_t *p_tables, bool p_use_newlines, bool p_include_model);
559+
void WriteProvenanceTable(tsk_table_collection_t *p_tables, bool p_use_newlines, bool p_include_model, slim_chromosome_index_t p_chromosome_index);
560560
void WriteTreeSequenceMetadata(tsk_table_collection_t *p_tables, EidosDictionaryUnretained *p_metadata_dict, slim_chromosome_index_t p_chromosome_index);
561561
void _MungeIsNullNodeMetadataToIndex0(TreeSeqInfo &p_treeseq, int original_index);
562562
void ReadTreeSequenceMetadata(TreeSeqInfo &p_treeseq, slim_tick_t *p_tick, slim_tick_t *p_cycle, SLiMModelType *p_model_type, int *p_file_version);

0 commit comments

Comments
 (0)