<commit_before>//(c) 2016 by Authors
//This file is a part of ABruijn program.
//Released under the BSD license (see LICENSE file)

#include <stdexcept>
#include <fstream>
#include <sstream>
#include <iostream>

#include "sequence_container.h"

size_t SequenceContainer::g_nextSeqId = 0;

namespace
{
	class ParseException : public std::runtime_error 
	{
	public:
		ParseException(const std::string & what):
			std::runtime_error(what)
		{}
	};

	char complementSymbol(char c)
	{
		switch (c)
		{
			case 'A': return 'T';
			case 'C': return 'G';
			case 'G': return 'C';
			case 'T': return 'A';
			case 'a': return 't';
			case 'c': return 'g';
			case 'g': return 'c';
			case 't': return 'a';
			default: return c;
		}
	}

	void reverseComplement(const FastaRecord::DnaRepr& dnaIn, 
						   FastaRecord::DnaRepr& dnaOut)
	{
		//std::string buffer;
		//buffer.reserve(dnaIn.length());
		for (size_t i = dnaIn.length(); i > 0; --i)
		{
			dnaOut.push_back(complementSymbol(dnaIn.at(i - 1)));
		}
	}
}

const FastaRecord::Id FastaRecord::ID_NONE = 
			Id(std::numeric_limits<uint32_t>::max());


void SequenceContainer::readFasta(const std::string& fileName)
{
	std::vector<FastaRecord> records;
	this->getSequencesWithComplements(records, fileName);
	_seqIndex.reserve(records.size());
	for (auto& rec : records)
	{
		_seqIndex[rec.id] = std::move(rec);
	}
}


const FastaRecord& 
	SequenceContainer::addSequence(const FastaRecord::DnaRepr& sequence, 
								   const std::string& description)
{
	FastaRecord::Id newId = FastaRecord::Id(g_nextSeqId);
	FastaRecord fwdRecord(sequence, "+" + description, newId);
	_seqIndex[fwdRecord.id] = std::move(fwdRecord);

	FastaRecord::DnaRepr revComplement;<commit_msg>shuffling input reads<commit_after>//(c) 2016 by Authors
//This file is a part of ABruijn program.
//Released under the BSD license (see LICENSE file)

#include <stdexcept>
#include <fstream>
#include <sstream>
#include <iostream>
#include <random>
#include <algorithm>

#include "sequence_container.h"

size_t SequenceContainer::g_nextSeqId = 0;

namespace
{
	class ParseException : public std::runtime_error 
	{
	public:
		ParseException(const std::string & what):
			std::runtime_error(what)
		{}
	};

	char complementSymbol(char c)
	{
		switch (c)
		{
			case 'A': return 'T';
			case 'C': return 'G';
			case 'G': return 'C';
			case 'T': return 'A';
			case 'a': return 't';
			case 'c': return 'g';
			case 'g': return 'c';
			case 't': return 'a';
			default: return c;
		}
	}

	void reverseComplement(const FastaRecord::DnaRepr& dnaIn, 
						   FastaRecord::DnaRepr& dnaOut)
	{
		//std::string buffer;
		//buffer.reserve(dnaIn.length());
		for (size_t i = dnaIn.length(); i > 0; --i)
		{
			dnaOut.push_back(complementSymbol(dnaIn.at(i - 1)));
		}
	}
}

const FastaRecord::Id FastaRecord::ID_NONE = 
			Id(std::numeric_limits<uint32_t>::max());


void SequenceContainer::readFasta(const std::string& fileName)
{
	std::vector<FastaRecord> records;
	this->getSequencesWithComplements(records, fileName);
	_seqIndex.reserve(records.size());

	//shuffling input reads
	std::vector<size_t> indicesPerm(records.size());
	for (size_t i = 0; i < indicesPerm.size(); ++i) indicesPerm[i] = i;
	std::random_shuffle(indicesPerm.begin(), indicesPerm.end());

	for (size_t i : indicesPerm)
	{
		_seqIndex[records[i].id] = std::move(records[i]);
	}
}


const FastaRecord& 
	SequenceContainer::addSequence(const FastaRecord::DnaRepr& sequence, 
								   const std::string& description)
{
	FastaRecord::Id newId = FastaRecord::Id(g_nextSeqId);
	FastaRecord fwdRecord(sequence, "+" + description, newId);
	_seqIndex[fwdRecord.id] = std::move(fwdRecord);

	FastaRecord::DnaRepr revComplement;
{'fraction_non_alphanumeric': 0.15413737155219037, 'fraction_numerical': 0.005137912385073012, 'mean_word_length': 4.621580547112462, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 22, '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': '2959401', 'n_tokens_mistral': 1483, 'n_tokens_neox': 1348, 'n_words': 299}