File: KmerInit.hpp

package info (click to toggle)
skesa 2.4.0-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 996 kB
  • sloc: cpp: 13,399; makefile: 375; sh: 19
file content (92 lines) | stat: -rw-r--r-- 4,013 bytes parent folder | download | duplicates (3)
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
/*===========================================================================
*
*                            PUBLIC DOMAIN NOTICE
*               National Center for Biotechnology Information
*
*  This software/database is a "United States Government Work" under the
*  terms of the United States Copyright Act.  It was written as part of
*  the author's official duties as a United States Government employee and
*  thus cannot be copyrighted.  This software/database is freely available
*  to the public for use. The National Library of Medicine and the U.S.
*  Government have not placed any restriction on its use or reproduction.
*
*  Although all reasonable efforts have been taken to ensure the accuracy
*  and reliability of the software and data, the NLM and the U.S.
*  Government do not and cannot warrant the performance or results that
*  may be obtained by using this software or data. The NLM and the U.S.
*  Government disclaim all warranties, express or implied, including
*  warranties of performance, merchantability or fitness for any particular
*  purpose.
*
*  Please cite the author in any work or product based on this material.
*
* ===========================================================================
*
*/

#ifndef _KmerInit_
#define _KmerInit_

#include "LargeInt.hpp"
#include <boost/variant.hpp>
#include <unordered_map>

/******************

This is the only place where we manipulate boost::variant directly. The rest of the code MUST use these definitions and boost::visitor

*******************/

using namespace std;
namespace DeBruijn {

#define MaxPrec 16  // kmer up to 512

    template<template<int, typename...> class BoundedType, typename... V> 
    using BoostVariant = boost::variant<BoundedType<1,V...>,  BoundedType<2,V...>,  BoundedType<3,V...>,  BoundedType<4,V...>,
                                        BoundedType<5,V...>,  BoundedType<6,V...>,  BoundedType<7,V...>,  BoundedType<8,V...>, 
                                        BoundedType<9,V...>,  BoundedType<10,V...>, BoundedType<11,V...>, BoundedType<12,V...>,
                                        BoundedType<13,V...>, BoundedType<14,V...>, BoundedType<15,V...>, BoundedType<16,V...>>;

    // for TKmer
    typedef BoostVariant<LargeInt> TLargeIntN;


    // for TKmerCount
    template<int N> using TLargeIntVec = vector<pair<LargeInt<N>,size_t>>;
    typedef BoostVariant<TLargeIntVec> TKmerCountN;
        
    // for TKmerMap
    struct SKmerHash {
        template<typename T> 
        size_t operator() (const T& kmer) const { return kmer.oahash(); }
    };
    template<int N, class V> using TLargeIntMap = unordered_map<LargeInt<N>,V,SKmerHash>;
    template<class V> using TKmerMapN = BoostVariant<TLargeIntMap, V>;
    
    // This variadic template could be used in construsctors of all boost::variants used in this code
    template<typename Variant, template<int, typename...> class BoundedType, typename... Params>
    Variant CreateVariant(int p) {
        switch(p) {
        case 1 :  return BoundedType<1, Params...>();
        case 2 :  return BoundedType<2, Params...>();
        case 3 :  return BoundedType<3, Params...>();
        case 4 :  return BoundedType<4, Params...>();
        case 5 :  return BoundedType<5, Params...>();
        case 6 :  return BoundedType<6, Params...>();
        case 7 :  return BoundedType<7, Params...>();
        case 8 :  return BoundedType<8, Params...>();
        case 9 :  return BoundedType<9, Params...>();
        case 10 : return BoundedType<10, Params...>();
        case 11 : return BoundedType<11, Params...>();
        case 12 : return BoundedType<12, Params...>();
        case 13 : return BoundedType<13, Params...>();
        case 14 : return BoundedType<14, Params...>();
        case 15 : return BoundedType<15, Params...>();
        case 16 : return BoundedType<16, Params...>();
        default :  throw runtime_error("Not supported kmer length");
        }
    }
            
}; // namespace
#endif /* _KmerInit_ */