MDA
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups
other_seq.hpp
1 /*
2  * other_seq.hpp
3  *
4  * Created on: Jun 9, 2013
5  * Author: Carsten Kemena
6  *
7  * This file is part of MDAT.
8  *
9  * MDAT is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * MDAT is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with MDAT. If not, see <http://www.gnu.org/licenses/>.
21  *
22  */
23 
24 #ifndef OTHER_SEQ_HPP_
25 #define OTHER_SEQ_HPP_
26 
27 #include "SequenceSet.hpp"
28 
29 
30 template<typename SequenceSetType>
31 double
32 avg_size(const SequenceSetType &seqSet)
33 {
34  size_t n_seqs = seqSet.n_seqs();
35  double length = 0;
36  for (size_t i=0; i<n_seqs; ++i)
37  length+= seqSet->size();
38  return length/n_seqs;
39 }
40 
41 
42 template<typename SequenceSetType>
43 size_t
44 max_size(const SequenceSetType &seqSet)
45 {
46  size_t max_len = 0;
47  size_t n_seqs = seqSet.n_seqs();
48  for (size_t i=0; i<n_seqs; ++i)
49  if (seqSet[i].size() > max_len)
50  max_len=seqSet[i].size();
51  return max_len;
52 }
53 
54 
55 template<typename SequenceType, typename MemoryType>
56 bool
57 check_set(const SequenceSet<SequenceType, MemoryType> &set)
58 {
59  size_t n_seqs = set.n_seqs();
60  size_t j, len;
61  size_t *val_counting = new size_t[256];
62  for (j=0; j<256; ++j)
63  val_counting[j] = 0;
64 
65  // counting occurrences of characters
66  for (size_t i=0; i<n_seqs; ++i)
67  {
68  const SequenceType &seq = set[i];
69  len=seq.size();
70  for (j=0; j<len; ++j)
71  ++val_counting[static_cast<int>(seq[j])];
72  }
73  // see if strange character has been found
74  for (j=0; j<45; ++j)
75  {
76  if (val_counting[j] != 0)
77  return false;
78  }
79  for (j=46; j<65; ++j)
80  {
81  if (val_counting[j] != 0)
82  return false;
83  }
84  for (j=91; j<97; ++j)
85  {
86  if (val_counting[j] != 0)
87  return false;
88  }
89  for (j=123; j<256; ++j)
90  {
91  if (val_counting[j] != 0)
92  return false;
93  }
94  return true;
95 }
96 
97 
98 
99 #endif /* OTHER_SEQ_HPP_ */