Skip to content

Commit

Permalink
PD-5181: StxTyper ver. 1.0.28
Browse files Browse the repository at this point in the history
  • Loading branch information
Vyacheslav Brover committed Dec 9, 2024
1 parent e1e9d05 commit 4184b32
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 104 deletions.
3 changes: 2 additions & 1 deletion amrfinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* Dependencies: NCBI BLAST, HMMer, libcurl, gunzip (optional)
*
* Release changes:
* 4.0.6 12/09/2024 PD-5181 StxTyper ver. 1.0.28
* 4.0.5 11/13/2024 PD-5175 prohibit --database_version and -p or -n
* 4.0.4 10/29/2024 colorizeDir()
* stxtyper/ -> stx/
Expand Down Expand Up @@ -338,7 +339,7 @@ using namespace GFF_sp;
const string dataVer_min ("2024-08-14.2");
// 3.12: "2023-12-15.2"
// 3.11: "2021-02-18.1"
const string stxTyperVersion ("1.0.27");
const string stxTyperVersion ("1.0.28");



Expand Down
59 changes: 51 additions & 8 deletions common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,35 @@ bool strBlank (const string &s)



bool getScientific (string numberS,
bool &hasPoint,
streamsize &decimals)
{
strUpper (numberS);
const size_t ePos = numberS. find ('E');
const size_t pointPos = numberS. find ('.');

hasPoint = (pointPos != string::npos);
decimals = 0;
if (ePos == string::npos)
{
if (hasPoint)
decimals = (streamoff) (numberS. size () - (pointPos + 1));
}
else
{
ASSERT (ePos != pointPos);
if (hasPoint && ePos < pointPos)
hasPoint = false;
if (hasPoint)
decimals = (streamoff) (ePos - (pointPos + 1));
}

return ePos != string::npos;
}



void strUpper (string &s)
{
for (char& c : s)
Expand Down Expand Up @@ -760,14 +789,23 @@ bool isLower (const string &s)



string::const_iterator stringInSet (const string &s,
const string &charSet)
size_t stringNotInSet (const string &s,
const string &charSet,
ebool uppercase)
{
CONST_ITER (string, it, s)
if (! charInSet (*it, charSet))
return it;

return s. end ();
FFOR (size_t, i, s. size ())
{
char c = s [i];
switch (uppercase)
{
case efalse: c = toLower (c); break;
case etrue: c = toUpper (c); break;
case enull: break;
}
if (! charInSet (c, charSet))
return i;
}
return no_index;
}


Expand Down Expand Up @@ -4093,7 +4131,12 @@ int Application::run (int argc,
string logFName (getArg ("log"));
ASSERT (! logPtr);
if (! logFName. empty ())
logPtr = new ofstream (logFName, ios_base::app);
{
logPtr = new ofstream (logFName, ios_base::app);
time_t rawtime;
time (& rawtime);
*logPtr << endl << ctime (& rawtime) << "$ " << getCommandLine () << endl;
}
}

string jsonFName;
Expand Down
90 changes: 54 additions & 36 deletions common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,9 @@ template <typename To, typename From>
inline void insertAll (To &to,
const From &from)
{
#pragma GCC diagnostic ignored "-Waggressive-loop-optimizations"
#pragma GCC diagnostic ignored "-Waggressive-loop-optimizations"
to. insert (to. begin (), from. begin (), from. end ());
#pragma GCC diagnostic warning "-Waggressive-loop-optimizations"
#pragma GCC diagnostic warning "-Waggressive-loop-optimizations"
}

template <typename To, typename From>
Expand Down Expand Up @@ -649,6 +649,10 @@ inline string unQuote (const string &s)

bool strBlank (const string &s);

bool getScientific (string numberS,
bool &hasPoint,
streamsize &decimals);

template <typename T>
string toString (const T &t)
{ ostringstream oss;
Expand Down Expand Up @@ -677,28 +681,6 @@ template <typename T>
catch (...) { return false; }
}

inline bool isLeft (const string &s,
const string &left)
{ return s. substr (0, left. size ()) == left; }

bool isRight (const string &s,
const string &right);

bool trimPrefix (string &s,
const string &prefix);
// Return: success

bool trimSuffix (string &s,
const string &suffix);
// Return: success

void trimSuffixNonAlphaNum (string &s);

bool trimTailAt (string &s,
const string &tailStart);
// Return: trimmed
// Update: s

void commaize (string &s);
// ' ' --> ','

Expand Down Expand Up @@ -742,16 +724,39 @@ inline bool charInSet (char c,
const string &charSet)
{ return charSet. find (c) != string::npos; }

string::const_iterator stringInSet (const string &s,
const string &charSet);
// Return: != s.end() => *Return is not in charSet
size_t stringNotInSet (const string &s,
const string &charSet,
ebool uppercase);
// Return: index in s which is not in charSet; may be no_index

size_t strCountSet (const string &s,
const string &charSet);

void strDeleteSet (string &s,
const string &charSet);

inline bool isLeft (const string &s,
const string &left)
{ return s. substr (0, left. size ()) == left; }

bool isRight (const string &s,
const string &right);

bool trimPrefix (string &s,
const string &prefix);
// Return: success

bool trimSuffix (string &s,
const string &suffix);
// Return: success

void trimSuffixNonAlphaNum (string &s);

bool trimTailAt (string &s,
const string &tailStart);
// Return: trimmed
// Update: s

void trimLeading (string &s);

void trimTrailing (string &s);
Expand All @@ -775,6 +780,17 @@ inline void trim (string &s,
trimLeading (s, c);
}

inline bool strNull (const string &s)
{ if (strBlank (s))
return true;
string s1 (s);
trim (s1);
strUpper (s1);
return s1 == "NULL"
|| s1 == "NA"
|| s1 == "N/A";
}

inline bool contains (const string &hay,
const string &needle)
{ return hay. find (needle) != string::npos; }
Expand Down Expand Up @@ -1117,15 +1133,15 @@ template <typename T>
{ *this << other; }
bool empty () const
{
#pragma GCC diagnostic ignored "-Wnull-dereference"
#pragma GCC diagnostic ignored "-Wnull-dereference"
return P::empty ();
#pragma GCC diagnostic warning "-Wnull-dereference"
#pragma GCC diagnostic warning "-Wnull-dereference"
}
size_t size () const
{
#pragma GCC diagnostic ignored "-Wnull-dereference"
#pragma GCC diagnostic ignored "-Wnull-dereference"
return P::size ();
#pragma GCC diagnostic warning "-Wnull-dereference"
#pragma GCC diagnostic warning "-Wnull-dereference"
}


Expand Down Expand Up @@ -2806,7 +2822,7 @@ template <typename T /* : Root */>
}
void deleteData ()
{ for (const T* t : *this)
delete t;
delete t;
P::clear ();
}
void erasePtr (size_t index)
Expand Down Expand Up @@ -2920,7 +2936,11 @@ template <typename T /* : Root */>
return *this;
}
~VectorOwn ()
{ P::deleteData (); }
{
#pragma GCC diagnostic ignored "-Wnull-dereference"
P::deleteData ();
#pragma GCC diagnostic warning "-Wnull-dereference"
}


VectorOwn<T>& operator<< (const T* value)
Expand Down Expand Up @@ -3221,9 +3241,7 @@ struct StringVector : Vector<string>
{}


string toString (const string& sep) const;
string toString () const
{ return toString (noString); }
string toString (const string& sep = noString) const;
bool same (const StringVector &vec,
const Vector<size_t> &indexes) const;
void to_xml (Xml::File &f,
Expand Down
15 changes: 10 additions & 5 deletions seq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ void Seq::qcName () const

void Seq::qcAlphabet () const
{
const string::const_iterator it = stringInSet (seq, getSeqAlphabet ());
if (it != seq. end ())
throw runtime_error ("Bad sequence character in " + strQuote (getId ()) + ": " + to_string (int (*it)) + " " + seq. substr ((size_t) (it - seq. begin ())));
const size_t i = stringNotInSet (seq, getSeqAlphabet (), etrue);
if (i != no_index)
throw runtime_error ("Bad sequence character in " + strQuote (getId ()) + ": ASCII=" + to_string (int (seq [i])) + " pos=" + to_string (i + 1) /*+ "\n" + seq*/);
}


Expand Down Expand Up @@ -3291,6 +3291,11 @@ AlignScore SubstMat::char2score (char c1,
{
QC_ASSERT (c1 >= '\0');
QC_ASSERT (c2 >= '\0');

if (strchr (peptideWildcards, c1))
c1 = 'X';
if (strchr (peptideWildcards, c2))
c2 = 'X';

const size_t i1 = (size_t) c1;
const size_t i2 = (size_t) c2;
Expand All @@ -3304,9 +3309,9 @@ AlignScore SubstMat::char2score (char c1,


if (! goodIndex (i1))
throw runtime_error ("Bad amino acid: " + string (1, c1) + " (" + to_string (i1));
throw runtime_error ("Bad amino acid: " + string (1, c1) + " (" + to_string (i1) + ")");
if (! goodIndex (i2))
throw runtime_error ("Bad amino acid: " + string (1, c2) + " (" + to_string (i2));
throw runtime_error ("Bad amino acid: " + string (1, c2) + " (" + to_string (i2) + ")");

const AlignScore s = sim [i1] [i2];
ASSERT (s == s);
Expand Down
2 changes: 1 addition & 1 deletion seq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ struct Seq : Named
public:
virtual Seq* copy () const override = 0;
void qc () const override
{ if (qc_on)
{ if (! qc_on)
return;
qcName ();
qcAlphabet ();
Expand Down
2 changes: 1 addition & 1 deletion stx
Submodule stx updated 8 files
+25 −0 METHODS.md
+43 −0 README.md
+123 −69 common.cpp
+108 −84 common.hpp
+7 −33 stxtyper.cpp
+20 −44 tsv.cpp
+12 −8 tsv.hpp
+1 −1 version.txt
Loading

0 comments on commit 4184b32

Please sign in to comment.