//
// selectCandidates: build a list of candidates
//
// Notes:
//		For primary detection.
void
SignalClassifier::classifySignals(Activity *act)
{
	SystemType origin = act->getMode();

	Debug(DEBUG_NEVER, 1, "classify signals");

	params = act->getActivityParams();
	int32_t maxCandidates = params.maxNumberOfCandidates;
	recentRfi = act->getRecentRfiMask();
	testSignal = act->getTestSignalMask();
	operations = params.operations;

	act->setCandidatesOverMax(candidatesOverMax = 0);

	SuperClusterer *superClusterer = act->getSuperClusterer();
	Assert(superClusterer);
	// scan the list of signals
	for (int32_t i = 0; i < superClusterer->getCount(); i++) {
		// get the next signal
		ClusterTag tag = superClusterer->getNthMainSignal(i);
		CwClusterer *cwClusterer = tag.holder->getCw();
		PulseClusterer *pulseClusterer = tag.holder->getPulse();
		if (cwClusterer) {
			Debug(DEBUG_NEVER, i, "cw clusterer");
			CwPowerSignal& signal = cwClusterer->getNth(tag.index);
			classifySignal(act, signal.sig, superClusterer, i, maxCandidates);
			signal.sig.containsBadBands = applyBadBands(act, signal.sig);
			if (signal.sig.sigClass == CLASS_CAND)
				act->addCwCandidate(&signal, origin);
			act->addCwSignal(&signal);
		}
		else if (pulseClusterer) {
			Debug(DEBUG_NEVER, i, "pulse cluster");
			PulseSignalHeader *signal = &pulseClusterer->getNth(tag.index);
//			cout << "SignalClassifier pulse " << *signal;
//			Pulse *p = (Pulse *) (signal + 1);
//			for (int j = 0; j < signal->train.numberOfPulses; ++j)
//				cout << "pulse " << j << p[j];
			classifySignal(act, signal->sig, superClusterer, i, maxCandidates);
			signal->sig.containsBadBands = applyBadBands(act, signal->sig);
			if (signal->sig.sigClass == CLASS_CAND)
				act->addPulseCandidate(signal, origin);
			act->addPulseSignal(signal);
//			displayPulseSignal(*signal);
		}
	}
	act->setCandidatesOverMax(candidatesOverMax);
}
Exemple #2
0
void PhylogenyViewer::gatherKmerObservations(){

	/* set to true to use only assembled kmers */
	bool useOnlyAssembledKmer=false;

	GridTableIterator iterator;
	iterator.constructor(m_subgraph,m_parameters->getWordSize(),m_parameters);

	//* only fetch half of the iterated things because we just need one k-mer
	// for any pair of reverse-complement k-mers 
	
	int parity=0;

	map<CoverageDepth,LargeCount> frequencies;

	while(iterator.hasNext()){

		#ifdef ASSERT
		assert(parity==0 || parity==1);
		#endif

		Vertex*node=iterator.next();
		Kmer key=*(iterator.getKey());
		
		if(parity==0){
			parity=1;
		}else if(parity==1){
			parity=0;

			continue; // we only need data with parity=0
		}

		// check for assembly paths

		/* here, we just want to find a path with
		* a good progression */

		Direction*a=node->m_directions;
		bool nicelyAssembled=false;

		while(a!=NULL){
			int progression=a->getProgression();

			if(progression>= CONFIG_NICELY_ASSEMBLED_KMER_POSITION){
				nicelyAssembled=true;
			}

			a=a->getNext();
		}

		if(useOnlyAssembledKmer && !nicelyAssembled){
			continue; // the k-mer is not nicely assembled...
		}

		#ifdef ASSERT
		assert(nicelyAssembled || !useOnlyAssembledKmer);
		#endif

		// at this point, we have a nicely assembled k-mer
		
		int kmerCoverage=node->getCoverage(&key);

		VirtualKmerColorHandle color=node->getVirtualColor();
		set<PhysicalKmerColor>*physicalColors=m_colorSet->getPhysicalColors(color);

		vector<TaxonIdentifier> taxons;

		// get a list of taxons associated with this kmer
		for(set<PhysicalKmerColor>::iterator j=physicalColors->begin();
			j!=physicalColors->end();j++){

			PhysicalKmerColor physicalColor=*j;
	
			PhysicalKmerColor nameSpace=physicalColor/COLOR_NAMESPACE_MULTIPLIER;
		
			if(nameSpace==COLOR_NAMESPACE_PHYLOGENY){
				PhysicalKmerColor colorForPhylogeny=physicalColor % COLOR_NAMESPACE_MULTIPLIER;

				#ifdef ASSERT
				if(m_colorsForPhylogeny.count(colorForPhylogeny)==0){
					//cout<<"Error: color "<<colorForPhylogeny<<" should be in m_colorsForPhylogeny which contains "<<m_colorsForPhylogeny.size()<<endl;
				}
				#endif

				//assert(m_colorsForPhylogeny.count(colorForPhylogeny)>0);

				// this means that this genome is not in the taxonomy tree
				if(m_genomeToTaxon.count(colorForPhylogeny)==0){

					if(m_warnings.count(colorForPhylogeny)==0){
						cout<<"Warning, color "<<colorForPhylogeny<<" is not stored, "<<m_genomeToTaxon.size()<<" available. This means that you provided a genome sequence that is not classified in the taxonomy."<<endl;

						#ifdef VERBOSE
						for(map<GenomeIdentifier,TaxonIdentifier>::iterator i=m_genomeToTaxon.begin();i!=m_genomeToTaxon.end();i++){
							cout<<" "<<i->first<<"->"<<i->second;
						}
						cout<<endl;
						#endif
					}

					m_warnings.insert(colorForPhylogeny);

					continue;
				}

				#ifdef ASSERT
				assert(m_genomeToTaxon.count(colorForPhylogeny)>0);
				#endif

				TaxonIdentifier taxon=m_genomeToTaxon[colorForPhylogeny];

				taxons.push_back(taxon);
			}
		}

		classifySignal(&taxons,kmerCoverage,node,&key);

		int count=taxons.size();

		frequencies[count]++;
	}
	
/*
 *
 * TODO: move this in colored operation files
 *
	cout<<endl;
	cout<<"Taxon frequencies (only one DNA strand selected)"<<endl;
	cout<<"Count	Frequency"<<endl;
	for(map<CoverageDepth,LargeCount>::iterator i=frequencies.begin();i!=frequencies.end();i++){
		cout<<""<<i->first<<"	"<<i->second<<endl;
	}

	cout<<"Taxon observations"<<endl;
*/

	//showObservations(&cout);

	m_gatheredObservations=true;

	m_syncedTree=false;
	m_unknownSent=false;
	m_messageReceived=true;
	m_messageSent=false;

	m_countIterator=m_taxonObservations.begin();
}