Пример #1
0
	void processResData_ByRotID( const std::string& resName, ContainerType& data, RotamerLibrary& _RotLib )
	{
		// Sort the data to increase efficiency below
		std::stable_sort( data.begin(), data.end(), sortPsi);
		std::stable_sort( data.begin(), data.end(), sortPhi);		
		std::stable_sort( data.begin(), data.end(), sortRotID);

		ContainerType subdata;
		
		while( true )
		{
			if( data.size() > 0 && (subdata.size() == 0 || subdata[0].rotID.compare( data.back().rotID,0,4,0 )) )
			{
				subdata.push_back( data.back() );
				data.erase(data.end()-1); // rob the end, not the start (ContainerType<> perfomance reasons!)
			}
			else
			{
				ASSERT( data.size() == (36*36), ParseException, "Assumption error!");
				ASSERT( data[0].phi == -180.0 && data[0].psi == -180.0, ParseException, "Wrong phi/psi");
				for( size_t j = 1; j < data.size(); j++ )
				{	
					ASSERT( data[j].phi == (-180.0+(j/36)*10) && data[j].psi == (-180.0+(j%36)*10), ParseException, "Wrong phi/psi");			
				}
				processData( resName, subdata, _RotLib, 40.0 ); // 40 degree tollerance delta from data[0]
				subdata.clear();
				if( data.size() == 0 )
				{
					return;
				}
			}
		}		
	}
Пример #2
0
void insert_elements( ContainerType& cont, int start, int finish )
{
    for( int num = start; num < finish; ++num )
    {
        cont.push_back( num );
    }
}
Пример #3
0
void BigInt::makeMultiplicationWithNumbersAndDigit(const ContainerType& numbers, RankType digit, ContainerType& result)
{
	result.clear();
	result.push_back(0);
	if (0 == digit)
	{
		return;
	}
	else if (1 == digit)
	{
		result = numbers;
	}
	else
	{
		for (int rankIndex = 0; rankIndex < numbers.size(); rankIndex++)
		{
			RankType multiplication = numbers[rankIndex] * digit;
			if (result.size() == rankIndex)
			{
				result.push_back(multiplication % kBaseValue);
			}
			else
			{
				result[rankIndex] += multiplication % kBaseValue;
			}

			if (result[rankIndex] / kBaseValue)
			{
				result[rankIndex] %= kBaseValue;
				result.push_back(1);
			}

			if (multiplication / kBaseValue)
			{
				if (result.size() == rankIndex + 1)
				{
					result.push_back(multiplication / kBaseValue);
				}
				else
				{
					result[rankIndex + 1] += multiplication / kBaseValue;
				}
			}
		}
	}
}
Пример #4
0
ContainerType split(std::string const& input, char del) {
    std::istringstream ss{input};
    ContainerType result;
    std::string e;
    while (std::getline(ss, e, del))
        result.push_back(e);
    return result;
}
Пример #5
0
	void processResData_ByChis( const std::string& resName, ContainerType& data, RotamerLibrary& _RotLib )
	{
		const double tollerance = 12.0;

		// Ensure full chi arrays
		size_t largestSoFar = data[0].chis.size();
		for( size_t i = 1; i < data.size(); i++ )
		{
			if( data[i].chis.size() > largestSoFar )
			{
				largestSoFar = data[i].chis.size();
				i = 0; // reset
			}
			while( data[i].chis.size() < largestSoFar )
			{
				data[i].chis.push_back(0.0);
			}
		}

		size_t done = 0;
		std::vector<bool> taken(data.size());
		while( data.size() > done )
		{
			ContainerType subdata;
			bool on = false;
			for( int i = (int)data.size()-1; i >= 0; i-- )
			{
				if( taken[i] != true && (!on || equalChis( subdata[0], data[i], tollerance ) ) )
				{
					subdata.push_back( data[i] );
					taken[i] = true;
					on = true;
					done++;
				}
			}
			processData( resName, subdata, _RotLib, tollerance );
			subdata.clear();
		}
		data.clear();
	}
Пример #6
0
void DataTest::testColumnList()
{
	typedef std::list<int> ContainerType;
	typedef Column<ContainerType> ColumnType;

	MetaColumn mc(0, "mc", MetaColumn::FDT_DOUBLE, 2, 3, true);

	assert (mc.name() == "mc");
	assert (mc.position() == 0);
	assert (mc.length() == 2);
	assert (mc.precision() == 3);
	assert (mc.type() == MetaColumn::FDT_DOUBLE);
	assert (mc.isNullable());

	ContainerType* pData = new ContainerType;
	pData->push_back(1);
	pData->push_back(2);
	pData->push_back(3);
	pData->push_back(4);
	pData->push_back(5);
	
	ColumnType c(mc, pData);

	assert (c.rowCount() == 5);
	assert (c[0] == 1);
	assert (c[1] == 2);
	assert (c[2] == 3);
	assert (c[3] == 4);
	assert (c[4] == 5);
	assert (c.name() == "mc");
	assert (c.position() == 0);
	assert (c.length() == 2);
	assert (c.precision() == 3);
	assert (c.type() == MetaColumn::FDT_DOUBLE);

	try
	{
		int i; i = c[100]; // to silence gcc
		fail ("must fail");
	}
	catch (RangeException&) { }

	ColumnType c1 = c;

	assert (c1.rowCount() == 5);
	assert (c1[0] == 1);
	assert (c1[1] == 2);
	assert (c1[2] == 3);
	assert (c1[3] == 4);
	assert (c1[4] == 5);

	ColumnType c2(c1);
	assert (c2.rowCount() == 5);
	assert (c2[0] == 1);
	assert (c2[1] == 2);
	assert (c2[2] == 3);
	assert (c2[3] == 4);
	assert (c2[4] == 5);

	ContainerType vi;
	vi.assign(c.begin(), c.end());
	assert (vi.size() == 5);
	ContainerType::const_iterator it = vi.begin();
	ContainerType::const_iterator end = vi.end();
	for (int i = 1; it != end; ++it, ++i)
		assert (*it == i);

	c.reset();
	assert (c.rowCount() == 0);
	assert (c1.rowCount() == 0);
	assert (c2.rowCount() == 0);

	ContainerType* pV1 = new ContainerType;
	pV1->push_back(1);
	pV1->push_back(2);
	pV1->push_back(3);
	pV1->push_back(4);
	pV1->push_back(5);
	ContainerType* pV2 = new ContainerType;
	pV2->push_back(5);
	pV2->push_back(4);
	pV2->push_back(3);
	pV2->push_back(2);
	pV2->push_back(1);
	Column<ContainerType> c3(mc, pV1);
	Column<ContainerType> c4(mc, pV2);
	
	Poco::Data::swap(c3, c4);
	assert (c3[0] == 5);
	assert (c3[1] == 4);
	assert (c3[2] == 3);
	assert (c3[3] == 2);
	assert (c3[4] == 1);

	assert (c4[0] == 1);
	assert (c4[1] == 2);
	assert (c4[2] == 3);
	assert (c4[3] == 4);
	assert (c4[4] == 5);

	std::swap(c3, c4);
	assert (c3[0] == 1);
	assert (c3[1] == 2);
	assert (c3[2] == 3);
	assert (c3[3] == 4);
	assert (c3[4] == 5);

	assert (c4[0] == 5);
	assert (c4[1] == 4);
	assert (c4[2] == 3);
	assert (c4[3] == 2);
	assert (c4[4] == 1);
}
Пример #7
0
	void RotLibConvert_Dunbrack_BBDep::readLib( const std::string& _LibraryFilename, RotamerLibrary& _RotLib )
	{
		StringBuilder sb;
		std::ifstream* p_torsionFile;
		try
		{
			if( _RotLib.isFinalised() ) 
				throw ProcedureException("readLib() is not allowed, the rotamer library has been finalised, no further import can occur");

			// Mappings for things like HIS -> HIE HID HIP
			_RotLib.addIonisationAliasWorkingDefaults();

			// Make sure Alanine and Glycine are defined non-rotamer residues (the library itself ignores them)
			_RotLib.addAsBlankRotamer("ALA");
			_RotLib.addAsBlankRotamer("GLY");

			p_torsionFile = new std::ifstream(_LibraryFilename.c_str(), std::ifstream::in);
			std::ifstream& torsionFile = *p_torsionFile;
			if( !torsionFile.is_open() ) 
				throw(IOException( "Dunbrack BB-independent torsional definition file not found: '" + _LibraryFilename + "'!" ));
		
			ParseData pd;
			ContainerType data; 
	
			StringBuilder prevResName(3);
			StringBuilder currResName(4);
			StringBuilder cacheLine;

			while( true )
			{
				if( cacheLine.size() > 0 )
				{
					sb.setTo(cacheLine);
					cacheLine.clear();
				}
				else if( !(sb << torsionFile) )
				{
					break;
				}

				sb.Trim();
				if( sb.size() == 0 ) 
					continue; // blank line

				currResName.setTo(sb,0,3);

				if( prevResName.size() == 0 )
				{
					prevResName.setTo( currResName );
					ASSERT( pd.parse( sb ), ParseException, "Malformed line");
					data.push_back( pd );
				}
				else if( prevResName.compare( currResName, 0, 3, 0 ) )
				{
					// Woooo - we found one :-D
					ASSERT( pd.parse( sb ), ParseException, "Malformed line");
					data.push_back( pd );
				}
				else
				{					
					if( data.size() > 0 )
					{
						processResData( prevResName.toString(), data, _RotLib, switchImportMode );
						ASSERT( data.size() == 0, CodeException, "CodeFail");
					}
					prevResName.setTo( currResName );
					cacheLine.setTo( sb ); // we havent actually processed the current line! Store it.
				}
			}
			if( data.size() > 0 )
			{
				processResData( prevResName.toString(), data, _RotLib, switchImportMode );
				ASSERT( data.size() == 0, CodeException, "CodeFail");
			}
			
			// Ensure file-handle cleanup
			p_torsionFile->close();
			delete p_torsionFile;
		}
		catch( ExceptionBase ex )
		{
			// Ensure file-handle cleanup
			p_torsionFile->close();
			delete p_torsionFile;
			throw ex;
		}
	}
Пример #8
0
  MSSpectrum &MSSpectrum::select(const std::vector<Size> &indices)
  {
    Size snew = indices.size();
    ContainerType tmp;
    tmp.reserve(indices.size());

    const Size peaks_old = size();

    for (Size i = 0; i < snew; ++i)
    {
      tmp.push_back(*(ContainerType::begin() + indices[i]));
    }
    ContainerType::swap(tmp);

    for (Size i = 0; i < float_data_arrays_.size(); ++i)
    {
      if (float_data_arrays_[i].size() != peaks_old)
      {
        throw Exception::Precondition(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "FloatDataArray[" + String(i) + "] size (" +
                                                                                  String(float_data_arrays_[i].size()) + ") does not match spectrum size (" + String(peaks_old) + ")");
      }

      std::vector<float> mda_tmp;
      mda_tmp.reserve(float_data_arrays_[i].size());
      for (Size j = 0; j < snew; ++j)
      {
        mda_tmp.push_back(*(float_data_arrays_[i].begin() + indices[j]));
      }
      std::swap(float_data_arrays_[i], mda_tmp);
    }

    for (Size i = 0; i < string_data_arrays_.size(); ++i)
    {
      if (string_data_arrays_[i].size() != peaks_old)
      {
        throw Exception::Precondition(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "StringDataArray[" + String(i) + "] size (" +
                                                                                  String(string_data_arrays_[i].size()) + ") does not match spectrum size (" + String(peaks_old) + ")");
      }
      std::vector<String> mda_tmp;
      mda_tmp.reserve(string_data_arrays_[i].size());
      for (Size j = 0; j < snew; ++j)
      {
        mda_tmp.push_back(*(string_data_arrays_[i].begin() + indices[j]));
      }
      std::swap(string_data_arrays_[i], mda_tmp);
    }

    for (Size i = 0; i < integer_data_arrays_.size(); ++i)
    {
      if (integer_data_arrays_[i].size() != peaks_old)
      {
        throw Exception::Precondition(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "IntegerDataArray[" + String(i) + "] size (" +
                                                                                  String(integer_data_arrays_[i].size()) + ") does not match spectrum size (" + String(peaks_old) + ")");
      }
      std::vector<Int> mda_tmp;
      mda_tmp.reserve(integer_data_arrays_[i].size());
      for (Size j = 0; j < snew; ++j)
      {
        mda_tmp.push_back(*(integer_data_arrays_[i].begin() + indices[j]));
      }
      std::swap(integer_data_arrays_[i], mda_tmp);
    }

    return *this;
  }