void MotifSearch::modify_params(int argc, char *argv[]){ GetArg2(argc, argv, "-expect", params.expect); GetArg2(argc, argv, "-minpass", params.minpass); GetArg2(argc, argv, "-seed", params.seed); GetArg2(argc, argv, "-undersample", params.undersample); GetArg2(argc, argv, "-oversample", params.oversample); }
JBoolean JBooleanXOR::Evaluate() const { const JBoolean arg1 = (GetArg1())->Evaluate(); const JBoolean arg2 = (GetArg2())->Evaluate(); return JConvertToBoolean((arg1 && !arg2) || (!arg1 && arg2)); }
void dCILInstrConditional::SetTargets (dCILInstrLabel* const target0, dCILInstrLabel* const target1) { dAssert(target0); dAssert (target0->GetArg0().m_label == GetArg1().m_label); m_tagetNode0 = target0->GetNode(); if (target1) { dAssert(target1->GetArg0().m_label == GetArg2().m_label); m_tagetNode1 = target1->GetNode(); } else { m_tagetNode1 = NULL; } }
JBoolean JLogB::Evaluate ( JFloat* result ) const { JFloat b,x; if (!(GetArg1())->Evaluate(&b) || b <= 1.0) { return kJFalse; } if (!(GetArg2())->Evaluate(&x)) { return kJFalse; } jclear_errno(); *result = log(x)/log(b); return jerrno_is_clear(); }
void JLogB::Render ( const JExprRenderer& renderer, const JExprRectList& rectList ) const { // find ourselves in the list JIndex ourIndex; const JBoolean found = rectList.FindFunction(this, &ourIndex); assert( found ); const JRect ourRect = rectList.GetRect(ourIndex); const JCoordinate ourMidline = rectList.GetMidline(ourIndex); const JSize fontSize = rectList.GetFontSize(ourIndex); // draw ourselves const JCharacter* name = GetName(); const JSize nameLength = strlen(name); assert( nameLength > 1 ); assert( name[ nameLength-1 ] == '(' ); const JString fnName = JString(name, nameLength-1); renderer.DrawString(ourRect.left, ourMidline, fontSize, fnName); // draw the base (GetArg1())->Render(renderer, rectList); // draw the argument const JFunction* arg = GetArg2(); arg->Render(renderer, rectList); JIndex argIndex; const JBoolean foundArg = rectList.FindFunction(arg, &argIndex); assert( foundArg ); renderer.DrawParentheses(rectList.GetRect(argIndex)); }
JBoolean JBooleanAND::Evaluate() const { return JConvertToBoolean( (GetArg1())->Evaluate() && (GetArg2())->Evaluate() ); }
JIndex JLogB::PrepareToRender ( const JExprRenderer& renderer, const JPoint& upperLeft, const JSize fontSize, JExprRectList* rectList ) { // intialize our rectangle const JCharacter* name = GetName(); const JSize nameLength = strlen(name); assert( nameLength > 1 ); assert( name[ nameLength-1 ] == '(' ); const JString fnName = JString(name, nameLength-1); JRect ourRect; ourRect.top = upperLeft.y; ourRect.left = upperLeft.x; ourRect.bottom = upperLeft.y + renderer.GetLineHeight(fontSize); ourRect.right = upperLeft.x + renderer.GetStringWidth(fontSize, fnName); // get rectangle for base JPoint argUpperLeft(ourRect.right, ourRect.top); const JSize baseFontSize = renderer.GetSuperSubFontSize(fontSize); JFunction* base = GetArg1(); const JIndex baseIndex = base->PrepareToRender(renderer, argUpperLeft, baseFontSize, rectList); const JRect baseRect = rectList->GetRect(baseIndex); argUpperLeft.x = baseRect.right; // get rectangle for argument -- gives our midline JFunction* arg = GetArg2(); const JIndex argIndex = arg->PrepareToRender(renderer, argUpperLeft, fontSize, rectList); const JRect argRect = rectList->GetRect(argIndex); ourRect = JCovering(ourRect, argRect); const JCoordinate ourMidline = rectList->GetMidline(argIndex); // shift argument to make space for left parenthesis const JSize parenWidth = renderer.GetParenthesisWidth(argRect.height()); rectList->ShiftRect(argIndex, parenWidth, 0); // we need space for two parentheses ourRect.right += 2*parenWidth; // shift the base down rectList->ShiftRect(baseIndex, 0, ourMidline - ourRect.top); ourRect = JCovering(ourRect, rectList->GetRect(baseIndex)); // save our rectangle return rectList->AddRect(ourRect, ourMidline, fontSize, this); }
int main(int argc, char *argv[]) { set_new_handler(alloc_error); if(argc < 6) { print_usage(cout); exit(0); } string seqfile; // file with sequences string exprfile; // file with expression data string subsetfile; // file with subset of sequence names to search string scorefile; // file with scores if(! GetArg2(argc, argv, "-s", seqfile)) { cerr << "Please specify sequence file\n\n"; print_usage(cout); exit(0); } if(! GetArg2(argc, argv, "-o", outfile)) { cerr << "Please specify output file\n\n"; print_usage(cout); exit(0); } int search_type = UNDEFINED; if(GetArg2(argc, argv, "-ex", exprfile)) { search_type = EXPRESSION; } if(GetArg2(argc, argv, "-su", subsetfile)) { search_type = SUBSET; } if(GetArg2(argc, argv, "-sc", scorefile)) { search_type = SCORE; } if(search_type == UNDEFINED) { cerr << "Please specify either an expression data file, a file with a subset of sequence names, or a file with sequence scores.\n\n"; print_usage(cout); exit(0); } // Decide mode of running archive = false; if(! GetArg2(argc, argv, "-worker", worker)) { worker = -1; archive = true; } // Read parameters vector<string> seqs; cerr << "Reading sequence data from '" << seqfile << "'... "; get_fasta_fast(seqfile.c_str(), seqs, seq_nameset); cerr << "done.\n"; ngenes = seq_nameset.size(); npoints = 0; if(search_type == EXPRESSION) { cerr << "Reading expression data from '" << exprfile << "'... "; get_expr(exprfile.c_str(), expr, data_nameset); cerr << "done.\n"; npoints = expr[0].size(); nsubset = 0; } else if(search_type == SUBSET) { cerr << "Reading subset of sequences to search from '" << subsetfile << "'... "; get_list(subsetfile.c_str(), subset); cerr << "done.\n"; npoints = 0; for(int i = 0; i < ngenes; i++) { vector<float> row(0); expr.push_back(row); } nsubset = subset.size(); sort(subset.begin(), subset.end()); } else if(search_type == SCORE) { cerr << "Reading sequence scores from '" << scorefile << "'... "; get_scores(scorefile.c_str(), scores, data_nameset); cerr << "done.\n"; npoints = 1; nsubset = 0; } vector<vector <float> > newexpr; vector<float> newscores; if(search_type == EXPRESSION) { order_data_expr(newexpr); } if(search_type == SCORE) { order_data_scores(newscores); } if(search_type == EXPRESSION) { cerr << "Successfully read input files -- dataset size is " << ngenes << " sequences X " << npoints << " timepoints\n"; } else if(search_type == SUBSET) { cerr << "Successfully read input files -- dataset size is " << ngenes << " sequences, with " << nsubset << " to be searched\n"; } else if(search_type == SCORE) { cerr << "Successfully read input files -- dataset size is " << ngenes << " scored sequences\n"; } cerr << "Setting up MotifSearch... "; if(! GetArg2(argc, argv, "-numcols", ncol)) ncol = 10; if(! GetArg2(argc, argv, "-order", order)) order = 0; if(! GetArg2(argc, argv, "-simcut", simcut)) simcut = 0.8; if(! GetArg2(argc, argv, "-maxm", maxm)) maxm = 20; MotifSearch* ms; if(search_type == EXPRESSION) { ms = new MotifSearchExpr(seq_nameset, seqs, ncol, order, simcut, maxm, newexpr, npoints); } else if(search_type == SCORE) { ms = new MotifSearchScore(seq_nameset, seqs, ncol, order, simcut, maxm, newscores); } else { ms = new MotifSearchSubset(seq_nameset, seqs, ncol, order, simcut, maxm, subset); } ms->modify_params(argc, argv); ms->set_final_params(); ms->ace_initialize(); cerr << "done.\n"; cerr << "Random seed: " << ms->get_params().seed << '\n'; if(archive) { cerr << "Running in archive mode...\n"; string archinstr(outfile); archinstr.append(".ms"); ifstream archin(archinstr.c_str()); if(archin) { cerr << "Refreshing from existing archive file " << archinstr << "... "; ms->get_archive().read(archin); cerr << "done.\n"; } while(true) { int found = read_motifs(ms); if(found > 0) output(ms); if(found < 50) sleep(10); } } else { cerr << "Running as worker " << worker << "...\n"; int nruns = ms->positions_in_search_space()/(ms->get_params().expect * ncol); nruns *= ms->get_params().oversample; nruns /= ms->get_params().undersample; cerr << "Restarts planned: " << nruns << '\n'; string archinstr(outfile); archinstr.append(".ms"); string lockstr(outfile); lockstr.append(".lock"); for(int j = 1; j <= nruns; j++) { if(j == 1 || j % 50 == 0 || search_type == SUBSET) { struct flock fl; int fd; fl.l_type = F_RDLCK; fl.l_whence = SEEK_SET; fl.l_start = 0; fl.l_len = 0; fl.l_pid = getpid(); fd = open(lockstr.c_str(), O_RDONLY); if(fd == -1) { if(errno != ENOENT) cerr << "\t\tUnable to read lock file, error was " << strerror(errno) << "\n"; } else { while(fcntl(fd, F_SETLK, &fl) == -1) { cerr << "\t\tWaiting for lock release on archive file... \n"; sleep(10); } ifstream archin(archinstr.c_str()); if(archin) { cerr << "\t\tRefreshing archive from " << archinstr << "..."; ms->get_archive().clear(); ms->get_archive().read(archin); archin.close(); cerr << "done.\n"; } fl.l_type = F_UNLCK; fcntl(fd, F_SETLK, &fl); close(fd); cerr << "\t\tArchive now has " << ms->get_archive().nmots() << " motifs\n"; } } cerr << "\t\tSearch restart #" << j << "/" << nruns << "\n"; ms->search_for_motif(worker, j, outfile); } } delete ms; return 0; }