コード例 #1
0
void init_fasta_enzyme_function ( const string& enzyme )
{
	static bool called = false;
	if ( called ) return;
	called = true;
	static DigestTable& digestTable = DigestTable::instance ();

	if ( enzyme == "No enzyme" ) {
		ErrorHandler::genError ()->error ( "No enzyme not valid option for this program." );
		return;
	}
	StringVector enzymeNameTable;
	cnbr_digest = false;
	StringSizeType start = 0;
	StringSizeType end = 0;
	for ( ; ; ) {
		end = enzyme.find_first_of ( "/", start );
		string enzymeName = enzyme.substr ( start, end-start );
		if ( enzymeName == "CNBr" ) cnbr_digest = true;
		enzymeNameTable.push_back ( enzymeName );
		if ( end == string::npos ) break;
		start = end + 1;
	}
	numDigests = enzymeNameTable.size ();

	for ( int i = 0 ; i < numDigests ; i++ ) {
		string br_aas = digestTable.getBreakMask (enzymeNameTable[i]);
		break_aas_array.push_back ( br_aas );
		break_mask_array.push_back ( string_to_mask ( br_aas ) );

		string exclude_aas = digestTable.getExcludeMask (enzymeNameTable[i]);
		exclude_aas_array.push_back ( exclude_aas );
		if ( exclude_aas != "-" ) exclude_mask_array.push_back ( string_to_mask ( exclude_aas ) );
		else exclude_mask_array.push_back ( 0 );

		digestSpecificityArray.push_back ( digestTable.getSpecificity (enzymeNameTable[i]) );
	}	
	if ( numDigests == 1 ) {
		break_mask = break_mask_array [0];
		break_aas = break_aas_array [0];
		exclude_mask = exclude_mask_array [0];
		digestSpecificity = digestSpecificityArray [0];
		if ( digestSpecificity == 'C' ) enzyme_fragmenter = calc_fasta_c_term_fragments;
		else enzyme_fragmenter = calc_fasta_n_term_fragments;
	}
	else {
		int i;
		for ( i = 1 ; i < numDigests ; i++ ) {
			if ( digestSpecificityArray [i] != digestSpecificityArray [0] ) break;
		}
		if ( i == numDigests ) digestSpecificity = digestSpecificityArray [0];	/* All digest specificities must be the same for digestSpecificity to be set */

		enzyme_fragmenter = calc_fasta_multi_digest_fragments;
	}
}
コード例 #2
0
EStatusCode CFFEmbeddedFontWriter::AddDependentGlyphs(UIntVector& ioSubsetGlyphIDs)
{
	EStatusCode status = PDFHummus::eSuccess;
	UIntSet glyphsSet;
	UIntVector::iterator it = ioSubsetGlyphIDs.begin();
	bool hasCompositeGlyphs = false;

	for(;it != ioSubsetGlyphIDs.end() && PDFHummus::eSuccess == status; ++it)
	{
		bool localHasCompositeGlyphs;
		status = AddComponentGlyphs(*it,glyphsSet,localHasCompositeGlyphs);
		hasCompositeGlyphs |= localHasCompositeGlyphs;
	}

	if(hasCompositeGlyphs)
	{
		UIntSet::iterator itNewGlyphs;

		for(it = ioSubsetGlyphIDs.begin();it != ioSubsetGlyphIDs.end(); ++it)
			glyphsSet.insert(*it);

		ioSubsetGlyphIDs.clear();
		for(itNewGlyphs = glyphsSet.begin(); itNewGlyphs != glyphsSet.end(); ++itNewGlyphs)
			ioSubsetGlyphIDs.push_back(*itNewGlyphs);
		
		sort(ioSubsetGlyphIDs.begin(),ioSubsetGlyphIDs.end());
	}	
	return status;
}
コード例 #3
0
static UIntVector GetOrderedKeys(const UIntAndGlyphEncodingInfoVector& inMap)
{
	UIntVector result;
	for(UIntAndGlyphEncodingInfoVector::const_iterator it = inMap.begin(); it != inMap.end(); ++it)
		result.push_back(it->first);
	sort(result.begin(),result.end());
	return result;
}
コード例 #4
0
EStatusCode CFFDescendentFontWriter::WriteFont(	ObjectIDType inDecendentObjectID, 
														const std::string& inFontName,
														FreeTypeFaceWrapper& inFontInfo,
														const UIntAndGlyphEncodingInfoVector& inEncodedGlyphs,
														ObjectsContext* inObjectsContext,
														bool inEmbedFont)
{
	// reset embedded font object ID (and flag...to whether it was actually embedded or not, which may 
	// happen due to font embedding restrictions)
	mEmbeddedFontFileObjectID = 0;

	// Logically speaking, i shouldn't be getting to CID writing
	// if in type 1. at least, this is the current assumption, since
	// i don't intend to support type 1 CIDs, but just regular type 1s.
	// as such - fail if got here for type 1
	const char* fontType = inFontInfo.GetTypeString();
	if(strcmp(scType1,fontType) == 0)
	{
		TRACE_LOG1("CFFDescendentFontWriter::WriteFont, Exception. identified type1 font when writing CFF CID font, font name - %s. type 1 CIDs are not supported.",inFontName.substr(0, MAX_TRACE_SIZE - 200).c_str());
		return PDFHummus::eFailure;
	}

	if (inEmbedFont)
	{
		CFFEmbeddedFontWriter embeddedFontWriter;
		UIntAndGlyphEncodingInfoVector encodedGlyphs = inEncodedGlyphs;
		UIntVector orderedGlyphs;
		UShortVector cidMapping;

		// Gal: the following sort completely ruins everything.
		// the order of the glyphs should be maintained per the ENCODED characthers
		// which is how the input is recieved. IMPORTANT - the order is critical
		// for the success of the embedding, as the order determines the order of the glyphs
		// in the subset font and so their GID which MUST match the encoded char.
		//sort(encodedGlyphs.begin(), encodedGlyphs.end(), sEncodedGlypsSort);

		for (UIntAndGlyphEncodingInfoVector::const_iterator it = encodedGlyphs.begin();
			it != encodedGlyphs.end();
			++it)
		{
			orderedGlyphs.push_back(it->first);
			cidMapping.push_back(it->second.mEncodedCharacter);
		}
		EStatusCode status = embeddedFontWriter.WriteEmbeddedFont(inFontInfo,
			orderedGlyphs,
			scCIDFontType0C,
			inFontName,
			inObjectsContext,
			&cidMapping,
			mEmbeddedFontFileObjectID);
		if (status != PDFHummus::eSuccess)
			return status;
	}

	DescendentFontWriter descendentFontWriter;

	return descendentFontWriter.WriteFont(inDecendentObjectID,inFontName,inFontInfo,inEncodedGlyphs,inObjectsContext,this);
}
コード例 #5
0
ファイル: KNearest.cpp プロジェクト: snailcoder/PASS
UIntVector KNearest::Nearest(const RealCoord &state, 
						     const RealCoordVector &state_set) const {
  UIntVector neighbors;
  std::size_t state_num = state_set.size();
  if (state_num <= k_) {
    for (unsigned i = 0; i < state_num; ++i) {
      neighbors.push_back(i);
    }
  } else {
    double *dist = new double[state_num];
	for (unsigned i = 0; i < state_num; ++i) {
      dist[i] = metric_->Distance(state, state_set[i]);
	}
	for (unsigned i = 0; i <= k_; ++i) {
      neighbors.push_back(i);
	}
	for (unsigned i = 1; i < k_; ++i) {
      double di = dist[i];
      unsigned j = i - 1;
	  while (j != std::numeric_limits<unsigned>::max() && dist[i] < dist[j]) {
        dist[j + 1] = dist[j];
        neighbors[j + 1] = neighbors[j];
        --j;
      }
      dist[j + 1] = di;
      neighbors[j + 1] = i;
    }
    for (unsigned i = k_; i < state_num; ++i) {
      double di = dist[i];
      unsigned j = k_ - 1;
	  while (j != std::numeric_limits<unsigned>::max() && dist[i] < dist[j]) {
        dist[j + 1] = dist[j];
        neighbors[j + 1] = neighbors[j];
        --j;
	  }
      neighbors[j + 1] = i;
	}
    delete[] dist;
  }
  neighbors.pop_back();
  return neighbors;
}
コード例 #6
0
void TrueTypeEmbeddedFontWriter::AddDependentGlyphs(UIntVector& ioSubsetGlyphIDs)
{
	UIntSet glyphsSet;
	UIntVector::iterator it = ioSubsetGlyphIDs.begin();
	bool hasCompositeGlyphs = false;

	for(;it != ioSubsetGlyphIDs.end(); ++it)
		hasCompositeGlyphs |= AddComponentGlyphs(*it,glyphsSet);

	if(hasCompositeGlyphs)
	{
		UIntSet::iterator itNewGlyphs;

		for(it = ioSubsetGlyphIDs.begin();it != ioSubsetGlyphIDs.end(); ++it)
			glyphsSet.insert(*it);

		ioSubsetGlyphIDs.clear();
		for(itNewGlyphs = glyphsSet.begin(); itNewGlyphs != glyphsSet.end(); ++itNewGlyphs)
			ioSubsetGlyphIDs.push_back(*itNewGlyphs);
		
		sort(ioSubsetGlyphIDs.begin(),ioSubsetGlyphIDs.end());
	}
}
コード例 #7
0
ファイル: CPythonCounter.cpp プロジェクト: zackkk/MIPS
/*!
* Extracts and stores logical lines of code.
* Determines and extract logical SLOC to place in the result variable
* using addSLOC function. Each time the addSLOC function is called,
* a new logical SLOC is added. This function assumes that the directive
* is handled before it is called.
*
* \param result counter results
* \param line processed physical line of code
* \param lineBak original physical line of code
* \param strLSLOC processed logical string
* \param strLSLOCBak original logical string
* \param paren_cnt count of parenthesis
* \param loopWhiteSpace count of white space to determine loop ends
*/
void CPythonCounter::LSLOC(results* result, string line, size_t lineNumber, string lineBak, string &strLSLOC, string &strLSLOCBak,
						   unsigned int &paren_cnt, UIntVector &loopWhiteSpace)
{
#define CONT_STR_LENGTH 18
	string continuation_str[] = {"is", "in", "not", "+", "-", "*", "/", "=", "<", ">", "|", "&", "%", "^", "\\", "~", ",", "$"};
	
	size_t start = 0;	// starting index of the working string
	size_t i = 0, idx, strSize;
	int n;
	bool trunc_flag = false;
	unsigned int cnt = 0, numWS;
	string exclude = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_$";

	string tmp;

	// process:
	// paren_cnt is used with {} [] ()
	// 1. check if the  current char is in one of the parentheses
	// 2.   if no, check if the line has : or ; (statement separators), except else:
	// 3.      if yes, count and put the statement in the result
	// 4. if the line does not ends with a continuation string or a statement separator (handled)
	//      and the line is not in one of the parentheses
	//      then count and put the statement in the result
	// 5. physical count considers all lines executables (or directives, no declarations)

	// check for loop ends, new loops, and record white space in order to determine ends
	if (print_cmplx)
	{
		// check white space for loop ends
		if (loopWhiteSpace.size() > 0)
		{
			// get white space
			tmp = line;
			tmp = CUtil::TrimString(tmp, -1);
			numWS = (unsigned)(line.length() - tmp.length());

			// check for loop ends
			for (n = (int)loopWhiteSpace.size() - 1; n >= 0; n--)
			{
				if (loopWhiteSpace.at(n) != numWS)
					break;
				else
					loopWhiteSpace.pop_back();
			}
		}

		// check for loop keywords (for, while)
		cnt = 0;
		CUtil::CountTally(line, loop_keywords, cnt, 1, exclude, "", "", NULL);
		if (cnt > 0)
		{
			if (loopWhiteSpace.size() < 1)
			{
				// get white space
				tmp = line;
				tmp = CUtil::TrimString(tmp, -1);
				numWS = (unsigned)(line.length() - tmp.length());
			}

			// add nested loop white space and record nested loop level
			for (i = 0; i < cnt; i++)
			{
				loopWhiteSpace.push_back(numWS);

				if ((unsigned int)result->cmplx_nestloop_count.size() < loopWhiteSpace.size())
					result->cmplx_nestloop_count.push_back(1);
				else
					result->cmplx_nestloop_count[loopWhiteSpace.size()-1]++;
			}
		}
	}

	line = CUtil::TrimString(line);
	lineBak = CUtil::TrimString(lineBak);
	size_t line_length = line.length();
	bool lineContinued = false;

	while (i < line_length)
	{
		switch (line[i])
		{
		case '{': case '[': case '(': // parentheses opener
			paren_cnt++;
			break;
		case '}': case ']': case ')': // parentheses closer
			if (paren_cnt > 0)
				paren_cnt--;
			break;
		}

		// 2. if no parentheses enclosing, and if the char is a statement separator
		if (paren_cnt == 0 && (line[i] == ';' || line[i] == ':'))
		{
			tmp = CUtil::ClearRedundantSpaces(line);
			// if line[..i] is else: then exit the outer if
			if (tmp.rfind("else:") != tmp.length() - 5)
			{
				// 3.
				strSize = CUtil::TruncateLine(i + 1 - start, strLSLOC.length(), this->lsloc_truncate, trunc_flag);
				if (strSize > 0)
				{
					strLSLOC += line.substr(start, i);
					strLSLOCBak += lineBak.substr(start, i);
				}
				if (result->addSLOC(strLSLOCBak, lineNumber, trunc_flag))
				{
					// increase logical SLOC here
					result->exec_lines[LOG]++;
				}
				strLSLOC = strLSLOCBak = "";
				start = i + 1;
			}
			else
				lineContinued = true;
		}
		i++;
	}

	if (paren_cnt == 0)
	{
		// add logical SLOC if the line does not end with a continuation string/char
		if (!lineContinued)
		{
			for (i = 0; i < CONT_STR_LENGTH; i++)
			{
				if (continuation_str[i].length() == 1)
				{
					if (line[line_length - 1] == continuation_str[i][0])
					{
						lineContinued = true;
						break;
					}
				}
				else
				{
					idx = CUtil::FindKeyword(line, continuation_str[i]);
					if (idx != string::npos && idx == line_length - continuation_str[i].length() - 1)
					{
						lineContinued = true;
						break;
					}
				}
			}
		}

		if (!lineContinued)
		{
			strSize = CUtil::TruncateLine(line_length - start, strLSLOC.length(), this->lsloc_truncate, trunc_flag);
			if (strSize > 0)
			{
				strLSLOC += line.substr(start, line_length);
				strLSLOCBak += lineBak.substr(start, line_length);
			}
			if (result->addSLOC(strLSLOCBak, lineNumber, trunc_flag))
			{
				// increase logical SLOC here
				result->exec_lines[LOG]++;
			}
			strLSLOC = strLSLOCBak = "";
		}
		else
		{
			tmp = CUtil::TrimString(line.substr(start, line_length - start));
			strSize = CUtil::TruncateLine(tmp.length(), strLSLOC.length(), this->lsloc_truncate, trunc_flag);
			if (strSize > 0)
			{
				strLSLOC += tmp.substr(0, strSize);
				tmp = CUtil::TrimString(lineBak.substr(start, line_length - start));
				strLSLOCBak += tmp.substr(0, strSize);
			}
		}
	}
	result->exec_lines[PHY]++;
}