Example #1
0
	unsigned int getSize()
	{
		unsigned int totalSize = 0;

		// Start with the size of the contents 
		// (don't use seek as we don't know if the client still wants to write stuff)
		totalSize += static_cast<unsigned int>(contents.size());

		if (!subChunks.empty())
		{
			// Sum up the size of the subchunks
			for (Chunk& chunk : subChunks)
			{
				totalSize += 4; // ID (4 bytes)
				totalSize += chunk.chunkSizeBytes; // Subchunk Size Info (can be 4 or 2 bytes)

				// While the child chunk size itself doesn't include padding, we need to respect
				// it when calculating the size of this parent chunk
				unsigned int childChunkSize = chunk.getSize();
				totalSize += childChunkSize + (childChunkSize % 2); // add 1 padding byte if odd
			}
		}
		else
		{
			totalSize += rawData.size();
		}

		return totalSize;
	}
Example #2
0
 PosibErr<const char *> operator() (ParmStr str)
 {
   if (conv) {
     buf.clear();
     RET_ON_ERR(conv->convert_ec(str, -1, buf, buf0, str));
     return buf.mstr();
   } else {
     return str.str();
   }
 }
Example #3
0
 PosibErr<char *> operator() (char * str, size_t sz)
 {
   if (conv) {
     buf.clear();
     RET_ON_ERR(conv->convert_ec(str, sz, buf, buf0, str));
     return buf.mstr();
   } else {
     return str;
   }
 }
Example #4
0
 const char * operator() (ParmStr str)
 {
   if (conv) {
     buf.clear();
     conv->convert(str, -1, buf, buf0);
     return buf.mstr();
   } else {
     return str;
   }
 }
Example #5
0
 const char * operator() (const char * str, size_t sz)
 {
   if (conv) {
     buf.clear();
     conv->convert(str, sz, buf, buf0);
     return buf.str();
   } else {
     return str;
   }
 }
Example #6
0
 char * operator() (char c)
 {
   buf.clear();
   if (conv) {
     char str[2] = {c, 0};
     conv->convert(str, 1, buf, buf0);
   } else {
     buf.append(c);
   }
   return buf.mstr();
 }
Example #7
0
void addStringToContents(CharVector& contents, const std::string& str)
{
	std::size_t bytesWritten = 0;

	for (std::size_t i = 0; i < str.length(); ++i)
	{
		contents.push_back(str[i]);
		++bytesWritten;
	}

	contents.push_back('\0');
	++bytesWritten;

	if (bytesWritten % 2 == 1)
	{
		contents.push_back('\0');
		++bytesWritten;
	}
}
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;
	}
}
void MSDigestSearch::printProteinCoverage ( ostream& os, const CharVector& aaCovered ) const
{
	int protLen = aaCovered.size ();
	if ( protLen ) {
		int coverCount = 0;
		for ( int m = 0; m < protLen ; m++ ) {
			if ( aaCovered [m] > 0 ) coverCount++;
		}
		os << "The&nbsp;matched&nbsp;peptides&nbsp;cover&nbsp;<b>" << 100 * coverCount / protLen << "%</b>";
		os << "&nbsp;";
		os << "(" << coverCount << "/" << protLen << "&nbsp;AA's)&nbsp;of&nbsp;the&nbsp;protein.";
		os << "<p />";
	}
}
Example #10
0
 void append_null(CharVector & out) const
 {
   const char nul[4] = {0,0,0,0}; // 4 should be enough
   out.write(nul, null_len_);
 }
void SQLiteAATable::insert ()
{
	v1 [3] = "";
	v1 [4] = "1";
	v1 [5] = "0";
	CharVector cv = AAInfo::getInfo ().getAminoAcids ();
	for ( StringVectorSizeType i = 0 ; i < cv.size () ; i++ ) {
		char c = cv [i];
		v1 [0] = AAInfo::getInfo ().getLongName ( c );

		v1 [1] = "one_letter_code";
		v1 [2] = string ( 1, c );
		insertTable ( tableName, n1, v1 );

		v1 [1] = "formula";
		v1 [2] = AAInfo::getInfo ().getElementalString ( c );
		insertTable ( tableName, n1, v1 );

		v1 [1] = "dw_substituent_a";
		string subA = AAInfo::getInfo ().getSubstituentA ( c );
		if ( subA != "0" ) {
			v1 [2] = subA;
			insertTable ( tableName, n1, v1 );
		}

		v1 [1] = "dw_substituent_b";
		string subB = AAInfo::getInfo ().getSubstituentB ( c );
		if ( subB != "0" ) {
			v1 [2] = subB;
			insertTable ( tableName, n1, v1 );
		}

		v1 [1] = "pk_c_term";
		string ctpk = AAInfo::convert_pk ( AAInfo::getInfo ().getCTermPK ( c ) );
		if ( ctpk != "n/a" ) {
			v1 [2] = ctpk;
			insertTable ( tableName, n1, v1 );
		}

		v1 [1] = "pk_n_term";
		string ntpk = AAInfo::convert_pk ( AAInfo::getInfo ().getNTermPK ( c ) );
		if ( ntpk != "n/a" ) {
			v1 [2] = ntpk;
			insertTable ( tableName, n1, v1 );
		}

		v1 [1] = "pk_acidic_sc";
		string ascpk = AAInfo::convert_pk ( AAInfo::getInfo ().getAcidicSCPK ( c ) );
		if ( ascpk != "n/a" ) {
			v1 [2] = ascpk;
			insertTable ( tableName, n1, v1 );
		}

		v1 [1] = "pk_basic_sc";
		string bscpk = AAInfo::convert_pk ( AAInfo::getInfo ().getBasicSCPK ( c ) );
		if ( bscpk != "n/a" ) {
			v1 [2] =  bscpk;
			insertTable ( tableName, n1, v1 );
		}
	}
}
Example #12
0
void parseFromStream(CharVector& buffer, int level, Chunk& parsedChunk)
{
	VectorBuffer<char> tempBuf(buffer);
	std::istream stream(&tempBuf);

	if (parsedChunk.id == "SURF")
	{
		std::string surfName = parseString0(stream);
		std::string parentName = parseString0(stream);

		addStringToContents(parsedChunk.contents, surfName);
		addStringToContents(parsedChunk.contents, parentName);
	}

	if (parsedChunk.id == "IMAP")
	{
		std::string ordinal = parseString0(stream);
		addStringToContents(parsedChunk.contents, ordinal);
	}

	while (!stream.eof())
	{
		// Read header
		Chunk chunk;

		char id[5];
		stream.read(id, 4);
		id[4] = '\0';

		chunk.id = id;

		if (stream.eof()) break;

		if (parsedChunk.id == "SURF" || parsedChunk.id == "BLOK" ||
			parsedChunk.id == "IMAP" || parsedChunk.id == "TMAP")
		{
			uint16_t size;
			stream.read((char*)&size, 2);
			size = reverse(size);
			chunk.size = size;
			chunk.chunkSizeBytes = 2;
		}
		else
		{
			uint32_t size;
			stream.read((char*)&size, 4);
			size = reverse(size);
			chunk.size = size;
			chunk.chunkSizeBytes = 4;
		}

		assert(!stream.fail());

		//std::string indent(level * 2, ' ');
		//std::cout << indent << id << " with size " << chunk.size << " bytes" << std::endl;

		// Check size restrictions
		assert(4 + chunk.chunkSizeBytes + chunk.size <= buffer.size());

		uint32_t dataSize = chunk.size;

		if (chunk.id == "FORM")
		{
			// LWO doesn't have the correct size?
			if (dataSize + 4 + 4 != buffer.size())
			{
				std::cout << "ERROR: FORM Size Value + 8 Bytes is not the same as the file size." << std::endl;
				assert(false);
			}

			// Read the LWO2 tag
			char lwo2[5];
			stream.read(lwo2, 4);
			lwo2[4] = '\0';

			assert(std::string(lwo2) == "LWO2");

			chunk.contents.push_back('L');
			chunk.contents.push_back('W');
			chunk.contents.push_back('O');
			chunk.contents.push_back('2');

			dataSize -= 4;
		}

		assert(!stream.fail());

		chunk.rawData.resize(dataSize);
		stream.read(&chunk.rawData.front(), dataSize);

#if 0
		if (chunk.id == "COLR")
		{
			uint32_t colr1Raw = *((uint32_t*)&chunk.rawData[0]);
			colr1Raw = reverse(colr1Raw);
			float colr1 = *((float*)&colr1Raw);
			std::cout << colr1;
		}
#endif

		assert(!stream.fail());

		// Fill bit if size is odd
		if (dataSize % 2 == 1)
		{
			char temp;
			stream.read(&temp, 1);
			assert(temp == '\0');
			assert(!stream.fail());
		}

		parsedChunk.subChunks.push_back(chunk);
	}

	// Try to parse the subchunks
	for (Chunk& chunk : parsedChunk.subChunks)
	{
		if (chunk.id == "FORM" || chunk.id == "SURF" || chunk.id == "BLOK" ||
			chunk.id == "IMAP" || chunk.id == "TMAP")
		{
			parseFromStream(chunk.rawData, level + 1, chunk);
		}
	}
}
Example #13
0
 virtual std::size_t size () const
 {
     return m_char_vector.size();
 }
Example #14
0
 virtual void put (midibyte b)
 {
     m_char_vector.push_back(b);
 }