Example #1
0
void readBenchmarkGeneList(string benchmarkGeneListFilename, vector<int>* cancerBenchmarkGenes, map<string, int>* geneSymbolToId){
	ifstream inFile;
	inFile.open(benchmarkGeneListFilename.c_str(), std::ifstream::in);

	map<string, int>::iterator end = geneSymbolToId->end();

	if (inFile.is_open()) {

		//for each row
		while (inFile.good()) {
			string s;
			if (!getline(inFile, s))
				break;

			istringstream rowStr(s);

			int i = 0;
			bool found = false;
			while (rowStr) {	//for each column
				string s;

				if (!getline(rowStr, s, '\t'))
					break;
				if(i == 0){ //read gene symbols at the first column

					//trim the whitespace at the end of the string
					s.erase(s.find_last_not_of(" \n\r\t")+1);

					map<string, int>::iterator it = geneSymbolToId->find(s);
					if(it != end){	//found in the network
						found = true;
						cancerBenchmarkGenes->push_back(it->second);	//add the gene id to geneEx
//						cout << s << endl;
					}else{
						found = false;
//						cout << s << " not found" << endl;
					}
				}
				else if(i == 7){	//read tumor type (somatic mutation)
				}

				if(!found)	//not found in the network, so skip this row (gene)
					break;

				i++;	//go to the next column (sample)
			}

		}
		inFile.close();
	} else {
		cerr << "Error opening file\n";
	}

}
Example #2
0
Island::Island(const std::string& filename, int pos_x, int pos_y, std::vector<bool>& waterTiles) : m_x(pos_x), m_y(pos_y), m_tiles(NULL), m_defaultTile(0)
{
	m_defaultTile = Tile::getDefaultTile();
	std::cout << "Trying to load island \"" << filename << "\"" << std::endl;
	TiXmlDocument document;
	if (!document.PHYSFS_LoadFile(filename))
	{
		throw FileLoadException(filename, document.ErrorDesc());
	}

	if(!document.RootElement() || document.RootElement()->ValueStr() != "island")
		throw XMLException(filename, -1, "This is no valid island XML file (missing island root element)");

	TiXmlElement *island = document.RootElement();
	if (!island->Attribute("cols"))
		throw XMLException(filename, island->Row(), "Missing attribute cols");
	if (!island->Attribute("rows"))
		throw XMLException(filename, island->Row(), "Missing attribute rows");
	if (!island->Attribute("clime"))
		throw XMLException(filename, island->Row(), "Missing attribute clime");
	std::stringstream attr;
	attr << island->Attribute("cols") << " " << island->Attribute("rows");
	attr >> m_cols >> m_rows;
	m_clime = island->Attribute("clime");
	std::cout << "Creating " << (m_rows * m_cols) << " tiles" << std::endl;
	m_tiles = new Tile* [m_rows * m_cols];
	memset(m_tiles, 0, sizeof(Tile*) * m_rows * m_cols);

	TiXmlElement *terrain = island->FirstChildElement("terrain");
	if (!terrain)
		throw XMLException(filename, island->Row(), "Missing toplevel element terrain");

	TiXmlElement *row = terrain->FirstChildElement("row");
	if (!terrain)
		throw XMLException(filename, terrain->Row(), "Missing row subelements");
	while (row)
	{
		if (!row->Attribute("value"))
			throw XMLException(filename, row->Row(), "Missing attribute value");
		std::stringstream rowStr(row->Attribute("value"));
		int rowInt;
		rowStr >> rowInt;
		rowInt--;
		TiXmlElement *col = row->FirstChildElement("col");
		if (!col)
			throw XMLException(filename, row->Row(), "Missing col subelements");
		while (col)
		{
			if (!col->Attribute("value"))
				throw XMLException(filename, col->Row(), "Missing attribute value");
			std::stringstream colStr(col->Attribute("value"));
			int colInt;
			colStr >> colInt;
			colInt--;

			TiXmlElement *tile = col->FirstChildElement("tile");
			if (!tile)
				throw XMLException(filename, col->Row(), "Missing tile subelement");
			if (((rowInt * m_cols) + colInt) >= m_cols * m_rows)
				std::cout << "WARNING! Index out of bounds. Row: " << rowInt << ", column: " << colInt << std::endl;
			else
			{
				m_tiles[(rowInt * m_cols) + colInt] = new Tile(tile);
				if (m_tiles[(rowInt * m_cols) + colInt] == NULL) {
					std::cout << "TILE CREATION FAILED" << std::endl;
				}
				waterTiles[(rowInt * m_cols) + colInt] = false;
			}

			col = col->NextSiblingElement("col");
		}
		row = row->NextSiblingElement("row");
	}

	std::cout << "Succesfully loaded island \"" << filename << "\"" << std::endl;
	std::cout << "\tColums: " << m_cols << std::endl;
	std::cout << "\tRows: " << m_rows << std::endl;
/*	std::cout << "debug-listing 0,0 to 9,9" << std::endl;
	for (int y = 0; y < 10; y++)
	{
		for (int x = 0; x < 10; x++)
		{
			std::cout << m_tiles[(y * m_cols) + x]->getName();
			std::cout << ",";
		}
		std::cout << std::endl;
	}*/
}