<commit_before>/*
  Usage: seq_sample N IN.fastq OUT.fastq

  Samples N reads from IN.fastq and writes them to OUT.fastq without
  duplicates.
 */

#include <fstream>
#include <iostream>
#include <set>

#include <seqan/basic.h>
#include <seqan/file.h>
#include <seqan/misc/misc_random.h>
#include <seqan/sequence.h>
#include <seqan/store.h>

using namespace seqan;

template < 
	typename TStream, 
	typename TSeq >
void dumpWrapped(
	TStream &out,
	TSeq &seq)
{
	unsigned size = length(seq);
	unsigned i;
	for (i = 0; i + 60 < size; i += 60)
		out << infix(seq, i, i + 60) << std::endl;
	out << infix(seq, i, size) << std::endl;
}


template <typename TStream, typename TStringSetSpec, typename TStringSetSpec2>
void write(TStream & stream,
           StringSet<String<Dna5Q>, TStringSetSpec> const & sequences,
           StringSet<CharString, TStringSetSpec2> const & seqIds,
           Fastq const &) {
    typedef StringSet<String<Dna5Q>, TStringSetSpec> TStringSet;
    typedef typename Position<TStringSet>::Type TPosition;

    CharString qualBuffer;
    for (TPosition i = 0; i < length(sequences); ++i) {
        stream << "@" << seqIds[i] << std::endl;
        dumpWrapped(stream, sequences[i]);
        stream << "+" << seqIds[i] << std::endl;
        resize(qualBuffer, length(sequences[i]), Exact());
        for (TPosition j = 0; j < length(sequences[i]); ++j) {
            qualBuffer[j] = getQualityValue(sequences[i][j]) + '!';
        }
        dumpWrapped(stream, qualBuffer);
    }
}


int main(int argc, char **argv) {
    if (argc != 4) {
        std::cerr << "ERROR: Wrong number of parameters!" << std::endl;
        std::cerr << "USAGE: seq_sample N IN.fastq OUT.fastq" << std::endl;
        return 1;
    }

    // TODO(holtgrew): Actually, we want to seed this!
//     const unsigned SEED = 42;
    mtRandInit();

    unsigned n = atoi(argv[1]);

    // Load reads using the fragment store.
    FragmentStore<> fragStore;
    if (!loadReads(fragStore, argv[2])) return 1;

    // The factor 10 is arbitrarily chosen to make sure the generation
    // is sufficiently fast.
    if (length(fragStore.readSeqStore) < 10 * n) {
        std::cerr << "Number of reads in file should be >= 10*n" << std::endl;
        return 1;
    }
<commit_msg>seq_sample does not wrap FASTQ any more<commit_after>/*
  Usage: seq_sample N IN.fastq OUT.fastq

  Samples N reads from IN.fastq and writes them to OUT.fastq without
  duplicates.
 */

#include <fstream>
#include <iostream>
#include <set>

#include <seqan/basic.h>
#include <seqan/file.h>
#include <seqan/misc/misc_random.h>
#include <seqan/sequence.h>
#include <seqan/store.h>

using namespace seqan;

template < 
	typename TStream, 
	typename TSeq >
void dumpWrapped(
	TStream &out,
	TSeq &seq)
{
	unsigned size = length(seq);
	unsigned i;
	for (i = 0; i + 60 < size; i += 60)
		out << infix(seq, i, i + 60) << std::endl;
	out << infix(seq, i, size) << std::endl;
}


template <typename TStream, typename TStringSetSpec, typename TStringSetSpec2>
void write(TStream & stream,
           StringSet<String<Dna5Q>, TStringSetSpec> const & sequences,
           StringSet<CharString, TStringSetSpec2> const & seqIds,
           Fastq const &) {
    typedef StringSet<String<Dna5Q>, TStringSetSpec> TStringSet;
    typedef typename Position<TStringSet>::Type TPosition;

    CharString qualBuffer;
    for (TPosition i = 0; i < length(sequences); ++i) {
        stream << "@" << seqIds[i] << std::endl;
        stream << sequences[i] << std::endl;
        stream << "+" << seqIds[i] << std::endl;
        resize(qualBuffer, length(sequences[i]), Exact());
        for (TPosition j = 0; j < length(sequences[i]); ++j) {
            qualBuffer[j] = getQualityValue(sequences[i][j]) + '!';
        }
        stream << qualBuffer << std::endl;
    }
}


int main(int argc, char **argv) {
    if (argc != 4) {
        std::cerr << "ERROR: Wrong number of parameters!" << std::endl;
        std::cerr << "USAGE: seq_sample N IN.fastq OUT.fastq" << std::endl;
        return 1;
    }

    // TODO(holtgrew): Actually, we want to seed this!
//     const unsigned SEED = 42;
    mtRandInit();

    unsigned n = atoi(argv[1]);

    // Load reads using the fragment store.
    FragmentStore<> fragStore;
    if (!loadReads(fragStore, argv[2])) return 1;

    // The factor 10 is arbitrarily chosen to make sure the generation
    // is sufficiently fast.
    if (length(fragStore.readSeqStore) < 10 * n) {
        std::cerr << "Number of reads in file should be >= 10*n" << std::endl;
        return 1;
    }

{'fraction_non_alphanumeric': 0.1433581762384919, 'fraction_numerical': 0.01183691363437089, 'mean_word_length': 3.0704727921498662, 'pattern_counts': {'":': 0, '<': 117, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '675310', 'n_tokens_mistral': 1610, 'n_tokens_neox': 1515, 'n_words': 434}