-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathKmerInfo.h
87 lines (73 loc) · 1.63 KB
/
KmerInfo.h
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
#ifndef _MOURISL_KMERINFO
#define _MOURISL_KMERINFO
#include <map>
#include <vector>
#include <stdlib.h>
#include "KmerCode.h"
#include "utils.h"
struct _kmerInRead
{
std::size_t readIdx ;
int kmerPos ;
bool rc ; // need reverse and complementary
} ;
class KmerInfo
{
private:
std::map<uint64_t, std::vector<struct _kmerInRead> > kmerInfo ;
std::map<uint64_t, std::size_t> kmerCnt ;
int kmerLength ;
public:
KmerInfo( int kl ):kmerLength( kl )
{
}
~KmerInfo()
{
}
int GetKmerLength()
{
return kmerLength ;
}
void AddKmerCount( KmerCode &kmer )
{
uint64_t code = kmer.GetCanonicalCode() ;
if ( kmerCnt.count( code ) == 0 )
kmerCnt[ code ] = 1 ;
else
{
++kmerCnt[ code ] ;
}
}
void AddReadInfo( KmerCode &kmer, std::size_t readIdx, int kmerPos )
{
struct _kmerInRead info ;
uint64_t code = kmer.GetCanonicalCode() ;
info.readIdx = readIdx ;
info.kmerPos = kmerPos ;
info.rc = ( code != kmer.GetCode() ) ;
kmerInfo[ code ].push_back( info ) ;
}
/*int GetKmerInfo( KmerCode &kmer, struct _kmerInRead *buffer, int bufferSize )
{
}*/
int GetReadsInfo( KmerCode &kmer, struct _kmerInRead **buffer )
{
uint64_t code = kmer.GetCanonicalCode() ;
int i, size ;
std::vector<struct _kmerInRead> &infoList = kmerInfo[code] ;
size = infoList.size() ;
*buffer = ( struct _kmerInRead * )malloc( sizeof( struct _kmerInRead ) * size ) ;
for ( i = 0 ; i < size ; ++i )
(*buffer)[i] = infoList[i] ;
return size ;
}
int GetKmerCount( KmerCode &kmer )
{
uint64_t code = kmer.GetCanonicalCode() ;
if ( kmerCnt.count( code ) == 0 )
return 0 ;
else
return kmerCnt[code] ;
}
} ;
#endif