コード例 #1
0
ファイル: ndsrom.cpp プロジェクト: DeejStar/xoreos
void NDSFile::load() {
	Common::File nds;
	open(nds);

	if (!isNDS(nds))
		throw Common::Exception("Not a support NDS ROM file");

	nds.seek(0x40);

	uint32 fileNameTableOffset = nds.readUint32LE();
	uint32 fileNameTableLength = nds.readUint32LE();
	uint32 fatOffset           = nds.readUint32LE();
	//uint32 fatLength = nds.readUint32LE();

	try {

		readNames(nds, fileNameTableOffset, fileNameTableLength);
		readFAT(nds, fatOffset);

	if (nds.err())
		throw Common::Exception(Common::kReadError);

	} catch (Common::Exception &e) {
		e.add("Failed reading NDS file");
		throw;
	}

}
コード例 #2
0
ファイル: bin_recorder.cpp プロジェクト: ahmadyan/ReaK
void bin_extractor::setStreamImpl(const shared_ptr<std::istream>& aStreamPtr) {
  if(colCount != 0)
    *this >> close;
  if((aStreamPtr) && (*aStreamPtr)) {
    ReaKaux::unique_lock< ReaKaux::mutex > lock_here(access_mutex);
    in_stream = aStreamPtr;
    readNames();
  };
};
コード例 #3
0
void KEditListBoxManager::setSubGroupName( const QString& name )
{
	if( _subGroupName )
		*_subGroupName = name;
	else
		_subGroupName = new QString( name );
		
	if( _config && _groupName )
		readNames();
}
コード例 #4
0
ファイル: main.c プロジェクト: EvaBr/HitWit
int main ( int argc, char * argv[] ) {
/*	bool read = true;
	bool dir = true;
	char *readdir = READ_DIRECTORY;
	if (argc>=2) {
		//char *file = argv[0];
		if (strstr(argv[0], ".xls")!=NULL) {
			read = false;
			dir = false;
			const char *namesfile = argv[0];
		} else if (strstr(argv[0], ".txt")!=NULL) {
			dir = false;
			const char *namesfile = argv[0];
		} else { readdir = argv[0]; }

	}

	if (dir) {*/
		/* namesfile is a .txt, to where names of all files to be analyzed will be written */
		const char *namesfile = "names.csv";
		printf ( "Reading directory \t %s \n", READ_DIRECTORY); //readdir );

		/* readNames function writes names of all the files that are to be analyzed into the given .txt file */
		readNames ( namesfile );//, readdir);
	//}

	//python? ########################################################
	/* now analyze al the xls files you found */
/*	FILE *fp;
	fp = fopen ( namesfile, "r" );
	if (fp==NULL) {
		printf ( "Can't read name-file   %s!\n", fileNames );
		exit(EXIT_FAILURE);
	}
	while(line):
		openfile(line, 'r')
		popravi na pravo obliko, organiziraj, parse
*/
	/* close file mit names */
//	fclose(fp);
	//################################################################
	printf("Done :) \n");
	return 0;
}
コード例 #5
0
ファイル: ndsrom.cpp プロジェクト: EffWun/xoreos-tools
void NDSFile::load() {
	Common::File nds;
	open(nds);

	if (!readHeader(nds))
		throw Common::Exception("Not a valid NDS ROM file");

	try {

		readNames(nds, _fileNameTableOffset, _fileNameTableLength);
		readFAT(nds, _fatOffset);

	if (nds.err())
		throw Common::Exception(Common::kReadError);

	} catch (Common::Exception &e) {
		e.add("Failed reading NDS file");
		throw;
	}

}
コード例 #6
0
ファイル: ndsrom.cpp プロジェクト: asr1/xoreos-tools
void NDSFile::load(Common::SeekableReadStream &nds) {
	if (!isNDS(nds, _title, _code, _maker))
		throw Common::Exception("Not a supported NDS ROM file");

	nds.seek(0x40);

	uint32 fileNameTableOffset = nds.readUint32LE();
	uint32 fileNameTableLength = nds.readUint32LE();
	uint32 fatOffset           = nds.readUint32LE();
	//uint32 fatLength = nds.readUint32LE();

	try {

		readNames(nds, fileNameTableOffset, fileNameTableLength);
		readFAT(nds, fatOffset);

	} catch (Common::Exception &e) {
		e.add("Failed reading NDS file");
		throw;
	}

}
コード例 #7
0
ファイル: XeTeXFontMgr_FC.cpp プロジェクト: luigiScarso/mflua
void
XeTeXFontMgr_FC::cacheFamilyMembers(const std::list<std::string>& familyNames)
{
	if (familyNames.size() == 0)
		return;
	for (int f = 0; f < allFonts->nfont; ++f) {
		FcPattern*	pat = allFonts->fonts[f];
		if (platformRefToFont.find(pat) != platformRefToFont.end())
			continue;
		char*	s;
		for (int i = 0; FcPatternGetString(pat, FC_FAMILY, i, (FcChar8**)&s) == FcResultMatch; ++i) {
			for (std::list<std::string>::const_iterator j = familyNames.begin(); j != familyNames.end(); ++j) {
				if (*j == s) {
					NameCollection*	names = readNames(pat);
					addToMaps(pat, names);
					delete names;
					goto cached;
				}
			}
		}
	cached:
		;
	}
}
コード例 #8
0
ファイル: XeTeXFontMgr_FC.cpp プロジェクト: luigiScarso/mflua
void
XeTeXFontMgr_FC::searchForHostPlatformFonts(const std::string& name)
{
	if (cachedAll) // we've already loaded everything on an earlier search
		return;

	std::string	famName;
	int	hyph = name.find('-');
	if (hyph > 0 && hyph < name.length() - 1)
		famName.assign(name.begin(), name.begin() + hyph);
	else
		hyph = 0;

	bool	found = false;
	while (1) {
		for (int f = 0; f < allFonts->nfont; ++f) {
		restart:
			FcPattern*	pat = allFonts->fonts[f];
			if (platformRefToFont.find(pat) != platformRefToFont.end())
				continue;

			if (cachedAll) {
				// failed to find it via FC; add everything to our maps (potentially slow) as a last resort
				NameCollection*	names = readNames(pat);
				addToMaps(pat, names);
				delete names;
				continue;
			}

			char*	s;
			int	i;
			for (i = 0; FcPatternGetString(pat, FC_FULLNAME, i, (FcChar8**)&s) == FcResultMatch; ++i) {
				if (name == s) {
					NameCollection*	names = readNames(pat);
					addToMaps(pat, names);
					cacheFamilyMembers(names->familyNames);
					delete names;
					found = true;
					goto next_font;
				}
			}
		
			for (i = 0; FcPatternGetString(pat, FC_FAMILY, i, (FcChar8**)&s) == FcResultMatch; ++i) {
				if (name == s || (hyph && famName == s)) {
					NameCollection*	names = readNames(pat);
					addToMaps(pat, names);
					cacheFamilyMembers(names->familyNames);
					delete names;
					found = true;
					goto next_font;
				}
				char*	t;
				for (int j = 0; FcPatternGetString(pat, FC_STYLE, j, (FcChar8**)&t) == FcResultMatch; ++j) {
					std::string full(s);
					full += " ";
					full += t;
					if (name == full) {
						NameCollection*	names = readNames(pat);
						addToMaps(pat, names);
						cacheFamilyMembers(names->familyNames);
						delete names;
						found = true;
						goto next_font;
					}
				}
			}

		next_font:
			;
		}

		if (found || cachedAll)
			break;
		cachedAll = true;
	}
}
コード例 #9
0
ファイル: connectome.cpp プロジェクト: johnsonjonaris/CoNECt
bool Connectome::generate(s16_cube label, const FiberTracts &fibers,
                          bool isFreesurfer, MyProgressDialog *progress)
{
    if (label.is_empty() || fibers.isEmpty())
        return false;
    // prepare progress bar
    progress->setLabelText("Generating Connectome ... ");
    progress->setRange(0,fibers.size()+100);
    progress->setFixedSize(progress->sizeHint());
    progress->setModal(true);
    progress->setValue(0);
    progress->show();
    // remove bad labels from label volume if freesurfer
    // in order to eliminate the unwanted values, the label must first
    // be converted into a 1D vector
    if (isFreesurfer) {
        label(find(label<8)).fill(0);
        s16_vec badLabels;
        badLabels<<14<<15<<24<<30<<31<<41<<43<<44<<46<<1000<<1004<<2000<<2004;
        for (int i = 0; i< badLabels.n_elem; ++i)
            label(find(label == badLabels.at(i))).fill(0);
        // remove regions > 60 and < 1000
        uvec loc = find(label > 60);
        label(loc(find(label(loc)<1000))).fill(0);
    }
    s16_vec lbl = s16_vec(label.memptr(),label.n_elem);
    // get labels values and their sizes, it is assumed that hist
    // will give the count of every label since the nbins = n labels
    s16_vec labels = unique(lbl);
    uvec labelsSize = hist(lbl,labels);
    if (labels[0] == 0) {
        labels.shed_row(0);
        labelsSize.shed_row(0);
    }
    int cc = 0;
    s16_vec idx = zeros<s16_vec>(labels.max()+1);
    for (uint i=0; i<labels.n_elem; ++i)
        idx(labels(i)) = cc++;
    progress->setValue(1);
    // compute centroids
    int r = label.n_rows, c = label.n_cols, s = label.n_slices;
    centroids = zeros<fmat>(labels.n_elem,3);
    for (uint i=0;i<labels.size();++i)
        centroids(i,span::all) = mean(conv_to<fmat>::
                                      from(getIndex(find(lbl == labels(i)),r,c,s)),0);

    // fill header
    fibers.getVoxelDimension(header.dx,header.dy,header.dz);
    header.nR = r, header.nC = c, header.nS = s;
    header.nRegions = labels.n_elem;
    // prepare intersection cube
//    frowvec t; t<<header.dx<<header.dy<<header.dz;
//    float cubeSizeLimit = max((cubeSize/2)/t);
//    float endSize = ceil(cubeSizeLimit*2)/2;
//    fvec index = linspace<fvec>(0,cubeSizeLimit,floor(cubeSizeLimit));
//    index.in;
    // form the network
    NW = zeros<mat>(labels.n_elem,labels.n_elem);
    // compute fiber pairs
    int x=0,y=0,z=0, p1, p2;
    for (int i =0; i<fibers.size();++i) {
        // first end
        x = qMax(qMin(qRound(fibers.getFiber(i).first().x()),r),0);
        y = qMax(qMin(qRound(fibers.getFiber(i).first().y()),c),0);
        z = qMax(qMin(qRound(fibers.getFiber(i).first().z()),s),0);
        p1 = label(x,y,z);
        // second end
        x = qMax(qMin(qRound(fibers.getFiber(i).last().x()),r),0);
        y = qMax(qMin(qRound(fibers.getFiber(i).last().y()),c),0);
        z = qMax(qMin(qRound(fibers.getFiber(i).last().z()),s),0);
        p2 = label(x,y,z);
        if (p1 > 0 && p2 > 0) {
            NW(idx(p1),idx(p2))++;
            NW(idx(p2),idx(p1))++;
        }
        progress->setValue(progress->value()+1);
    }
    // remove self connections
    NW.diag().fill(0);
    // normalize the network w.r.t. labels sizes
    for (uint i =0;i<labels.n_elem;++i) {
        for (uint j =i+1;j<labels.n_elem;++j) {
            NW(i,j) = NW(i,j)/(labelsSize(i)+labelsSize(j));
            NW(j,i) = NW(i,j);
        }
    }
    // prepare mask
    label(find(label>0)).fill(1);
    maskImage = conv_to<uchar_cube>::from(label);
    progress->setValue(progress->maximum());
    if (isFreesurfer)
        readNames(QDir::currentPath()+"/FreesurferLabels.txt");
    return true;
}
コード例 #10
0
ファイル: readblast.cpp プロジェクト: EdwardMoseley/mothur
//assumptions about the blast file: 
//1. if duplicate lines occur the first line is always best and is chosen
//2. blast scores are grouped together, ie. a a .... score, a b .... score, a c ....score...
int ReadBlast::read(NameAssignment* nameMap) {
	try {
	
		//if the user has not given a names file read names from blastfile
		if (nameMap->size() == 0) { readNames(nameMap);  }
		int nseqs = nameMap->size();
		
		if (m->control_pressed) { return 0; }

		ifstream fileHandle;
		m->openInputFile(blastfile, fileHandle);
		
		string firstName, secondName, eScore, currentRow;
		string repeatName = "";
		int count = 1;
		float distance, thisoverlap, refScore;
		float percentId; 
		float numBases, mismatch, gap, startQuery, endQuery, startRef, endRef, score, lengthThisSeq;
		
		ofstream outDist;
		ofstream outOverlap;
		
		//create objects needed for read
		if (!hclusterWanted) {
			matrix = new SparseDistanceMatrix();
            matrix->resize(nseqs);
		}else{
			overlapFile = m->getRootName(blastfile) + "overlap.dist";
			distFile = m->getRootName(blastfile) + "hclusterDists.dist";
			
			m->openOutputFile(overlapFile, outOverlap);
			m->openOutputFile(distFile, outDist);
		}
		
		if (m->control_pressed) { 
			fileHandle.close();
			if (!hclusterWanted) {  delete matrix; }
			else { outOverlap.close(); m->mothurRemove(overlapFile); outDist.close(); m->mothurRemove(distFile);  }
			return 0;
		}
		
		Progress* reading = new Progress("Reading blast:     ", nseqs * nseqs);
		
		//this is used to quickly find if we already have a distance for this combo
		vector< map<int,float> > dists;  dists.resize(nseqs);  //dists[0][1] = distance from seq0 to seq1
		map<int, float> thisRowsBlastScores;
		
		if (!fileHandle.eof()) {
			//read in line from file
			fileHandle >> firstName >> secondName >> percentId >> numBases >> mismatch >> gap >> startQuery >> endQuery >> startRef >> endRef >> eScore >> score;
			m->gobble(fileHandle);
			
			currentRow = firstName;
			lengthThisSeq = numBases;
			repeatName = firstName + secondName;
			
			if (firstName == secondName) {   refScore = score;  }
			else{
				//convert name to number
				map<string,int>::iterator itA = nameMap->find(firstName);
				map<string,int>::iterator itB = nameMap->find(secondName);
				if(itA == nameMap->end()){  m->mothurOut("AAError: Sequence '" + firstName + "' was not found in the names file, please correct\n"); exit(1);  }
				if(itB == nameMap->end()){  m->mothurOut("ABError: Sequence '" + secondName + "' was not found in the names file, please correct\n"); exit(1);  }
				
				thisRowsBlastScores[itB->second] = score;
				
				//calc overlap score
				thisoverlap = 1.0 - (percentId * (lengthThisSeq - startQuery) / endRef / 100.0 - penalty);
				
				//if there is a valid overlap, add it
				if ((startRef <= length) && ((endQuery+length) >= lengthThisSeq) && (thisoverlap < cutoff)) {
					if (!hclusterWanted) {
						seqDist overlapValue(itA->second, itB->second, thisoverlap);
						overlap.push_back(overlapValue);
					}else {
						outOverlap << itA->first << '\t' << itB->first << '\t' << thisoverlap << endl;
					}
				}
			}
		}else { m->mothurOut("Error in your blast file, cannot read."); m->mothurOutEndLine(); exit(1); }

       
		//read file
		while(!fileHandle.eof()){  
		
			if (m->control_pressed) { 
				fileHandle.close();
				if (!hclusterWanted) {  delete matrix; }
				else { outOverlap.close(); m->mothurRemove(overlapFile); outDist.close(); m->mothurRemove(distFile);  }
				delete reading;
				return 0;
			}
			
			//read in line from file
			fileHandle >> firstName >> secondName >> percentId >> numBases >> mismatch >> gap >> startQuery >> endQuery >> startRef >> endRef >> eScore >> score;
			//cout << firstName << '\t' << secondName << '\t' << percentId << '\t' << numBases << '\t' << mismatch << '\t' << gap << '\t' << startQuery << '\t' << endQuery << '\t' << startRef << '\t' << endRef << '\t' << eScore << '\t' << score << endl;	
			m->gobble(fileHandle);
			
			string temp = firstName + secondName; //to check if this file has repeat lines, ie. is this a blast instead of a blscreen file
			
			//if this is a new pairing
			if (temp != repeatName) {
				repeatName = temp; 
				
				if (currentRow == firstName) {
					//cout << "first = " << firstName << " second = " << secondName << endl;	
					if (firstName == secondName) { 
						refScore = score;  
						reading->update((count + nseqs));  
						count++; 
					}else{
						//convert name to number
						map<string,int>::iterator itA = nameMap->find(firstName);
						map<string,int>::iterator itB = nameMap->find(secondName);
						if(itA == nameMap->end()){  m->mothurOut("AAError: Sequence '" + firstName + "' was not found in the names file, please correct\n"); exit(1);  }
						if(itB == nameMap->end()){  m->mothurOut("ABError: Sequence '" + secondName + "' was not found in the names file, please correct\n"); exit(1);  }
						
						//save score
						thisRowsBlastScores[itB->second] = score;
							
						//calc overlap score
						thisoverlap = 1.0 - (percentId * (lengthThisSeq - startQuery) / endRef / 100.0 - penalty);
						
						//if there is a valid overlap, add it
						if ((startRef <= length) && ((endQuery+length) >= lengthThisSeq) && (thisoverlap < cutoff)) {
							if (!hclusterWanted) {
								seqDist overlapValue(itA->second, itB->second, thisoverlap);
								//cout << "overlap = " << itA->second << '\t' << itB->second << '\t' << thisoverlap << endl;
								overlap.push_back(overlapValue);
							}else {
								outOverlap << itA->first << '\t' << itB->first << '\t' << thisoverlap << endl;
							}
						}
					} //end else
				}else { //end row
					//convert blast scores to distance and add cell to sparse matrix if we can
					map<int, float>::iterator it;
					map<int, float>::iterator itDist;
					for(it=thisRowsBlastScores.begin(); it!=thisRowsBlastScores.end(); it++) {  
						distance = 1.0 - (it->second / refScore);
		
						
						//do we already have the distance calculated for b->a
						map<string,int>::iterator itA = nameMap->find(currentRow);
						itDist = dists[it->first].find(itA->second);
						
						//if we have it then compare
						if (itDist != dists[it->first].end()) {
	
							//if you want the minimum blast score ratio, then pick max distance
							if(minWanted) {	 distance = max(itDist->second, distance);  }
							else{	distance = min(itDist->second, distance);  }

							//is this distance below cutoff
							if (distance < cutoff) {
								if (!hclusterWanted) {
                                    if (itA->second < it->first) {
                                        PDistCell value(it->first, distance);
                                        matrix->addCell(itA->second, value);
                                    }else {
                                        PDistCell value(itA->second, distance);
                                        matrix->addCell(it->first, value);
                                    }
                                }else{
									outDist << itA->first << '\t' << nameMap->get(it->first) << '\t' << distance << endl;
								}
							}
							//not going to need this again
							dists[it->first].erase(itDist);
						}else { //save this value until we get the other ratio
							dists[itA->second][it->first] = distance;
						}
					}
					//clear out last rows info
					thisRowsBlastScores.clear();
					
					currentRow = firstName;
					lengthThisSeq = numBases;
					
					//add this row to thisRowsBlastScores
					if (firstName == secondName) {   refScore = score;  }
					else{ //add this row to thisRowsBlastScores
						
						//convert name to number
						map<string,int>::iterator itA = nameMap->find(firstName);
						map<string,int>::iterator itB = nameMap->find(secondName);
						if(itA == nameMap->end()){  m->mothurOut("AAError: Sequence '" + firstName + "' was not found in the names file, please correct\n"); exit(1);  }
						if(itB == nameMap->end()){  m->mothurOut("ABError: Sequence '" + secondName + "' was not found in the names file, please correct\n"); exit(1);  }
						
						thisRowsBlastScores[itB->second] = score;
						
						//calc overlap score
						thisoverlap = 1.0 - (percentId * (lengthThisSeq - startQuery) / endRef / 100.0 - penalty);
						
						//if there is a valid overlap, add it
						if ((startRef <= length) && ((endQuery+length) >= lengthThisSeq) && (thisoverlap < cutoff)) {
							if (!hclusterWanted) {
								seqDist overlapValue(itA->second, itB->second, thisoverlap);
								overlap.push_back(overlapValue);
							}else {
								outOverlap << itA->first << '\t' << itB->first << '\t' << thisoverlap << endl;
							}
						}
					}
				}//end if current row
			}//end if repeat
		}//end while
		
		//get last rows info stored
		//convert blast scores to distance and add cell to sparse matrix if we can
		map<int, float>::iterator it;
		map<int, float>::iterator itDist;
		for(it=thisRowsBlastScores.begin(); it!=thisRowsBlastScores.end(); it++) {  
			distance = 1.0 - (it->second / refScore);
			
			//do we already have the distance calculated for b->a
			map<string,int>::iterator itA = nameMap->find(currentRow);
			itDist = dists[it->first].find(itA->second);
			
			//if we have it then compare
			if (itDist != dists[it->first].end()) {
				//if you want the minimum blast score ratio, then pick max distance
				if(minWanted) {	 distance = max(itDist->second, distance);  }
				else{	distance = min(itDist->second, distance);  }
				
				//is this distance below cutoff
				if (distance < cutoff) {
					if (!hclusterWanted) {
						if (itA->second < it->first) {
                            PDistCell value(it->first, distance);
                            matrix->addCell(itA->second, value);
                        }else {
                            PDistCell value(itA->second, distance);
                            matrix->addCell(it->first, value);
                        }
					}else{
						outDist << itA->first << '\t' << nameMap->get(it->first) << '\t' << distance << endl;
					}
				}
				//not going to need this again
				dists[it->first].erase(itDist);
			}else { //save this value until we get the other ratio
				dists[itA->second][it->first] = distance;
			}
		}
		//clear out info
		thisRowsBlastScores.clear();
		dists.clear();
		
		if (m->control_pressed) { 
				fileHandle.close();
				if (!hclusterWanted) {  delete matrix; }
				else { outOverlap.close(); m->mothurRemove(overlapFile); outDist.close(); m->mothurRemove(distFile);  }
				delete reading;
				return 0;
		}
		
		if (!hclusterWanted) {
			sort(overlap.begin(), overlap.end(), compareOverlap);
		}else {
			outDist.close();
			outOverlap.close();
		}
		
		if (m->control_pressed) { 
				fileHandle.close();
				if (!hclusterWanted) {  delete matrix; }
				else {  m->mothurRemove(overlapFile);  m->mothurRemove(distFile);  }
				delete reading;
				return 0;
		}
		
		reading->finish();
		delete reading;
		fileHandle.close();
		
		return 0;
	}
コード例 #11
0
void KEditListBoxManager::setConfig( KConfig* config )
{
	_config = config;
	if( _groupName )
		readNames();
}