コード例 #1
0
ファイル: Manager.cpp プロジェクト: daotranminh/web-explorer
void
Manager::processBatch(const std::string &file_url_collection,
                      Database &db)
{
    // read from file_url_collection and call processSingle for each pair <filename,url>
    std::ifstream file_input(file_url_collection.c_str());
    
    if (file_input.is_open())
    {
        while (file_input.good())
        {
            FetchedInfoScholarship fis;
            
            if (!getInput(file_input, fis)) break;
            
            processSingle(fis, db);
        }
        
        db.showDatabase();
        db.storeDatabase();
        db.writeToCategoryFile();
        db.writeNotification(true /* singleLine */);
    }
    else
    {
        DBGERR(__FUNCTION__ << ": Cannot open file \"" << file_url_collection << "\"!")
    }
    
}
コード例 #2
0
// Process Search
std::deque<WebPage*> SearchEngine::processSearch(std::string inStr,bool usePR,User* us) {
    // Bring input to lowercase
    std::string line;
    std::transform(inStr.begin(),inStr.end(),inStr.begin(),::tolower);

    // Get only the first word
    std::stringstream ss;
    ss << inStr;
    ss >> inStr;
    // And then the rest of the line
    getline(ss,line);

    // Add on blank space to allow last word to be processed if AND/OR
    line += "\n";

    // Get Set S
    Set<WebPage*> S;
    if(inStr == "and") S = processAND(line);
    else if(inStr == "or") S = processOR(line);
    else S = processSingle(inStr,line);

    // Generate T
    Set<WebPage*> T = generateT(S);

    // Then make adjacency matrix & generate page rank
    if(usePR)   {
        std::map<std::string,double> pr = generatePageRank(generateAdjacency(T));
        if(us != NULL) us->generatePreferences(pr);
        return MapToDeque(pr);
    }
    else return SetToDeque(T);
}
コード例 #3
0
// processBestReplicate - finish up a best replicate selection
void SpectraSTReplicates::processBestReplicate(SpectraSTLibEntry* best, vector<Replicate*>& usedReps, bool isRaw) {
  

  best->setOneComment("Spec", "BestReplicate");
  
  best->setInstrumentInfo(m_instruments);	
  best->setSeqInfo(m_seqs);
  best->setSampleInfo(m_samples);
  
  stringstream numRepss;
  numRepss << m_numUsed << '/' << m_numTotal;
  best->setOneComment("Nreps", numRepss.str());
  
  processSingle(best, isRaw);
  
  aggregateStats(best, best->getPeakList(), usedReps, false);
}
コード例 #4
0
// What to do when the user issues an or command
Set<WebPage*> SearchEngine::processOR(const std::string line)  {
    Set<WebPage*> result,singleword;
    std::string word="";

    // Go through and generate all the queries
    for(unsigned int i=0; i<line.size(); i++)    {
        if(alphanumeric(line[i])) word += line[i];
        else    {
            // This means we're at end of the word - check for content
            if(word.size() > 0) {
                // Put the query to lowercase and try to get; if not, make an entry if necessary
                std::transform(word.begin(),word.end(),word.begin(),::tolower);
                singleword = processSingle(word,"");
                // Then add it to result
                if(result.empty()) result = singleword;
                else result = result.setUnion(singleword);
                // Reset word for the next word in query
                word = "";
            }
        }
    }
    return result;
}
コード例 #5
0
// makeConsensusSpectrum - creates a consensus spectrum of the replicates
SpectraSTLibEntry* SpectraSTReplicates::makeConsensusSpectrum() {
  
  if (m_reps.empty()) {
    stringstream logss;
    logss << "Removing spectrum: " << m_name << " (NO GOOD REPLICATE)";
    g_log->log("CREATE", logss.str());
    return (NULL);
  }

  if (m_numUsed < m_params.minimumNumReplicates) {
    stringstream logss;
    logss << "Removing spectrum: " << m_name << " (NOT ENOUGH REPLICATES)";
    g_log->log("CREATE", logss.str());    
    return (NULL);
  }

  // only one replicate (which could be a consensus of replicates previously!) - 
  // this will be our "consensus"
  if (m_reps.size() == 1) {
    SpectraSTLibEntry* single = m_reps[0].entry;
    
    if (m_numUsed == 1) {
      // a real single
      processSingle(single, true);  
 
      stringstream logss;
      logss << "Keeping single spectrum: " << m_name;
      g_log->log("CREATE", logss.str());
      
    } else {
      // actually a spectrum from a consensus of many previously
      processSingle(single, false);  
      
      stringstream logss;
      logss << "Keeping previous consensus spectrum: " << m_name;
      g_log->log("CREATE", logss.str());

    }
    return (single);
  }

  // sort replicates by weight now
  sort(m_reps.begin(), m_reps.end(), SpectraSTReplicates::sortReplicatesByWeight);
  
  // remove dissimilar replicates
  if (m_params.removeDissimilarReplicates) {
    if (!removeDissimilarReplicates()) {
      stringstream logss;
      logss << "Removing spectrum: " << m_name << " (NOT ENOUGH SIMILAR REPLICATES)";
      g_log->log("CREATE", logss.str());          
      return (NULL);
    }
  } 

  // reset num used counter; go down the list of replicates to select replicates that we will use
  m_numUsed = 0;	
  vector<Replicate*> usedReps;
  vector<SpectraSTPeakList*> pls;
  bool enough = false;
  for (vector<Replicate>::iterator rep = m_reps.begin(); rep != m_reps.end(); rep++) {
    
    if (enough) {
      rep->status = 0;
    }
    
    if (rep->status == 1) {
      m_numUsed += rep->numUsed;
      
      // update the "USED" statistics of the Se, Sample and Instrument fields
      rep->entry->getSeqInfo(m_seqs);
      rep->entry->getInstrumentInfo(m_instruments, "USED_ONLY");
      rep->entry->getSampleInfo(m_samples, "USED_ONLY");
      
      usedReps.push_back(&(*rep));
      pls.push_back(rep->entry->getPeakList());
      
      if (m_numUsed >= m_params.maximumNumReplicates) {
        // if we are capping the number of replicates used, and we already hit the maximum
        // we are done, not need to add more replicates
        enough = true;
      }
    }
  }
  
  if (usedReps.size() == 1) {
    // single (we got here because removeDissimilarReplicates() got rid of all but one replicate spectrum)
    // numTotal might have been increased, need to set Nreps
    stringstream numRepss;
    numRepss << m_numUsed << '/' << m_numTotal;
    usedReps[0]->entry->setOneComment("Nreps", numRepss.str());
          
    if (m_numUsed == 1) {
      processSingle(usedReps[0]->entry, true);  

      stringstream logss;
      logss << "Keeping single spectrum: " << m_name;
      g_log->log("CREATE", logss.str());
    } else {
      processSingle(usedReps[0]->entry, false);  

      stringstream logss;
      logss << "Keeping previous consensus spectrum: " << m_name;
      g_log->log("CREATE", logss.str());      
    }
    return (usedReps[0]->entry);
    
  } else {
  
    // now we actually have more than one spectra that we need to "consensus" together
    stringstream logss;
    logss << "Creating consensus of " << m_numUsed << " (of " << m_numTotal << ") replicates: " << m_name;
    g_log->log("CREATE", logss.str());

    // calling the consensus-forming constructor
    SpectraSTPeakList* cpl = new SpectraSTPeakList(pls, usedReps[0]->entry->getPeptidePtr(), m_numUsed, m_params.peakQuorum, m_params.maximumNumPeaksUsed, m_denoiser, m_params.keepRawIntensities);
  
    // use top entry as holder for consensus -- note that consensus->getPeakList() still points to the best replicate;
    // it has not been set to the actual consensus spectrum (cpl) yet
    SpectraSTLibEntry* consensus = usedReps[0]->entry;
    
    processConsensus(consensus, cpl, usedReps);

    // up tp this point, consensus->getPeakList() stills holds the best replicate (which is also pointed to by the usedReps vector)
    // now that we are done with evaluating the replicates, we finally can overwrite the best replicate with the consensus spectrum
    consensus->setPeakList(cpl);
    
    return (consensus);
  }
}
コード例 #6
0
ファイル: main.cpp プロジェクト: dhganey/430p2
int main()
{
	//set the global ints
	currentFunction = 1;
	uniqueVarNum = 1;
	uniqueStructNum = 1;
	numThreads = 0;

	readInput();

	processVariables();

	//First, handle parallels
	bool foundConstruct = true;
	while (foundConstruct)
	{
		foundConstruct = processParallel();
	}

	//next, handle parallel for
	foundConstruct = true;
	while (foundConstruct)
	{
		foundConstruct = processParallelFor();
	}

	//next, handle criticals
	foundConstruct = true;
	while (foundConstruct)
	{
		foundConstruct = processCritical();
	}

	//next, handle single
	foundConstruct = true;
	while (foundConstruct)
	{
		foundConstruct = processSingle();
	}

	//last, change all omp_get_thread_num calls to use the paramstruct
	processGetThreadNum();

	//put global vars at the top
	eliminateDuplicates(globalVars);
	insertAfterIncludes(globalVars);

	//put private vars back in main
	eliminateDuplicates(totalPrivBackup);
	declarePrivatesInMain(totalPrivBackup);

	//create and insert the parameter struct
	strvec newStruct = createStartEndStruct();
	insertAfterIncludes(newStruct);

	//create and add the mutex call
	strvec synchronization;
	synchronization.push_back("pthread_mutex_t theMutex = PTHREAD_MUTEX_INITIALIZER;");
	insertAfterIncludes(synchronization);

	//create and add new includes
	strvec includes;
	includes.push_back("#include <pthread.h>");
	includes.push_back("#include <algorithm>");
	includes.push_back("#include <cstring>");
	insertAfterIncludes(includes);

	//print output (to use for file redirection)
	printVector(input);
}