BUStools / bustools

Tools for working with BUS files
https://bustools.github.io/
BSD 2-Clause "Simplified" License
92 stars 23 forks source link

Project->Text did not work on Windows - easy fix #51

Open johan-gson opened 4 years ago

johan-gson commented 4 years ago

I experienced that project -> text didn't work as expected, I got a text file of 47 GB, containing mainly long strings like AAAATTTEEEAA...

I had a similar bug when I was writing some code in BUSTools, and the problem then was that I had opened my out file in text mode, not binary. What happens in Windows then is that \n is replaced by \r\n, which inserts an extra byte. This happens in the header for 10x data, since one of the lengths (I think it is the UMI) happens to have the value '\n', leading to a huge umi length. When looking at the code for project, I see the following lines (around line 250):

std::streambuf *buf = nullptr;
if (!opt.stream_out) {
  of.open(opt.output); 
  buf = of.rdbuf();
} else {
  buf = std::cout.rdbuf();
}
std::ostream o(buf);

The bug would most likely be fixed by changing one of these lines from of.open(opt.output); to of.open(opt.output, std::ios::binary);

This is the code in the devel branch. I am not able to build on Windows, not sure how to do it, so I cannot verify the fix.