⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 taxon1.cpp

📁 ncbi源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	on.ResetGcode();    }    if( db_orgRef.GetOrgname().IsSetMgcode() ) {	on.SetMgcode( db_orgRef.GetOrgname().GetMgcode() );    } else {	on.ResetMgcode();    }    if( db_orgRef.GetOrgname().IsSetDiv() ) {	on.SetDiv( db_orgRef.GetOrgname().GetDiv() );    } else {	on.ResetDiv();    }}boolCTaxon1::LookupByOrgRef(const COrg_ref& inp_orgRef, int* pTaxid,			COrgName::TMod& hitMods ){    SetLastError(NULL);    CTaxon1_req  req;    CTaxon1_resp resp;    SerialAssign< COrg_ref >( req.SetLookup(), inp_orgRef );    if( SendRequest( req, resp ) ) {        if( resp.IsLookup() ) {            // Correct response, return object	    COrg_ref& result = resp.SetLookup().SetOrg();	    *pTaxid = result.GetTaxId();	    if( result.IsSetOrgname() &&		result.GetOrgname().IsSetMod() ) {		hitMods.swap( result.SetOrgname().SetMod() );	    }// 		for( COrgName::TMod::const_iterator ci =// 			 result.GetOrgname().GetMod().begin();// 		     ci != result.GetOrgname().GetMod().end();// 		     ++ci ) {// 		    if( (*ci)->GetSubtype() == COrgMod::eSubtype_old_name ) {// 			hitMod->Assign( *ci );// 			bHitFound = true;// 			break;// 		    }// 		}// 	    }// 	    if( bHitFound ) {// 		hitMod.Reset( NULL );// 	    }	    return true;        } else { // Internal: wrong respond type            SetLastError( "Response type is not Lookup" );        }    }    return false;}voidCTaxon1::PopulateReplaced( COrg_ref& org, COrgName::TMod& lMods  ){    if( org.IsSetOrgname() ) {	CRef< COrgMod > pOldNameMod;	COrgName& on = org.SetOrgname();	for( COrgName::TMod::iterator i = lMods.begin();	     i != lMods.end();	     ++i ) {	    if( (*i)->GetSubtype() == COrgMod::eSubtype_old_name ) {		pOldNameMod = *i;		continue;	    }	    if( on.IsSetMod() ) {		PFindModByType fmbt( (*i)->GetSubtype() );		if( find_if( on.GetMod().begin(), on.GetMod().end(), fmbt )		    != on.GetMod().end() ) {		    /* modifier already present in target orgref */		    continue;		}	    }	    /* adding this modifier */	    on.SetMod().push_back( *i );	}	if( pOldNameMod ) {	    if( on.IsSetMod() ) {		PFindModByType fmbt( COrgMod::eSubtype_old_name );		COrgName::TMod::iterator i =		    find_if( on.SetMod().begin(), on.SetMod().end(), fmbt );		if( i != on.SetMod().end() ) {		    // There is old-name in the target already		    if( !(*i)->IsSetAttrib() && pOldNameMod->IsSetAttrib() &&			NStr::CompareNocase(pOldNameMod->GetSubname(), 					    (*i)->GetSubname() ) == 0 ) {			(*i)->SetAttrib( pOldNameMod->GetAttrib() );		    }		    return;		}	    }	    /* we probably don't need to populate search name */	    if( org.IsSetTaxname() &&		NStr::CompareNocase( org.GetTaxname(),				     pOldNameMod->GetSubname() ) == 0 ) {		if( pOldNameMod->IsSetAttrib() ) {		    const string& sAttrib = pOldNameMod->GetAttrib();		    if( !sAttrib.empty() && sAttrib[0] == '(' ) {			try {			    CRef< COrgMod > srchMod( new COrgMod );			    string::size_type pos = sAttrib.find("=");			    if( pos == string::npos ) {				return;			    }			    if( on.IsSetMod() ) {				const COrgName::TMod& mods = on.GetMod();				srchMod->SetSubname()				    .assign( sAttrib.c_str()+pos+1 );				srchMod->SetSubtype				    ( COrgMod::TSubtype                                      (NStr::StringToInt				      (sAttrib.substr(1, pos-1), 10,				       NStr::eCheck_Skip) ) );				PFindMod mf;				mf.SetModToMatch( srchMod );				if( find_if( mods.begin(), mods.end(),					     mf ) != mods.end() ) {				    return;				}			    }			} catch(...) { return; }		    } else			return;		} else		    return;	    }	    // Add old-name to modifiers	    on.SetMod().push_back( pOldNameMod );	}    }}CRef< CTaxon2_data >CTaxon1::Lookup(const COrg_ref& inp_orgRef ){    SetLastError(NULL);    // Check if this taxon is in cache    CTaxon2_data* pData = 0;    COrgName::TMod hitMod;    int tax_id = 0; //GetTaxIdByOrgRef( inp_orgRef );    if( LookupByOrgRef( inp_orgRef, &tax_id, hitMod )	&& tax_id > 0        && m_plCache->LookupAndInsert( tax_id, &pData ) && pData ) {        CTaxon2_data* pNewData = new CTaxon2_data();	//        SerialAssign<CTaxon2_data>( *pNewData, *pData  );	COrg_ref* pOrf = new COrg_ref;	pOrf->Assign( inp_orgRef );	if( pOrf->IsSetOrgname() && pOrf->GetOrgname().IsSetMod() ) {	    // Clean up modifiers	    pOrf->SetOrgname().ResetMod();	}	pNewData->SetOrg( *pOrf );			const COrg_ref& db_orgRef = pData->GetOrg();	OrgRefAdjust( pNewData->SetOrg(), db_orgRef, tax_id );	// Copy all other fields	if( pData->IsSetBlast_name() ) {	    pNewData->SetBlast_name() = pData->GetBlast_name();	}	if( pData->IsSetIs_uncultured() ) {	    pNewData->SetIs_uncultured( pData->GetIs_uncultured() );	}	if( pData->IsSetIs_species_level() ) {	    pNewData->SetIs_species_level( pData->GetIs_species_level() );	}	// Insert the hitMod if necessary	if( hitMod.size() > 0 ) {	    PopulateReplaced( pNewData->SetOrg(), hitMod );	}        return CRef<CTaxon2_data>(pNewData);    }    return CRef<CTaxon2_data>(NULL);}CConstRef< CTaxon2_data >CTaxon1::LookupMerge(COrg_ref& inp_orgRef ){    CTaxon2_data* pData = 0;    SetLastError(NULL);    COrgName::TMod hitMod;    int tax_id = 0; //GetTaxIdByOrgRef( inp_orgRef );    if( LookupByOrgRef( inp_orgRef, &tax_id, hitMod )	&& tax_id > 0        && m_plCache->LookupAndInsert( tax_id, &pData ) && pData ) {	const COrg_ref& db_orgRef = pData->GetOrg();		OrgRefAdjust( inp_orgRef, db_orgRef, tax_id );	if( hitMod.size() > 0 ) {	    PopulateReplaced( inp_orgRef, hitMod );	}    }    return CConstRef<CTaxon2_data>(pData);}intCTaxon1::GetTaxIdByOrgRef(const COrg_ref& inp_orgRef){    SetLastError(NULL);    CTaxon1_req  req;    CTaxon1_resp resp;    SerialAssign< COrg_ref >( req.SetGetidbyorg(), inp_orgRef );    if( SendRequest( req, resp ) ) {        if( resp.IsGetidbyorg() ) {            // Correct response, return object            return resp.GetGetidbyorg();        } else { // Internal: wrong respond type            SetLastError( "Response type is not Getidbyorg" );        }    }    return 0;}intCTaxon1::GetTaxIdByName(const string& orgname){    SetLastError(NULL);    if( orgname.empty() )        return 0;    COrg_ref orgRef;        orgRef.SetTaxname().assign( orgname );        return GetTaxIdByOrgRef(orgRef);}intCTaxon1::FindTaxIdByName(const string& orgname){    SetLastError(NULL);    if( orgname.empty() )        return 0;    int id( GetTaxIdByName(orgname) );    if(id < 1) {	        int idu = 0;        CTaxon1_req  req;        CTaxon1_resp resp;        req.SetGetunique().assign( orgname );        if( SendRequest( req, resp ) ) {            if( resp.IsGetunique() ) {                // Correct response, return object                idu = resp.GetGetunique();            } else { // Internal: wrong respond type                SetLastError( "Response type is not Getunique" );            }        }        if( idu > 0 )            id= idu;    }    return id;}//----------------------------------------------// Get tax_id by organism name using fancy search modes.// Returns: tax_id - if the only organism found//               0 - no organism found//         -tax_id - if multiple nodes found//                   (where -tax_id is id of one of the nodes)///intCTaxon1::SearchTaxIdByName(const string& orgname, ESearch mode,			   list< CRef< CTaxon1_name > >* pNameList){    // Use fancy searches    SetLastError(NULL);    if( orgname.empty() ) {	return 0;    }    CRef< CTaxon1_info > pQuery( new CTaxon1_info() );    int nMode = 0;    switch( mode ) {    default:    case eSearch_Exact:    nMode = 0; break;    case eSearch_TokenSet: nMode = 1; break;    case eSearch_WildCard: nMode = 2; break; // shell-style wildcards, i.e. *,?,[]    case eSearch_Phonetic: nMode = 3; break;    }    pQuery->SetIval1( nMode );    pQuery->SetIval2( 0 );    pQuery->SetSval( orgname );        CTaxon1_req  req;    CTaxon1_resp resp;    req.SetSearchname( *pQuery );        if( SendRequest( req, resp ) ) {	if( resp.IsSearchname() ) {	    // Correct response, return object	    int retc = 0;	    const CTaxon1_resp::TSearchname& lNm = resp.GetSearchname();	    if( lNm.size() == 0 ) {		retc = 0;	    } else if( lNm.size() == 1 ) {		retc = lNm.front()->GetTaxid();	    } else {		retc = -1;	    }	    // Fill the names list	    if( pNameList ) {		pNameList->swap( resp.SetSearchname() );	    }	    return retc;	} else { // Internal: wrong respond type	    SetLastError( "Response type is not Searchname" );	    return 0;	}    }    return 0;}intCTaxon1::GetAllTaxIdByName(const string& orgname, TTaxIdList& lIds){    int count = 0;    SetLastError(NULL);    if( orgname.empty() )        return 0;    CTaxon1_req  req;    CTaxon1_resp resp;    req.SetFindname().assign(orgname);    if( SendRequest( req, resp ) ) {        if( resp.IsFindname() ) {            // Correct response, return object            const list< CRef< CTaxon1_name > >& lNm = resp.GetFindname();            // Fill in the list            for( list< CRef< CTaxon1_name > >::const_iterator                     i = lNm.begin();                 i != lNm.end(); ++i, ++count )                lIds.push_back( (*i)->GetTaxid() );        } else { // Internal: wrong respond type            SetLastError( "Response type is not Findname" );            return 0;        }    }    return count;}CConstRef< COrg_ref >CTaxon1::GetOrgRef(int tax_id,                   bool& is_species,                   bool& is_uncultured,                   string& blast_name){    SetLastError(NULL);    if( tax_id > 1 ) {        CTaxon2_data* pData = 0;        if( m_plCache->LookupAndInsert( tax_id, &pData ) && pData ) {            is_species = pData->GetIs_species_level();            is_uncultured = pData->GetIs_uncultured();            if( pData->GetBlast_name().size() > 0 ) {                blast_name.assign( pData->GetBlast_name().front() );            }            return CConstRef<COrg_ref>(&pData->GetOrg());        }    }    return null;}boolCTaxon1::SetSynonyms(bool on_off){    SetLastError(NULL);    bool old_val( m_bWithSynonyms );    m_bWithSynonyms = on_off;    return old_val;}intCTaxon1::GetParent(int id_tax){    CTaxon1Node* pNode = 0;    SetLastError(NULL);    if( m_plCache->LookupAndAdd( id_tax, &pNode )        && pNode && pNode->GetParent() ) {        return pNode->GetParent()->GetTaxId();    }    return 0;}intCTaxon1::GetGenus(int id_tax){    CTaxon1Node* pNode = 0;    SetLastError(NULL);    if( m_plCache->LookupAndAdd( id_tax, &pNode )        && pNode ) {        int genus_rank(m_plCache->GetGenusRank());        while( !pNode->IsRoot() ) {            int rank( pNode->GetRank() );            if( rank == genus_rank )                return pNode->GetTaxId();            if( (rank > 0) && (rank < genus_rank))                return -1;            pNode = pNode->GetParent();        }    }    return -1;}intCTaxon1::GetSuperkingdom(int id_tax){    CTaxon1Node* pNode = 0;    SetLastError(NULL);    if( m_plCache->LookupAndAdd( id_tax, &pNode )        && pNode ) {        int sk_rank(m_plCache->GetSuperkingdomRank());        while( !pNode->IsRoot() ) {            int rank( pNode->GetRank() );            if( rank == sk_rank )                return pNode->GetTaxId();            if( (rank > 0) && (rank < sk_rank))                return -1;            pNode = pNode->GetParent();        }    }    return -1;}intCTaxon1::GetChildren(int id_tax, TTaxIdList& children_ids){    int count(0);    CTaxon1Node* pNode = 0;    SetLastError(NULL);    if( m_plCache->LookupAndAdd( id_tax, &pNode )        && pNode ) {        CTaxon1_req  req;        CTaxon1_resp resp;	        req.SetTaxachildren( id_tax );	        if( SendRequest( req, resp ) ) {            if( resp.IsTaxachildren() ) {                // Correct response, return object                list< CRef< CTaxon1_name > >& lNm = resp.SetTaxachildren();                // Fill in the list                CTreeIterator* pIt = m_plCache->GetTree().GetIterator();                pIt->GoNode( pNode );                for( list< CRef< CTaxon1_name > >::const_iterator                         i = lNm.begin();                     i != lNm.end(); ++i, ++count ) {                    children_ids.push_back( (*i)->GetTaxid() );                    // Add node to the partial tree                    CTaxon1Node* pNewNode = new CTaxon1Node(*i);                    m_plCache->SetIndexEntry(pNewNode->GetTaxId(), pNewNode);                    pIt->AddChild( pNewNode );                }            } else { // Internal: wrong respond type                SetLastError( "Response type is not Taxachildren" );                return 0;            }        }    }    return count;}boolCTaxon1::GetGCName(short gc_id, string& gc_name_out ){    SetLastError(NULL);    if( m_gcStorage.empty() ) {        CTaxon1_req  req;        CTaxon1_resp resp;        req.SetGetgcs();        if( SendRequest( req, resp ) ) {            if( resp.IsGetgcs() ) {                // Correct response, return object                const list< CRef< CTaxon1_info > >& lGc = resp.GetGetgcs();                // Fill in storage                for( list< CRef< CTaxon1_info > >::const_iterator                         i = lGc.begin();                     i != lGc.end(); ++i ) {                    m_gcStorage.insert( TGCMap::value_type((*i)->GetIval1(),                                                           (*i)->GetSval()) );		}            } else { // Internal: wrong respond type                SetLastError( "Response type is not Getgcs" );                return false;            }        }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -