File: kmer_file_header.h

package info (click to toggle)
kmc 3.2.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,716 kB
  • sloc: cpp: 38,308; python: 664; makefile: 216; perl: 179; sh: 34
file content (95 lines) | stat: -rw-r--r-- 2,146 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
  This file is a part of KMC software distributed under GNU GPL 3 licence.
  The homepage of the KMC project is http://sun.aei.polsl.pl/kmc
  
  Authors: Marek Kokot
  
  Version: 3.2.4
  Date   : 2024-02-09
*/

#ifndef _KMER_FILE_HEADER_H
#define _KMER_FILE_HEADER_H
#include "defs.h"
#include "kff_info_reader.h"
#include <string>
#include <iostream>

//************************************************************************************************************
// CKmerFileHeader - represents header of k-mer database.
//************************************************************************************************************

enum class KmerFileType { KMC1, KMC2, KFF1 };

struct CKmerFileHeader
{
	bool is_kff_file(std::string& fname);
	void read_from_kff_file(const std::string& fname);
	CKFFFileStruct kff_file_struct;

	uint64_t GetFromFooterOrDefault(const std::string& name, uint64_t default_value)
	{
		const auto& m = kff_file_struct.footer;
		auto r = m.find(name);
		if (r != m.end())
			return r->second;
		return default_value;
	}
public:
	uint32 kmer_len = 0;
	uint32 mode = 0;
	uint32 counter_size = 0;
	uint32 lut_prefix_len = 0;
	uint32 signature_len = 0; //only for kmc2
	uint32 min_count = 0;
	uint64 max_count = 0;
	uint64 total_kmers = 0;
	bool both_strands = true;
	uint32 db_version = 0;
	uint32 header_offset = 0;
	
	uint32 no_of_bins = 0; //only for kmc2
	KmerFileType kmer_file_type;
	//bool IsKMC2() const
	//{
	//	return db_version == 0x200;
	//}

	KmerFileType GetType() const
	{
		return kmer_file_type;
	}

	uint8_t GetEncoding() const
	{
		switch (kmer_file_type)
		{
			case KmerFileType::KMC1:
			case KmerFileType::KMC2:
				return 0b00011011;
			case KmerFileType::KFF1:
				return kff_file_struct.encoding;
			default:
			{
				std::cerr << "Error: this should never happen, please contact authors: " << __FILE__ << "\t" << __LINE__ << "\n";
				exit(1);
			}
		}
	}
	CKmerFileHeader(std::string file_name);

	

private:
	template<typename T> void load_uint(FILE* file, T& res)
	{
		res = 0;
		for (uint32 i = 0; i < sizeof(T); ++i)
			res += (T)getc(file) << (i << 3);
	}
};

#endif


// ***** EOF