Example #1
0
static void HitTube(int TubeIndex, int q)
	{
	TubeState *Tube = Tubes + TubeIndex%MaxActiveTubes;

#if	TRACE
	Log("HitTube(TubeIndex=%d, q=%d) Count=%d\n",
	  TubeIndex, q, Tube->Count);
#endif

	if (0 == Tube->Count)
		{
		Tube->Count = 1;
		Tube->qLo = q;
		Tube->qHi = q;
		return;
		}

	if (q - Tube->qHi > MaxKmerDist)
		{
		if (Tube->Count >= MinKmersPerHit)
			AddHit(TubeIndex, Tube->qLo, Tube->qHi);

		Tube->Count = 1;
		Tube->qLo = q;
		Tube->qHi = q;
		return;
		}

	++(Tube->Count);
	Tube->qHi = q;
	}
int CLocalSearch::ExecuteSharedFiles(int nMaximum)
{
	CQuickLock oLock( Library.m_pSection );
	CPtrList* pFiles = Library.Search( m_pSearch, nMaximum );
	if ( pFiles == NULL ) return 0;

	int nHits = pFiles->GetCount();

	while ( pFiles->GetCount() )
	{
		int nInThisPacket = min( pFiles->GetCount(), (int)Settings.Gnutella.HitsPerPacket );

		CreatePacket( nInThisPacket );

        int nHitB = 0;
		for ( int nHitA = 0 ; nHitA < nInThisPacket ; nHitA++ )
		{
			CLibraryFile* pFile = (CLibraryFile*)pFiles->RemoveHead();
			if ( AddHit( pFile, nHitB ) ) nHitB ++;
		}

		WriteTrailer();
		if ( nHitB > 0 ) DispatchPacket(); else DestroyPacket();
	}

	delete pFiles;

	return nHits;
}
Example #3
0
// Called when q=Qlen - 1 to flush any hits in each tube.
static void TubeFlush(int TubeIndex)
	{
	TubeState *Tube = Tubes + TubeIndex%MaxActiveTubes;
#if	TRACE
	Log("TubeFlush(TubeIndex=%d) Count=%d\n",
	  TubeIndex, Tube->Count);
#endif
	if (Tube->Count < MinKmersPerHit)
		return;

	AddHit(TubeIndex, Tube->qLo, Tube->qHi);
	Tube->Count = 0;
	}
Example #4
0
void CLocalSearch::SendHits(const CList< T* >& oFiles)
{
	CPacket* pPacket = NULL;
	CSchemaMap pSchemas;

	BYTE nHits = 0;
	for ( POSITION pos = oFiles.GetHeadPosition(); pos; )
	{
		if ( ! pPacket )
			pPacket = CreatePacket();

		AddHit( pPacket, pSchemas, oFiles.GetNext( pos ), nHits ++ );

		bool bSend = false;
		switch ( m_nProtocol )
		{
		case PROTOCOL_G1:
		case PROTOCOL_G2:
			bSend = nHits >= Settings.Gnutella.HitsPerPacket ||
				pPacket->m_nLength >= MAX_QUERY_PACKET_SIZE;
			break;
		case PROTOCOL_DC:
			// One hit per packet in DC++ protocol
			bSend = true;
			break;
		default:
			ASSERT( FALSE );
		}

		// Send full packet
		if ( bSend )
		{
			WriteTrailer( pPacket, pSchemas, nHits );
			DispatchPacket( pPacket );
			pPacket = NULL;
			nHits = 0;
		}
	}

	if ( nHits )
	{
		WriteTrailer( pPacket, pSchemas, nHits );
		DispatchPacket( pPacket );
		pPacket = NULL;
	}

	ASSERT( pPacket == NULL );
	ASSERT( pSchemas.IsEmpty() );
}
Example #5
0
// Called when end of a tube is reached
// A point in the tube -- the point with maximal q -- is (Tlen-1,q-1).
static void TubeEnd(int q)
	{
	int DiagIndex = CalcDiagIndex(Tlen - 1, q - 1);
	int TubeIndex = CalcTubeIndex(DiagIndex);

	TubeState *Tube = Tubes + TubeIndex%MaxActiveTubes;
#if	TRACE
	Log("TubeEnd(%d) DiagIndex=%d TubeIndex=%d Count=%d\n",
	  q, DiagIndex, TubeIndex, Tube->Count);
#endif
	if (Tube->Count >= MinKmersPerHit)
		AddHit(TubeIndex, Tube->qLo, Tube->qHi);

	Tube->Count = 0;
	}
Example #6
0
void SingleAlign::SnpAlign(RefSeq &ref, bit32_t mode) {
   	bit32_t i,j,m, modeindex, cmodeindex, mc, h, read_chain_index_mask;
   	Hit prefetch_hit, _hHit;

   	//cout<<_pread->seq<<endl;
    if(param.RRBS_flag){ //RRBS mode
    	for(read_chain_index=0; read_chain_index<2;read_chain_index++){
            if(!xflag_chain[read_chain_index]) continue;
            cmodeindex=modeindex=xseedindex[read_chain_index][mode].second;
            if(read_chain_index) cmodeindex=map_readlen/param.seed_size-1-modeindex;
       		_seed=xseeds[read_chain_index][modeindex][0];
    		//cout<<"mode:"<<mode<<" m="<<ref.index[_seed].n1<<" seed:"<<_seed;
            //cout<<"    "; disp_bfa(param.map3to4(_seed), param.seed_size); cout<<endl;    		
    		if((m=ref.index[_seed].n1)==0) continue; 
 	    	_refloc=ref.index[_seed].loc1;  //list of seeded reference locations
       		h=param.profile[modeindex][0]+cseed_offset*read_chain_index;
       		read_chain_index_mask=read_chain_index<<24;
       		for(j=0; j!=m; j++) {
   	    		_hHit=_refloc[j];
   	    		if(((_hHit.chr^read_chain_index_mask)>>16)!=cmodeindex) continue; // mode or strand not match
   	    		_hit.chr=_hHit.chr&0xffff;
   	    		if(_hHit.loc<h) continue; //underflow the start of refseq
   	    		_hit.loc=_hHit.loc-h;
   	    		//cout<<" j="<<j<<" chr"<<(int)_hit.chr<<":"<<_hit.loc<<endl;
                CountMismatch(xseq[read_chain_index], (_hit.loc%SEGLEN)<<1, ref.bfa[_hit.chr].s+_hit.loc/SEGLEN);
   	    		//cout<<" mis:"<<tmp_snp<<endl;
   	    	 	if(tmp_snp<=snp_thres) {
   	    	 	    _ghit=int2hit(ref,_hit,0,0);
                    if(!param.pairend){
                        seg_info=ref.CCGG_seglen(_ghit.chr, _ghit.loc, map_readlen); //get fragment information
                        //cout<<"seg1:"<<seg_info.first<<" seg2:"<<seg_info.second<<endl;
                        //if(seg_info.second>param.max_insert) continue; // fragment too large
                    }
          			if(AddHit(ref, tmp_snp, mode)) return;
                }
                if(param.gap>0) {
                    if(GapAlign(ref, mode, h)) return;
                }                             
    		}
    	}
    }
    else{ //WGBS mode
        for(read_chain_index=0; read_chain_index<2;read_chain_index++){
Example #7
0
void TGgSchRSet::Merge(const PGgSchRSet& RSet){
  if (RSet.Empty()){return;}
  // create hash table of existing urls
  TStrH TitleStrH(GetHits());
  for (int HitN=0; HitN<GetHits(); HitN++){
    TitleStrH.AddKey(GetHit(HitN)->TitleStr);
  }
  // merge hits
  for (int HitN=0; HitN<RSet->GetHits(); HitN++){
    PGgSchRef Ref=RSet->GetHit(HitN);
    if (!TitleStrH.IsKey(Ref->TitleStr)){
      AddHit(Ref);
      TitleStrH.AddKey(Ref->TitleStr);
    }
  }
  // reset fixed fields
  PutNextUrlStr("");
  PutAllHits(-1);
}
Example #8
0
void TRSet::Merge(const PRSet& RSet){
  if (RSet.Empty()){return;}
  // create hash table of existing urls
  TStrH UrlStrH(GetHits());
  for (int HitN=0; HitN<GetHits(); HitN++){
    UrlStrH.AddKey(GetHitUrlStr(HitN));
  }
  // merge hits
  for (int HitN=0; HitN<RSet->GetHits(); HitN++){
    TStr HitUrlStr; TStr HitTitleStr; TStr HitSrcNm; TStr HitCtxStr;
    RSet->GetHit(HitN, HitUrlStr, HitTitleStr, HitSrcNm, HitCtxStr);
    if (!UrlStrH.IsKey(HitUrlStr)){
      AddHit(HitUrlStr, HitTitleStr, HitSrcNm, HitCtxStr);
      UrlStrH.AddKey(HitUrlStr);
    }
  }
  // reset fixed fields
  PutNextUrlStr("");
  PutAllHits(-1);
}
int CLocalSearch::ExecutePartialFiles(int nMaximum)
{
	ASSERT( m_nProtocol == PROTOCOL_G2 );
	ASSERT( m_pSearch != NULL );

	if ( m_pSearch->m_bTiger == FALSE && m_pSearch->m_bSHA1 == FALSE &&
		 m_pSearch->m_bED2K  == FALSE && m_pSearch->m_bBTH == FALSE ) return 0;

	CSingleLock pLock( &Transfers.m_pSection );
	if ( ! pLock.Lock( 50 ) ) return 0;

	int nCount = 0;
	m_pPacket = NULL;

	for ( POSITION pos = Downloads.GetIterator() ; pos ; )
	{
		CDownload* pDownload = Downloads.GetNext( pos );

		if ( ! pDownload->IsShared() ) continue;

		if (	( m_pSearch->m_bTiger && pDownload->m_bTiger && m_pSearch->m_pTiger == pDownload->m_pTiger )
			||	( m_pSearch->m_bSHA1  && pDownload->m_bSHA1  && m_pSearch->m_pSHA1  == pDownload->m_pSHA1 )
			||	( m_pSearch->m_bED2K  && pDownload->m_bED2K  && m_pSearch->m_pED2K  == pDownload->m_pED2K )
			||	( m_pSearch->m_bBTH   && pDownload->m_bBTH   && m_pSearch->m_pBTH   == pDownload->m_pBTH ) )
		{
			if ( pDownload->m_bBTH || pDownload->IsStarted() )
			{
				if ( m_pPacket == NULL ) CreatePacketG2();
				AddHit( pDownload, nCount++ );
			}
		}
	}

	if ( m_pPacket != NULL )
	{
		WriteTrailerG2();
		DispatchPacket();
	}

	return nCount;
}
Example #10
0
void Tan()
	{
// Image file annotated with from-to pile indexes
// Produced by:
//		piler2 -trs banded_hits.gff -images mainband_images.gff
	const char *HitFileName = RequiredValueOpt("tan");
	const char *OutFileName = RequiredValueOpt("out");
	const char *PyramidFileName = ValueOpt("pyramid");
	const char *MotifFileName = ValueOpt("motif");
	const char *strMinHits = ValueOpt("minhits");
	const char *strMaxMargin = ValueOpt("maxmargin");
	const char *strMinRatio = ValueOpt("minratio");

	if (0 != strMinHits)
		MIN_HIT_COUNT = atoi(strMinHits);
	if (0 != strMaxMargin)
		MAX_FRACT_MARGIN = atof(strMaxMargin);
	if (0 != strMinRatio)
		MIN_RATIO = atof(strMinRatio);

	FILE *fInput = OpenStdioFile(HitFileName);

	ProgressStart("Initialize piles");
	GFFRecord Rec;
	int HitCount = 0;
	while (GetNextGFFRecord(fInput, Rec))
		{
		if (0 != strcmp(Rec.Feature, "hit"))
			continue;

		int QueryPileIndex = -1;
		int TargetPileIndex = -1;
		ParsePilesAttrs(Rec.Attrs, &QueryPileIndex, &TargetPileIndex);
		if (QueryPileIndex != TargetPileIndex)
			continue;

		char TargetLabel[128];
		int TargetStart;
		int TargetEnd;
		ParseTargetAttrs(Rec.Attrs, TargetLabel, sizeof(TargetLabel), &TargetStart, &TargetEnd);
		if (0 != strcmp(Rec.SeqName, TargetLabel))
			Quit("Labels don't match");

		const int QueryFrom = Rec.Start - 1;
		const int QueryTo = Rec.End - 1;
		const int TargetFrom = TargetStart - 1;
		const int TargetTo = TargetEnd - 1;
		const bool Rev = (Rec.Strand == '-');

		AddHit(QueryPileIndex, Rec.SeqName, QueryFrom, QueryTo, TargetFrom, TargetTo, Rev);
		++HitCount;
		}
	ProgressDone();

	Progress("%d hits, %d piles", HitCount, PileCount);

	ProgressStart("Allocate piles");
	for (int PileIndex = 0; PileIndex < PileCount; ++PileIndex)
		{
		TanPile &Pile = Piles[PileIndex];
		Pile.Hits = all(HitData, Pile.HitCount);
		Pile.HitCount = 0;
		}
	ProgressDone();

	ProgressStart("Assign hits to piles");
	Rewind(fInput);
	while (GetNextGFFRecord(fInput, Rec))
		{
		if (0 != strcmp(Rec.Feature, "hit"))
			continue;

		int QueryPileIndex = -1;
		int TargetPileIndex = -1;
		ParsePilesAttrs(Rec.Attrs, &QueryPileIndex, &TargetPileIndex);
		if (QueryPileIndex != TargetPileIndex)
			continue;

		char TargetLabel[128];
		int TargetStart;
		int TargetEnd;
		ParseTargetAttrs(Rec.Attrs, TargetLabel, sizeof(TargetLabel), &TargetStart, &TargetEnd);
		if (0 != strcmp(Rec.SeqName, TargetLabel))
			Quit("Labels don't match");

		const int QueryFrom = Rec.Start - 1;
		const int QueryTo = Rec.End - 1;
		const int TargetFrom = TargetStart - 1;
		const int TargetTo = TargetEnd - 1;
		const bool Rev = (Rec.Strand == '-');

		AssignHit(QueryPileIndex, Rec.SeqName, QueryFrom, QueryTo, TargetFrom, TargetTo, Rev);
		}
	ProgressDone();

	fOut = OpenStdioFile(OutFileName, FILEIO_MODE_WriteOnly);
	fPyramid = (0 == PyramidFileName ? 0 : OpenStdioFile(PyramidFileName, FILEIO_MODE_WriteOnly));
	fMotif = (0 == PyramidFileName ? 0 : OpenStdioFile(MotifFileName, FILEIO_MODE_WriteOnly));

	ProgressStart("Find pyramids");
	for (int PileIndex = 0; PileIndex < PileCount; ++PileIndex)
		FindPyramids(PileIndex);
	int PyramidCount = PyramidIndex;
	ProgressDone();

	Progress("%d pyramids", PyramidCount);
	}
Example #11
0
PyObject * PyHit_PushWord(PyObject * pSelf, PyObject* args, PyObject* kwargs)
{
	/*
	= You can change the iPos & iPhrase setting without add a real hit by push a Empty word("").
	@param:
	- pos:
	- phrase:
	*/

	csfHelper_HitCollectorObject *self = (csfHelper_HitCollectorObject *)pSelf;
	static char *kwlist[] = {"word", "pos", "phrase", "fieldindex", NULL};

	const char* sWord = NULL;
	int iPos = -1;
	int iPhrase = -1;
	int iField = -1;

	int ok = PyArg_ParseTupleAndKeywords( args, kwargs, "z|iii", kwlist, &sWord, 
		&iPos , &iPhrase, &iField );  //not inc the value refer

	if(!ok) {
		if(PyErr_Occurred()) {
			PyErr_Print();
			PyErr_Clear();
		}		
		return NULL;  
	}

	if(iPos < 1 ) iPos = -1; // 0 and < is invalid.
	if(iPhrase <1) iPhrase = -1;

	//fast setting
	if(!sWord) {
		if(iPos != -1)	
			self->iPos = iPos; 

		if(iPhrase == -1) 
			self->iPhrase = iPhrase; //refresh iPos
		
		RET_PYNONE;
	}
	
	if(iPos == -1)
		iPos = self->iPos;
	else
	{
		if(iField == -1) 
			self->iPos = iPos; //refresh iPos
	}

	// no more than 24, if greater than 24, just leave field as current.
	if(iField > SPH_MAX_FIELDS || iField < 0)
		iField = -1;
	
	if(iPhrase == -1)
		iPhrase = self->iPhrase;
	else
	{
		if(iField == -1) 
			self->iPhrase = iPhrase; //refresh iPos
	}

	if(iField == -1) 
		iField = self->iField; //NO, NO, u can NOT change field via a filled parameters' pushWord call...
	

	{
		CSphSource_Python* pPySource = dynamic_cast<CSphSource_Python*>(self->m_pSource);
		BYTE sBuf [ 16+3*SPH_MAX_WORD_LEN + 1024 ];
		
		if(pPySource){
			CSphDict* pDict = pPySource->GetDict();
			bool bWordDict = pDict->GetSettings().m_bWordDict;
			bool bGlobalPartialMatch = !bWordDict && ( pPySource->m_iMinPrefixLen > 0 || pPySource->m_iMinInfixLen > 0 );
			
			{
				SphWordID_t iWord = pDict->GetWordID ((BYTE*) sWord );
				iPos = HITMAN::Create(iField, iPos);
				AddHit(self, iWord, iPos, iPhrase);
			}
			
			if ( bGlobalPartialMatch )
			{
				int iBytes = strlen ( (const char*)sWord );
				memcpy ( sBuf + 1, sWord, iBytes );
				sBuf[0] = MAGIC_WORD_HEAD;
				sBuf[iBytes+1] = '\0';
				AddHit(self, pDict->GetWordIDWithMarkers ( sBuf ), iPos, iPhrase);
			}

			if ( pPySource->m_bIndexExactWords )
			{
				int iBytes = strlen ( (const char*)sWord );
				memcpy ( sBuf + 1, sWord, iBytes );
				sBuf[0] = MAGIC_WORD_HEAD_NONSTEMMED;
				sBuf[iBytes+1] = '\0';
				AddHit(self, pDict->GetWordIDNonStemmed ( sBuf ), iPos, iPhrase);
			}

			self->iPos++ ;
		}
	}
	RET_PYNONE;
}
Example #12
0
PyObject * PyHit_Push(PyObject * pSelf, PyObject* args, PyObject* kwargs)
{

	//int iPos = HIT_PACK ( iField, iStartPos );
	csfHelper_HitCollectorObject *self = (csfHelper_HitCollectorObject *)pSelf;
	static char *kwlist[] = {"wordid", "pos", "phrase", "fieldindex", NULL};
	
	SphWordID_t iWord;
	int iPos = -1;
	int iPhrase = -1;
	int iField = -1;
#if USE_64BIT
	int ok = PyArg_ParseTupleAndKeywords( args, kwargs, "K|iii", kwlist, &iWord, 
#else
	int ok = PyArg_ParseTupleAndKeywords( args, kwargs, "k|iii", kwlist, &iWord, 
#endif
		&iPos , &iPhrase, &iField );  //not inc the value refer

	if(!ok) {
		if(PyErr_Occurred()) {
			PyErr_Print();
			//PyErr_Clear();
		}		
		return NULL;  
	}

	if(iPos < 1 ) iPos = -1; // 0 and < is invalid.
	if(iPhrase <1) iPhrase = -1;

	// fast setting
	if(!iWord) {
		if(iPos != -1)	
			self->iPos = iPos; 

		if(iPhrase == -1) 
			self->iPhrase = iPhrase; //refresh iPos

		RET_PYNONE;
	}

	// push hit
	if(iPos == -1)
		iPos = self->iPos;
	else
	{
		if(iField == -1) 
			self->iPos = iPos; //refresh iPos
	}

	// no more than 24, if greater than 24, just leave field as current.
	if(iField > SPH_MAX_FIELDS || iField < 0)
		iField = -1;
	


	if(iPhrase == -1)
		iPhrase = self->iPhrase;
	else
	{
		if(iField == -1) 
			self->iPhrase = iPhrase; //refresh iPos
	}

	if(iField == -1) 
		iField = self->iField; //NO, NO, u can NOT change field via a filled parameters' pushWord call...
	

	{	
		iPos = HITMAN::Create(iField, iPos);
		AddHit(self, iWord, iPos, iPhrase);
		self->iPos++ ;
	}
	RET_PYNONE;
}