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
|
#include "myutils.h"
#include "chime.h"
#include "seqdb.h"
#include "dp.h"
#include "ultra.h"
#include "hspfinder.h"
#include <algorithm>
#include <set>
bool SearchChime(Ultra &U, const SeqData &QSD, float QAb,
const AlnParams &AP, const AlnHeuristics &AH, HSPFinder &HF,
float MinFractId, ChimeHit2 &Hit);
FILE *g_fUChime;
FILE *g_fUChimeAlns;
const vector<float> *g_SortVecFloat;
bool g_UchimeDeNovo = false;
void Usage()
{
printf("\n");
printf("UCHIME %s by Robert C. Edgar\n", MY_VERSION);
printf("http://www.drive5.com/uchime\n");
printf("\n");
printf("This software is donated to the public domain\n");
printf("\n");
printf(
#include "help.h"
);
}
void SetBLOSUM62()
{
Die("SetBLOSUM62 not implemented");
}
void ReadSubstMx(const string &/*FileName*/, Mx<float> &/*Mxf*/)
{
Die("ReadSubstMx not implemented");
}
void LogAllocs()
{
/*empty*/
}
static bool CmpDescVecFloat(unsigned i, unsigned j)
{
return (*g_SortVecFloat)[i] > (*g_SortVecFloat)[j];
}
void Range(vector<unsigned> &v, unsigned N)
{
v.clear();
v.reserve(N);
for (unsigned i = 0; i < N; ++i)
v.push_back(i);
}
void SortDescending(const vector<float> &Values, vector<unsigned> &Order)
{
StartTimer(Sort);
const unsigned N = SIZE(Values);
Range(Order, N);
g_SortVecFloat = &Values;
sort(Order.begin(), Order.end(), CmpDescVecFloat);
EndTimer(Sort);
}
float GetAbFromLabel(const string &Label)
{
vector<string> Fields;
Split(Label, Fields, '/');
const unsigned N = SIZE(Fields);
for (unsigned i = 0; i < N; ++i)
{
const string &Field = Fields[i];
if (Field.substr(0, 3) == "ab=")
{
string a = Field.substr(3, string::npos);
return (float) atof(a.c_str());
}
}
if (g_UchimeDeNovo)
Die("Missing abundance /ab=xx/ in label >%s", Label.c_str());
return 0.0;
}
int main(int argc, char *argv[])
{
MyCmdLine(argc, argv);
if (argc < 2)
{
Usage();
return 0;
}
if (opt_version)
{
printf("uchime v" MY_VERSION ".%s\n", SVN_VERSION);
return 0;
}
printf("uchime v" MY_VERSION ".%s\n", SVN_VERSION);
printf("by Robert C. Edgar\n");
printf("http://drive5.com/uchime\n");
printf("This code is donated to the public domain.\n");
printf("\n");
if (!optset_w)
opt_w = 8;
float MinFractId = 0.95f;
if (optset_id)
MinFractId = (float) opt_id;
Log("%8.2f minh\n", opt_minh);
Log("%8.2f xn\n", opt_xn);
Log("%8.2f dn\n", opt_dn);
Log("%8.2f xa\n", opt_xa);
Log("%8.2f mindiv\n", opt_mindiv);
Log("%8u maxp\n", opt_maxp);
if (opt_input == "" && opt_uchime != "")
opt_input = opt_uchime;
if (opt_input == "")
Die("Missing --input");
g_UchimeDeNovo = (opt_db == "");
if (opt_uchimeout != "")
g_fUChime = CreateStdioFile(opt_uchimeout);
if (opt_uchimealns != "")
g_fUChimeAlns = CreateStdioFile(opt_uchimealns);
SeqDB Input;
SeqDB DB;
Input.FromFasta(opt_input);
if (!Input.IsNucleo())
Die("Input contains amino acid sequences");
const unsigned QuerySeqCount = Input.GetSeqCount();
vector<unsigned> Order;
for (unsigned i = 0; i < QuerySeqCount; ++i)
Order.push_back(i);
if (g_UchimeDeNovo)
{
vector<float> Abs;
for (unsigned i = 0; i < QuerySeqCount; ++i)
{
const char *Label = Input.GetLabel(i);
float Ab = GetAbFromLabel(Label);
Abs.push_back(Ab);
}
SortDescending(Abs, Order);
DB.m_IsNucleoSet = true;
DB.m_IsNucleo = true;
}
else
{
DB.FromFasta(opt_db);
if (!DB.IsNucleo())
Die("Database contains amino acid sequences");
}
vector<ChimeHit2> Hits;
unsigned HitCount = 0;
for (unsigned i = 0; i < QuerySeqCount; ++i)
{
unsigned QuerySeqIndex = Order[i];
SeqData QSD;
Input.GetSeqData(QuerySeqIndex, QSD);
float QAb = -1.0;
if (g_UchimeDeNovo)
QAb = GetAbFromLabel(QSD.Label);
ChimeHit2 Hit;
AlnParams &AP = *(AlnParams *) 0;
AlnHeuristics &AH = *(AlnHeuristics *) 0;
HSPFinder &HF = *(HSPFinder *) 0;
bool Found = SearchChime(DB, QSD, QAb, AP, AH, HF, MinFractId, Hit);
if (Found)
++HitCount;
else
{
if (g_UchimeDeNovo)
DB.AddSeq(QSD.Label, QSD.Seq, QSD.L);
}
WriteChimeHit(g_fUChime, Hit);
ProgressStep(i, QuerySeqCount, "%u/%u chimeras found (%.1f%%)", HitCount, i, Pct(HitCount, i+1));
}
Log("\n");
Log("%s: %u/%u chimeras found (%.1f%%)\n",
opt_input.c_str(), HitCount, QuerySeqCount, Pct(HitCount, QuerySeqCount));
CloseStdioFile(g_fUChime);
CloseStdioFile(g_fUChimeAlns);
ProgressExit();
return 0;
}
|