Пример #1
0
void CallLinkStatus::dump(PrintStream& out) const
{
    if (!isSet()) {
        out.print("Not Set");
        return;
    }
    
    CommaPrinter comma;
    
    if (m_isProved)
        out.print(comma, "Statically Proved");
    
    if (m_couldTakeSlowPath)
        out.print(comma, "Could Take Slow Path");
    
    if (m_isBasedOnStub)
        out.print(comma, "Based On Stub");
    
    if (!m_variants.isEmpty())
        out.print(comma, listDump(m_variants));
    
    if (m_maxNumArguments)
        out.print(comma, "maxNumArguments = ", m_maxNumArguments);
}
Пример #2
0
void Config::process(int argc, char* argv[])
{
    processCommandLineArguments(argc-1, argv+1);
    if (isSet("config")) {
        string path;
        get("config", path);

        ifstream f(path.c_str());
        if (!f) {
            cerr << "Failed to open config file " << path << endl;
            return;
        }

        while (f) {
            string str;
            getline(f, str);
            boost::trim(str);
            if (str[0] == '#') continue;
            if (str.empty()) continue;
            processArgument(str.c_str());
        }
    }
    processEnvArguments();
}
Пример #3
0
void CallLinkStatus::dump(PrintStream& out) const
{
    if (!isSet()) {
        out.print("Not Set");
        return;
    }
    
    CommaPrinter comma;
    
    if (m_isProved)
        out.print(comma, "Statically Proved");
    
    if (m_couldTakeSlowPath)
        out.print(comma, "Could Take Slow Path");
    
    if (m_callTarget)
        out.print(comma, "Known target: ", m_callTarget);
    
    if (m_executable)
        out.print(comma, "Executable/CallHash: ", RawPointer(m_executable), "/", m_executable->hashFor(CodeForCall));
    
    if (m_structure)
        out.print(comma, "Structure: ", RawPointer(m_structure));
}
Пример #4
0
void UserConnection::on(BufferedSocketListener::Line, const string& aLine) throw () {

	COMMAND_DEBUG(aLine, DebugManager::TYPE_CLIENT, DebugManager::INCOMING, getRemoteIp());
	
	if(aLine.length() < 2) {
		fire(UserConnectionListener::ProtocolError(), this, "Invalid data"); // TODO: translate
		return;
	}

	if(aLine[0] == 'C' && !isSet(FLAG_NMDC)) {
		if(!Text::validateUtf8(aLine)) {
			fire(UserConnectionListener::ProtocolError(), this, "Non-UTF-8 data in an ADC connection");  // TODO: translate
			return;
		}
		dispatch(aLine);
		return;
	} else if(aLine[0] == '$') {
		setFlag(FLAG_NMDC);
	} else {
		// We shouldn't be here?
		fire(UserConnectionListener::ProtocolError(), this, "Invalid data");  // TODO: translate
		return;
	}

	string cmd;
	string param;

	string::size_type x;
                
	if( (x = aLine.find(' ')) == string::npos) {
		cmd = aLine.substr(1);
	} else {
		cmd = aLine.substr(1, x - 1);
		param = aLine.substr(x+1);
    }
    
	if(cmd == "MyNick") {
		if(!param.empty())
			fire(UserConnectionListener::MyNick(), this, param);
	} else if(cmd == "Direction") {
		x = param.find(" ");
		if(x != string::npos) {
			fire(UserConnectionListener::Direction(), this, param.substr(0, x), param.substr(x+1));
		}
	} else if(cmd == "Error") {
		if(Util::stricmp(param.c_str(), FILE_NOT_AVAILABLE) == 0 ||
			param.rfind(/*path/file*/" no more exists") != string::npos) { 
    		fire(UserConnectionListener::FileNotAvailable(), this);
    	} else {
			fire(UserConnectionListener::ProtocolError(), this, param);
	    }
	} else if(cmd == "GetListLen") {
    	fire(UserConnectionListener::GetListLength(), this);
	} else if(cmd == "Get") {
		x = param.find('$');
		if(x != string::npos) {
			fire(UserConnectionListener::Get(), this, Text::toUtf8(param.substr(0, x), encoding), Util::toInt64(param.substr(x+1)) - (int64_t)1);
	    }
	} else if(cmd == "Key") {
		if(!param.empty())
			fire(UserConnectionListener::Key(), this, param);
	} else if(cmd == "Lock") {
		if(!param.empty()) {
			x = param.find(" Pk=");
			if(x != string::npos) {
				fire(UserConnectionListener::CLock(), this, param.substr(0, x));
			} else {
				// Workaround for faulty linux clients...
				x = param.find(' ');
				if(x != string::npos) {
					fire(UserConnectionListener::CLock(), this, param.substr(0, x));
	    		} else {
					fire(UserConnectionListener::CLock(), this, param);
    			}
	        }
       	}
	} else if(cmd == "Send") {
    	fire(UserConnectionListener::Send(), this);
	} else if(cmd == "MaxedOut") {
		fire(UserConnectionListener::MaxedOut(), this, param);
	} else if(cmd == "Supports") {
		if(!param.empty()) {
			fire(UserConnectionListener::Supports(), this, StringTokenizer<string>(param, ' ').getTokens());
	    }
	} else if(cmd.compare(0, 3, "ADC") == 0) {
    	dispatch(aLine, true);
	} else if (cmd == "ListLen") {
		if(!param.empty()) {
			fire(UserConnectionListener::ListLength(), this, param);
		}
	} else {

		
		fire(UserConnectionListener::ProtocolError(), this, "Invalid data"); // TODO: translate
	}
}
Пример #5
0
seqan::ArgumentParser::ParseResult
parseArgs(FxFaidxOptions & options,
          int argc,
          char const ** argv)
{
    seqan::ArgumentParser parser("fx_faidx");
    setShortDescription(parser, "Indexing FASTA and indexed FASTA access.");
    setVersion(parser, "0.1");
    setDate(parser, "May 2012");
    
    addUsageLine(parser, "[\\fIOPTIONS\\fP] [\\fB-f\\fP \\fIFASTA\\fP] [\\fB-r\\fP \\fIREGION\\fP]+");
    addDescription(parser, "Equivalent program to samtools faidx.");

    // TODO(holtgrew): I want a custom help text!
    // addOption(parser, seqan::ArgParseOption("h", "help", "This helpful screen."));
    addOption(parser, seqan::ArgParseOption("v", "verbose", "Verbose, log to STDERR."));
    addOption(parser, seqan::ArgParseOption("vv", "very-verbose", "Very verbose, log to STDERR."));
    hideOption(parser, "very-verbose");

    addSection(parser, "FASTA / FAIDX Files");
    addOption(parser, seqan::ArgParseOption("f", "fasta-file", "Path to the FASTA file.", seqan::ArgParseArgument::STRING, false, "FASTA"));
    setRequired(parser, "fasta-file");
    addOption(parser, seqan::ArgParseOption("i", "index-file", "Path to the .fai index file.  Defaults to FASTA.fai", seqan::ArgParseArgument::STRING, false, "FASTA"));
    addOption(parser, seqan::ArgParseOption("o", "out-file", "Path to the resulting file.  If omitted, result is printed to stdout.", seqan::ArgParseArgument::STRING, false, "FASTA"));

    addSection(parser, "Regions");
    addOption(parser, seqan::ArgParseOption("r", "region", "Region to retrieve from FASTA file.  You can specify multiple regions with multiple \\fB-r\\fP \\fIREGION\\fP.  Note that regions are one-based, see below for detailed information about the format.", seqan::ArgParseArgument::STRING, true, "REGION"));

    addTextSection(parser, "Regions");
    addText(parser,
            "Regions can be specified in the formats \\fICHR\\fP, \\fICHR\\fP:\\fISTART\\fP, \\fICHR\\fP:\\fISTART\\fP:\\fIEND\\fP.  \\fICHR\\fP is the id of the reference sequence in the FASTA file, \\fISTART\\fP and \\fIEND\\fP are the start end end positions of the region.  These positions are one-based.");
    addTextSection(parser, "Region Examples");
    addListItem(parser, "\\fIchr1\\fP", "All of the sequence with the identifier \"chr1\".");
    addListItem(parser, "\\fIchrX\\fP:\\fI1,000\\fP", "The characters in the X chromsome, starting with the 1,000th base.");
    addListItem(parser, "\\fIchr2\\fP:\\fI1,500,000\\fP-\\fI2,000,000\\fP", "The character 1,500,000 up to and including character 2,000,000 in the same chromosome.");

    addTextSection(parser, "Usage Examples");
    addListItem(parser, "\\fBfx_faidx\\fP \\fB-f\\fP \\fIREF.fa\\fP", "Create index for file \\fIREF.fa\\fP, index is written to \\fIREF.fa.fai\\fP");
    addListItem(parser, "\\fBfx_faidx\\fP \\fB-f\\fP \\fIREF.fa\\fP \\fB-i\\fP \\fIINDEX.fai\\fP", "Create index for file \\fIREF.fa\\fP, index is written to \\fIINDEX.fai\\fP");
    addListItem(parser, "\\fBfx_faidx\\fP \\fB-f\\fP \\fIREF.fa\\fP \\fB-r\\fP \\fIchr1\\fP", "Retrieve sequence named \"chr1\" from file \\fIREF.fa\\fP using the index with the default name \\fIREF.fa.fai\\fP.  The index file name is created if it does not exist.");
    addListItem(parser, "\\fBfx_faidx\\fP \\fB-f\\fP \\fIREF.fa\\fP \\fB-r\\fP \\fIchr1:100-1100\\fP", "Retrieve characters 100 to 1,100 from the sequence named \"chr1\" from file \\fIREF.fa\\fP using the index with the default name \\fIREF.fa.fai\\fP.");
    addListItem(parser, "\\fBfx_faidx\\fP \\fB-f\\fP \\fIREF.fa\\fP \\fB-r\\fP \\fIchr1:100-1100\\fP \\fB-r\\fP \\fIchr2:2,000\\fP", "Retrieve characters 100-1,000 from \"chr1\" and all characters from 2,000 of \"chr2\".");
    
    seqan::ArgumentParser::ParseResult res = parse(parser, argc, argv);

    if (res == seqan::ArgumentParser::PARSE_OK)
    {
        getOptionValue(options.inFastaPath, parser, "fasta-file");

        // Set default FAI file name.
        options.inFaiPath = options.inFastaPath;
        append(options.inFaiPath, ".fai");
        // Get FAI file name from parser if set.
        if (isSet(parser, "index-file"))
            getOptionValue(options.inFaiPath, parser, "index-file");

        if (isSet(parser, "region"))
            options.regions = getOptionValues(parser, "region");

        if (isSet(parser, "out-file"))
            getOptionValue(options.outFastaPath, parser, "out-file");

        if (isSet(parser, "verbose"))
            options.verbosity = 2;
        if (isSet(parser, "very-verbose"))
            options.verbosity = 3;
    }

    return res;
}
Пример #6
0
void UserConnection::on(BufferedSocketListener::Line, const string& aLine) throw () {
        if(aLine.length() < 2) {
                fire(UserConnectionListener::ProtocolError(), this, _("Invalid data"));
        return;
        }

    if(aLine[0] == 'C' && !isSet(FLAG_NMDC)) {
        if(!Text::validateUtf8(aLine)) {
                        fire(UserConnectionListener::ProtocolError(), this, _("Non-UTF-8 data in an ADC connection"));
            return;
        }
        dispatch(aLine);
        return;
    } else if(aLine[0] == '$') {
        setFlag(FLAG_NMDC);
    } else {
                fire(UserConnectionListener::ProtocolError(), this, _("Invalid data"));
        return;
    }
    COMMAND_DEBUG(aLine, DebugManager::CLIENT_IN, getRemoteIp());
    string cmd;
    string param;

    string::size_type x;
#ifdef LUA_SCRIPT
    if(onUserConnectionMessageIn(this, aLine)) {
        disconnect(true);
        return;
    }
#endif

    if( (x = aLine.find(' ')) == string::npos) {
        cmd = aLine;
    } else {
        cmd = aLine.substr(0, x);
        param = aLine.substr(x+1);
    }

    if(cmd == "$MyNick") {
        if(!param.empty())
            fire(UserConnectionListener::MyNick(), this, param);
    } else if(cmd == "$Direction") {
        x = param.find(" ");
        if(x != string::npos) {
            fire(UserConnectionListener::Direction(), this, param.substr(0, x), param.substr(x+1));
        }
    } else if(cmd == "$Error") {
        if(Util::stricmp(param.c_str(), FILE_NOT_AVAILABLE) == 0 ||
            param.rfind(/*path/file*/" no more exists") != string::npos) {
            fire(UserConnectionListener::FileNotAvailable(), this);
        } else {
                        fire(UserConnectionListener::ProtocolError(), this, param);
        }
    } else if(cmd == "$GetListLen") {
        fire(UserConnectionListener::GetListLength(), this);
    } else if(cmd == "$Get") {
        x = param.find('$');
        if(x != string::npos) {
            fire(UserConnectionListener::Get(), this, Text::toUtf8(param.substr(0, x), encoding), Util::toInt64(param.substr(x+1)) - (int64_t)1);
        }
    } else if(cmd == "$Key") {
        if(!param.empty())
            fire(UserConnectionListener::Key(), this, param);
    } else if(cmd == "$Lock") {
        if(!param.empty()) {
            x = param.find(" Pk=");
            if(x != string::npos) {
                fire(UserConnectionListener::CLock(), this, param.substr(0, x), param.substr(x + 4));
            } else {
                // Workaround for faulty linux clients...
                x = param.find(' ');
                if(x != string::npos) {
                    setFlag(FLAG_INVALIDKEY);
                    fire(UserConnectionListener::CLock(), this, param.substr(0, x), Util::emptyString);
                } else {
                    fire(UserConnectionListener::CLock(), this, param, Util::emptyString);
                }
            }
        }
    } else if(cmd == "$Send") {
        fire(UserConnectionListener::Send(), this);
    } else if(cmd == "$MaxedOut") {
        fire(UserConnectionListener::MaxedOut(), this);
    } else if(cmd == "$Supports") {
        if(!param.empty()) {
            fire(UserConnectionListener::Supports(), this, StringTokenizer<string>(param, ' ').getTokens());
        }
    } else if(cmd.compare(0, 4, "$ADC") == 0) {
        dispatch(aLine, true);
    } else {
        fire(UserConnectionListener::ProtocolError(), this, _("Invalid data"));
    }
}
Пример #7
0
MSString MSMBSDate::asMSF(void) const
{
  MSString buf;
  if (isSet()==MSTrue) (void)format(&buf,MSDate::Database);
  return buf;
}
Пример #8
0
void KoShapeSavingContext::removeOption(ShapeSavingOption option)
{
    if (isSet(option))
        m_savingOptions = m_savingOptions ^ option; // xor to remove it.
}
Пример #9
0
bool MLP::learn(realnumber ME, realnumber MT, realnumber LR, bool ALR, realnumber lambda, realnumber lambda1, realnumber lambda2)
// learn permet de réaliser l'apprentissage du MLP
{

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *                                                                                                                           *
 *                                                  A IMPLEMENTER                                                            *
 *                                                                                                                           *
 *      normaliser les données d'entrainement                                                                                *
 *      erreur en dessous de laquelle un exemple n'est plus traité                                                           *
 *      weight decay                                                                                                         *
 *      OK: variation du taux d'apprentissage (algo de Vogl) OU poids distinct pour chaque connexion (Sanossian & Evans)     *
 *      élagage                                                                                                              *
 *      injection de bruit                                                                                                   *
 *      ensemble de validation                                                                                               *
 *      early stop                                                                                                           *
 *                                                                                                                           *
 *                                                                                                                           *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/*
 * ME = MAX_ERROR
 * MT = MAX_TIME
 * LR = LEARNING_RATE
 * ALR = ADAPTATIVELR (adaptative learning rate)
 */

    if (isSet())
    {
        integer index, compteur = 0;
        realnumber  nextDisplayTime = 0,
                newMQE = MQE(lambda, lambda1, lambda2),
                oldMQE = newMQE;
        clock_t start = clock();


        displayInfo(lambda, lambda1, lambda2);
        display("learning starting...");

        // pour la suite: "index" est le numéro de l'exemple que l'on est en train de traiter
        // et "j" est le numéro de la couche
        while(newMQE > ME && (clock() - start) / (realnumber)CLOCKS_PER_SEC < MT)
        {
            // affiche "mqe" et "m_learningRate" si le dernier affichage date de plus d'une seconde
            displayMQE(start, nextDisplayTime, newMQE, LR);

            // présente un exemple au hasard pour l'apprendre

            index = rand()% m_input.cols(); // ATTENTION! A améliorer

            saveWeights();
            weightDecay(lambda, lambda1, lambda2);
            modifyWeights(index, LR);

            // on vérifie s'ils sont meilleurs que les anciens, sinon on revient en arrière
            newMQE = MQE(lambda, lambda1, lambda2);
            modifyLearningRate(LR, ALR, oldMQE, newMQE);
            compteur++;
        }


        display("learning finished! \n");
        display("Iterations: " + toStr(int(compteur)) + "; Temps en secondes :  " + toStr ((clock() - start) / (realnumber)CLOCKS_PER_SEC) + "");
        displayInfo(lambda, lambda1, lambda2);
        return (newMQE <= ME);
    }
    else
        return 0;
}
Пример #10
0
void MSAConnection::doReadBurst(void)
{
  int burstLength,n;
  if (isSet(MSProtocolConnection<MSA>::Reset)==MSTrue) return;
#ifdef MS_WINSOCK
  if (ioctlsocket(fd(),FIONREAD,(unsigned long*)&burstLength) == -1)
#else
  if (ioctl(fd(),FIONREAD,(caddr_t)&burstLength) == -1)
#endif
   {
     resetWithError(MSProtocolConnection<MSA>::Read);
     return;
   }
  if (burstLength<0) {return;}
  if (burstLength==0) 
   {
     MSMessageLog::infoMessage("MSAConnection: No data to be read on read event\n");
     burstLength=4;
   }
  MSBuffer b(burstLength);
  if (n=readTheBuffer(&b,burstLength)<0)
   {
        return;
   }
  if (n==0&&burstLength==0)
   {
     unset(MSProtocolConnection<MSA>::Read);
     return;
   }
  MSA d(getAobjectFromBuffer(&b));
  if (d.isNullMSA()==MSTrue) {return;}
  int count=1,s=0;
  char *cp;
  for(cp=b.get();cp<b.put();cp+=s) 
   {
     s=MSA::longAt(cp);
     cp+=sizeof(long);
     if(b.put()-cp>=s) ++count;
   }

  MSA z(MSA::gv(MSA::ETYPE,count));
  int i;
  for(i=0;i<count;++i) z.aStructPtr()->p[i]=0;
  int index=0;
  z.aStructPtr()->p[index++]=(long)d.aStructPtr();

  while(index<count)
   {
     d=getAobjectFromBuffer(&b);
     if(d.isNullMSA()==MSTrue) break;
     z.aStructPtr()->p[index++]=(long)d.aStructPtr();
   }

  if (index<count) 
   {
     MSMessageLog::warningMessage("MSAConnection: Burst Mode Aborted. Possible Data Loss.\n");
   }
  if (b.get()==b.put()) unset(MSProtocolConnection<MSA>::Read);
  else 
   {
     d=getAobjectFromBuffer(&b);
     if (d.isNullMSA()==MSFalse || b.get()!=b.put())
      {
        MSMessageLog::warningMessage("MSAConnection: Burst Buffer Not Cleared\n");
      }
   }
  readNotify(d);
}
Пример #11
0
// ---------------------------------------------------------------------------
//  Token: Helper mthods
// ---------------------------------------------------------------------------
int Token::analyzeFirstCharacter(RangeToken* const rangeTok,
								 const int options,
                                 TokenFactory* const tokFactory)
{
	switch(fTokenType) {
	case T_CONCAT:
		{
			int ret = FC_CONTINUE;
			for (int i=0; i<size(); i++) {

				Token* tok = getChild(i);
				if (tok
					&& (ret=tok->analyzeFirstCharacter(rangeTok,
                                    options, tokFactory))!= FC_CONTINUE)
					break;
			}
			return ret;
		}
	case T_UNION:
		{
			unsigned int childSize = size();
            if (childSize == 0)
                return FC_CONTINUE;

            int ret = FC_CONTINUE;
			bool hasEmpty = false;

			for (unsigned int i=0; i < childSize; i++) {

                ret = getChild(i)->analyzeFirstCharacter(rangeTok, options, tokFactory);

				if (ret == FC_ANY)
					break;
				else
					hasEmpty = true;
			}
			return hasEmpty ? FC_CONTINUE : ret;
		}
	case T_CONDITION:
		{
            int ret1 = getChild(0)->analyzeFirstCharacter(rangeTok, options, tokFactory);

            if (size() == 1)
                return FC_CONTINUE;

			int ret2;
			if (ret1 != FC_ANY) {
			    ret2 = getChild(1)->analyzeFirstCharacter(rangeTok, options, tokFactory);
			}

			if (ret1 == FC_ANY || ret2 == FC_ANY)
				return FC_ANY;

			if (ret1 == FC_CONTINUE || ret2 == FC_CONTINUE)
				return FC_CONTINUE;

			return FC_TERMINAL;
		}
	case T_CLOSURE:
	case T_NONGREEDYCLOSURE:
		{
			Token* tok = getChild(0);
			if (tok)
				tok->analyzeFirstCharacter(rangeTok, options, tokFactory);
			return FC_CONTINUE;
		}
	case T_DOT:
    return FC_ANY;
	case T_EMPTY:
	case T_ANCHOR:
		return FC_CONTINUE;
	case T_CHAR:
		{
            XMLInt32 ch = getChar();
			rangeTok->addRange(ch, ch);
			if (ch < 0x1000 && isSet(options,RegularExpression::IGNORE_CASE)) {
				//REVISIT
			}
		}
		return FC_TERMINAL;
	case T_RANGE:
		{
			if (isSet(options, RegularExpression::IGNORE_CASE)) {
                rangeTok->mergeRanges(((RangeToken*)
                                         this)->getCaseInsensitiveToken(tokFactory));
			}
			else {
				rangeTok->mergeRanges(this);
			}
			return FC_TERMINAL;
		}
	case T_NRANGE:
		{
			if (isSet(options, RegularExpression::IGNORE_CASE)) {

				RangeToken* caseITok = (((RangeToken*)
					                       this)->getCaseInsensitiveToken(tokFactory));
				rangeTok->mergeRanges(RangeToken::complementRanges(caseITok, tokFactory, fMemoryManager));
			}
			else {
				rangeTok->mergeRanges(
					RangeToken::complementRanges((RangeToken*) this, tokFactory, fMemoryManager));
			}
		}
	case T_INDEPENDENT:
	case T_PAREN:
		{
			Token* tok = getChild(0);
			if (tok)
				return tok->analyzeFirstCharacter(rangeTok,options, tokFactory);
		}
	case T_MODIFIERGROUP:
	case T_BACKREFERENCE:
		rangeTok->addRange(0, UTF16_MAX);
		return FC_ANY;
	case T_STRING:
		{
			const XMLCh* str = getString();
            XMLInt32 ch = str[0];

			if (RegxUtil::isHighSurrogate((XMLCh) ch)) {
			}

		    rangeTok->addRange(ch, ch);
		    if (ch<0x10000 && isSet(options,RegularExpression::IGNORE_CASE)) {
                //REVISIT
            }
		}
		return FC_TERMINAL;
	case T_LOOKAHEAD:
	case T_NEGATIVELOOKAHEAD:
	case T_LOOKBEHIND:
	case T_NEGATIVELOOKBEHIND:
		return FC_CONTINUE;
//	default:
//		throw;
	}

	return 0;
}
Пример #12
0
void DeviceLock::init()
{
    setState(isSet() && lockingGConfItem->value(-1).toInt() >= 0 ? Locked : Unlocked);
}
Пример #13
0
void CountsVisitor::apply(osg::Drawable* draw)
{
    apply(draw->getStateSet());

    pushStateSet(draw->getStateSet());

    if(_countUserMode)
    {
        if(isSet(_userMode, _stateStack.back().get()))
        {
            if(isEnabled(_userMode, _stateStack.back().get()))
                _drawUserModeOn++;
            else
                _drawUserModeOff++;
        }
        else
            _drawUserModeNotSet++;
    }

    _totalDrawables++;
    osg::Geometry* geom;
    if (dynamic_cast<osgText::Text*>(draw) != NULL)
    {
        _texts++;
        osg::ref_ptr<osg::Object> rp = (osg::Object*)draw;
        _uTexts.insert(rp);
    }
    else if ((geom = dynamic_cast<osg::Geometry*>(draw)) != NULL)
    {
        _geometries++;
        osg::ref_ptr<osg::Object> rp = (osg::Object*)geom;
        _uGeometries.insert(rp);

        //if (!geom->areFastPathsUsed())
        //    _slowPathGeometries++;

        if(geom->getNumPrimitiveSets() > 0)
        {
            unsigned int idx;
            for(idx=0; idx < geom->getNumPrimitiveSets(); idx++)
            {
                osg::PrimitiveSet* ps = geom->getPrimitiveSet(idx);
                _vertices += ps->getNumIndices();
            }
        }
        else
            _nullGeometries++;
        osg::ref_ptr<osg::Object> rpv = (osg::Object*)(geom->getVertexArray());
        _uVertices.insert(rpv);

        if(geom->getNumPrimitiveSets() > 0)
        {
            _primitiveSets += geom->getNumPrimitiveSets();
            osg::Geometry::PrimitiveSetList& psl = geom->getPrimitiveSetList();
            osg::Geometry::PrimitiveSetList::const_iterator pslit;
            for(pslit = psl.begin(); pslit != psl.end(); ++pslit)
            {
                osg::ref_ptr<osg::Object> rpps = (osg::Object*)(pslit->get());
                _uPrimitiveSets.insert(rpps);
                const osg::DrawArrays* da = dynamic_cast< const osg::DrawArrays* >(pslit->get());
                if(da)
                {
                    _drawArrays++;
                    osg::ref_ptr<osg::Object> rpda = (osg::Object*)(da);
                    _uDrawArrays.insert(rpda);
                }
            }
        }
    }
    else
    {
        _drawables++;
        osg::ref_ptr<osg::Object> rp = (osg::Object*)draw;
        _uDrawables.insert(rp);
    }

    popStateSet();
}
Пример #14
0
		Parser::Result Parser::parseOptions()
		{
			if (!parse(QCoreApplication::arguments()))
			{
				QString const errorDescription = "Command line error >> description: " + errorText();
				return std::make_pair(Status::Error, errorDescription);
			}

			if (isSet(m_helpOption))
			{
				return std::make_pair(Status::ShowHelp, QString());
			}

			if (isSet(launchColorCubeDemo))
			{
				return std::make_pair(Status::LaunchColorCubeDemo, QString());
			}

			if (isSet(launchTextureCubeDemo))
			{
				return std::make_pair(Status::LaunchTextureCubeDemo, QString());
			}

			if (isSet(launchMonoWebcamDemo))
			{
				return std::make_pair(Status::LaunchMonoWebcamDemo, QString());
			}

			if (isSet(launchStereoWebcamDemo))
			{
				return std::make_pair(Status::LaunchStereoWebcamDemo, QString());
			}

			if (isSet(launchClientDemo))
			{
				QStringList const serverAddressOptionValues = values(launchClientDemo);

				if (serverAddressOptionValues.isEmpty())
				{
					return std::make_pair(Status::Error, "Command line error >> description: no server address specified");
				}

				if (serverAddressOptionValues.size() > 1)
				{
					return std::make_pair(Status::Error, "Command line error >> description: too many server addresses specified");
				}

				return std::make_pair(Status::LaunchClientDemo, QString());
			}

			if (isSet(launchServerDemo))
			{
				return std::make_pair(Status::LaunchServerDemo, QString());
			}

			if (isSet(launchFirstPersonViewDemo))
			{
				return std::make_pair(Status::LaunchFirstPersonViewDemo, QString());
			}

			return std::make_pair(Status::Error, "Command line error >> description: unknown option");
		}
static int
orFirstMustChunkWithDeletes(PostingsState *sub,
                            double *tsCache,
                            float termWeight,
                            int endDoc,
                            unsigned int *filled,
                            int *docIDs,
                            float *scores,
                            unsigned int *coords,
                            unsigned char *liveDocsBytes) {

  int nextDocID = sub->nextDocID;
  unsigned int *docDeltas = sub->docDeltas;
  unsigned int *freqs = sub->freqs;

  int blockLastRead = sub->docFreqBlockLastRead;
  int blockEnd = sub->docFreqBlockEnd;

  int numFilled = 0;

  // First scorer is different because we know slot is
  // "new" for every hit:
  if (scores == 0) {
    while (nextDocID < endDoc) {
      if (isSet(liveDocsBytes, nextDocID)) {
        //printf("  docID=%d\n", nextDocID);
        int slot = nextDocID & MASK;
        if (docIDs[slot] != nextDocID) {
          docIDs[slot] = nextDocID;
          coords[slot] = 1;
          filled[numFilled++] = slot;
        }
      }

      // Inlined nextDoc:
      if (blockLastRead == blockEnd) {
        if (sub->docsLeft == 0) {
          nextDocID = NO_MORE_DOCS;
          break;
        } else {
          nextDocFreqBlock(sub);
          blockLastRead = -1;
          blockEnd = sub->docFreqBlockEnd;
        }
      }
      nextDocID += docDeltas[++blockLastRead];
    }
  } else {

    //printf("scorers[0]\n");fflush(stdout);
    while (nextDocID < endDoc) {
      //printf("  docID=%d\n", nextDocID);
      if (isSet(liveDocsBytes, nextDocID)) {
        int slot = nextDocID & MASK;
        if (docIDs[slot] != nextDocID) {
          int freq = freqs[blockLastRead];
          docIDs[slot] = nextDocID;
          if (freq < TERM_SCORES_CACHE_SIZE) {
            scores[slot] = tsCache[freq];
          } else {
            scores[slot] = sqrt(freq) * termWeight;
          }
          coords[slot] = 1;
          filled[numFilled++] = slot;
        }
      }
      // Inlined nextDoc:
      if (blockLastRead == blockEnd) {
        if (sub->docsLeft == 0) {
          nextDocID = NO_MORE_DOCS;
          break;
        } else {
          nextDocFreqBlock(sub);
          blockLastRead = -1;
          blockEnd = sub->docFreqBlockEnd;
        }
      }
      nextDocID += docDeltas[++blockLastRead];
    }
  }

  sub->nextDocID = nextDocID;
  sub->docFreqBlockLastRead = blockLastRead;
  //printf("return numFilled=%d\n", numFilled);
  return numFilled;
}
Пример #16
0
bool RegularExpression::matches(const XMLCh* const expression, const int start,
                                const int end, Match* const pMatch
                                , MemoryManager* const manager)	{
		
	if (fOperations == 0)
		prepare();

	Context context(manager);
	int		 strLength = XMLString::stringLen(expression);

    context.reset(expression, strLength, start, end, fNoClosures);

	bool adoptMatch = false;
	Match* lMatch = pMatch;

	if (lMatch != 0) {
		lMatch->setNoGroups(fNoGroups);
	}
	else if (fHasBackReferences) {

		lMatch = new (fMemoryManager) Match(fMemoryManager);
		lMatch->setNoGroups(fNoGroups);
		adoptMatch = true;
	}

	if (context.fAdoptMatch)
		delete context.fMatch;
    context.fMatch = lMatch;
	context.fAdoptMatch = adoptMatch;

	if (isSet(fOptions, XMLSCHEMA_MODE)) {

		int matchEnd = match(&context, fOperations, context.fStart, 1);

		if (matchEnd == context.fLimit) {

			if (context.fMatch != 0) {

				context.fMatch->setStartPos(0, context.fStart);
				context.fMatch->setEndPos(0, matchEnd);
			}		
			return true;
		}

		return false;
	}

	/*
	 *	If the pattern has only fixed string, use Boyer-Moore
	 */
	if (fFixedStringOnly) {

		int ret = fBMPattern->matches(expression, context.fStart,
			                          context.fLimit);
		if (ret >= 0) {

			if (context.fMatch != 0) {
				context.fMatch->setStartPos(0, ret);
				context.fMatch->setEndPos(0, ret + strLength);
			}		
			return true;
		}		
		return false;
	}

	/*
	 *	If the pattern contains a fixed string, we check with Boyer-Moore
	 *	whether the text contains the fixed string or not. If not found
	 *	return false
	 */
	if (fFixedString != 0) {

		int ret = fBMPattern->matches(expression, context.fStart,
                                      context.fLimit);

		if (ret < 0) { // No match
			return false;
		}
	}

	int limit = context.fLimit - fMinLength;
	int matchStart;
	int matchEnd = -1;

	/*
	 *	Check whether the expression start with ".*"
	 */
	if (fOperations != 0 && fOperations->getOpType() == Op::O_CLOSURE
        && fOperations->getChild()->getOpType() == Op::O_DOT) {

		if (isSet(fOptions, SINGLE_LINE)) {
			matchStart = context.fStart;
			matchEnd = match(&context, fOperations, matchStart, 1);
		}
		else {
			bool previousIsEOL = true;

			for (matchStart=context.fStart; matchStart<=limit; matchStart++) {

				XMLCh ch = expression[matchStart];
				if (RegxUtil::isEOLChar(ch)) {
					previousIsEOL = true;
				}
				else {

					if (previousIsEOL) {
						if (0 <= (matchEnd = match(&context, fOperations,
                                                   matchStart, 1)))
                            break;
					}

					previousIsEOL = false;
				}
			}
		}
	}
	else {
        /*
         *	Optimization against the first char
         */
		if (fFirstChar != 0) {
			bool ignoreCase = isSet(fOptions, IGNORE_CASE);
			RangeToken* range = fFirstChar;

			if (ignoreCase)
				range = fFirstChar->getCaseInsensitiveToken(fTokenFactory);

			for (matchStart=context.fStart; matchStart<=limit; matchStart++) {

                XMLInt32 ch;

				if (!context.nextCh(ch, matchStart, 1))
					break;

				if (!range->match(ch)) {

					if (!ignoreCase)
						continue;

					// Perform case insensitive match
					// REVISIT
					continue;
				}

				if (0 <= (matchEnd = match(&context,fOperations,matchStart,1)))
					break;
            }
		}
		else {

            /*
             *	Straightforward matching
             */
			for (matchStart=context.fStart; matchStart<=limit; matchStart++) {

				if (0 <= (matchEnd = match(&context,fOperations,matchStart,1)))
					break;
			}
		}
	}

	if (matchEnd >= 0) {

		if (context.fMatch != 0) {

			context.fMatch->setStartPos(0, matchStart);
			context.fMatch->setEndPos(0, matchEnd);
		}		
		return true;
	}
	return false;
}
Пример #17
0
int RegularExpression::match(Context* const context, const Op* const operations
							 , int offset, const short direction)
{
	const Op* tmpOp = operations;
	bool ignoreCase = isSet(fOptions, IGNORE_CASE);

	while (true) {

		if (tmpOp == 0)
			break;

		if (offset > context->fLimit || offset < context->fStart)
			return -1;

		switch(tmpOp->getOpType()) {
		case Op::O_CHAR:
			if (!matchChar(context, tmpOp->getData(), offset, direction,
						   ignoreCase))
				return -1;
			tmpOp = tmpOp->getNextOp();
			break;
		case Op::O_DOT:
			if (!matchDot(context, offset, direction))
				return -1;
			tmpOp = tmpOp->getNextOp();
			break;
		case Op::O_RANGE:
		case Op::O_NRANGE:
			if (!matchRange(context, tmpOp, offset, direction, ignoreCase))
				return -1;
			tmpOp = tmpOp->getNextOp();
			break;
		case Op::O_ANCHOR:
			if (!matchAnchor(context, tmpOp->getData(), offset))
				return -1;
			tmpOp = tmpOp->getNextOp();
			break;
		case Op::O_BACKREFERENCE:
			if (!matchBackReference(context, tmpOp->getData(), offset,
									direction, ignoreCase))
				return -1;
			tmpOp = tmpOp->getNextOp();
			break;
		case Op::O_STRING:
			if (!matchString(context, tmpOp->getLiteral(), offset, direction,
							 ignoreCase))
				return -1;
			tmpOp = tmpOp->getNextOp();
			break;
		case Op::O_CLOSURE:
			{
				XMLInt32 id = tmpOp->getData();
				if (id >= 0) {
					int prevOffset = context->fOffsets[id];
					if (prevOffset < 0 || prevOffset != offset) {
						context->fOffsets[id] = offset;
					}
					else {

						context->fOffsets[id] = -1;
						tmpOp = tmpOp->getNextOp();
						break;
					}
				}

				int ret = match(context, tmpOp->getChild(), offset, direction);
				if (id >= 0) {
					context->fOffsets[id] = -1;
				}

				if (ret >= 0)
					return ret;

				tmpOp = tmpOp->getNextOp();
			}
			break;
		case Op::O_QUESTION:
			{
				int ret = match(context, tmpOp->getChild(), offset, direction);
				if (ret >= 0)
					return ret;
				tmpOp = tmpOp->getNextOp();
			}
			break;
		case Op::O_NONGREEDYCLOSURE:
		case Op::O_NONGREEDYQUESTION:
			{
				int ret = match(context,tmpOp->getNextOp(),offset,direction);
				if (ret >= 0)
					return ret;
				tmpOp = tmpOp->getChild();
			}
			break;
		case Op::O_UNION:
			{
				return matchUnion(context, tmpOp, offset, direction);
			}
		case Op::O_CAPTURE:
			if (context->fMatch != 0 && tmpOp->getData() != 0)
				return matchCapture(context, tmpOp, offset, direction);
			tmpOp = tmpOp->getNextOp();
			break;
		case Op::O_LOOKAHEAD:
			if (0 > match(context, tmpOp->getChild(), offset, 1))
				return -1;
			tmpOp = tmpOp->getNextOp();
			break;
		case Op::O_NEGATIVELOOKAHEAD:
			if (0 <= match(context, tmpOp->getChild(), offset, 1))
				return -1;
			tmpOp = tmpOp->getNextOp();
			break;
		case Op::O_LOOKBEHIND:
			if (0 > match(context, tmpOp->getChild(), offset, -1))
				return - 1;
			tmpOp = tmpOp->getNextOp();
			break;
		case Op::O_NEGATIVELOOKBEHIND:
			if (0 <= match(context, tmpOp->getChild(), offset, -1))
				return -1;
			tmpOp = tmpOp->getNextOp();
			break;
		case Op::O_INDEPENDENT:
        case Op::O_MODIFIER:
			{
				int ret = (tmpOp->getOpType() == Op::O_INDEPENDENT)
					   ? match(context, tmpOp->getChild(), offset, direction)
                       : matchModifier(context, tmpOp, offset, direction);
                if (ret < 0)
                    return ret;
				offset = ret;
				tmpOp = tmpOp->getNextOp();
			}
			break;
		case Op::O_CONDITION:
			if (tmpOp->getRefNo() >= fNoGroups)
				return -1;
			if (matchCondition(context, tmpOp, offset, direction))
				tmpOp = tmpOp->getYesFlow();
			else
				if (tmpOp->getNoFlow() != 0)
                    tmpOp = tmpOp->getNoFlow();
                else
                    tmpOp = tmpOp->getNextOp();
			break;
		}
	}
	
	return offset;
}
Пример #18
0
void Download::open(int64_t bytes, bool z, bool hasDownloadedBytes) {
	if(getType() == Transfer::TYPE_FILE) {
		auto target = getDownloadTarget();
		auto fullSize = tt.getFileSize();

		if(getOverlapped() && bundle) {
			setOverlapped(false);
 	 
			bool found = false;
			// ok, we got a fast slot, so it's possible to disconnect original user now
			for(auto d: bundle->getDownloads()) {
				if(d != this && compare(d->getPath(), getPath()) == 0 && d->getSegment().contains(getSegment())) {
 	 
					// overlapping has no sense if segment is going to finish
					if(d->getSecondsLeft() < 10)
						break;
 	 
					found = true;
 	 
					// disconnect slow chunk
					d->getUserConnection().disconnect();
					break;
				}
			}

			if(!found) {
				// slow chunk already finished ???
				throw Exception(STRING(DOWNLOAD_FINISHED_IDLE));
			}
		}

		if(hasDownloadedBytes) {
			if(File::getSize(target) != fullSize) {
				// When trying the download the next time, the resume pos will be reset
				throw Exception(CSTRING(TARGET_FILE_MISSING));
			}
		} else {
			File::ensureDirectory(target);
		}

		int flags = File::OPEN | File::CREATE | File::SHARED_WRITE;
		if (getSegment().getEnd() != fullSize) {
			//segmented download, let Windows decide the buffering
			flags |= File::BUFFER_AUTO;
		}

		unique_ptr<SharedFileStream> f(new SharedFileStream(target, File::WRITE, flags));

		if(f->getSize() != fullSize) {
			f->setSize(fullSize);
		}

		f->setPos(getSegment().getStart());
		output = move(f);
		tempTarget = target;
	} else if(getType() == Transfer::TYPE_FULL_LIST) {
		auto target = getPath();
		File::ensureDirectory(target);

		if(isSet(Download::FLAG_XML_BZ_LIST)) {
			target += ".xml.bz2";
		} else {
			target += ".xml";
		}

		output.reset(new File(target, File::WRITE, File::OPEN | File::TRUNCATE | File::CREATE));
		tempTarget = target;
	} else if(getType() == Transfer::TYPE_PARTIAL_LIST) {
		output.reset(new StringOutputStream(pfs));
	} else if(getType() == Transfer::TYPE_TREE) {
		output.reset(new MerkleTreeOutputStream<TigerTree>(tt));
	}

	if((getType() == Transfer::TYPE_FILE || getType() == Transfer::TYPE_FULL_LIST) && SETTING(BUFFER_SIZE) > 0 ) {
		output.reset(new BufferedOutputStream<true>(output.release()));
	}

	if(getType() == Transfer::TYPE_FILE && !SettingsManager::lanMode) {
		typedef MerkleCheckOutputStream<TigerTree, true> MerkleStream;

		output.reset(new MerkleStream(tt, output.release(), getStartPos()));
		setFlag(Download::FLAG_TTH_CHECK);
	}

	// Check that we don't get too many bytes
	output.reset(new LimitedOutputStream<true>(output.release(), bytes));

	if(z) {
		setFlag(Download::FLAG_ZDOWNLOAD);
		output.reset(new FilteredOutputStream<UnZFilter, true>(output.release()));
	}
}
Пример #19
0
bool MLP::setArchitecture(initialise init, integer I, integer O)
{
    if (!isSet())
    {
        if (m_last > 1 && m_perLayer > 0)
        {
            if (I == 0 && O == 0)
            {
                I = m_input.rows();
                O = m_output.rows();
            }

            if (I > 0 && O > 0)
            {
                if (m_input.cols() != m_output.cols())
                {
                    display("Error! not the same number of examples");
                    m_input.resize(I, min(m_input.cols(),m_output.cols()));
                    m_output.resize(O, min(m_input.cols(),m_output.cols()));
                }

                m_layers = new EigenMatrix[m_last+1];
                m_Delta = new EigenMatrix[m_last+1];
                m_oldLayers = new EigenMatrix[m_last+1];

                // initialise randomly
                if (init)
                {
                    m_layers[0]      = EigenMatrix::Random(m_perLayer,I+1);
                    for(integer j = 1; j < m_last ; ++j)
                        m_layers[j] = EigenMatrix::Random(m_perLayer,m_perLayer+1);
                    m_layers[m_last] = EigenMatrix::Random(O,m_perLayer+1);

                    // rescale
                    for(integer j = 0; j <= m_last; ++j)
                        m_layers[j] *= 0.5;//sqrt(6/(I+O));


                    // create a backup
                    for(integer j = 0; j <= m_last; ++j)
                        m_oldLayers[j] = m_layers[j];
                }
                else
                {
                    m_layers[0].resize(m_perLayer,I+1);
                    for(integer j = 1; j < m_last; ++j)
                        m_layers[j].resize(m_perLayer,m_perLayer+1);
                    m_layers[m_last].resize(O,m_perLayer+1);

                    m_oldLayers[0].resize(m_perLayer,I+1);
                    for(integer j = 1; j < m_last; ++j)
                        m_oldLayers[j].resize(m_perLayer,m_perLayer+1);
                    m_oldLayers[m_last].resize(O,m_perLayer+1);
                }

                m_Delta[0].resize(m_perLayer,1);
                for(integer j = 1; j < m_last ; ++j)
                    m_Delta[j].resize(m_perLayer,1);
                m_Delta[m_last].resize(O,1);
            }
            else
                display("Error! There isn't any input or output");
        }
        else
            clear();
    }
    else if (m_input.rows()+1 != m_layers[0].cols() || m_output.rows() != m_layers[m_last].rows())
            reset();
    return isSet();
}
Пример #20
0
/**
* Return the ERA.  We need a special method for this because the
* default ERA is AD, but a zero (unset) ERA is BC.
*/
int32_t
GregorianCalendar::internalGetEra() const {
    return isSet(UCAL_ERA) ? internalGet(UCAL_ERA) : (int32_t)AD;
}
Пример #21
0
seqan::ArgumentParser::ParseResult
parseCommandLine(Options & options, int argc, char const ** argv)
{
    // Setup ArgumentParser.
    seqan::ArgumentParser parser("roiGFF");

    // Set short description, version, and date.
    setShortDescription(parser, "get ROIs based on GFF annotation");
    setVersion(parser, VERSION);
    setDate(parser, "March 2013");

    // Define usage line and long description.
    addUsageLine(parser,
                 "[\\fIOPTIONS\\fP] \\fB-if\\fP \\fIIN.roi\\fP"
				 "\\fB-ig\\fP \\fIIN.gff\fP"
                 "\\fB-of\\fP \\fIOUT.roi\\fP"
				 "[\\fB-ss\\fP] [\\fB-t\\fP \\fItype\\fP] "
				 "[\\fB-p\\fP \\fIparent attribute\\fP]]");
	addDescription(parser,
       "Takes regions from GFF file, calculates the overlap with the ROI file"
       "and creates a new ROI file based on the GFF regions.");
	
	// General Options

    addOption(parser, seqan::ArgParseOption("v", "verbose", "Verbose mode."));
    addOption(parser, seqan::ArgParseOption("vv", "vverbose", "Very verbose mode."));

    // Input / Output Options

    addSection(parser, "Input / Output Parameters");

	addOption(parser, seqan::ArgParseOption("if", "roi-file", "roi file", seqan::ArgParseOption::INPUTFILE));
    setValidValues(parser, "roi-file", "roi");
    setRequired(parser, "roi-file");

	addOption(parser, seqan::ArgParseOption("ig", "gff-file", "gff file", seqan::ArgParseOption::INPUTFILE));
    setValidValues(parser, "gff-file", "gff");
    setRequired(parser, "gff-file");

    addOption(parser, seqan::ArgParseOption("of", "output-file", "Output file", seqan::ArgParseOption::OUTPUTFILE));
    setValidValues(parser, "output-file", "roi");
    setRequired(parser, "output-file");

    // Optional Parameter
	addOption(parser,
		seqan::ArgParseOption("ss", "strandspecific",
			"calculate strandspecific stats (only position sorted)"));

	addOption(parser,
		seqan::ArgParseOption("t", "type",
		"Type to used (3. column in GFF file). If not set all types will be used."
		"There can only be one or none set.", seqan::ArgParseOption::STRING));
	setDefaultValue(parser, "type", "");

	addOption(parser,
		seqan::ArgParseOption("p", "parent",
			"tag to used to identify regions that should be concatednated."
			"They are sorted by start position and then concatenated. If empty/not set"
			"there will be no concatenation performed", 
			seqan::ArgParseOption::STRING));
	setDefaultValue(parser, "parent", "");


    // Parse command line.
    seqan::ArgumentParser::ParseResult res = seqan::parse(parser, argc, argv);

    // Extract option values.
	if (isSet(parser, "verbose"))
        options.verbosity = 1;
    if (isSet(parser, "vverbose"))
        options.verbosity = 2;

    getOptionValue(options.roiFileName, parser, "roi-file");
    getOptionValue(options.gffFileName, parser, "gff-file");
    getOptionValue(options.outputFileName, parser, "output-file");
    getOptionValue(options.strandSpecific, parser, "strandspecific");
    getOptionValue(options.type, parser, "type");
    getOptionValue(options.parent, parser, "parent");
	
    return seqan::ArgumentParser::PARSE_OK;

}
Пример #22
0
DelayedConst<T>::operator T_reference ()
{
    assert(isSet());

    return m_value;
}
Пример #23
0
void UserConnection::accept(const Socket& aServer) throw(SocketException, ThreadException) {
    dcassert(!socket);
    socket = BufferedSocket::getSocket(0);
    socket->addListener(this);
    socket->accept(aServer, isSet(FLAG_SECURE), BOOLSETTING(ALLOW_UNTRUSTED_CLIENTS));
}
Пример #24
0
seqan::ArgumentParser::ParseResult
parseCommandLine(SeqConsOptions & options, int argc, char const ** argv)
{
    // Setup ArgumentParser.
    seqan::ArgumentParser parser("seqcons2");
    // Set short description, version, and date.
    setShortDescription(parser, "Compute consensus from sequences.");
    setVersion(parser, SEQAN_APP_VERSION " [" SEQAN_REVISION "]");
    setDate(parser, SEQAN_DATE);

    // Define usage line and long description.
    addUsageLine(parser,
                 "\\fB-i\\fP \\fIINPUT.{fa,sam}\\fP [\\fB-oa\\fP \\fIOUT_ALIGN.{fa,sam}\\fP] "
                 "[\\fB-oc\\fP \\fIOUT_CONSENSUS.fa\\fP]");
    addDescription(parser,
                   "Compute consensus from sequences with and without approximate alignment information.");

    // Overall Program Options
    addOption(parser, seqan::ArgParseOption("q", "quiet", "Set verbosity to a minimum."));
    addOption(parser, seqan::ArgParseOption("v", "verbose", "Enable verbose output."));
    addOption(parser, seqan::ArgParseOption("vv", "very-verbose", "Enable very verbose output."));

    addOption(parser, seqan::ArgParseOption("m", "method", "Method to perform.  See section \\fIMethods\\fP "
                                            "below for details.", seqan::ArgParseOption::STRING, "METHOD"));
    setValidValues(parser, "method", "nop realign align_consensus overlap_consensus contig_consensus pos_consensus");
    setDefaultValue(parser, "method", "pos_consensus");

    // I/O Options
    addSection(parser, "I/O Options");

    addOption(parser, seqan::ArgParseOption("i", "input-file", "Input file.", seqan::ArgParseOption::INPUT_FILE,
                                            "INPUT"));
    setRequired(parser, "input-file", true);
    setValidValues(parser, "input-file", "sam fa fasta");

    addOption(parser, seqan::ArgParseOption("oa", "output-alignment-file", "Output file with alignment.",
                                            seqan::ArgParseOption::OUTPUT_FILE, "OUT_ALIGNMENT"));
    setRequired(parser, "output-alignment-file", false);
    setValidValues(parser, "output-alignment-file", "sam txt");

    addOption(parser, seqan::ArgParseOption("oc", "output-consensus-file", "Output file with consensus sequence.",
                                            seqan::ArgParseOption::OUTPUT_FILE, "OUT_CONSENSUS"));
    setRequired(parser, "output-consensus-file", false);
    setValidValues(parser, "output-consensus-file", "fa fasta");

    // Alignment Quality Filter Options
    addSection(parser, "Alignment Quality Filter Options");

    addOption(parser, seqan::ArgParseOption("", "overlap-min-length", "Minimal overlap length.",
                                            seqan::ArgParseOption::INTEGER, "LENGTH"));
    setMinValue(parser, "overlap-min-length", "0");
    setDefaultValue(parser, "overlap-min-length", "20");

    addOption(parser, seqan::ArgParseOption("", "overlap-max-error", "Maximal error rate in overlap as percentage.",
                                            seqan::ArgParseOption::DOUBLE, "RATE"));
    setMinValue(parser, "overlap-max-error", "0.0");
    setDefaultValue(parser, "overlap-max-error", "5.0");

    addOption(parser, seqan::ArgParseOption("", "overlap-min-count", "Minimal overlap count.",
                                            seqan::ArgParseOption::INTEGER, "COUNT"));
    setMinValue(parser, "overlap-min-count", "0");
    setDefaultValue(parser, "overlap-min-count", "3");

    addOption(parser, seqan::ArgParseOption("", "overlap-window-size", "Window size to look for alignments.",
                                            seqan::ArgParseOption::INTEGER, "SIZE"));
    setMinValue(parser, "overlap-window-size", "0");
    setDefaultValue(parser, "overlap-window-size", "20");

    // K-mer Filter Options
    addSection(parser, "K-Mer Filter Options");

    addOption(parser, seqan::ArgParseOption("", "k-mer-size", "The k-mer size to use.",
                                            seqan::ArgParseOption::INTEGER, "LENGTH"));
    setMinValue(parser, "k-mer-size", "5");
    setDefaultValue(parser, "k-mer-size", "20");

    addOption(parser, seqan::ArgParseOption("", "k-mer-max-occ", "Ignore k-mer with higher occurence count, 0 to disable.",
                                            seqan::ArgParseOption::INTEGER, "COUNT"));
    setMinValue(parser, "k-mer-max-occ", "0");
    setDefaultValue(parser, "k-mer-max-occ", "200");

    // Realignment Options
    addSection(parser, "Realignment Options");

    addOption(parser, seqan::ArgParseOption("", "realign-bandwidth",
                                            "Bandwidth to use for pairwise alignments in realignment.",
                                            seqan::ArgParseOption::INTEGER, "LENGTH"));
    setMinValue(parser, "realign-bandwidth", "5");
    setDefaultValue(parser, "realign-bandwidth", "10");

    addOption(parser, seqan::ArgParseOption("", "realign-environment",
                                            "Environment for extraction in realignment.",
                                            seqan::ArgParseOption::INTEGER, "COUNT"));
    setMinValue(parser, "realign-environment", "5");
    setDefaultValue(parser, "realign-environment", "20");

    // Add Methods Section
    addTextSection(parser, "Methods");
    addListItem(parser, "\\fBnop\\fP",
                "Perform no action, just perform file conversion if possible.");
    addListItem(parser, "\\fBrealign\\fP",
                "Perform realignment, requires input to be a SAM file to provide approximate position "
                "information, creates consensus sequence after realignment.");
    addListItem(parser, "\\fBoverlap_consensus\\fP",
                "Perform MSA with overlap alignments of the input ignoring any given coordinates, then realign. "
                "This is most suited when computing the consensus of reads where the underlying sequence is very "
                "similar and most differences stem from sequencing errors and not genomic variation. All "
                "pairwise alignments computed here are banded.");
    addListItem(parser, "\\fBalign_consensus\\fP",
                "Perform MSA with global alignments of the input ignoring any given coordinates, then realign. "
                "This will computed unbanded global ends-gap free pairwise alignments.  This is also suitable "
                "when aligning different sequences, e.g. clustered transcripts.  Using this method, seqcons "
                "will be similar to calling SeqAn::T-Coffee, followed by realignment and consensus computation.");
    addListItem(parser, "\\fBcontig_consensus\\fP",
                "Perform MSA of the input, contig by contig, requires contig information, then realign. Input "
                "must be SAM.");
    addListItem(parser, "\\fBpos_consensus\\fP",
                "Perform consensus of the input, then realign. Requires approximate coordinate information in "
                "SAM file.");

    // Add Output Section
    addTextSection(parser, "Output Formats");
    addText(parser,
            "The program can write out the consensus sequence in FASTA format and optionally the alignment of the "
            "input sequences against the consensus in SAM/BAM format.  When using the extension \\fI.txt\\fP, seqcons "
            "will write out the MSA as a plain text visualization.");

    // Add Examples Section
    addTextSection(parser, "Examples");
    addListItem(parser,
                "\\fBseqcons\\fP \\fB-m\\fP \\fIovl_consensus\\fP \\fB-i\\fP \\fIreads.fa\\fP \\fB-oa\\fP "
                "\\fIout.sam\\fP \\fB-oc\\fP \\fIcons.fa\\fP",
                "Compute MSA of the sequences in \\fIreads.fa\\fP.  The consensus sequence is written to "
                "\\fIcons.fa\\fP and the alignment of the sequences in \\fIreads.fa\\fP is written to "
                "\\fIout.sam\\fP.");
    addListItem(parser,
                "\\fBseqcons\\fP \\fB-m\\fP \\fIrealign\\fP \\fB-i\\fP \\fIin.sam\\fP \\fB-oa\\fP \\fIout.sam\\fP",
                "Read in multi-read alignment from \\fIin.sam\\fP, refine it using Anson-Myers realignment and "
                "write out the refined alignment to \\fIout.sam\\fP");

    // Parse command line.
    seqan::ArgumentParser::ParseResult res = seqan::parse(parser, argc, argv);

    // Only extract  options if the program will continue after parseCommandLine()
    if (res != seqan::ArgumentParser::PARSE_OK)
        return res;

    // Extract option values.

    if (isSet(parser, "quiet"))
        options.verbosity = 0;
    if (isSet(parser, "verbose"))
        options.verbosity = 2;
    if (isSet(parser, "very-verbose"))
        options.verbosity = 3;

    std::string opStr;
    getOptionValue(opStr, parser, "method");
    options.operation = strToMethod(opStr.c_str());

    getOptionValue(options.inputFile, parser, "input-file");
    getOptionValue(options.outputFileAlignment, parser, "output-alignment-file");
    getOptionValue(options.outputFileConsensus, parser, "output-consensus-file");

    getOptionValue(options.overlapMinLength, parser, "overlap-min-length");
    getOptionValue(options.overlapMaxErrorRate, parser, "overlap-max-error");
    getOptionValue(options.overlapWindowSize, parser, "overlap-window-size");

    getOptionValue(options.kMerSize, parser, "k-mer-size");
    getOptionValue(options.kMerMaxOcc, parser, "k-mer-max-occ");

    getOptionValue(options.reAlignmentBandwidth, parser, "realign-bandwidth");
    getOptionValue(options.reAlignmentEnvironment, parser, "realign-environment");

    return seqan::ArgumentParser::PARSE_OK;
}
Пример #25
0
seqan::ArgumentParser::ParseResult
parseArgs(SakOptions & options,
          int argc,
          char ** argv)
{
    seqan::ArgumentParser parser("sak");
    setShortDescription(parser, "Slicing and dicing of FASTA/FASTQ files..");
    setVersion(parser, SEQAN_APP_VERSION " [" SEQAN_REVISION "]");
    setDate(parser, SEQAN_DATE);
    setCategory(parser, "Utilities");

    addUsageLine(parser, "[\\fIOPTIONS\\fP] [\\fB-o\\fP \\fIOUT.{fa,fq}\\fP] \\fIIN.{fa,fq}\\fP");
    addDescription(parser, "\"It slices, it dices and it makes the laundry!\"");
    addDescription(parser, "Original SAK tool by David Weese. Rewrite by Manuel Holtgrewe.");

    // The only argument is the input file.
    addArgument(parser, seqan::ArgParseArgument(seqan::ArgParseArgument::INPUT_FILE, "IN"));

    // Only FASTA and FASTQ files are allowed as input.
    setValidValues(parser, 0, seqan::SeqFileIn::getFileExtensions());

    // TODO(holtgrew): I want a custom help text!
    // addOption(parser, seqan::ArgParseOption("h", "help", "This helpful screen."));
    addOption(parser, seqan::ArgParseOption("v", "verbose", "Verbose, log to STDERR."));
    hideOption(parser, "verbose");
    addOption(parser, seqan::ArgParseOption("vv", "very-verbose", "Very verbose, log to STDERR."));
    hideOption(parser, "very-verbose");

    addSection(parser, "Output Options");
    addOption(parser, seqan::ArgParseOption("o", "out-path",
                                            "Path to the resulting file.  If omitted, result is printed to stdout in FastQ format.",
                                            seqan::ArgParseOption::OUTPUT_FILE, "FASTX"));
    setValidValues(parser, "out-path", seqan::SeqFileOut::getFileExtensions());
    addOption(parser, seqan::ArgParseOption("rc", "revcomp", "Reverse-complement output."));
    addOption(parser, seqan::ArgParseOption("l", "max-length", "Maximal number of sequence characters to write out.",
                                            seqan::ArgParseOption::INTEGER, "LEN"));

    addSection(parser, "Filter Options");
    addOption(parser, seqan::ArgParseOption("s", "sequence", "Select the given sequence for extraction by 0-based index.",
                                            seqan::ArgParseOption::INTEGER, "NUM", true));
    addOption(parser, seqan::ArgParseOption("sn", "sequence-name", "Select sequence with name prefix being \\fINAME\\fP.",
                                            seqan::ArgParseOption::STRING, "NAME", true));
    addOption(parser, seqan::ArgParseOption("ss", "sequences",
                                            "Select sequences \\fIfrom\\fP-\\fIto\\fP where \\fIfrom\\fP and \\fIto\\fP "
                                            "are 0-based indices.",
                                            seqan::ArgParseArgument::STRING, "RANGE", true));
    addOption(parser, seqan::ArgParseOption("i", "infix",
                                            "Select characters \\fIfrom\\fP-\\fIto\\fP where \\fIfrom\\fP and \\fIto\\fP "
                                            "are 0-based indices.",
                                            seqan::ArgParseArgument::STRING, "RANGE", true));

    addOption(parser, seqan::ArgParseOption("ll", "line-length",
                                            "Set line length in output file.  See section \\fILine Length\\fP for details.",
                                            seqan::ArgParseArgument::INTEGER, "LEN", false));
    setMinValue(parser, "line-length", "-1");

    addTextSection(parser, "Line Length");
    addText(parser,
            "You can use the setting \\fB--line-length\\fP for setting the resulting line length.  By default, "
            "sequences in FASTA files are written with at most 70 characters per line and sequences in FASTQ files are "
            "written without any line breaks.  The quality sequence in FASTQ file is written in the same way as the "
            "residue sequence.");
    addText(parser,
            "The default is selected with a \\fB--line-length\\fP value of \\fI-1\\fP and line breaks can be disabled "
            "with a value of \\fI0\\fP.");

    addTextSection(parser, "Usage Examples");
    addListItem(parser, "\\fBsak\\fP \\fB-s\\fP \\fI10\\fP \\fIIN.fa\\fP",
                "Cut out 11th sequence from \\fIIN.fa\\fP and write to stdout as FASTA.");
    addListItem(parser, "\\fBsak\\fP \\fB-ss\\fP \\fI10-12\\fP \\fB-ss\\fP \\fI100-200\\fP \\fIIN.fq\\fP",
                "Cut out 11th up to and including 12th and 101th up to and including 199th sequence from \\fIIN.fq\\fP "
                "and write to stdout as FASTA.");

    seqan::ArgumentParser::ParseResult res = parse(parser, argc, argv);

    if (res != seqan::ArgumentParser::PARSE_OK)
        return res;

    getArgumentValue(options.inFastxPath, parser, 0);

    seqan::CharString tmp;
    getOptionValue(tmp, parser, "out-path");

    if (isSet(parser, "out-path"))
        getOptionValue(options.outPath, parser, "out-path");

    if (isSet(parser, "verbose"))
        options.verbosity = 2;
    if (isSet(parser, "very-verbose"))
        options.verbosity = 3;

    if (isSet(parser, "sequence"))
    {
        std::vector<std::string> sequenceIds = getOptionValues(parser, "sequence");
        for (unsigned i = 0; i < seqan::length(sequenceIds); ++i)
        {
            unsigned idx = 0;
            if (!seqan::lexicalCast(idx, sequenceIds[i]))
            {
                std::cerr << "ERROR: Invalid sequence index " << sequenceIds[i] << "\n";
                return seqan::ArgumentParser::PARSE_ERROR;
            }
            appendValue(options.seqIndices, idx);
        }
    }

    if (isSet(parser, "sequences"))
    {
        std::vector<std::string> sequenceRanges = getOptionValues(parser, "sequences");
        seqan::CharString buffer;
        for (unsigned i = 0; i < seqan::length(sequenceRanges); ++i)
        {
            seqan::Pair<uint64_t> range;
            if (!parseRange(range.i1, range.i2, sequenceRanges[i]))
            {
                std::cerr << "ERROR: Invalid range " << sequenceRanges[i] << "\n";
                return seqan::ArgumentParser::PARSE_ERROR;
            }
            appendValue(options.seqIndexRanges, range);
        }
    }

    if (isSet(parser, "infix"))
    {
        seqan::CharString buffer;
        getOptionValue(buffer, parser, "infix");
        if (!parseRange(options.seqInfixBegin, options.seqInfixEnd, buffer))
        {
            std::cerr << "ERROR: Invalid range " << buffer << "\n";
            return seqan::ArgumentParser::PARSE_ERROR;
        }
    }

    options.reverseComplement = isSet(parser, "revcomp");

    if (isSet(parser, "max-length"))
        getOptionValue(options.maxLength, parser, "max-length");

    if (isSet(parser, "sequence-name"))
        getOptionValue(options.readPattern, parser, "sequence-name");

    getOptionValue(options.seqOutOptions.lineLength, parser, "line-length");

    return res;
}
Пример #26
0
bool
OptionsCont::processMetaOptions(bool missingOptions) {
    if (missingOptions) {
        // no options are given
        std::cout << myFullName << std::endl;
        std::cout << " Build features: " << HAVE_ENABLED << std::endl;
        for (std::vector<std::string>::const_iterator it =
                    myCopyrightNotices.begin(); it != myCopyrightNotices.end(); ++it) {
            std::cout << " " << *it << std::endl;
        }
        std::cout << " License GPLv3+: GNU GPL Version 3 or later <http://gnu.org/licenses/gpl.html>\n";
        std::cout << " Use --help to get the list of options." << std::endl;
        return true;
    }

    // check whether the help shall be printed
    if (getBool("help")) {
        std::cout << myFullName << std::endl;
        for (std::vector<std::string>::const_iterator it =
                    myCopyrightNotices.begin(); it != myCopyrightNotices.end(); ++it) {
            std::cout << " " << *it << std::endl;
        }
        printHelp(std::cout);
        return true;
    }
    // check whether the help shall be printed
    if (getBool("version")) {
        std::cout << myFullName << std::endl;
        std::cout << " Build features: " << HAVE_ENABLED << std::endl;
        for (std::vector<std::string>::const_iterator it =
                    myCopyrightNotices.begin(); it != myCopyrightNotices.end(); ++it) {
            std::cout << " " << *it << std::endl;
        }
        std::cout << "\n" << myFullName << " is part of SUMO.\n";
        std::cout << "SUMO is free software: you can redistribute it and/or modify\n";
        std::cout << "it under the terms of the GNU General Public License as published by\n";
        std::cout << "the Free Software Foundation, either version 3 of the License, or\n";
        std::cout << "(at your option) any later version.\n\n";
        std::cout << "This program is distributed in the hope that it will be useful,\n";
        std::cout << "but WITHOUT ANY WARRANTY; without even the implied warranty of\n";
        std::cout << "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n";
        std::cout << "GNU General Public License for more details.\n\n";
        std::cout << "You should have received a copy of the GNU General Public License\n";
        std::cout << "along with this program. If not, see http://www.gnu.org/licenses/gpl.html" << std::endl;
        return true;
    }
    // check whether the settings shall be printed
    if (exists("print-options") && getBool("print-options")) {
        std::cout << (*this);
    }
    // check whether something has to be done with options
    // whether the current options shall be saved
    if (isSet("save-configuration", false)) { // sumo-gui does not register these
        if (getString("save-configuration") == "-" || getString("save-configuration") == "stdout") {
            writeConfiguration(std::cout, true, false, getBool("save-commented"));
            return true;
        }
        std::ofstream out(getString("save-configuration").c_str());
        if (!out.good()) {
            throw ProcessError("Could not save configuration to '" + getString("save-configuration") + "'");
        } else {
            writeConfiguration(out, true, false, getBool("save-commented"));
            if (getBool("verbose")) {
                WRITE_MESSAGE("Written configuration to '" + getString("save-configuration") + "'");
            }
            return true;
        }
    }
    // whether the template shall be saved
    if (isSet("save-template", false)) { // sumo-gui does not register these
        if (getString("save-template") == "-" || getString("save-template") == "stdout") {
            writeConfiguration(std::cout, false, true, getBool("save-commented"));
            return true;
        }
        std::ofstream out(getString("save-template").c_str());
        if (!out.good()) {
            throw ProcessError("Could not save template to '" + getString("save-template") + "'");
        } else {
            writeConfiguration(out, false, true, getBool("save-commented"));
            if (getBool("verbose")) {
                WRITE_MESSAGE("Written template to '" + getString("save-template") + "'");
            }
            return true;
        }
    }
    if (isSet("save-schema", false)) { // sumo-gui does not register these
        if (getString("save-schema") == "-" || getString("save-schema") == "stdout") {
            writeSchema(std::cout, getBool("save-commented"));
            return true;
        }
        std::ofstream out(getString("save-schema").c_str());
        if (!out.good()) {
            throw ProcessError("Could not save schema to '" + getString("save-schema") + "'");
        } else {
            writeSchema(out, getBool("save-commented"));
            if (getBool("verbose")) {
                WRITE_MESSAGE("Written schema to '" + getString("save-schema") + "'");
            }
            return true;
        }
    }
    return false;
}
Пример #27
0
SetType::SetType(const Type& t) throw(IllegalArgumentException)
    : Type(t) {
  PrettyCheckArgument(isNull() || isSet(), this);
}
Пример #28
0
bool RegularExpression::matchAnchor(Context* const context, const XMLInt32 ch,
									const int offset)
{
	switch ((XMLCh) ch) {
	case chLatin_A:
		if (offset != context->fStart)
			return false;
		break;
	case chLatin_B:
		if (context->fLength == 0)
			break;
		{
			int after = getWordType(context->fString, context->fStart,
									context->fLimit, offset);
			if (after == WT_IGNORE
				|| after == getPreviousWordType(context->fString,
												context->fStart,
												context->fLimit, offset))
				break;
		}
		return false;
	case chLatin_b:
		if (context->fLength == 0)
			return false;
		{
			int after = getWordType(context->fString, context->fStart,
									context->fLimit, offset);
			if (after == WT_IGNORE
				|| after == getPreviousWordType(context->fString,
												context->fStart
												, context->fLimit, offset))
				return false;
		}
		break;
	case chLatin_Z:
	case chDollarSign:
		if ( (XMLCh) ch == chDollarSign && isSet(fOptions, MULTIPLE_LINE)) {
			if (!(offset == context->fLimit || (offset < context->fLimit
				&& RegxUtil::isEOLChar(context->fString[offset]))))
				return false;
		}
		else {

			if (!(offset == context->fLimit
				|| (offset+1 == context->fLimit
				    && RegxUtil::isEOLChar(context->fString[offset]))
				|| (offset+2 == context->fLimit
				    && context->fString[offset] == chCR
					&& context->fString[offset+1] == chLF)))
				return false;
		}
		break;
	case chLatin_z:
		if (offset != context->fLimit)
			return false;
		break;
	case chAt:
	case chCaret:
		if ( (XMLCh) ch == chCaret && !isSet(fOptions, MULTIPLE_LINE)) {

			if (offset != context->fStart)
				return false;
		}
		else {

			if (!(offset == context->fStart || (offset > context->fStart
				      && RegxUtil::isEOLChar(context->fString[offset-1]))))
				return false;
		}
		break;
	case chOpenAngle:
		if (context->fLength == 0 || offset == context->fLimit)
			return false;

		if (getWordType(context->fString, context->fStart, context->fLimit,
						offset) != WT_LETTER
			|| getPreviousWordType(context->fString, context->fStart,
								   context->fLimit, offset) != WT_OTHER)
			return false;
		break;
	case chCloseAngle:
		if (context->fLength == 0 || offset == context->fStart)
			return false;

		if (getWordType(context->fString, context->fStart, context->fLimit,
						offset) != WT_OTHER
			|| getPreviousWordType(context->fString, context->fStart,
								   context->fLimit, offset) != WT_LETTER)
			return false;
		break;
	}

	return true;
}
Пример #29
0
seqan::ArgumentParser::ParseResult
parseCommandLine(ModifyStringOptions & options, int argc, char const ** argv)
{
    // Setup ArgumentParser.
    seqan::ArgumentParser parser("modify_string");
    // Set short description, version, and date.
    setShortDescription(parser, "String Modifier");
    setVersion(parser, "1.0");
    setDate(parser, "July 2012");

    // Define usage line and long description.
    addUsageLine(parser,
                 "[\\fIOPTIONS\\fP] \"\\fITEXT\\fP\"");
    addDescription(parser,
                   "This program allows simple character modifications to "
                           "each i-th character.");

    // We require one argument.
    addArgument(parser, seqan::ArgParseArgument(
            seqan::ArgParseArgument::STRING, "TEXT"));

    // Define Options -- Section Modification Options
    addSection(parser, "Modification Options");
    addOption(parser, seqan::ArgParseOption(
            "i", "period", "Period to use for the index.",
            seqan::ArgParseArgument::INTEGER, "INT"));
    setDefaultValue(parser, "period", "1");
    addOption(parser, seqan::ArgParseOption(
            "U", "uppercase", "Select to-uppercase as operation."));
    addOption(parser, seqan::ArgParseOption(
            "L", "lowercase", "Select to-lowercase as operation."));

    // Add Examples Section.
    addTextSection(parser, "Examples");
    addListItem(parser,
                "\\fBmodify_string\\fP \\fB-U\\fP \\fIveryverylongword\\fP",
                "Print upper case version of \"veryverylongword\"");
    addListItem(parser,
                "\\fBmodify_string\\fP \\fB-L\\fP \\fB-i\\fP \\fI3\\fP "
                        "\\fIveryverylongword\\fP",
                "Print \"veryverylongword\" with every third character "
                        "converted to upper case.");

    // Parse command line.
    seqan::ArgumentParser::ParseResult res = seqan::parse(parser, argc, argv);

    // Only extract  options if the program will continue after parseCommandLine()
    if (res != seqan::ArgumentParser::PARSE_OK)
        return res;

    // Extract option values.
    getOptionValue(options.period, parser, "period");
    options.toUppercase = isSet(parser, "uppercase");
    options.toLowercase = isSet(parser, "lowercase");
    seqan::getArgumentValue(options.text, parser, 0);

    // If both to-uppercase and to-lowercase were selected then this is an error.
    if (options.toUppercase && options.toLowercase)
    {
        std::cerr << "ERROR: You cannot specify both to-uppercase and to-lowercase!\n";
        return seqan::ArgumentParser::PARSE_ERROR;
    }

    return seqan::ArgumentParser::PARSE_OK;
}
Пример #30
0
/*
 * Prepares for matching. This method is called just before starting matching
 */
void RegularExpression::prepare() {

	XMLMutexLock lockInit(&fMutex);

	compile(fTokenTree);

	fMinLength = fTokenTree->getMinLength();
	fFirstChar = 0;

	if (!isSet(fOptions, PROHIBIT_HEAD_CHARACTER_OPTIMIZATION) &&
		!isSet(fOptions, XMLSCHEMA_MODE))							{

		RangeToken* rangeTok = fTokenFactory->createRange();
		int result = fTokenTree->analyzeFirstCharacter(rangeTok, fOptions, fTokenFactory);

		if (result == Token::FC_TERMINAL) {

			rangeTok->compactRanges();
			fFirstChar = rangeTok;
		}
	}

	if (fOperations != 0 && fOperations->getNextOp() == 0 &&
		(fOperations->getOpType() == Op::O_STRING ||
		 fOperations->getOpType() == Op::O_CHAR) )			 {

		fFixedStringOnly = true;

		if (fOperations->getOpType() == Op::O_STRING) {
			fMemoryManager->deallocate(fFixedString);//delete [] fFixedString;
			fFixedString = XMLString::replicate(fOperations->getLiteral(), fMemoryManager);
		}
		else{
			
			XMLInt32 ch = fOperations->getData();

			if ( ch >= 0x10000) { // add as constant
				fMemoryManager->deallocate(fFixedString);//delete [] fFixedString;
				fFixedString = RegxUtil::decomposeToSurrogates(ch, fMemoryManager);
			}
			else {

				XMLCh* dummyStr = (XMLCh*) fMemoryManager->allocate(2 * sizeof(XMLCh));//new XMLCh[2];
				dummyStr[0] = (XMLCh) fOperations->getData();
				dummyStr[1] = chNull;
				fMemoryManager->deallocate(fFixedString);//delete [] fFixedString;
				fFixedString = dummyStr;
			}
		}

		fBMPattern = new (fMemoryManager) BMPattern(fFixedString, 256,
								  isSet(fOptions, IGNORE_CASE), fMemoryManager);
	}
	else if (!isSet(fOptions, XMLSCHEMA_MODE) &&
			 !isSet(fOptions, PROHIBIT_FIXED_STRING_OPTIMIZATION)) {

		int fixedOpts = 0;
		Token* tok = fTokenTree->findFixedString(fOptions, fixedOpts);

		fMemoryManager->deallocate(fFixedString);//delete [] fFixedString;

		fFixedString = (tok == 0) ? 0
			: XMLString::replicate(tok->getString(), fMemoryManager);

		if (fFixedString != 0 && XMLString::stringLen(fFixedString) < 2) {

			fMemoryManager->deallocate(fFixedString);//delete [] fFixedString;
			fFixedString = 0;
		}
		
		if (fFixedString != 0) {

			fBMPattern = new (fMemoryManager) BMPattern(fFixedString, 256,
									   isSet(fixedOpts, IGNORE_CASE));
		}
	}
}