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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
|
/*==========================================================================
SeqAn - The Library for Sequence Analysis
https://www.seqan.de
============================================================================
Copyright (C) 2007
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
============================================================================
$Id$
==========================================================================*/
#ifndef SEQAN_HEADER_BASE_H
#define SEQAN_HEADER_BASE_H
namespace seqan2
{
//////////////////////////////////////////////////////////////////////////////
// create possible tuples with length n:
//////////////////////////////////////////////////////////////////////////////
template<typename TStringSet, typename TSpec, typename TConfig, typename TId>
inline void
create_nTuple(TStringSet &tupleSet, FragmentStore<TSpec, TConfig> &fragStore, const TStringSet &annoIds, const TId &parentId, const unsigned &n)
{
typedef typename Iterator<TStringSet>::Type TSetIter;
typedef typename Value<TStringSet>::Type TString;
typedef typename Iterator<TString const>::Type TStringIter;
typedef typename FragmentStore<TSpec, TConfig>::TAnnotationStore TAnnotationStore;
typedef typename Value<TAnnotationStore>::Type TAnnotationStoreElement;
static const TId INVALID_ANNO_ID = TAnnotationStoreElement::INVALID_ID;
clear(tupleSet);
TStringIter itStr;
TStringIter itStrEnd;
TSetIter itSet;
TSetIter itSetEnd;
TStringSet tempAnnoIds;
resize(tempAnnoIds, n);
TStringSet tempTupleSet;
for (unsigned i = 0; i <= length(annoIds) - n; ++i)
{
for ( unsigned j = i; j < i + n; ++j)
{
clear(value(tempAnnoIds, j - i));
itStr = begin(annoIds[j]);
itStrEnd = end(annoIds[j]);
for ( ; itStr != itStrEnd; goNext(itStr))
{
if (getValue(itStr) != INVALID_ANNO_ID && getValue(fragStore.annotationStore, getValue(itStr)).parentId == parentId)
{
appendValue(value(tempAnnoIds, j - i), getValue(itStr), Generous() );
}
}
}
clear(tempTupleSet);
createCombinations(tempTupleSet, tempAnnoIds);
itSet = begin(tempTupleSet);
itSetEnd = end(tempTupleSet);
for ( ; itSet != itSetEnd; goNext(itSet))
{
appendValue(tupleSet, *itSet, Generous());
}
}
}
//////////////////////////////////////////////////////////////////////////////
// create all possible tuples: for each n <= length
//////////////////////////////////////////////////////////////////////////////
template<typename TStringSet, typename TSpec, typename TConfig, typename TId>
inline void
create_Tuple(TStringSet &tupleSet, FragmentStore<TSpec, TConfig> &fragStore, const TStringSet &annoIds, const TId &parentId, const unsigned &n)
{
typedef typename Iterator<TStringSet>::Type TIter;
clear(tupleSet);
TIter it;
TIter itEnd;
TStringSet tempTupleSet;
for (unsigned i = 1; i <= n && i <= length(annoIds); ++i)
{
clear(tempTupleSet);
create_nTuple(tempTupleSet, fragStore, annoIds, parentId, i);
it = begin(tempTupleSet);
itEnd = end(tempTupleSet);
for ( ; it != itEnd; goNext(it))
{
appendValue(tupleSet, *it, Generous());
}
}
}
//////////////////////////////////////////////////////////////////////////////
// create possible tuples:
//////////////////////////////////////////////////////////////////////////////
template<typename TStringSet>
inline void
createCombinations(TStringSet &tupleSet, TStringSet &annoIds)
{
//typedef typename Value<TStringSet>::Type TString;
//typedef typename Value<TString>::Type TId;
typedef typename Iterator<TStringSet>::Type TStringSetIter;
//typedef typename Iterator<TString>::Type TStringIter;
if (!empty(annoIds))
{
TStringSetIter itStrSet = begin(annoIds);
TStringSetIter itStrSetEnd = end(annoIds);
unsigned n = 1;
for ( ; itStrSet != itStrSetEnd; goNext(itStrSet))
{
n = n * length(*itStrSet);
}
clear(tupleSet);
resize(tupleSet, n);
/*
TStringSetIter itT = begin(tupleSet);
TStringSetIter itTEnd = end(tupleSet);
for ( ; itT != itTEnd; goNext(itT))
{
resize(value(itT), length(annoIds));
}
*/
// TId id;
unsigned pos;
unsigned help = n;
for (unsigned i = 0; i < length(annoIds); ++i)
{
unsigned m = length(getValue(annoIds, i));
help = help / m;
for (unsigned j = 0; j< length(getValue(annoIds, i)); ++j)
{
// id = getValue(getValue(annoIds, i), j);
for (unsigned k = 0; k < unsigned (n/ (help*m)) ; ++k)
{
for (unsigned l = 0; l < help; ++l)
{
pos = j*help + k*m*help + l;
// assignValue(value(tupleSet, pos), i, getValue(getValue(annoIds, i), j) );
appendValue(value(tupleSet, pos), getValue(getValue(annoIds, i), j), Generous() );
}
}
}
}
}
}
//////////////////////////////////////////////////////////////////////////////
// getDifference
//////////////////////////////////////////////////////////////////////////////
template<typename TString>
inline void
getDifference(TString &difference, const TString &string1, const TString &string2)
{
typedef typename Iterator<TString>::Type TIter;
resize(difference, length(string1));
TString str1 = string1;
TString str2 = string2;
std::stable_sort(begin(str1), end(str1));
std::stable_sort(begin(str2), end(str2));
TIter it = std::set_difference(begin(str1), end(str1), begin(str2), end(str2), begin(difference));
erase(difference, position(it, difference), endPosition(difference));
}
//////////////////////////////////////////////////////////////////////////////
// searchValue
//////////////////////////////////////////////////////////////////////////////
template<typename TPos, typename TValue, typename TString>
inline bool
searchValue(TPos & pos, TValue const & value, TString const & string)
{
typedef typename Iterator<TString const>::Type TIter;
TIter it = std::lower_bound(begin(string), end(string), value);
pos = position(it, string);
if (it == end(string) || getValue(it) != value) return false;
else return true;
}
//////////////////////////////////////////////////////////////////////////////
// intersection
//////////////////////////////////////////////////////////////////////////////
template<typename TList>
inline bool
interSec(TList &result, const TList &list1, const TList &list2)
{
//typedef typename Value<TList>::Type TValue;
typedef typename Iterator<TList>::Type TIter;
resize(result, length(list1));
TList sort1 = list1;
TList sort2 = list2;
std::stable_sort(begin(sort1), end(sort1));
std::stable_sort(begin(sort2), end(sort2));
TIter itR = std::set_intersection(begin(sort1), end(sort1), begin(sort2), end(sort2), begin(result));
erase(result, position(itR, result), endPosition(result));
if (empty(result)) return false;
else return true;
}
//////////////////////////////////////////////////////////////////////////////
// isElement
//////////////////////////////////////////////////////////////////////////////
template<typename TValue>
inline bool
isElement(const TValue &value, const String<TValue> &string)
{
return std::binary_search(begin(string), end(string), value);
}
//////////////////////////////////////////////////////////////////////////////
// isElement
//////////////////////////////////////////////////////////////////////////////
template<typename TValue>
inline bool
isElement_unsorted(TValue const & value, String<TValue> const & string)
{
typedef typename Iterator<String<TValue> const>::Type TIter;
TIter it = std::find(begin(string), end(string), value);
if (atEnd(it, string)) return false;
else return true;
}
//////////////////////////////////////////////////////////////////////////////
}// namespace seqan2
#endif //#ifndef SEQAN_HEADER_...
|