8000 Add records to existing fastq file · Issue #3364 · seqan/seqan3 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add records to existing fastq file #3364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
PawelWojciechowski opened this issue May 19, 2025 · 4 comments
Closed

Add records to existing fastq file #3364

PawelWojciechowski opened this issue May 19, 2025 · 4 comments
Labels
question a user question how to do certain things

Comments

@PawelWojciechowski
Copy link

Platform

  • SeqAn version: 3.4
  • Operating system: n/a
  • Compiler: n/a

Question

Is it possible to open a .fastq file for writing in append mode? I want to split one large file into smaller ones without having to load the entire large file at once.
Thank you!

@PawelWojciechowski PawelWojciechowski added the question a user question how to do certain things label May 19, 2025
@SGSSGene
Copy link
Contributor

Hi @PawelWojciechowski
Yes, appending to a file is possible.

Checkout the example https://docs.seqan.de/seqan3/main_user/cookbook.html#autotoc_md74
In that example an already "opened" file is being used:

    seqan3::sequence_file_output fout{std::cout, seqan3::format_fasta{}};

For your case, you have to use a std::fstream that is opened in write and append mode. So something like this:

    std::fstream fs{"my_file.fastq", std::ios_base::binary | std::ios_base::out};
    seqan3::sequence_file_output fout{fs, seqan3::format_fastq{}};

Writing should work just as in the linked example above.

@PawelWojciechowski
Copy link
Author

Hi @SGSSGene
Thank you. It works after adding append mode:

std::fstream fs{"my_file.fastq.gz", std::ios_base::binary | std::ios_base::out | std::fstream::app};

But the final file is not gziped. How to do it?

@SGSSGene
Copy link
Contributor

Hi @PawelWojciechowski
Yes of course std::ios_base::app not std::ios_base::binary....

To achieve compression, you need an extra stream layer that does the compression. Notice that the compression layer must exists longer than the seqan3::sequence_file_output.

    std::fstream fs{"my_file.fastq", std::ios_base::app | std::ios_base::out};
    seqan3::contrib::gz_ostream cfs{fs};
    seqan3::sequence_file_output fout{cfs, seqan3::format_fastq{}};

(I believe seqan3::contrib::gz_ostream is technical not public API, so API might change in the future, but currently I do not see that happening ;-) )

@PawelWojciechowski
Copy link
Author

Hi @SGSSGene,
It works perfectly. Thank you again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question a user question how to do certain things
Projects
None yet
Development

No branches or pull requests

2 participants
0