File: seqdb.h

package info (click to toggle)
mothur 1.48.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 13,684 kB
  • sloc: cpp: 161,854; makefile: 122; sh: 31
file content (108 lines) | stat: -rwxr-xr-x 2,231 bytes parent folder | download | duplicates (9)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
#ifndef seqdb_h
#define seqdb_h

#include <vector>
#include <map>

struct SeqData;

using namespace std;

struct SeqDB
	{
private:
	SeqDB(const SeqDB &rhs);
	SeqDB &operator=(const SeqDB &rhs);

public:
	string m_FileName;
	char **m_Labels;
	byte **m_Seqs;
	unsigned *m_SeqLengths;
	unsigned m_SeqCount;
	unsigned m_Size;

	bool m_Aligned;
	bool m_IsNucleo;
	bool m_IsNucleoSet;

public:
	SeqDB();
	~SeqDB();
	void Clear(bool ctor = false);
	void InitEmpty(bool Nucleo);

	unsigned AddSeq(const char *Label, const byte *Seq, unsigned L);

	byte *GetSeq(unsigned SeqIndex) const
		{
		asserta(SeqIndex < m_SeqCount);
		return m_Seqs[SeqIndex];
		}

	const char *GetLabel(unsigned SeqIndex) const
		{
		asserta(SeqIndex < m_SeqCount);
		return m_Labels[SeqIndex];
		}

	unsigned GetSeqLength(unsigned SeqIndex) const
		{
		asserta(SeqIndex < m_SeqCount);
		return m_SeqLengths[SeqIndex];
		}

	unsigned GetSeqCount() const
		{
		return m_SeqCount;
		}

	unsigned GetPairCount() const
		{
		unsigned SeqCount = GetSeqCount();
		return (SeqCount*(SeqCount - 1))/2;
		}

	unsigned GetPairIndex(unsigned SeqIndex1, unsigned SeqIndex2) const
		{
		if (SeqIndex1 > SeqIndex2)
			return (SeqIndex1*(SeqIndex1 - 1))/2 + SeqIndex2;
		return (SeqIndex2*(SeqIndex2 - 1))/2 + SeqIndex1;
		}

	unsigned GetColCount() const
		{
		if (!m_Aligned)
			Die("SeqDB::GetColCount, not aligned");
		if (m_SeqCount == 0)
			Die("SeqDB::GetColCount, empty");
		return m_SeqLengths[0];
		}

	bool IsNucleo() const
		{
		asserta(m_IsNucleoSet);
		return m_IsNucleo;
		}

	void GetSeqData(unsigned Id, SeqData &Buffer) const;

	unsigned GetMaxLabelLength() const;
	unsigned GetMaxSeqLength() const;
	void SetIsNucleo();
	unsigned GetIndex(const char *Label) const;
	void MakeLabelToIndex(map<string, unsigned> &LabelToIndex);

	void LogMe() const;
	void FromFasta(const string &FileName, bool AllowGaps = false);

	void ToFasta(const string &FileName) const;
	void ToFasta(FILE *f, unsigned SeqIndex) const;
	void SeqToFasta(FILE *f, unsigned SeqIndex, bool WithLabel = false) const;

	unsigned GetTotalLength() const;
	};

bool isgap(byte c);

#endif