Example #1
0
unsigned char String::startsWith( const String &s2 ) const
{
	if (len < s2.len) return 0;
	return startsWith(s2, 0);
}
Example #2
0
boolean originalData(char *symbol)
/* Return TRUE if it's not just a repackaging. */
{
return (symbol != NULL && !startsWith("wgEncodeAwg", symbol) && !startsWith("wgEncodeReg", symbol));
}
Example #3
0
static void gfQuerySeqTransTrans(int conn, struct dnaSeq *seq, 
    struct gfClump *clumps[2][3][3], 
    struct lm *lm, struct gfSeqSource **retSsList, int *retTileSize)
/* Query server for clumps where translated DNA sequence hits translated 
 * index. */
{
int qFrame, tFrame, isRc, rowSize;
struct gfClump *clump;
int tileSize = 0;
char *line;
char buf[256], *row[12];
struct gfSeqSource *ssList = NULL, *ss;

for (isRc = 0; isRc <= 1; ++isRc)
    for (qFrame = 0; qFrame<3; ++qFrame)
	for (tFrame = 0; tFrame<3; ++tFrame)
	    clumps[isRc][qFrame][tFrame] = NULL;

/* Send sequence to server. */
startSeqQuery(conn, seq, "transQuery");
line = netRecieveString(conn, buf);
if (!startsWith("Error:", line))
    {
    tileSize = findTileSize(line);

    /* Read results line by line and save in memory. */
    for (;;)
	{
	/* Read and parse first line that describes clump overall. */
	netRecieveString(conn, buf);
	if (sameString(buf, "end"))
	    {
	    break;
	    }
	else if (startsWith("Error:", buf))
	    {
	    gfServerWarn(seq, buf);
	    break;
	    }
	rowSize = chopLine(buf, row);
	if (rowSize < 9)
	    errAbort("Expecting 9 words from server got %d", rowSize);
	AllocVar(clump);
	clump->qStart = sqlUnsigned(row[0]);
	clump->qEnd = sqlUnsigned(row[1]);
	AllocVar(ss);
	ss->fileName = cloneString(row[2]);
	slAddHead(&ssList, ss);
	clump->target = ss;
	clump->tStart = sqlUnsigned(row[3]);
	clump->tEnd = sqlUnsigned(row[4]);
	clump->hitCount = sqlUnsigned(row[5]);
	isRc = ((row[6][0] == '-') ? 1 : 0);
	qFrame = sqlUnsigned(row[7]);
	tFrame = sqlUnsigned(row[8]);
	slAddHead(&clumps[isRc][qFrame][tFrame], clump);

	/* Read and parse next (long) line that describes hits. */
	clump->hitList = getHitsFromServer(conn, lm);
	assert(slCount(clump->hitList) == clump->hitCount);
	}
    for (isRc = 0; isRc <= 1; ++isRc)
	for (qFrame = 0; qFrame<3; ++qFrame)
	    for (tFrame = 0; tFrame<3; ++tFrame)
		slReverse(&clumps[isRc][qFrame][tFrame]);
    }
else
    {
    gfServerWarn(seq, buf);
    }
*retSsList = ssList;
*retTileSize = tileSize;
}
Example #4
0
File: fun.c Project: code4tots/fun
int extractString(char **stringPointer, Token *token) {
  if (startsWith(*stringPointer, "'") ||
      startsWith(*stringPointer, "r'") ||
      startsWith(*stringPointer, "\"") ||
      startsWith(*stringPointer, "r\"")) {
    int raw, stringLength;
    char quote[4], *afterFirstQuotes, *p;

    token->type = TOKEN_TYPE_STR;

    if (**stringPointer == 'r') {
      (*stringPointer)++;
      raw = 1;
    } else {
      raw = 0;
    }

    if (startsWith(*stringPointer, "'''") ||
        startsWith(*stringPointer, "\"\"\"")) {
      quote[0] = quote[1] = quote[2] = (*stringPointer)[0];
      quote[3] = '\0';
    } else {
      quote[0] = (*stringPointer)[0];
      quote[1] = '\0';
    }
    (*stringPointer) += strlen(quote);

    /* Here, we just run through the string to get the string size. */
    afterFirstQuotes = *stringPointer;
    stringLength = 0;
    while (!startsWith(*stringPointer, quote)) {
      if (!raw && **stringPointer == '\\')
        (*stringPointer) += 2;
      else
        (*stringPointer)++;
      stringLength++;
    }

    /* Now run it again, but copy over the string this time. */
    p = token->value.string = (char*) malloc(sizeof(char) * (stringLength+1));
    (*stringPointer) = afterFirstQuotes;
    while (!startsWith(*stringPointer, quote)) {
      if (!raw && **stringPointer == '\\') {
        (*stringPointer)++;
        switch (*((*stringPointer)++)) {
        case 'n':
          *p++ = '\n';
          break;
        case 't':
          *p++ = '\t';
          break;
        case '\\':
          *p++ = '\\';
          break;
        default:
          /* Error */
          return 0;
        }
      } else {
        *p++ = *((*stringPointer)++);
      }
    }
    *p = '\0';
    (*stringPointer) += strlen(quote);
    return 1;
  }
  return 0;
}
Example #5
0
void writeMdbListAsResults(struct mdbObj *mdbList, char *fileName)
/* Write selected fields in list in tab-separated result format to file. */
{
FILE *f = mustOpen(fileName, "w");
struct mdbObj *mdb;
int id = 0;
for (mdb = mdbList; mdb != NULL; mdb = mdb->next)
    {
    char *experiment = NULL;
    char *replicate = NULL;
    char *objType = NULL;
    char *fileName = NULL;
    char *md5sum = NULL;
    char *tableName = NULL;
    char *view = NULL;
    char *dateSubmitted = NULL;
    char *dateResubmitted = NULL;
    char *dateUnrestricted = NULL;
    struct mdbVar *v;
    for (v = mdb->vars; v != NULL; v = v->next)
	{
	char *var = v->var, *val = v->val;
	if (sameString(var, "expId"))
	    experiment = val;
	else if (sameString(var, "replicate"))
	    replicate = val;
	else if (sameString(var, "objType"))
	    objType = val;
	else if (sameString(var, "fileName"))
	    {
	    fileName = val;
	    /* Do surgery on file name, cutting off second comma separated index file. */
	    char *comma = strchr(fileName, ',');
	    if (comma != NULL)
	        *comma = 0;
	    }
	else if (sameString(var, "md5sum"))
	    {
	    md5sum = val;
	    char *comma = strchr(fileName, ',');
	    if (comma != NULL)
	        *comma = 0;
	    }
	else if (sameString(var, "tableName"))
	    tableName = val;
	else if (sameString(var, "view"))
	    view = val;
	else if (sameString(var, "dateSubmitted"))
	    dateSubmitted = val;
	else if (sameString(var, "dateResubmitted"))
	    dateResubmitted = val;
	else if (sameString(var, "dateUnrestricted"))
	    dateUnrestricted = val;
	}
    if (objType != NULL && !sameString(objType, "composite"))
	{
	if (experiment != NULL)
	    {
	    fprintf(f, "%d\t", ++id);
	    fprintf(f, "%s\t", emptyForNull(experiment));
	    fprintf(f, "%s\t", emptyForNull(replicate));
	    fprintf(f, "%s\t", emptyForNull(view));
	    fprintf(f, "%s\t", emptyForNull(objType));
	    fprintf(f, "%s\t", emptyForNull(fileName));
	    fprintf(f, "%s\t", emptyForNull(md5sum));
	    fprintf(f, "%s\t", emptyForNull(tableName));
	    fprintf(f, "%s\t", emptyForNull(dateSubmitted));
	    fprintf(f, "%s\t", emptyForNull(dateResubmitted));
	    fprintf(f, "%s\n", emptyForNull(dateUnrestricted));
	    }
	else
	    {
	    if (!startsWith("wgEncodeUmassWengTfbsValid", mdb->obj))	// These validation files not associated with encode experiment
		warn("No experiment for %s", mdb->obj);
	    }
	}
    }
carefulClose(&f);
}
void rWriteJson(FILE *f, struct tagStorm *storm, struct tagStanza *stanza, 
    struct ttjSubObj *obj, struct ttjSubObj *labeledObj, struct hash *schemaHash,
    struct dyString *scratch)
/* Write out json object recursively */
{
boolean isArray = allDigitNames(obj->children);
struct ttjSubObj *field; 
if (isArray)
    {
    fprintf(f, "["); 
    for (field = obj->children; field != NULL; field = field->next)
        {
	if (field != obj->children) // Only write comma separators after the first one
	   fprintf(f, ",");
	rWriteJson(f, storm, stanza, field, labeledObj, schemaHash, scratch);
	}
    fprintf(f, "]");
    }
else
    { 
    fprintf(f, "{"); 
    boolean firstOut = TRUE;

    /* Figure out if we need to attach a core object and do so.  The figuring bit is
     * frankly clunky. */
    char *objType = labeledObj->name;
    if (sameString(objType, "submitter") || sameString(objType, "contributors"))
         objType = "contact";
    else if (sameString(objType, "publications"))
         objType = "publication";
    else if (sameString(objType, "protocol"))  // protocol is actually just protocol_id
         objType = "string";
    else if (sameString(objType, "protocols")) // but protocols array is protocol
         objType = "protocol";
    else if (sameString(objType, "umi_barcode"))
         objType = "barcode";
    if (objNeedsCore(objType))
        printCore(f, objType, &firstOut);


    for (field = obj->children; field != NULL; field = field->next)
	{
	char *fieldName = field->name;
	if (field->children != NULL)
	     {
	     /* Look for funny characteristics_ as these are largely up to user. */
	     if (startsWith("characteristics_", field->name))
	         errAbort("No '.' allowed in field name after characteristics_ in %s", 
		    field->children->fullName);

	     /* If actually have data in this stanza write our field. */
	     if (prefixDotInStanza(field->fullName, stanza, scratch))
		 {
		 writeJsonTag(f, fieldName, &firstOut);
		 rWriteJson(f, storm, stanza, field, field, schemaHash, scratch);
		 }
	     }
	else
	    {
	    char *val = tagFindVal(stanza, field->fullName);
	    if (val != NULL)
		{
		boolean isNum = FALSE;
		char *schemaName = tagSchemaFigureArrayName(field->fullName, scratch);
		struct tagSchema *schema = hashFindVal(schemaHash, schemaName);
		if (schema != NULL)
		   isNum = (schema->type == '#' || schema->type == '%');
		if (sameString(fieldName, "files"))
		    {
		    writeJsonTag(f, "lanes", &firstOut);
		    writeLaneArray(f, stanza, val);
		    }
		else
		    {
		    boolean isArray = FALSE;
		    writeJsonTag(f, fieldName, &firstOut);
		    if (schema != NULL)
			isArray = schema->isArray;
		    struct slName *list = csvParse(val);
		    if (isArray)
			fputc('[', f);
		    else
			{
			if (list->next != NULL)  // more than one element
			   errAbort("Multiple vals for scalar tag %s in stanza starting line %d of %s",
				field->fullName, stanza->startLineIx, storm->fileName);
			}
		    struct slName *el;
		    for (el = list; el != NULL; el = el->next)
			{
			writeJsonVal(f, el->name, isNum);
			if (el->next != NULL)
			    fputc(',', f);
			}
		    if (isArray)
			fputc(']', f);
		    slFreeList(&list);
		    }
		}
	    }
	}
    fprintf(f, "}");
    }
}
Example #7
0
void
TUIGame::handleTestSuite(const std::string& cmd) {
    std::ifstream fr;
    int lineNo = -1;
    try {
        size_t idx = cmd.find_first_of(' ');
        if (idx == cmd.npos)
            return;
        std::string filename(cmd.substr(0, idx));
        std::string timeStr(cmd.substr(idx + 1));
        int timeLimit;
        if (!str2Num(timeStr, timeLimit)) {
            std::cout << "Error parsing number: " << timeStr << std::endl;
            return;
        }
//        std::cout << "file:" << filename << " time:" << timeStr << " (" << timeLimit << ")" << std::endl;
        fr.open(filename.c_str());
        Player& pl = whitePlayer->isHumanPlayer() ? *blackPlayer : *whitePlayer;
        if (pl.isHumanPlayer()) {
            std::cout << "No computer player available" << std::endl;
            return;
        }
        ComputerPlayer& cp = static_cast<ComputerPlayer&>(pl);
        int numRight = 0;
        int numTotal = 0;
        std::string line;
        lineNo = 0;
        while (getline(fr, line).good()) {
            lineNo++;
            if (startsWith(line, "#") || (line.length() == 0))
                continue;
            size_t idx1 = line.find(" bm ");
            if (idx1 == line.npos) {
                std::cout << "Parse error, line:" << lineNo << std::endl;
                return;
            }
            std::string fen = line.substr(0, idx1);
            size_t idx2 = line.find(";", idx1);
            if (idx2 == line.npos) {
                std::cout << "Parse error, line:" << lineNo << std::endl;
                return;
            }
            std::string bm = line.substr(idx1+4, idx2 - (idx1+4));
//            std::cout << "Line " << std::setw(3) << lineNo << ": fen:" << fen << " bm:" << bm << std::endl;
            Position testPos = TextIO::readFEN(fen);
            cp.clearTT();
            std::pair<Move, std::string> ret = cp.searchPosition(testPos, timeLimit);
            Move sm = ret.first;
            std::string PV = ret.second;
            Move m(sm);
            std::vector<std::string> answers;
            splitString(bm, answers);
            bool correct = false;
            for (size_t i = 0; i < answers.size(); i++) {
                const std::string& a = answers[i];
                Move am(TextIO::stringToMove(testPos, a));
                if (am.isEmpty())
                    throw ChessParseError("Invalid move " + a);
                if (am.equals(m)) {
                    correct = true;
                    break;
                }
            }
            if (correct)
                numRight++;
            numTotal++;
            std::cout << std::setw(3) << lineNo
                      << ' ' << std::setw(6) << TextIO::moveToString(testPos, sm, false)
                      << ' ' << std::setw(6) << sm.score()
                      << ' ' << (correct ? 1 : 0)
                      << ' ' << std::setw(3) << numRight
                      << '/' << std::setw(3) << numTotal
                      << ' ' << bm << " : " << PV << std::endl;
        }
        fr.close();
    } catch (const std::ifstream::failure& ex) {
        std::cout << "IO error: " << ex.what() << std::endl;
    } catch (const ChessParseError& cpe) {
        std::cout << "Parse error, line " << lineNo << ": " << cpe.what() << std::endl;
    }
}
Example #8
0
static int call_damapper(libmaus2::util::ArgParser const & arg, libmaus2::util::ArgInfo const & arginfo)
{
	unsigned int const damapper_arg_k = arg.uniqueArgPresent("k") ? arg.getUnsignedNumericArg<uint64_t>("k") : 20;
	         int const damapper_arg_t = arg.uniqueArgPresent("t") ? arg.getParsedArg<int>("t") : -1;
	         int const damapper_arg_M = arg.uniqueArgPresent("M") ? arg.getParsedArg<int>("M") : -1;
	double const damapper_arg_e = arg.uniqueArgPresent("e") ? arg.getParsedArg<double>("e") : std::numeric_limits<double>::min();
	         int const damapper_arg_s = arg.uniqueArgPresent("s") ? arg.getParsedArg<int>("s") : -1;
	double const damapper_arg_n = arg.uniqueArgPresent("n") ? arg.getParsedArg<double>("n") : std::numeric_limits<double>::min();
	         int const damapper_arg_B = arg.uniqueArgPresent("B") ? arg.getParsedArg<int>("B") : -1;
	         int const damapper_arg_T = arg.uniqueArgPresent("T") ? arg.getParsedArg<int>("T") : -1;
	         int const damapper_arg_b = arg.uniqueArgPresent("b") ? 1 :  0; // comp bias
	         int const damapper_arg_v = arg.uniqueArgPresent("v") ? 1 :  0; // verbose
	         int const damapper_arg_p = arg.uniqueArgPresent("p") ? 1 :  0; // repeat profile (not used)

	unsigned int const numthreads = damapper_arg_T < 0 ? 4 : damapper_arg_T;

	unsigned int const refblocksize = arg.uniqueArgPresent("refblocksize") ? arg.getUnsignedNumericArg<uint64_t>("refblocksize") : 250;
	unsigned int const readblocksize = arg.uniqueArgPresent("readblocksize") ? arg.getUnsignedNumericArg<uint64_t>("readblocksize") : 250;

	std::string const argindexdir = arg.uniqueArgPresent("I") ? arg["I"] :  std::string();
	std::string const argworkdir = arg.uniqueArgPresent("W") ? arg["W"] :  std::string();
	std::string const workdir = makeAbsolute(argworkdir.size() ? argworkdir : ".");

	mkdirP(workdir);

	unsigned int const fastacolwidth = 80;
	bool const reformatref = true;
	bool const reformatreads = true;

	std::string progname = arg.progname;
	ProgramDescriptor PD_fasta2DAM("fasta2DAM",progname);
	ProgramDescriptor PD_DBsplit("DBsplit",progname);
	ProgramDescriptor PD_HPC_damapper("HPC.damapper",progname);
	ProgramDescriptor PD_damapper("damapper",progname);
	ProgramDescriptor PD_lascat("lascat",progname);
	ProgramDescriptor PD_laschainsort("laschainsort",progname);
	ProgramDescriptor PD_lastobam("lastobam",progname);
	ProgramDescriptor PD_LAsort("LAsort",progname);
	ProgramDescriptor PD_LAcat("LAcat",progname);
	ProgramDescriptor PD_LAmerge("LAmerge",progname);

	std::vector<std::string> Vpathadd;
	Vpathadd.push_back(PD_LAsort.dir);
	Vpathadd.push_back(PD_LAcat.dir);
	Vpathadd.push_back(PD_LAmerge.dir);
	std::sort(Vpathadd.begin(),Vpathadd.end());
	Vpathadd.resize ( std::unique(Vpathadd.begin(),Vpathadd.end()) - Vpathadd.begin() );

	std::ostringstream npathstr;
	npathstr << getenv("PATH");
	for ( uint64_t i = 0; i < Vpathadd.size(); ++i )
		npathstr << ":" << Vpathadd[i];
	std::string const npath = npathstr.str();
	libmaus2::util::WriteableString Wnpath(npath);
	setenv("PATH",Wnpath.A.begin(),1 /* overwrite */);

	std::string const reffn = arg[0];

	if ( ! libmaus2::util::GetFileSize::fileExists(reffn) )
	{
		libmaus2::exception::LibMausException lme;
		lme.getStream() << "call.damapper: reference file " << reffn << " does not exist" << std::endl;
		lme.finish();
		throw lme;
	}

	static char const * faend[] = { ".fasta",".fa",0 };

	std::string const refdir = sdirname(reffn);
	std::string const indexdir = makeAbsolute(argindexdir.size() ? argindexdir : refdir);
	std::string const reffile = sbasename(reffn);
	std::string const reffileclipped = libmaus2::util::OutputFileNameTools::endClip(reffile,&faend[0]);

	mkdirP(indexdir);

	std::string const refdam = indexdir + "/"  + reffileclipped + ".dam";
	std::string const refidx = indexdir + "/." + reffileclipped + ".idx";
	std::string const refhdr = indexdir + "/." + reffileclipped + ".hdr";
	std::string const refbps = indexdir + "/." + reffileclipped + ".bps";
	std::string const indexfasta = indexdir + "/"  + reffileclipped + ".dam.fasta";

	if (
		! libmaus2::util::GetFileSize::fileExists(refdam) || libmaus2::util::GetFileSize::isOlder(refdam,reffn) ||
		! libmaus2::util::GetFileSize::fileExists(refidx) || libmaus2::util::GetFileSize::isOlder(refidx,reffn) ||
		! libmaus2::util::GetFileSize::fileExists(refhdr) || libmaus2::util::GetFileSize::isOlder(refhdr,reffn) ||
		! libmaus2::util::GetFileSize::fileExists(refbps) || libmaus2::util::GetFileSize::isOlder(refbps,reffn) ||
		! libmaus2::util::GetFileSize::fileExists(indexfasta) || libmaus2::util::GetFileSize::isOlder(indexfasta,reffn)
	)
	{
		std::string const tmpbase = arginfo.getDefaultTmpFileName();
		std::string const reffastatmp  = indexdir + "/"  + tmpbase + ".fasta";
		std::string const refdamtmp    = indexdir + "/"  + tmpbase + ".dam";
		std::string const refdamidxtmp = indexdir + "/." + tmpbase + ".idx";
		std::string const refdamhdrtmp = indexdir + "/." + tmpbase + ".hdr";
		std::string const refdambpstmp = indexdir + "/." + tmpbase + ".bps";

		libmaus2::util::TempFileRemovalContainer::addTempFile(refdamtmp);
		libmaus2::util::TempFileRemovalContainer::addTempFile(refdamidxtmp);
		libmaus2::util::TempFileRemovalContainer::addTempFile(refdamhdrtmp);
		libmaus2::util::TempFileRemovalContainer::addTempFile(refdambpstmp);
		libmaus2::util::TempFileRemovalContainer::addTempFile(reffastatmp);

		if ( reformatref )
		{
			libmaus2::fastx::FastAReader FAreader(reffn);
			libmaus2::fastx::FastAReader::pattern_type pat;
			libmaus2::aio::OutputStreamInstance::unique_ptr_type OSI(new libmaus2::aio::OutputStreamInstance(reffastatmp));
			while ( FAreader.getNextPatternUnlocked(pat) )
				pat.printMultiLine(*OSI,fastacolwidth);
			OSI->flush();
			OSI.reset();
		}
		else
		{
			if ( symlink(reffn.c_str(),reffastatmp.c_str()) )
			{
				int const error = errno;

				libmaus2::exception::LibMausException lme;
				lme.getStream() << "call.damapper: symlink(" << reffn << "," << reffastatmp << "): " << strerror(error) << std::endl;
				lme.finish();
				throw lme;
			}
		}

		std::string const fasta2DAMcom = PD_fasta2DAM.path + " " + refdamtmp + " " + reffastatmp;

		int const fasta2DAMcomres = callsystem(fasta2DAMcom.c_str());

		if ( damapper_arg_v )
			std::cerr << "[V] " << fasta2DAMcom << std::endl;

		if ( fasta2DAMcomres != 0 )
		{
			libmaus2::exception::LibMausException lme;
			lme.getStream() << "call.damapper: " << fasta2DAMcom << " failed" << std::endl;
			lme.finish();
			throw lme;
		}

		std::ostringstream splitstr;
		splitstr << PD_DBsplit.path << " -s" << refblocksize << " -x" << damapper_arg_k << " " << refdamtmp;
		std::string const splitcom = splitstr.str();

		int const splitcomres = callsystem(splitcom.c_str());

		if ( damapper_arg_v )
			std::cerr << "[V] " << splitcom << std::endl;

		if ( splitcomres != 0 )
		{
			libmaus2::exception::LibMausException lme;
			lme.getStream() << "call.damapper: " << splitcomres << " failed" << std::endl;
			lme.finish();
			throw lme;
		}

		callrename(refdamtmp,refdam);
		callrename(refdamidxtmp,refidx);
		callrename(refdamhdrtmp,refhdr);
		callrename(refdambpstmp,refbps);
		callrename(reffastatmp,indexfasta);
	}

	std::string const tmpbase = arginfo.getDefaultTmpFileName();
	std::string const readsfastatmp = workdir + "/" + tmpbase + "_reads" + ".fasta";
	std::string const readsdamtmp = workdir + "/" + tmpbase + "_reads" + ".dam";
	std::string const readsidxtmp = workdir + "/." + tmpbase + "_reads" + ".idx";
	std::string const readsbpstmp = workdir + "/." + tmpbase + "_reads" + ".bps";
	std::string const readshdrtmp = workdir + "/." + tmpbase + "_reads" + ".hdr";
	std::string const readsdamtmpscript = workdir + "/" + tmpbase + "_reads" + ".dam.script";
	std::string const readslastmp = workdir + "/" + tmpbase + "_reads" + ".las";

	libmaus2::util::TempFileRemovalContainer::addTempFile(readsfastatmp);
	libmaus2::util::TempFileRemovalContainer::addTempFile(readsdamtmp);
	libmaus2::util::TempFileRemovalContainer::addTempFile(readsidxtmp);
	libmaus2::util::TempFileRemovalContainer::addTempFile(readsbpstmp);
	libmaus2::util::TempFileRemovalContainer::addTempFile(readshdrtmp);
	libmaus2::util::TempFileRemovalContainer::addTempFile(readsdamtmpscript);
	libmaus2::util::TempFileRemovalContainer::addTempFile(readslastmp);

	libmaus2::aio::OutputStreamInstance::unique_ptr_type OSI(new libmaus2::aio::OutputStreamInstance(readsfastatmp));
	if ( reformatreads )
	{
		libmaus2::fastx::StreamFastAReaderWrapper SFAR(std::cin);
		libmaus2::fastx::StreamFastAReaderWrapper::pattern_type pat;
		while ( SFAR.getNextPatternUnlocked(pat) )
			pat.printMultiLine(*OSI,fastacolwidth);

	}
	else
	{
		libmaus2::autoarray::AutoArray<char> A(4096,false);
		while ( std::cin )
		{
			std::cin.read(A.begin(),A.size());
			uint64_t const r = std::cin.gcount();
			OSI->write(A.begin(),r);
		}
	}
	OSI->flush();
	OSI.reset();

	std::string const fasta2DAMcom = PD_fasta2DAM.path + " " + readsdamtmp + " " + readsfastatmp;

	int const fasta2DAMcomres = callsystem(fasta2DAMcom.c_str());

	if ( damapper_arg_v )
		std::cerr << "[V] " << fasta2DAMcom << std::endl;

	if ( fasta2DAMcomres != 0 )
	{
		libmaus2::exception::LibMausException lme;
		lme.getStream() << "call.damapper: " << fasta2DAMcom << " failed" << std::endl;
		lme.finish();
		throw lme;
	}

	std::ostringstream splitstr;
	splitstr << PD_DBsplit.path << " -s" << readblocksize << " -x" << damapper_arg_k << " " << readsdamtmp;
	std::string const splitcom = splitstr.str();

	int const splitcomres = callsystem(splitcom.c_str());

	if ( damapper_arg_v )
		std::cerr << "[V] " << splitcom << std::endl;

	if ( splitcomres != 0 )
	{
		libmaus2::exception::LibMausException lme;
		lme.getStream() << "call.damapper: " << splitcomres << " failed" << std::endl;
		lme.finish();
		throw lme;
	}

	std::string const calldir = getCurrentDir();
	if ( chdir(workdir.c_str()) )
	{
		int const error = errno;
		libmaus2::exception::LibMausException lme;
		lme.getStream() << "call.damapper: chdir(" << workdir << "): " << strerror(error) << std::endl;
		lme.finish();
		throw lme;
	}

	std::ostringstream HPC1str;
	HPC1str << PD_HPC_damapper.path;

	HPC1str << " -k" << damapper_arg_k;
	if ( damapper_arg_t != -1 )
		HPC1str << " -t" << damapper_arg_t;
	if ( damapper_arg_M != -1 )
		HPC1str << " -M" << damapper_arg_M;
	if ( damapper_arg_e != std::numeric_limits<double>::min() )
		HPC1str << " -e" << damapper_arg_e;
	if ( damapper_arg_s != -1 )
		HPC1str << " -s" << damapper_arg_s;
	if ( damapper_arg_n != std::numeric_limits<double>::min() )
		HPC1str << " -n" << damapper_arg_n;
	if ( damapper_arg_B != -1 )
		HPC1str << " -B" << damapper_arg_B;
	HPC1str << " -T" << numthreads;
	if ( damapper_arg_b )
		HPC1str << " -b";
	if ( damapper_arg_v )
		HPC1str << " -v";
	if ( damapper_arg_p )
		HPC1str << " -p";

	HPC1str << " -C -N " << refdam << " " << readsdamtmp << " >" << readsdamtmpscript;
	std::string const HPC1 = HPC1str.str();

	int const HPC1res = system(HPC1.c_str());

	if ( damapper_arg_v )
		std::cerr << "[V] " << HPC1 << std::endl;

	if ( HPC1res != 0 )
	{
		libmaus2::exception::LibMausException lme;
		lme.getStream() << "call.damapper: " << HPC1 << " failed" << std::endl;
		lme.finish();
		throw lme;
	}

	std::vector<std::string> Voutput;
	std::vector<std::string> Vdamapper;
	libmaus2::aio::InputStreamInstance::unique_ptr_type HPCisi(new libmaus2::aio::InputStreamInstance(readsdamtmpscript));
	std::string const exp = "# Catenate jobs (2)";
	std::string const expdamapper = "# Damapper jobs (1)";
	std::string const expsub = "LAsort -a ";
	std::string const expcheck = "# Check all .las files (optional but recommended)";
	std::string const expchecksub = "LAcheck -vS ";

	bool activedamapper = false;
	bool activeoutput = false;
	bool activationfound = false;
	bool activationdamapperfound = false;

	while ( *HPCisi )
	{
		std::string line;
		std::getline(*HPCisi,line);

		// std::cerr << line << std::endl;

		if ( line.size() )
		{
			if ( line[0] == '#' )
			{
				activeoutput = false;
				activedamapper = false;

				if ( line == expcheck )
				{
					activeoutput = true;
					activationfound = true;
				}
				else if ( line == expdamapper )
				{
					activedamapper = true;
					activationdamapperfound = true;
				}
			}
			else if ( activeoutput )
			{
				if (
					line.size() >= expchecksub.size()
					&&
					line.substr(0,expchecksub.size()) == expchecksub
				)
				{
					line = line.substr(expchecksub.size());

					std::vector<std::string> tokens;
					uint64_t l = 0;
					while ( l < line.size() )
					{
						while ( l < line.size() && ::std::isspace(static_cast<unsigned char>(line[l])) )
							++l;

						uint64_t h = l;
						while ( h < line.size() && ! ::std::isspace(static_cast<unsigned char>(line[h])) )
							++h;

						if ( h > l )
						{
							tokens.push_back(line.substr(l,h-l));
							// std::cerr << "token " << tokens.back() << std::endl;
						}

						l = h;
					}

					if ( tokens.size() == 3 )
					{
						Voutput.push_back(tokens[2] + ".las");
					}
					else
					{
						libmaus2::exception::LibMausException lme;
						lme.getStream() << "call.damapper: cannot understand line " << line << std::endl;
						lme.finish();
						throw lme;
					}
				}
				else
				{
					libmaus2::exception::LibMausException lme;
					lme.getStream() << "call.damapper: cannot understand line " << line << std::endl;
					lme.finish();
					throw lme;
				}
			}
			else if ( activedamapper )
			{
				if ( startsWith(line,"damapper ") )
				{
					line = line.substr(std::string("damapper ").size());
					line = PD_damapper.path + " " + line;
					Vdamapper.push_back(line);
				}
				else
				{
					libmaus2::exception::LibMausException lme;
					lme.getStream() << "call.damapper: cannot understand line " << line << std::endl;
					lme.finish();
					throw lme;
				}
			}
		}
	}
	HPCisi.reset();

	if ( ! activationfound )
	{
		libmaus2::exception::LibMausException lme;
		lme.getStream() << "call.damapper: activation line for cat jobs not found" << std::endl;
		lme.finish();
		throw lme;
	}
	if ( ! activationdamapperfound )
	{
		libmaus2::exception::LibMausException lme;
		lme.getStream() << "call.damapper: activation line for damapper not found" << std::endl;
		lme.finish();
		throw lme;
	}

	for ( uint64_t i = 0; i < Voutput.size(); ++i )
		libmaus2::util::TempFileRemovalContainer::addTempFile(Voutput[i]);

	/* call damapper */
	for ( uint64_t i = 0; i < Vdamapper.size(); ++i )
	{
		int const damapperret = callsystem(Vdamapper[i].c_str());

		if ( damapper_arg_v )
			std::cerr << "[V] " << Vdamapper[i] << std::endl;

		if ( damapperret != 0 )
		{
			libmaus2::exception::LibMausException lme;
			lme.getStream() << "call.damapper: damapper call failed" << std::endl;
			lme.finish();
			throw lme;
		}
	}

	/* concatenate all output .las files */
	std::ostringstream catostr;
	catostr << PD_laschainsort.path << " -sba " << readslastmp;
	for ( uint64_t i = 0; i < Voutput.size(); ++i )
	{
		catostr << " " << Voutput[i];
	}
	std::string const catcom = catostr.str();

	if ( damapper_arg_v )
		std::cerr << "[V] " << catcom << std::endl;

	if ( system(catcom.c_str()) != 0 )
	{
		libmaus2::exception::LibMausException lme;
		lme.getStream() << "call.damapper: laschainsort call " << catcom << " failed" << std::endl;
		lme.finish();
		throw lme;
	}

	for ( uint64_t i = 0; i < Voutput.size(); ++i )
		::remove(Voutput[i].c_str());

	/* convert .las file to BAM */
	std::ostringstream lastobamstr;
	lastobamstr << PD_lastobam.path << " -t" << numthreads << " -snone " << refdam << " " << indexfasta << " " << readsdamtmp << " " << readsfastatmp << " " << readslastmp;
	std::string const lastobamcom = lastobamstr.str();

	if ( damapper_arg_v )
		std::cerr << "[V] " << lastobamcom << std::endl;

	if ( system(lastobamcom.c_str()) != 0 )
	{
		libmaus2::exception::LibMausException lme;
		lme.getStream() << "call.damapper: lastobam call " << lastobamcom << " failed" << std::endl;
		lme.finish();
		throw lme;
	}

	if ( chdir(calldir.c_str()) )
	{
		int const error = errno;
		libmaus2::exception::LibMausException lme;
		lme.getStream() << "call.damapper: chdir(" << calldir << "): " << strerror(error) << std::endl;
		lme.finish();
		throw lme;
	}


	return EXIT_SUCCESS;
}
Example #9
0
void processline(char *line) {
    int rc;
    int async = ((line[0] == 'a') && !(startsWith(line, "addauth ")));
    if (async) {
        line++;
    }
    if (startsWith(line, "help")) {
      fprintf(stderr, "    create [+[e|s]] <path>\n");
      fprintf(stderr, "    delete <path>\n");
      fprintf(stderr, "    set <path> <data>\n");
      fprintf(stderr, "    get <path>\n");
      fprintf(stderr, "    ls <path>\n");
      fprintf(stderr, "    sync <path>\n");
      fprintf(stderr, "    exists <path>\n");
      fprintf(stderr, "    myid\n");
      fprintf(stderr, "    verbose\n");
      fprintf(stderr, "    addauth <id> <scheme>\n");
      fprintf(stderr, "    quit\n");
      fprintf(stderr, "\n");
      fprintf(stderr, "    prefix the command with the character 'a' to run the command asynchronously.\n");
      fprintf(stderr, "    run the 'verbose' command to toggle verbose logging.\n");
      fprintf(stderr, "    i.e. 'aget /foo' to get /foo asynchronously\n");
    } else if (startsWith(line, "verbose")) {
      if (verbose) {
        verbose = 0;
        zoo_set_debug_level(ZOO_LOG_LEVEL_WARN);
        fprintf(stderr, "logging level set to WARN\n");
      } else {
        verbose = 1;
        zoo_set_debug_level(ZOO_LOG_LEVEL_DEBUG);
        fprintf(stderr, "logging level set to DEBUG\n");
      }
    } else if (startsWith(line, "get ")) {
        line += 4;
        if (line[0] != '/') {
            fprintf(stderr, "Path must start with /, found: %s\n", line);
            return;
        }
        gettimeofday(&startTime, 0);
        rc = zoo_aget(zh, line, 1, my_data_completion, strdup(line));
        if (rc) {
            fprintf(stderr, "Error %d for %s\n", rc, line);
        }
    } else if (startsWith(line, "set ")) {
        char *ptr;
        line += 4;
        if (line[0] != '/') {
            fprintf(stderr, "Path must start with /, found: %s\n", line);
            return;
        }
        ptr = strchr(line, ' ');
        if (!ptr) {
            fprintf(stderr, "No data found after path\n");
            return;
        }
        *ptr = '\0';
        ptr++;
        if (async) {
            rc = zoo_aset(zh, line, ptr, strlen(ptr), -1, my_stat_completion,
                    strdup(line));
        } else {
            struct Stat stat;
            rc = zoo_set2(zh, line, ptr, strlen(ptr), -1, &stat);
        }
        if (rc) {
            fprintf(stderr, "Error %d for %s\n", rc, line);
        }
    } else if (startsWith(line, "ls ")) {
        line += 3;
        if (line[0] != '/') {
            fprintf(stderr, "Path must start with /, found: %s\n", line);
            return;
        }
        gettimeofday(&startTime, 0);
        rc= zoo_aget_children(zh, line, 1, my_strings_completion, strdup(line));
        if (rc) {
            fprintf(stderr, "Error %d for %s\n", rc, line);
        }
    } else if (startsWith(line, "create ")) {
        int flags = 0;
        line += 7;
        if (line[0] == '+') {
            line++;
            if (line[0] == 'e') {
                flags |= ZOO_EPHEMERAL;
                line++;
            }
            if (line[0] == 's') {
                flags |= ZOO_SEQUENCE;
                line++;
            }
            line++;
        }
        if (line[0] != '/') {
            fprintf(stderr, "Path must start with /, found: %s\n", line);
            return;
        }
        fprintf(stderr, "Creating [%s] node\n", line);
//        {
//            struct ACL _CREATE_ONLY_ACL_ACL[] = {{ZOO_PERM_CREATE, ZOO_ANYONE_ID_UNSAFE}};
//            struct ACL_vector CREATE_ONLY_ACL = {1,_CREATE_ONLY_ACL_ACL};
//            rc = zoo_acreate(zh, line, "new", 3, &CREATE_ONLY_ACL, flags,
//                    my_string_completion, strdup(line));
//        }
        rc = zoo_acreate(zh, line, "new", 3, &ZOO_OPEN_ACL_UNSAFE, flags,
                my_string_completion, strdup(line));
        if (rc) {
            fprintf(stderr, "Error %d for %s\n", rc, line);
        }
    } else if (startsWith(line, "delete ")) {
        line += 7;
        if (line[0] != '/') {
            fprintf(stderr, "Path must start with /, found: %s\n", line);
            return;
        }
        if (async) {
            rc = zoo_adelete(zh, line, -1, my_void_completion, strdup(line));
        } else {
            rc = zoo_delete(zh, line, -1);
        }
        if (rc) {
            fprintf(stderr, "Error %d for %s\n", rc, line);
        }
    } else if (startsWith(line, "sync ")) {
        line += 5;
        if (line[0] != '/') {
            fprintf(stderr, "Path must start with /, found: %s\n", line);
            return;
        }
        rc = zoo_async(zh, line, my_string_completion, strdup(line));
        if (rc) {
            fprintf(stderr, "Error %d for %s\n", rc, line);
        }
    } else if (startsWith(line, "exists ")) {
        line += 7;
        if (line[0] != '/') {
            fprintf(stderr, "Path must start with /, found: %s\n", line);
            return;
        }
#ifndef THREADED
        rc = zoo_aexists(zh, line, 1, my_stat_completion, strdup(line));
#else
        struct Stat stat;
        rc = zoo_exists(zh, line, 1, &stat);
#endif
        if (rc) {
            fprintf(stderr, "Error %d for %s\n", rc, line);
        }
    } else if (strcmp(line, "myid") == 0) {
        printf("session Id = %llx\n", _LL_CAST_ zoo_client_id(zh)->client_id);
    } else if (strcmp(line, "reinit") == 0) {
        zookeeper_close(zh);
        // we can't send myid to the server here -- zookeeper_close() removes 
        // the session on the server. We must start anew.
        zh = zookeeper_init(hostPort, watcher, 30000, 0, 0, 0);
    } else if (startsWith(line, "quit")) {
        fprintf(stderr, "Quitting...\n");
        shutdownThisThing=1;
    } else if (startsWith(line, "od")) {
        const char val[]="fire off";
        fprintf(stderr, "Overdosing...\n");
        rc = zoo_aset(zh, "/od", val, sizeof(val)-1, -1, od_completion, 0);
        if (rc)
            fprintf(stderr, "od command failed: %d\n", rc);
    } else if (startsWith(line, "addauth ")) {
      line += 8;
      char *ptr;
      ptr = strchr(line, ' ');
      if (ptr) {
        *ptr = '\0';
        ptr++;
      }
      zoo_add_auth(zh, line, ptr, ptr ? strlen(ptr)-1 : 0, NULL, NULL);
    }
}
Example #10
0
void readOneOut(char *rmskFile)
/* Read .out file rmskFile, check each line, and print OK lines to .tab. */
{
    struct lineFile *lf;
    char *line, *words[24];
    int lineSize, wordCount;

    /* Open .out file and process header. */
    lf = lineFileOpen(rmskFile, TRUE);
    if (!lineFileNext(lf, &line, &lineSize))
        errAbort("Empty %s", lf->fileName);
    if (!startsWith("   SW  perc perc", line))
    {
        if (!startsWith("   SW   perc perc", line))
            errAbort("%s doesn't seem to be a RepeatMasker .out file, first "
                     "line seen:\n%s", lf->fileName, line);
    }
    lineFileNext(lf, &line, &lineSize);
    lineFileNext(lf, &line, &lineSize);

    /* Process line oriented records of .out file. */
    while (lineFileNext(lf, &line, &lineSize))
    {
        static struct rmskOut r;
        char *s;

        wordCount = chopLine(line, words);
        if (wordCount < 14)
            errAbort("Expecting 14 or 15 words line %d of %s",
                     lf->lineIx, lf->fileName);
        r.swScore = atoi(words[0]);
        r.milliDiv = makeMilli(words[1], lf);
        r.milliDel = makeMilli(words[2], lf);
        r.milliIns = makeMilli(words[3], lf);
        r.genoName = words[4];
        r.genoStart = atoi(words[5])-1;
        r.genoEnd = atoi(words[6]);
        r.genoLeft = parenSignInt(words[7], lf);
        r.strand[0]  = (words[8][0] == '+' ? '+' : '-');
        r.repName = words[9];
        r.repClass = words[10];
        char *repClassTest = cloneString(r.repClass);
        stripChar(repClassTest, '(');
        stripChar(repClassTest, ')');
        int nonDigitCount = countLeadingNondigits(repClassTest);
        int wordOffset = 0;
        // this repClass is only digits, (or only (digits) with surrounding parens)
        //   this is the sign of an empty field here
        // due to custom library in use that has no class/family indication
        if (0 == nonDigitCount)
        {
            wordOffset = 1;
            r.repClass = cloneString("Unspecified");
            r.repFamily = cloneString("Unspecified");
        }
        else
        {
            s = strchr(r.repClass, '/');
            if (s == NULL)
                r.repFamily = r.repClass;
            else
            {
                *s++ = 0;
                r.repFamily = s;
            }
        }
        r.repStart = parenSignInt(words[11-wordOffset], lf);
        r.repEnd = atoi(words[12-wordOffset]);
        r.repLeft = parenSignInt(words[13-wordOffset], lf);
        r.id[0] = ((wordCount > (14-wordOffset)) ? words[14-wordOffset][0] : ' ');
        if (checkRepeat(&r, lf))
        {
            FILE *f = getFileForChrom(r.genoName);
            if (!noBin)
                fprintf(f, "%u\t", hFindBin(r.genoStart, r.genoEnd));
            rmskOutTabOut(&r, f);
        }
    }
}
void hgGoldGapGl(char *database, char *gsDir, char *ooSubDir, boolean doGl, char *oneChrom)
/* hgGoldGapGl - Put chromosome .agp and .gl files into browser database.. */
{
    struct fileInfo *chrFiList, *chrFi;
    struct sqlConnection *conn = NULL;
    char ooDir[512];
    char pathName[512];
    struct hash *cloneVerHash = newHash(0);
    boolean gotAny = FALSE;
    struct hash *chromDirHash = newHash(4);
    char *chromLst = optionVal("chromLst", NULL);

    if (! noLoad)
        conn = sqlConnect(database);

    verbose(2,"#\tcomplete gold, gap and .gl files produced\n");

    if (chromLst != NULL)
    {
        struct lineFile *clf = lineFileOpen(chromLst, TRUE);
        char *row[1];
        while (lineFileRow(clf, row))
        {
            hashAdd(chromDirHash, row[0], NULL);
        }
        lineFileClose(&clf);
    }

    sprintf(ooDir, "%s/%s", gsDir, ooSubDir);
    /* target prefix is used in zoo browser */
    if (oneChrom != NULL && (startsWith("chr", oneChrom) || startsWith("target", oneChrom)))
        oneChrom += 3;


    if (doGl)
    {
        sprintf(pathName, "%s/ffa/sequence.inf", gsDir);
        makeCloneVerHash(pathName, cloneVerHash);
    }

    chrFiList = listDirX(ooDir, "*", FALSE);
    for (chrFi = chrFiList; chrFi != NULL; chrFi = chrFi->next)
    {
        if (chrFi->isDir &&
                ((strlen(chrFi->name) <= 2) || startsWith("NA_", chrFi->name) ||
                 (NULL != hashLookup(chromDirHash, chrFi->name))))
        {
            if (oneChrom == NULL || sameWord(chrFi->name, oneChrom))
            {
                sprintf(pathName, "%s/%s", ooDir, chrFi->name);
                makeGoldAndGap(conn, pathName);
                if (doGl)
                    makeGl(conn, pathName, cloneVerHash);
                gotAny = TRUE;
                uglyf("done %s\n", chrFi->name);
            }
        }
    }
    slFreeList(&chrFiList);
    if (! noLoad)
        sqlDisconnect(&conn);
    hashFree(&chromDirHash);
    if (!gotAny)
        errAbort("No contig agp and gold files found");
}
	Bool isCommandQuit(char * cmd){
		return startsWith("quit" , cmd);
	}
std::vector<DictionaryAttribute> DictionaryStructure::getAttributes(
	const Poco::Util::AbstractConfiguration & config, const std::string & config_prefix,
	const bool hierarchy_allowed, const bool allow_null_values)
{
	Poco::Util::AbstractConfiguration::Keys keys;
	config.keys(config_prefix, keys);
	auto has_hierarchy = false;

	std::vector<DictionaryAttribute> attributes;

	for (const auto & key : keys)
	{
		if (!startsWith(key.data(), "attribute"))
			continue;

		const auto prefix = config_prefix + '.' + key + '.';

		const auto name = config.getString(prefix + "name");
		const auto type_string = config.getString(prefix + "type");
		const auto type = DataTypeFactory::instance().get(type_string);
		const auto underlying_type = getAttributeUnderlyingType(type_string);

		const auto expression = config.getString(prefix + "expression", "");
		if (!expression.empty())
			has_expressions = true;

		Field null_value;
		if (allow_null_values)
		{
			const auto null_value_string = config.getString(prefix + "null_value");
			try
			{
				ReadBufferFromString null_value_buffer{null_value_string};
				ColumnPtr column_with_null_value = type->createColumn();
				type->deserializeTextEscaped(*column_with_null_value, null_value_buffer);
				null_value = (*column_with_null_value)[0];
			}
			catch (const std::exception & e)
			{
				throw Exception{
					std::string{"Error parsing null_value: "} + e.what(),
					ErrorCodes::BAD_ARGUMENTS};
			}
		}

		const auto hierarchical = config.getBool(prefix + "hierarchical", false);
		const auto injective = config.getBool(prefix + "injective", false);
		if (name.empty())
			throw Exception{
				"Properties 'name' and 'type' of an attribute cannot be empty",
				ErrorCodes::BAD_ARGUMENTS};

		if (has_hierarchy && !hierarchy_allowed)
			throw Exception{
				"Hierarchy not allowed in '" + prefix,
				ErrorCodes::BAD_ARGUMENTS};

		if (has_hierarchy && hierarchical)
			throw Exception{
				"Only one hierarchical attribute supported",
				ErrorCodes::BAD_ARGUMENTS};

		has_hierarchy = has_hierarchy || hierarchical;

		attributes.emplace_back(DictionaryAttribute{
			name, underlying_type, type, expression, null_value, hierarchical, injective
		});
	}

	return attributes;
}
bool DefaultGdbServerProviderFactory::canRestore(const QVariantMap &data) const
{
    const auto id = idFromMap(data);
    return id.startsWith(QLatin1String(Constants::DEFAULT_PROVIDER_ID)
                         + QLatin1Char(':'));
}
Example #15
0
void autoUpgradeTableAddSessionKey(struct sqlConnection *conn, char *tableName)
/* Try to upgrade the table by adding sessionKey field
 * in a safe way handling success failures and retries
 * with multiple CGIs running. */
{

boolean testAgain = checkAutoUpgradeTableResultTimeIsOld(tableName);
if (testAgain)
    {
    // Get the advisory lock for this table
    // This prevents multiple CGI processes from trying to upgrade simultaneously
    char lockName[256];
    safef(lockName, sizeof lockName, "AUTO_UPGRADE_%s", tableName);
    sqlGetLock(conn, lockName);

    // Make sure that the table has not been already upgraded by some earlier process.
    // We do not want to upgrade more than once.
    if (sqlFieldIndex(conn, tableName, "sessionKey") == -1)
	{

	char result[4096];

	// Put a catch around the table upgrade attempt,
	// both to allow us to continue if it fails,
	// and to catch the error message and save it in the results file
	struct errCatch *errCatch = errCatchNew();
	if (errCatchStart(errCatch))
	    { 
	    char query[256];
	    sqlSafef(query, sizeof query, "alter table %s add column sessionKey varchar(255) NOT NULL default ''", tableName);
	    sqlUpdate(conn, query);
	    }
	errCatchEnd(errCatch);
	if (errCatch->gotError)
	    {
	    safef(result, sizeof result, "AUTOUPGRADE FAILED\n%s", errCatch->message->string);
	    }
	else
	    {
	    safef(result, sizeof result, "OK\n");
	    }

	errCatchFree(&errCatch);

	writeAutoUpgradeTableResult(tableName, result);

	}

    // Release the advisory lock for this table
    sqlReleaseLock(conn, lockName);

    }
else
    {  // in the interests of speed, just use the old result
    char *oldResult = readAutoUpgradeTableResult(tableName);
    if (oldResult)
	{
	if (startsWith("AUTOUPGRADE FAILED", oldResult))
	    {
	    // cannot do this here since it is too early and the warn handler does not work right
	    // it ends up writing html and javascript before the cookie and response header have even been finished.
	    // warn("%s", oldResult);  
	    // instead, save the error message for access later from select places like hgGateway
	    if (!dyUpgradeError)
		dyUpgradeError = dyStringNew(256);
	    else
		dyStringPrintf(dyUpgradeError,"\n");
	    dyStringPrintf(dyUpgradeError,"%s", oldResult);
	    }
	}
    }

}
Example #16
0
int main( int argc, const char** argv )
{
  std::string filename;
  std::string configFile = "";
  bool outputJson = false;
  int seektoms = 0;
  bool detectRegion = false;
  std::string templateRegion;
  std::string country;
  int topn;

  TCLAP::CmdLine cmd("OpenAlpr Command Line Utility", ' ', Alpr::getVersion());

  TCLAP::UnlabeledValueArg<std::string>  fileArg( "image_file", "Image containing license plates", false, "", "image_file_path"  );

  
  TCLAP::ValueArg<std::string> countryCodeArg("c","country","Country code to identify (either us for USA or eu for Europe).  Default=us",false, "us" ,"country_code");
  TCLAP::ValueArg<int> seekToMsArg("","seek","Seek to the specied millisecond in a video file. Default=0",false, 0 ,"integer_ms");
  TCLAP::ValueArg<std::string> configFileArg("","config","Path to the openalpr.conf file",false, "" ,"config_file");
  TCLAP::ValueArg<std::string> templateRegionArg("t","template_region","Attempt to match the plate number against a region template (e.g., md for Maryland, ca for California)",false, "" ,"region code");
  TCLAP::ValueArg<int> topNArg("n","topn","Max number of possible plate numbers to return.  Default=10",false, 10 ,"topN");

  TCLAP::SwitchArg jsonSwitch("j","json","Output recognition results in JSON format.  Default=off", cmd, false);
  TCLAP::SwitchArg detectRegionSwitch("d","detect_region","Attempt to detect the region of the plate image.  Default=off", cmd, false);
  TCLAP::SwitchArg clockSwitch("","clock","Measure/print the total time to process image and all plates.  Default=off", cmd, false);

  try
  {
    cmd.add( templateRegionArg );
    cmd.add( seekToMsArg );
    cmd.add( topNArg );
    cmd.add( configFileArg );
    cmd.add( fileArg );
    cmd.add( countryCodeArg );

    
    if (cmd.parse( argc, argv ) == false)
    {
      // Error occured while parsing.  Exit now.
      return 1;
    }

    filename = fileArg.getValue();

    country = countryCodeArg.getValue();
    seektoms = seekToMsArg.getValue();
    outputJson = jsonSwitch.getValue();
    configFile = configFileArg.getValue();
    detectRegion = detectRegionSwitch.getValue();
    templateRegion = templateRegionArg.getValue();
    topn = topNArg.getValue();
    measureProcessingTime = clockSwitch.getValue();
  }
  catch (TCLAP::ArgException &e)    // catch any exceptions
  {
    std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl;
    return 1;
  }

  
  cv::Mat frame;

  Alpr alpr(country, configFile);
  alpr.setTopN(topn);

  if (detectRegion)
    alpr.setDetectRegion(detectRegion);

  if (templateRegion.empty() == false)
    alpr.setDefaultRegion(templateRegion);

  if (alpr.isLoaded() == false)
  {
    std::cerr << "Error loading OpenALPR" << std::endl;
    return 1;
  }

  if (filename.empty())
  {
    std::string filename;
    while (std::getline(std::cin, filename))
    {
      if (fileExists(filename.c_str()))
      {
	frame = cv::imread( filename );
	detectandshow( &alpr, frame, "", outputJson);
      }
      else
      {
	std::cerr << "Image file not found: " << filename << std::endl;
      }

    }
  }
  else if (filename == "webcam")
  {
    int framenum = 0;
    cv::VideoCapture cap(0);
    if (!cap.isOpened())
    {
      std::cout << "Error opening webcam" << std::endl;
      return 1;
    }

    while (cap.read(frame))
    {
      detectandshow(&alpr, frame, "", outputJson);
      cv::waitKey(1);
      framenum++;
    }
  }
  else if (startsWith(filename, "http://") || startsWith(filename, "https://"))
  {
    int framenum = 0;
    
    VideoBuffer videoBuffer;
    
    videoBuffer.connect(filename, 5);
    
    cv::Mat latestFrame;
    
    while (program_active)
    {
      int response = videoBuffer.getLatestFrame(&latestFrame);
      
      if (response != -1)
      {
        detectandshow( &alpr, latestFrame, "", outputJson);
      }
      
      cv::waitKey(10);
    }
    
    videoBuffer.disconnect();
    
    std::cout << "Video processing ended" << std::endl;
  }
  else if (hasEndingInsensitive(filename, ".avi") || hasEndingInsensitive(filename, ".mp4") || hasEndingInsensitive(filename, ".webm") || 
	   hasEndingInsensitive(filename, ".flv") || hasEndingInsensitive(filename, ".mjpg") || hasEndingInsensitive(filename, ".mjpeg"))
  {
    if (fileExists(filename.c_str()))
    {
      int framenum = 0;

      cv::VideoCapture cap=cv::VideoCapture();
      cap.open(filename);
      cap.set(CV_CAP_PROP_POS_MSEC, seektoms);

      while (cap.read(frame))
      {
        if (SAVE_LAST_VIDEO_STILL)
        {
          cv::imwrite(LAST_VIDEO_STILL_LOCATION, frame);
        }
        std::cout << "Frame: " << framenum << std::endl;

        detectandshow( &alpr, frame, "", outputJson);
        //create a 1ms delay
        cv::waitKey(1);
        framenum++;
      }
    }
    else
    {
      std::cerr << "Video file not found: " << filename << std::endl;
    }
  }
  else if (hasEndingInsensitive(filename, ".png") || hasEndingInsensitive(filename, ".jpg") || 
	   hasEndingInsensitive(filename, ".jpeg") || hasEndingInsensitive(filename, ".gif"))
  {
    if (fileExists(filename.c_str()))
    {
      frame = cv::imread( filename );

      detectandshow( &alpr, frame, "", outputJson);
    }
    else
    {
      std::cerr << "Image file not found: " << filename << std::endl;
    }
  }
  else if (DirectoryExists(filename.c_str()))
  {
    std::vector<std::string> files = getFilesInDir(filename.c_str());

    std::sort( files.begin(), files.end(), stringCompare );

    for (int i = 0; i< files.size(); i++)
    {
      if (hasEndingInsensitive(files[i], ".jpg") || hasEndingInsensitive(files[i], ".png"))
      {
        std::string fullpath = filename + "/" + files[i];
        std::cout << fullpath << std::endl;
        frame = cv::imread( fullpath.c_str() );
        if (detectandshow( &alpr, frame, "", outputJson))
        {
          //while ((char) cv::waitKey(50) != 'c') { }
        }
        else
        {
          //cv::waitKey(50);
        }
      }
    }
  }
  else
  {
    std::cerr << "Unknown file type" << std::endl;
    return 1;
  }

  return 0;
}
Example #17
0
int main(int argc, char *argv[])
{
    RedditUserLogged *user = NULL;
    char *subreddit = NULL;
    char *password = NULL, *username = NULL;
    optParser parser;

    DEBUG_START(DEBUG_FILE, DEBUG_FILENAME);

    memset(&parser, 0, sizeof(optParser));

    parser.argc = argc;
    parser.argv = argv;

    optAddOptions (&parser, mainOptions, MOPT_ARG_COUNT);

    handleArguments(&parser);

    if (mainOptions[MOPT_HELP].isSet) {
        displayHelp(&parser);
        return 0;
    }

    optClearParser(&parser);

    setlocale(LC_CTYPE, "");


    initscr();
    raw();//We want character for character input
    keypad(stdscr,1);//Enable extra keys like arrowkeys
    noecho();
    start_color();
    use_default_colors();
    init_pair(1, -1, -1);
    init_pair(2, COLOR_BLACK, COLOR_WHITE);

    DEBUG_PRINT(L"Starting...\n");

    /* Start libreddit */
    redditGlobalInit();

    globalState = redditStateNew();

    globalState->userAgent = redditCopyString("cReddit/0.0.1");

    redditStateSet(globalState);

    if (mainOptions[MOPT_USERNAME].isSet) {
        username = mainOptions[MOPT_USERNAME].svalue;
        if (!mainOptions[MOPT_PASSWORD].isSet)
            password = getPassword();
        else
            password = mainOptions[MOPT_PASSWORD].svalue;

        user = redditUserLoggedNew();
        redditUserLoggedLogin(user, username, password);

        /* Don't want to leave that important Reddit password in memory */
        memset(password, 0, strlen(password));
        if (!mainOptions[MOPT_PASSWORD].isSet)
            free(password);
    }
    if (mainOptions[MOPT_SUBREDDIT].isSet) {
        subreddit = mainOptions[MOPT_SUBREDDIT].svalue;
        if (!startsWith("/r/", subreddit) && strcmp("/", subreddit) != 0)
            prepend("/r/", subreddit);

    } else {
        subreddit = "/";
    }
    showSubreddit(subreddit);

    redditUserLoggedFree(user);
    redditStateFree(globalState);
    redditGlobalCleanup();
    endwin();

    DEBUG_END(DEBUG_FILE);
    return 0;
}
Example #18
0
/** scan the makefile -nd output */
static void GraphScan(GraphPtr graph,TargetPtr root,FILE* in)
	{
	char* line=NULL;
	char* makefile_name=NULL;
	while((line=readline(in))!=NULL)
		{
		 if(startsWith(line,"Considering target file"))
		        {
		        char* tName=targetName(line);
		        if(!graph->show_root && 
		           makefile_name!=NULL &&
		           strcmp(tName,makefile_name)==0)
		        	{
		        	free(tName);
		        	free(line);
		        	//skip lines
		        	while((line=readline(in))!=NULL)
		        		{
		        		if(startsWith(line,"Finished prerequisites of target file "))
						{
						tName=targetName(line);
						free(line);
						if(strcmp(tName,makefile_name)==0)
							{
							free(tName);
							break;
							}
						free(tName);
						continue;
						}
					free(line);
					}
		        	continue;
		        	} 

		        TargetPtr child=GraphGetTarget(graph,tName);

		        free(tName);

		        TargetAddChildren(root,child);
		        GraphScan(graph,child,in);

		        }
		    else if(startsWith(line,"Must remake target "))
			     {
			     char* tName=targetName(line);
			     GraphGetTarget(graph,tName)->must_remake=1;
			     free(tName);
			     }
		    else if(startsWith(line,"Pruning file "))
			     {
			     char* tName=targetName(line);
			     TargetAddChildren(root,GraphGetTarget(graph,tName));
			     free(tName);
			     }
/*		    else if(startsWith(line,"Finished prerequisites of target file "))
			{
			char* tName=targetName(line);
			if(strcmp(tName,root->name)!=0)
				 {
				 fprintf(stderr,"expected %s got %s\n", root->name , line);
				 exit(EXIT_FAILURE);
				 }
			free(tName);
			free(line);
			break;
			}*/
		    else if(startsWith(line,"Reading makefile "))
			{
			free(makefile_name);
			makefile_name=targetName(line);
			}
		       
		free(line);
		}
	free(makefile_name);
	}
Example #19
0
File: strlib.c Project: cs50/spl
static void testStartsWith(void) {
   test(startsWith("start", ""), true);
   test(startsWith("start", "star"), true);
   test(startsWith("start", "start"), true);
   test(startsWith("start", "startx"), false);
}
char *scanSettingsForCT(char *userName, char *sessionName, char *contents,
			int *pLiveCount, int *pExpiredCount)
/* Parse the CGI-encoded session contents into {var,val} pairs and search
 * for custom tracks.  If found, refresh the custom track.  Parsing code 
 * taken from cartParseOverHash. 
 * If any nonexistent custom track files are found, return a SQL update
 * command that will remove those from this session.  We can't just do 
 * the update here because that messes up the caller's query. */
{
int contentLength = strlen(contents);
struct dyString *newContents = dyStringNew(contentLength+1);
struct dyString *oneSetting = dyStringNew(contentLength / 4);
char *updateIfAny = NULL;
char *contentsToChop = cloneString(contents);
char *namePt = contentsToChop;
verbose(3, "Scanning %s %s\n", userName, sessionName);
while (isNotEmpty(namePt))
    {
    char *dataPt = strchr(namePt, '=');
    char *nextNamePt;
    if (dataPt == NULL)
	errAbort("Mangled session content string %s", namePt);
    *dataPt++ = 0;
    nextNamePt = strchr(dataPt, '&');
    if (nextNamePt != NULL)
	*nextNamePt++ = 0;
    dyStringClear(oneSetting);
    dyStringPrintf(oneSetting, "%s=%s%s",
		   namePt, dataPt, (nextNamePt ? "&" : ""));
    if (startsWith(CT_FILE_VAR_PREFIX, namePt))
	{
	boolean thisGotLiveCT = FALSE, thisGotExpiredCT = FALSE;
	cgiDecode(dataPt, dataPt, strlen(dataPt));
	verbose(3, "Found variable %s = %s\n", namePt, dataPt);
	/* If the file does not exist, omit this setting from newContents so 
	 * it doesn't get copied from session to session.  If it does exist,
	 * leave it up to customFactoryTestExistence to parse the file for 
	 * possible customTrash table references, some of which may exist 
	 * and some not. */
	if (! fileExists(dataPt))
	    {
	    verbose(3, "Removing %s from %s %s\n", oneSetting->string,
		    userName, sessionName);
	    thisGotExpiredCT = TRUE;
	    }
	else
	    {
	    char *db = namePt + strlen(CT_FILE_VAR_PREFIX);
	    dyStringAppend(newContents, oneSetting->string);
	    customFactoryTestExistence(db, dataPt,
				       &thisGotLiveCT, &thisGotExpiredCT);
	    }
	if (thisGotLiveCT && pLiveCount != NULL)
	    (*pLiveCount)++;
	if (thisGotExpiredCT && pExpiredCount != NULL)
	    (*pExpiredCount)++;
	if (thisGotExpiredCT)
	    {
	    if (verboseLevel() >= 3)
		verbose(3, "Found expired custom track in %s %s: %s\n",
			userName, sessionName, dataPt);
	    else
		verbose(2, "Found expired custom track: %s\n", dataPt);
	    }
	if (thisGotLiveCT)
	    verbose(4, "Found live custom track: %s\n", dataPt);
	}
    else
	dyStringAppend(newContents, oneSetting->string);
    namePt = nextNamePt;
    }
if (newContents->stringSize != contentLength)
    {
    struct dyString *update = dyStringNew(contentLength*2);
    if (newContents->stringSize > contentLength)
	errAbort("Uh, why is newContents (%d) longer than original (%d)??",
		 newContents->stringSize, contentLength);
    dyStringPrintf(update, "UPDATE %s set contents='", savedSessionTable);
    dyStringAppendN(update, newContents->string, newContents->stringSize);
    dyStringPrintf(update, "', lastUse=now(), useCount=useCount+1 "
		   "where userName=\"%s\" and sessionName=\"%s\";",
		   userName, sessionName);
    verbose(3, "Removing one or more dead CT file settings from %s %s "
	    "(original length %d, now %d)\n", 
	    userName, sessionName,
	    contentLength, newContents->stringSize);
    updateIfAny = dyStringCannibalize(&update);
    }
dyStringFree(&oneSetting);
dyStringFree(&newContents);
freeMem(contentsToChop);
return updateIfAny;
}
Example #21
0
 void Command::htmlHelp(stringstream& ss) const {
     string helpStr;
     {
         stringstream h;
         help(h);
         helpStr = h.str();
     }
     ss << "\n<tr><td>";
     bool web = _webCommands->count(name) != 0;
     if( web ) ss << "<a href=\"/" << name << "?text=1\">";
     ss << name;
     if( web ) ss << "</a>";
     ss << "</td>\n";
     ss << "<td>";
     int l = locktype();
     //if( l == NONE ) ss << "N ";
     if( l == READ ) ss << "R ";
     else if( l == WRITE ) ss << "W ";
     if( slaveOk() )
         ss << "S ";
     if( adminOnly() )
         ss << "A";
     ss << "</td>";
     ss << "<td>";
     if( helpStr != "no help defined" ) {
         const char *p = helpStr.c_str();
         while( *p ) {
             if( *p == '<' ) {
                 ss << "&lt;";
                 p++; continue;
             }
             else if( *p == '{' )
                 ss << "<code>";
             else if( *p == '}' ) {
                 ss << "}</code>";
                 p++;
                 continue;
             }
             if( strncmp(p, "http:", 5) == 0 ) {
                 ss << "<a href=\"";
                 const char *q = p;
                 while( *q && *q != ' ' && *q != '\n' )
                     ss << *q++;
                 ss << "\">";
                 q = p;
                 if( startsWith(q, "http://www.mongodb.org/display/") )
                     q += 31;
                 while( *q && *q != ' ' && *q != '\n' ) {
                     ss << (*q == '+' ? ' ' : *q);
                     q++;
                     if( *q == '#' )
                         while( *q && *q != ' ' && *q != '\n' ) q++;
                 }
                 ss << "</a>";
                 p = q;
                 continue;
             }
             if( *p == '\n' ) ss << "<br>";
             else ss << *p;
             p++;
         }
     }
     ss << "</td>";
     ss << "</tr>\n";
 }
void printStackTrace(std::ostream& out) {
    // constructing the following object jumps into fancy code in call_stack_gcc/windows.cpp
    // to rebuild the stack trace; implementation differs for each operating system
    stacktrace::call_stack trace;
    std::vector<stacktrace::entry> entries = trace.stack;
    
    // get longest line string length to line up stack traces
    void* fakeStackPtr = stacktrace::getFakeCallStackPointer();
    int entriesToShowCount = 0;
    int funcNameLength = 0;
    int lineStrLength = 0;
    for (size_t i = 0; i < entries.size(); ++i) {
        // remove references to std:: namespace
        stringReplaceInPlace(entries[i].function, "std::", "");
        
        // remove template arguments
        while (stringContains(entries[i].function, "<") && stringContains(entries[i].function, ">")) {
            int lessThan = stringIndexOf(entries[i].function, "<");
            int greaterThan = stringIndexOf(entries[i].function, ">", lessThan);
            if (lessThan >= 0 && greaterThan > lessThan) {
                entries[i].function.erase(lessThan, greaterThan - lessThan + 1);
            }
        }
        
        if (!STACK_TRACE_SHOULD_FILTER || !shouldFilterOutFromStackTrace(entries[i].function)) {
            lineStrLength = std::max(lineStrLength, (int) entries[i].lineStr.length());
            funcNameLength = std::max(funcNameLength, (int) entries[i].function.length());
            entriesToShowCount++;
        }
    }
    
    if (entries.empty() || entriesToShowCount == 0) {
        return;   // couldn't get a stack trace, or had no useful data  :-(
    }
    
    if (lineStrLength > 0) {
        out << " *** Stack trace (line numbers are approximate):" << std::endl;
        if (STACK_TRACE_SHOW_TOP_BOTTOM_BARS) {
            out << " *** "
                      << std::setw(lineStrLength) << std::left
                      << "file:line" << "  " << "function" << std::endl;
            out << " *** "
                      << std::string(lineStrLength + 2 + funcNameLength, '=') << std::endl;
        }
    } else {
        out << " *** Stack trace:" << std::endl;
    }
    
    for (size_t i = 0; i < entries.size(); ++i) {
        stacktrace::entry entry = entries[i];
        entry.file = getTail(entry.file);
        
        // skip certain entries for clarity
        if (STACK_TRACE_SHOULD_FILTER && shouldFilterOutFromStackTrace(entry.function)) {
            continue;
        }
        
        // show Main() as main() to hide hidden case-change by Stanford C++ lib internals
        if (startsWith(entry.function, "Main(")) {
            entry.function.replace(0, 5, "main(");
        }
        
        std::string lineStr = "";
        if (!entry.lineStr.empty()) {
            lineStr = entry.lineStr;
        } else if (entry.line > 0) {
            lineStr = "line " + integerToString(entry.line);
        }
        
        out << " *** " << std::left << std::setw(lineStrLength) << lineStr
                  << "  " << entry.function << std::endl;
        
        // don't show entries beneath the student's main() function, for simplicity
        if (entry.function == "main()") {
            break;
        }
    }
    if (entries.size() == 1 && entries[0].address == fakeStackPtr) {
        out << " *** (partial stack due to crash)" << std::endl;
    }

    if (STACK_TRACE_SHOW_TOP_BOTTOM_BARS && lineStrLength > 0) {
        out << " *** "
                  << std::string(lineStrLength + 2 + funcNameLength, '=') << std::endl;
    }
    
//    out << " ***" << std::endl;
//    out << " *** NOTE:" << std::endl;
//    out << " *** Any line numbers listed above are approximate." << std::endl;
//    out << " *** To learn more about why the program crashed, we" << std::endl;
//    out << " *** suggest running your program under the debugger." << std::endl;
    
    out << " ***" << std::endl;
}
bool VmhConfig::readFromFile(const char *filename)
{
    char *line = NULL;
    FILE *fp = fopen(filename,"r");
    if (fp == NULL) {
        // perror(filename);
        return false;
    }
    while ((line = fgets(linebuf,4095,fp)) != NULL) {
        while ((*line == ' ') || (*line == '\t'))
            line++;
        trim(line);

        if (startsWith(line,"#"))
            continue;
        else if (startsWith(line,"type="))
            strncpy(serverType,line + 5,255);
        else if (startsWith(line,"host="))
            strncpy(serverHost,line + 5,255);
        else if (startsWith(line,"user="))
            strncpy(serverUser,line + 5,31);
        else if (startsWith(line,"username="))
            strncpy(serverUser,line + 9,31);
        else if (startsWith(line,"pass="))
            strncpy(serverPass,line + 5,31);
        else if (startsWith(line,"password="))
            strncpy(serverPass,line + 9,31);
        else if (startsWith(line,"guestuser="))
            strncpy(guestUser,line + 10,31);
        else if (startsWith(line,"guestpass="))
            strncpy(guestPass,line + 10,31);
        else if (startsWith(line,"guesttype=")) {
            initGuest(guestTypes + guestTypeCount,line + 10);
            guestTypeCount++;
        } else if (startsWith(line,"installer="))
            strncpy(guestTypes[guestTypeCount - 1].installPackage,line + 10,511);
        else if (startsWith(line,"uninstall="))
            strncpy(guestTypes[guestTypeCount - 1].uninstallCommand,line + 10,511);
        else if (startsWith(line,"uninstallArgs="))
            strncpy(guestTypes[guestTypeCount - 1].uninstallArgs,line + 14,511);
        else if (startsWith(line,"tag="))
            strncpy(guestTypes[guestTypeCount - 1].hostTag,line + 4,255);
        else if (startsWith(line,"halokey="))
            strncpy(halokey,line + 8,255);
    }
    fclose(fp);
    return true;
}
Example #24
0
void featureBits(char *database, int tableCount, char *tables[])
/* featureBits - Correlate tables via bitmap projections and booleans. */
{
struct sqlConnection *conn = NULL;
char *bedName = optionVal("bed", NULL), *faName = optionVal("fa", NULL);
char *binName = optionVal("bin", NULL);
char *bedRegionInName = optionVal("bedRegionIn", NULL);
char *bedRegionOutName = optionVal("bedRegionOut", NULL);
FILE *bedFile = NULL, *faFile = NULL, *binFile = NULL;
FILE *bedRegionOutFile = NULL;
struct bed *bedRegionList = NULL;
boolean faIndependent = FALSE;
struct chromInfo *cInfo;

if (bedName)
    bedFile = mustOpen(bedName, "w");
if (binName)
    binFile = mustOpen(binName, "w");
if ((bedRegionInName && !bedRegionOutName) || (!bedRegionInName && bedRegionOutName))
    errAbort("bedRegionIn and bedRegionOut must both be specified");
if (faName)
    {
    boolean faMerge = optionExists("faMerge");
    faFile = mustOpen(faName, "w");
    if (tableCount > 1)
        {
	if (!faMerge)
	    errAbort("For fa output of multiple tables you must use the "
	             "faMerge option");
	}
    faIndependent = (!faMerge);
    }

if (chromSizes != NULL)
    chromInfoList = chromInfoLoadAll(chromSizes);
else
    chromInfoList = fbCreateChromInfoList(clChrom, database);

if (!countGaps)
    conn = hAllocConn(database);
checkInputExists(conn, database, chromInfoList, tableCount, tables);

if (!faIndependent)
    {
    double totalBases = 0, totalBits = 0;
    int firstTableBits = 0, secondTableBits = 0;
    int *pFirstTableBits = NULL, *pSecondTableBits = NULL;
    double totalFirstBits = 0, totalSecondBits = 0;
    static int dotClock = 1;

    if (calcEnrichment)
        {
	pFirstTableBits = &firstTableBits;
	pSecondTableBits = &secondTableBits;
	}
    if (bedRegionInName)
	{
	struct lineFile *lf = lineFileOpen(bedRegionInName, TRUE);
	struct bed *bed;
	char *row[3];
	
	bedRegionOutFile = mustOpen(bedRegionOutName, "w");
	while (lineFileRow(lf, row))
	    {
	    if (startsWith(row[0],"#")||startsWith(row[0],"chrom"))
		continue;
	    bed = bedLoad3(row);
	    slAddHead(&bedRegionList, bed);
	    }
	lineFileClose(&lf);
	slReverse(&bedRegionList);
	}
    for (cInfo = chromInfoList; cInfo != NULL; cInfo = cInfo->next)
	{
	if (inclChrom(cInfo->chrom))
	    {
	    int chromBitSize;
	    int chromSize = cInfo->size;
	    verbose(3,"chromFeatureBits(%s)\n", cInfo->chrom);
	    chromFeatureBits(conn, database, cInfo->chrom, tableCount, tables,
		bedFile, faFile, binFile, bedRegionList, bedRegionOutFile, 
		chromSize, &chromBitSize, pFirstTableBits, pSecondTableBits
		);
	    totalBases += countBases(conn, cInfo->chrom, chromSize, database);
	    totalBits += chromBitSize;
	    totalFirstBits += firstTableBits;
	    totalSecondBits += secondTableBits;
	    if (dots > 0)
		{
		if (--dotClock <= 0)
		    {
		    fputc('.', stdout);
		    fflush(stdout);
		    dotClock = dots;
		    }
		}
	    }
	}
	if (dots > 0)
	    {
	    fputc('\n', stdout);
	    fflush(stdout);
	    }
    if (calcEnrichment)
        fprintf(stderr,"%s %5.3f%%, %s %5.3f%%, both %5.3f%%, cover %4.2f%%, enrich %4.2fx\n",
		tables[0], 
		100.0 * totalFirstBits/totalBases,
		tables[1],
		100.0 * totalSecondBits/totalBases,
		100.0 * totalBits/totalBases,
		100.0 * totalBits / totalFirstBits,
		(totalBits/totalSecondBits) / (totalFirstBits/totalBases) );
    else
	fprintf(stderr,"%1.0f bases of %1.0f (%4.3f%%) in intersection\n",
	    totalBits, totalBases, 100.0*totalBits/totalBases);
    }
else
    {
    int totalItems = 0;
    double totalBases = 0;
    int itemCount, baseCount;
    for (cInfo = chromInfoList; cInfo != NULL; cInfo = cInfo->next)
        {
	if (inclChrom(cInfo->chrom))
	    {
	    chromFeatureSeq(conn, database, cInfo->chrom, tables[0],
		    bedFile, faFile, &itemCount, &baseCount);
	    totalBases += countBases(conn, cInfo->chrom, baseCount, database);
	    totalItems += itemCount;
	    }
	}
    }
hFreeConn(&conn);
}
void addBacEndInfo(char *spFile)
/* Add BAC end info from Shiaw-Pyng's file to clones in cloneHash. */
{
struct lineFile *lf = lineFileOpen(spFile, TRUE);
char *line;
int lineSize, wordCount;
int spCount = 0;
char *words[16];

while (lineFileNext(lf, &line, &lineSize))
    {
    char *s, *e, c;
    struct clone *clone;
    struct endInfo *end;
    char *firstWord;
    char *contig;

    if (line[0] == '#')
       continue;
    wordCount = chopLine(line, words);
    if (wordCount == 0)
        continue;
    firstWord = words[0];
    s = strchr(firstWord, '.');
    if (s == NULL)
	errAbort("Expecting dot line %d of %s\n", lf->lineIx, lf->fileName);
    *s++ = 0;
    if ((clone = hashFindVal(cloneHash, firstWord)) == NULL)
	{
	warn("%s in %s but not .finf files", firstWord, spFile);
	continue;
	}
    if (!startsWith("Contig", s))
	errAbort("Expecting .Contig line %d of %s\n", lf->lineIx, lf->fileName);
    s += 6;
    contig = s;
    if (wordCount == 1)
	{
	/* Older style - just one word. */
	e = strrchr(contig, '.');
	if (e == NULL)
	    errAbort("Expecting last dot line %d of %s\n", lf->lineIx, lf->fileName);
	*e++ = 0;
	AllocVar(end);
	subChar(s, '.', '_');
	end->contig = cloneString(contig);
	end->text = cloneString(e);
	c = lastChar(end->text);
	if (!(c == 'L' || c == 'R'))
	    c = '?';
	end->lr = c;
	slAddHead(&clone->spList, end);
	++spCount;
	}
    else if (wordCount == 15)
        {
	/* Newer style - 15 words. */
	if (!sameWord(words[11], "total_repeats"))
	    {
	    AllocVar(end);
	    end->contig = cloneString(contig);
	    end->text = cloneString(words[2]);
	    c = words[3][0];
	    if (!(c == 'L' || c == 'R'))
		c = '?';
	    end->lr = c;
	    slAddHead(&clone->spList, end);
	    ++spCount;
	    }
	}
    else
        {
	lineFileExpectWords(lf, 15, wordCount);
	}
    }
lineFileClose(&lf);
printf("Info on %d ends in %s\n", spCount, spFile);
}
Example #26
0
File: init.c Project: wynney/robovm
static void parseArg(char* arg, Options* options) {
    if (startsWith(arg, "log=trace")) {
        if (options->logLevel == 0) options->logLevel = LOG_LEVEL_TRACE;
    } else if (startsWith(arg, "log=debug")) {
        if (options->logLevel == 0) options->logLevel = LOG_LEVEL_DEBUG;
    } else if (startsWith(arg, "log=info")) {
        if (options->logLevel == 0) options->logLevel = LOG_LEVEL_INFO;
    } else if (startsWith(arg, "log=warn")) {
        if (options->logLevel == 0) options->logLevel = LOG_LEVEL_WARN;
    } else if (startsWith(arg, "log=error")) {
        if (options->logLevel == 0) options->logLevel = LOG_LEVEL_ERROR;
    } else if (startsWith(arg, "log=fatal")) {
        if (options->logLevel == 0) options->logLevel = LOG_LEVEL_FATAL;
    } else if (startsWith(arg, "log=silent")) {
        if (options->logLevel == 0) options->logLevel = LOG_LEVEL_SILENT;
    } else if (startsWith(arg, "mx") || startsWith(arg, "ms")) {
        char* unit;
        jlong n = strtol(&arg[2], &unit, 10);
        if (n > 0) {
            if (unit[0] != '\0') {
                switch (unit[0]) {
                case 'g':
                case 'G':
                    n *= 1024 * 1024 * 1024;
                    break;
                case 'm':
                case 'M':
                    n *= 1024 * 1024;
                    break;
                case 'k':
                case 'K':
                    n *= 1024;
                    break;
                }
            }
        }
        if (startsWith(arg, "mx")) {
            options->maxHeapSize = n;
        } else {
            options->initialHeapSize = n;
        }
    } else if (startsWith(arg, "MainClass=")) {
        if (!options->mainClass) {
            char* s = strdup(&arg[10]);
            jint j;
            for (j = 0; s[j] != 0; j++) {
                if (s[j] == '.') s[j] = '/';
            }
            options->mainClass = s;
        }
    } else if (startsWith(arg, "EnableGCHeapStats")) {
        options->enableGCHeapStats = TRUE;
    } else if (startsWith(arg, "EnableHooks")) {
        options->enableHooks = TRUE;
    } else if (startsWith(arg, "WaitForResume")) {
        options->waitForResume = TRUE;
        options->enableHooks = TRUE; // WaitForResume also enables hooks
    } else if (startsWith(arg, "PrintPID=")) {
        options->printPID = TRUE;
        if (!options->pidFile) {
            char* s = strdup(&arg[9]);
            options->pidFile = s;
        }
    } else if (startsWith(arg, "PrintPID")) {
        options->printPID = TRUE;
    } else if (startsWith(arg, "PrintDebugPort=")) {
        options->printDebugPort = TRUE;
        if (!options->debugPortFile) {
            char* s = strdup(&arg[15]);
            options->debugPortFile = s;
        }
    } else if (startsWith(arg, "PrintDebugPort")) {
        options->printDebugPort = TRUE;
    } else if (startsWith(arg, "D")) {
        char* s = strdup(&arg[1]);
        // Split the arg string on the '='. 'key' will have the
        // part on the left and 's' will have the value on the right
        char* key = strsep(&s, "=");

        SystemProperty* property = calloc(1, sizeof(SystemProperty));
        property->key = key;
        property->value = s;
        DL_APPEND(options->properties, property);
    }
}
Example #27
0
OSMAND_CORE_UTILS_API bool OSMAND_CORE_UTILS_CALL OsmAnd::Voyager::parseCommandLineArguments( const QStringList& cmdLineArgs, Configuration& cfg, QString& error )
{
    bool wasObfRootSpecified = false;
    bool wasRouterConfigSpecified = false;
    for(auto itArg = cmdLineArgs.begin(); itArg != cmdLineArgs.end(); ++itArg)
    {
        auto arg = *itArg;
        if (arg.startsWith("-config="))
        {
            QFile configFile(arg.mid(strlen("-config=")));
            if(!configFile.exists())
            {
                error = "Router configuration file does not exist";
                return false;
            }
            configFile.open(QIODevice::ReadOnly | QIODevice::Text);
            if(!RoutingConfiguration::parseConfiguration(&configFile, *cfg.routingConfig.get()))
            {
                error = "Bad router configuration";
                return false;
            }
            configFile.close();
            wasRouterConfigSpecified = true;
        }
        else if (arg == "-verbose")
        {
            cfg.verbose = true;
        }
        else if (arg == "-xml")
        {
            cfg.generateXml = true;
        }
        else if (arg == "-recalc")
        {
            cfg.doRecalculate = true;
        }
        else if (arg.startsWith("-obfsDir="))
        {
            QDir obfRoot(arg.mid(strlen("-obfsDir=")));
            if(!obfRoot.exists())
            {
                error = "OBF directory does not exist";
                return false;
            }
            Utilities::findFiles(obfRoot, QStringList() << "*.obf", cfg.obfs);
            wasObfRootSpecified = true;
        }
        else if (arg.startsWith("-vehicle="))
        {
            cfg.vehicle = arg.mid(strlen("-vehicle="));
        }
        else if (arg.startsWith("-memlimit="))
        {
            bool ok;
            cfg.memoryLimit = arg.mid(strlen("-memlimit=")).toInt(&ok);
            if(!ok || cfg.memoryLimit < 0)
            {
                error = "Bad memory limit";
                return false;
            }
        }
        else if (arg.startsWith("-start="))
        {
            auto coords = arg.mid(strlen("-start=")).split(QChar(';'));
            cfg.startLatitude = coords[0].toDouble();
            cfg.startLongitude = coords[1].toDouble();
        }
        else if (arg.startsWith("-waypoint="))
        {
            auto coords = arg.mid(strlen("-waypoint=")).split(QChar(';'));
            auto latitude = coords[0].toDouble();
            auto longitude = coords[1].toDouble();
            cfg.waypoints.push_back(std::pair<double, double>(latitude, longitude));
        }
        else if (arg.startsWith("-end="))
        {
            auto coords = arg.mid(strlen("-end=")).split(QChar(';'));
            cfg.endLatitude = coords[0].toDouble();
            cfg.endLongitude = coords[1].toDouble();
        }
        else if (arg == "-left")
        {
            cfg.leftSide = true;
        }
        else if (arg.startsWith("-gpx="))
        {
            cfg.gpxPath = arg.mid(strlen("-gpx="));
        }
    }

    if(!wasObfRootSpecified)
        Utilities::findFiles(QDir::current(), QStringList() << "*.obf", cfg.obfs);
    if(cfg.obfs.isEmpty())
    {
        error = "No OBF files loaded";
        return false;
    }
    if(!wasRouterConfigSpecified)
        RoutingConfiguration::loadDefault(*cfg.routingConfig);
    
    return true;
}
Example #28
0
    //
    // system warnings
    //
    void show_warnings() {
        // each message adds a leading and a trailing newline

        bool warned = false;
        {
            const char * foo = strchr( versionString , '.' ) + 1;
            int bar = atoi( foo );
            if ( ( 2 * ( bar / 2 ) ) != bar ) {
                log() << startupWarningsLog;
                log() << "** NOTE: This is a development version (" << versionString << ") of MongoDB." << startupWarningsLog;
                log() << "**       Not recommended for production." << startupWarningsLog;
                warned = true;
            }
        }

        if ( sizeof(int*) == 4 ) {
            log() << startupWarningsLog;
            log() << "** NOTE: This is a 32 bit MongoDB binary." << startupWarningsLog;
            log() << "**       32 bit builds are limited to less than 2GB of data (or less with --journal)." << startupWarningsLog;
            if( !cmdLine.dur ) { 
                log() << "**       Note that journaling defaults to off for 32 bit and is currently off." << startupWarningsLog;
            }
            log() << "**       See http://dochub.mongodb.org/core/32bit" << startupWarningsLog;
            warned = true;
        }

        if ( !ProcessInfo::blockCheckSupported() ) {
            log() << startupWarningsLog;
            log() << "** NOTE: your operating system version does not support the method that MongoDB" << startupWarningsLog;
            log() << "**       uses to detect impending page faults." << startupWarningsLog;
            log() << "**       This may result in slower performance for certain use cases" << startupWarningsLog;
            warned = true;
        }
#ifdef __linux__
        if (boost::filesystem::exists("/proc/vz") && !boost::filesystem::exists("/proc/bc")) {
            log() << startupWarningsLog;
            log() << "** WARNING: You are running in OpenVZ. This is known to be broken!!!" << startupWarningsLog;
            warned = true;
        }

        if (boost::filesystem::exists("/sys/devices/system/node/node1")){
            // We are on a box with a NUMA enabled kernel and more than 1 numa node (they start at node0)
            // Now we look at the first line of /proc/self/numa_maps
            //
            // Bad example:
            // $ cat /proc/self/numa_maps
            // 00400000 default file=/bin/cat mapped=6 N4=6
            //
            // Good example:
            // $ numactl --interleave=all cat /proc/self/numa_maps
            // 00400000 interleave:0-7 file=/bin/cat mapped=6 N4=6

            std::ifstream f("/proc/self/numa_maps", std::ifstream::in);
            if (f.is_open()) {
                char line[100]; //we only need the first line
                f.getline(line, sizeof(line));
                if (f.fail()) {
                    warning() << "failed to read from /proc/self/numa_maps: "
                              << errnoWithDescription() << startupWarningsLog;
                    warned = true;
                }
                else {
                    // just in case...
                    line[98] = ' ';
                    line[99] = '\0';
                    
                    // skip over pointer
                    const char* space = strchr(line, ' ');
                    
                    if ( ! space ) {
                        log() << startupWarningsLog;
                        log() << "** WARNING: cannot parse numa_maps" << startupWarningsLog;
                        warned = true;
                    }
                    else if ( ! startsWith(space+1, "interleave") ) {
                        log() << startupWarningsLog;
                        log() << "** WARNING: You are running on a NUMA machine." << startupWarningsLog;
                        log() << "**          We suggest launching mongod like this to avoid performance problems:" << startupWarningsLog;
                        log() << "**              numactl --interleave=all mongod [other options]" << startupWarningsLog;
                        warned = true;
                    }
                }
            }
        }

        if (cmdLine.dur){
            fstream f ("/proc/sys/vm/overcommit_memory", ios_base::in);
            unsigned val;
            f >> val;

            if (val == 2) {
                log() << startupWarningsLog;
                log() << "** WARNING: /proc/sys/vm/overcommit_memory is " << val << startupWarningsLog;
                log() << "**          Journaling works best with it set to 0 or 1" << startupWarningsLog;
            }
        }
Example #29
0
void
HT_WriteOutAsBookmarks1 (RDF rdf, PRFileDesc *fp, RDF_Resource u, RDF_Resource top, int indent)
{
    RDF_Cursor c = RDF_GetSources(rdf, u, gCoreVocab->RDF_parent, RDF_RESOURCE_TYPE, true);
    RDF_Resource next;
    char *date, *name, *url;
    int loop;

    if (c == NULL) return;
    if (u == top) {
      name = RDF_GetResourceName(rdf, u);
      ht_rjcprintf(fp, "<!DOCTYPE NETSCAPE-Bookmark-file-1>\n", NULL);
      ht_rjcprintf(fp, "<!-- This is an automatically generated file.\n", NULL);
      ht_rjcprintf(fp, "It will be read and overwritten.\n", NULL);
      ht_rjcprintf(fp, "Do Not Edit! -->\n", NULL);

      ht_rjcprintf(fp, "<TITLE>%s</TITLE>\n", (name) ? name:"");
      ht_rjcprintf(fp, "<H1>%s</H1>\n<DL><p>\n", (name) ? name:"");
    }
    while (next = RDF_NextValue(c)) {

      url = resourceID(next);
      if (containerp(next) && (!startsWith("ftp:",url)) && (!startsWith("file:",url))
	    && (!startsWith("IMAP:", url)) && (!startsWith("nes:", url))
	    && (!startsWith("mail:", url)) && (!startsWith("cache:", url))
	    && (!startsWith("ldap:", url))) {
		for (loop=0; loop<indent; loop++)	ht_rjcprintf(fp, "    ", NULL);

		date = numericDate(resourceID(next));
		ht_rjcprintf(fp, "<DT><H3 ADD_DATE=\"%s\">", (date) ? date:"");
		if (date) freeMem(date);
		name = RDF_GetResourceName(rdf, next);
		ht_rjcprintf(fp, "%s</H3>\n", name);

		for (loop=0; loop<indent; loop++)	ht_rjcprintf(fp, "    ", NULL);
		ht_rjcprintf(fp, "<DL><p>\n", NULL);
		HT_WriteOutAsBookmarks1(rdf, fp, next, top, indent+1);

		for (loop=0; loop<indent; loop++)	ht_rjcprintf(fp, "    ", NULL);

		ht_rjcprintf(fp, "</DL><p>\n", NULL);
      }
      else if (isSeparator(next)) {
	for (loop=0; loop<indent; loop++)	ht_rjcprintf(fp, "    ", NULL);
	ht_rjcprintf(fp, "<HR>\n", NULL);
      }
      else {
	char* bkAddDate = (char*)RDF_GetSlotValue(rdf, next, 
						  gNavCenter->RDF_bookmarkAddDate, 
						  RDF_STRING_TYPE, false, true);

        for (loop=0; loop<indent; loop++)	ht_rjcprintf(fp, "    ", NULL);

	ht_rjcprintf(fp, "<DT><A HREF=\"%s\" ", resourceID(next));
	date = numericDate(bkAddDate);
	ht_rjcprintf(fp, "ADD_DATE=\"%s\" ", (date) ? date: "");
	if (date) freeMem(date);
	ht_rjcprintf(fp, "LAST_VISIT=\"%s\" ", resourceLastVisitDate(rdf, next));
	ht_rjcprintf(fp, "LAST_MODIFIED=\"%s\">", resourceLastModifiedDate(rdf, next));
	ht_rjcprintf(fp, "%s</A>\n", RDF_GetResourceName(rdf, next));

	if (resourceDescription(rdf, next) != NULL) {
	  ht_rjcprintf(fp, "<DD>%s\n", resourceDescription(rdf, next));
	}
      }
    }
    RDF_DisposeCursor(c);
    if (u == top) {
      ht_rjcprintf(fp, "</DL>\n", NULL);
    }
}