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; |
|
} |
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 :
ramtools/src/rntuple/RAMNTupleRecord.cxx
Lines 616 to 647 in e7a295d