/* BaitFisher (version 1.2.7) a program for designing DNA target enrichment baits
* Copyright 2013-2016 by Christoph Mayer
*
* This source file is part of the BaitFisher-package.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with BaitFisher. If not, see .
*
*
* For any enquiries send an Email to Christoph Mayer
* c.mayer.zfmk@uni-bonn.de
*
* When publishing work that is based on the results please cite:
* Mayer et al. 2016: BaitFisher: A software package for multi-species target DNA enrichment probe design
*
*/
#ifndef DNASTRING_H
#define DNASTRING_H
#include "primefactors.h"
#include "faststring2.h"
#include
#include "basic-DNA-RNA-AA-routines.h"
// Todo:
// - Check for correct nucl. in push_back, set routine
inline bool isReducibleUnit_global(const char *beg, const char* end)
{
unsigned len = end-beg;
const char *test_pos;
int factor_index;
unsigned factor;
unsigned factor_len;
unsigned i;
bool composite;
factor_index = 0;
while( (factor = primeFactors[len][factor_index]) != 0 )
{
composite = true;
factor_len = len/factor;
test_pos = beg;
for (i=1; i(s).c_str();
char *pos = tmp;
char *pos_end = pos + len;
//unsigned i;
char *min_str;
int strncmp_result;
bool found_subpattern = false;
strcpy(tmp, orig);
strcpy(tmp+len, orig);
min_str = tmp;
++pos;
for (; pos != pos_end; ++pos)
{
strncmp_result = strncmp(pos, min_str, len);
if ( strncmp_result < 0 )
min_str = pos;
else if ( strncmp_result == 0 )
{
// New pattern is from
found_subpattern = true;
}
}
*(min_str+len) = '\0'; /* At this position within tmp we have the end of the unit */
faststring::assign(min_str);
delete [] tmp;
return found_subpattern;
}
// Returns true if a subpattern has been found,
// false if no subpattern has been found.
bool setToMinAlphaRepModRevCompAndCyclicPermOf(const CDnaString &s)
{
CDnaString tmp;
bool found_subpattern;
tmp.setToReverseComplementOf(s);
found_subpattern = setToMinAlphaRepModCyclicPermOf(tmp); // *this contains minimum representation of rev comp of s
tmp.setToMinAlphaRepModCyclicPermOf(s); // tmp contains minimum representation of s itself
if ( strcmp(c_str(), tmp.c_str() ) > 0 )
{
assign( tmp.c_str() );
}
return found_subpattern;
}
// Returns true if a subpattern has been found,
// false if no subpattern has been found.
bool setToMinAlphaRepModRevCompAndCyclicPermOf(const CDnaString &s, signed char &direction)
{
CDnaString tmp;
bool found_subpattern;
tmp.setToReverseComplementOf(s);
found_subpattern = setToMinAlphaRepModCyclicPermOf(tmp); // *this contains minimum representation of rev comp of s
tmp.setToMinAlphaRepModCyclicPermOf(s); // tmp contains minimum representation of s itself
direction = 1;
if ( strcmp(c_str(), tmp.c_str() ) > 0 )
{
assign( tmp.c_str() );
direction = -1;
}
return found_subpattern;
}
bool isCompositeUnitLength(int x)
{
return primeFactors[x][0];
}
// Old and inefficient:
/* bool isReducibleUnit_old() */
/* { */
/* unsigned len = size(); */
/* char *tmp = new char [2*len+1]; */
/* const char *orig = c_str(); */
/* int factor_index; */
/* unsigned shift; */
/* strcpy(tmp, orig); */
/* strcpy(tmp+len, orig); */
/* factor_index = 0; */
/* while( (shift = primeFactors[len][factor_index]) != 0 ) */
/* { */
/* if ( strncmp(tmp, tmp+shift, len) == 0) */
/* return true; */
/* ++factor_index; */
/* } */
/* return false; */
/* } */
// New and works but is redundent - equivalent to current version
/* bool isReducibleUnit_ok() */
/* { */
/* unsigned len = size(); */
/* const char *orig = c_str(); */
/* int factor_index; */
/* unsigned factor; */
/* unsigned factor_len; */
/* unsigned i; */
/* bool composite; */
/* factor_index = 0; */
/* while( (factor = primeFactors[len][factor_index]) != 0 ) */
/* { */
/* composite = true; */
/* factor_len = len/factor; */
/* orig = c_str(); */
/* for (i=1; i(a).c_str(), const_cast(b).c_str() ) < 0);
}
};
#endif