Debian Codegraph @

tools/kissnp2/src/Filter.cpp

raw
1 /*****************************************************************************
2 * discoSnp++: discovering polymorphism from raw unassembled NGS reads
3 * A tool from the GATB (Genome Assembly Tool Box)
4 * Copyright (C) 2014 INRIA
5 * Authors: P.Peterlongo, E.Drezen
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *****************************************************************************/
20
21 #include <Filter.hpp>
22 #include <gatb/gatb_core.hpp>
23 using namespace std;
24
25 static int NT2int(char nt) { return (nt>>1)&3; }
26
27
28 /*********************************************************************
29 ** METHOD :
30 ** PURPOSE :
31 ** INPUT :
32 ** OUTPUT :
33 ** RETURN : True if the sequence is of high complexity else return false
34 ** REMARKS : TODO: comment and validate this function.
35 *********************************************************************/
36 bool filterLowComplexityPath(const std::string& seq){
37 int DUSTSCORE[64]; // all tri-nucleotides
38 for (int i=0; i<64; i++) DUSTSCORE[i]=0;
39 size_t lenseq = seq.size();
40 for (int j=2; j<lenseq; ++j) ++DUSTSCORE[NT2int(seq[j-2])*16 + NT2int(seq[j-1])*4 + NT2int(seq[j])];
41 int m,s=0;
42
43 for (int i=0; i<64; ++i)
44 {
45 m = DUSTSCORE[i];
46 s += (m*(m-1))/2;
47 }
48
49 return s<((lenseq-2)/4 * (lenseq-6)/4)/2;
50 }
51
52 /*********************************************************************
53 ** METHOD :
54 ** PURPOSE :
55 ** INPUT :
56 ** OUTPUT :
57 ** RETURN : True if the two sequences are of high complexity else return false
58 ** REMARKS : The smaller the score, the higher the complexity
59 *********************************************************************/
60 bool filterLowComplexity2Paths (const std::string& seq1, const std::string& seq2)
61 {
62 return filterLowComplexityPath(seq1) && filterLowComplexityPath(seq2);
63 }