Skip to content

[Feature Request] RNTupleToSAM converter #40

Description

@neo-0007

Adding a converter from RNtuple based RAM files to SAM files would be beneficial for the project. Since the project is in it's early stage we should keep it backward compatible with the standard SAM format. This would allow us to convert back our root files to sam files for analysis and comparison with samtools and others.

A incomplete implementation is already present that is not being used now :

void RAMNTupleConverter::ConvertRAMNTupleToSAM(const std::string &ram_file, const std::string &sam_file)
{
auto reader = RAMNTupleRecord::OpenRAMFile(ram_file);
if (!reader) {
::Error("ConvertRAMNTupleToSAM", "Cannot open RAM file: %s", ram_file.c_str());
return;
}
std::ofstream sam(sam_file);
if (!sam) {
::Error("ConvertRAMNTupleToSAM", "Cannot create SAM file: %s", sam_file.c_str());
return;
}
sam << "@HD\tVN:1.6\tSO:unsorted\n";
auto refs = RAMNTupleRecord::GetRnameRefs();
if (refs) {
for (size_t i = 0; i < refs->Size(); ++i) {
sam << "@SQ\tSN:" << refs->GetRefName(i) << "\tLN:1\n";
}
}
auto view = reader->GetView<RAMNTupleRecord>("record");
for (auto i : reader->GetEntryRange()) {
const auto &rec = view(i);
rec.Print();
}
std::cout << "Conversion complete. Wrote " << reader->GetNEntries() << " records to SAM file." << std::endl;
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions