📄 taxon1.cpp
字号:
req.SetGetorgprop( *pProp ); try { if( SendRequest( req, resp ) ) { if( !resp.IsGetorgprop() ) { // error ERR_POST( "Response type is not Getorgprop" ); } else { if( resp.GetGetorgprop().size() > 0 ) { CRef<CTaxon1_info> pInfo ( resp.GetGetorgprop().front() ); prop_val.assign( pInfo->GetSval() ); return true; } } } else if( resp.IsError() && resp.GetError().GetLevel() != CTaxon1_error::eLevel_none ) { string sErr; resp.GetError().GetErrorText( sErr ); ERR_POST( sErr ); } } catch( exception& e ) { ERR_POST( e.what() ); SetLastError( e.what() ); } } else { SetLastError( "Empty property name is not accepted" ); ERR_POST( GetLastError() ); } return false;}boolCTaxon1::GetNodeProperty( int tax_id, const string& prop_name, bool& prop_val ){ SetLastError(NULL); CTaxon1_req req; CTaxon1_resp resp; CRef<CTaxon1_info> pProp( new CTaxon1_info() ); CDiagAutoPrefix( "Taxon1::GetNodeProperty" ); if( !prop_name.empty() ) { pProp->SetIval1( tax_id ); pProp->SetIval2( -3 ); // Get bool property by name pProp->SetSval( prop_name ); req.SetGetorgprop( *pProp ); try { if( SendRequest( req, resp ) ) { if( !resp.IsGetorgprop() ) { // error ERR_POST( "Response type is not Getorgprop" ); } else { if( resp.GetGetorgprop().size() > 0 ) { CRef<CTaxon1_info> pInfo = resp.GetGetorgprop().front(); prop_val = pInfo->GetIval2() != 0; return true; } } } else if( resp.IsError() && resp.GetError().GetLevel() != CTaxon1_error::eLevel_none ) { string sErr; resp.GetError().GetErrorText( sErr ); ERR_POST( sErr ); } } catch( exception& e ) { ERR_POST( e.what() ); SetLastError( e.what() ); } } else { SetLastError( "Empty property name is not accepted" ); ERR_POST( GetLastError() ); } return false;}boolCTaxon1::GetNodeProperty( int tax_id, const string& prop_name, int& prop_val ){ SetLastError(NULL); CTaxon1_req req; CTaxon1_resp resp; CRef<CTaxon1_info> pProp( new CTaxon1_info() ); CDiagAutoPrefix( "Taxon1::GetNodeProperty" ); if( !prop_name.empty() ) { pProp->SetIval1( tax_id ); pProp->SetIval2( -2 ); // Get int property by name pProp->SetSval( prop_name ); req.SetGetorgprop( *pProp ); try { if( SendRequest( req, resp ) ) { if( !resp.IsGetorgprop() ) { // error ERR_POST( "Response type is not Getorgprop" ); } else { if( resp.GetGetorgprop().size() > 0 ) { CRef<CTaxon1_info> pInfo = resp.GetGetorgprop().front(); prop_val = pInfo->GetIval2(); return true; } } } else if( resp.IsError() && resp.GetError().GetLevel() != CTaxon1_error::eLevel_none ) { string sErr; resp.GetError().GetErrorText( sErr ); ERR_POST( sErr ); } } catch( exception& e ) { ERR_POST( e.what() ); SetLastError( e.what() ); } } else { SetLastError( "Empty property name is not accepted" ); ERR_POST( GetLastError() ); } return false;}//-----------------------------------// Iterator stuff//// 'Downward' traverse mode (nodes that closer to root processed first)ITreeIterator::EAction ITreeIterator::TraverseDownward(I4Each& cb, unsigned levels){ if( levels ) { switch( cb.Execute(GetNode()) ) { default: case eOk: if(!IsTerminal()) { switch( cb.LevelBegin(GetNode()) ) { case eStop: return eStop; default: case eOk: if(GoChild()) { do { if(TraverseDownward(cb, levels-1)==eStop) return eStop; } while(GoSibling()); } case eSkip: // Means skip this level break; } GoParent(); if( cb.LevelEnd(GetNode()) == eStop ) return eStop; } case eSkip: break; case eStop: return eStop; } } return eOk;}// 'Upward' traverse mode (nodes that closer to leaves processed first)ITreeIterator::EActionITreeIterator::TraverseUpward(I4Each& cb, unsigned levels){ if( levels > 0 ) { if(!IsTerminal()) { switch( cb.LevelBegin(GetNode()) ) { case eStop: return eStop; default: case eOk: if(GoChild()) { do { if( TraverseUpward(cb, levels-1) == eStop ) return eStop; } while(GoSibling()); } case eSkip: // Means skip this level break; } GoParent(); if( cb.LevelEnd(GetNode()) == eStop ) return eStop; } return cb.Execute(GetNode()); } return eOk;}// 'LevelByLevel' traverse (nodes that closer to root processed first)ITreeIterator::EActionITreeIterator::TraverseLevelByLevel(I4Each& cb, unsigned levels){ switch( cb.Execute( GetNode() ) ) { case eStop: return eStop; case eSkip: return eSkip; case eOk: default: break; } if(!IsTerminal()) { vector< const ITaxon1Node* > skippedNodes; return TraverseLevelByLevelInternal(cb, levels, skippedNodes); } return eOk;}ITreeIterator::EActionITreeIterator::TraverseLevelByLevelInternal(I4Each& cb, unsigned levels, vector< const ITaxon1Node* >& skp){ size_t skp_start = skp.size(); if( levels > 1 ) { if(!IsTerminal()) { switch( cb.LevelBegin(GetNode()) ) { case eStop: return eStop; default: case eOk: if(GoChild()) { // First pass - call Execute for all children do { switch( cb.Execute(GetNode()) ) { default: case eOk: break; case eSkip: // Means skip this node skp.push_back( GetNode() ); break; case eStop: return eStop; } } while( GoSibling() ); GoParent(); // Start second pass size_t skp_cur = skp_start; GoChild(); do { if( skp.size() == skp_start || skp[skp_cur] != GetNode() ) { if(TraverseLevelByLevelInternal(cb, levels-1, skp) == eStop ) { return eStop; } } else { ++skp_cur; } } while(GoSibling()); GoParent(); } if( cb.LevelEnd( GetNode() ) == eStop ) return eStop; break; case eSkip: break; } } } skp.resize( skp_start ); return eOk;}// Scans all the ancestors starting from immediate parent up to the root// (no levelBegin, levelEnd calls performed)ITreeIterator::EActionITreeIterator::TraverseAncestors(I4Each& cb){ const ITaxon1Node* pNode = GetNode(); EAction stat = eOk; while( GoParent() ) { stat = cb.Execute(GetNode()); switch( stat ) { case eStop: return eStop; // Stop scan, some error occurred default: case eOk: case eSkip: // Means skip further scan, no error generated break; } if( stat == eSkip ) { break; } } GoNode( pNode ); return stat;}boolCTaxon1::CheckOrgRef( const COrg_ref& orgRef, TOrgRefStatus& stat_out ){ CDiagAutoPrefix( "Taxon1::CheckOrgRef" ); SetLastError(NULL); int tax_id; tax_id = GetTaxIdByOrgRef( orgRef ); stat_out = eStatus_Ok; if( tax_id == 0 ) { SetLastError( "No organism found for specified org_ref" ); ERR_POST( GetLastError() ); return false; } else if( tax_id < 0 ) { SetLastError( "Multiple organisms found for specified org_ref" ); ERR_POST( GetLastError() ); return false; } else { CRef< CTaxon2_data > pData( GetById( tax_id ) ); if( pData ) { // Compare orgrefs const COrg_ref& goodOr = pData->GetOrg(); if( !orgRef.IsSetOrgname() ) { stat_out |= eStatus_NoOrgname; } else { const COrgName& goodOn = goodOr.GetOrgname(); const COrgName& inpOn = orgRef.GetOrgname(); if( !inpOn.IsSetGcode() || !goodOn.IsSetGcode() || inpOn.GetGcode() != goodOn.GetGcode() ) { stat_out |= eStatus_WrongGC; } if( !inpOn.IsSetMgcode() ) { // mgc not set in input if( goodOn.IsSetMgcode() && goodOn.GetMgcode() != 0 ) { stat_out |= eStatus_WrongMGC; } } else { // mgc set if( !goodOn.IsSetMgcode() ) { if( inpOn.GetMgcode() != 0 ) { // not unassigned stat_out |= eStatus_WrongMGC; } } else if( inpOn.GetMgcode() != goodOn.GetMgcode() ) { stat_out |= eStatus_WrongMGC; } } if( !inpOn.IsSetLineage() || !goodOn.IsSetLineage() || inpOn.GetLineage().compare( goodOn.GetLineage() ) != 0 ) { stat_out |= eStatus_WrongLineage; } if( !inpOn.IsSetName() || !goodOn.IsSetName() || inpOn.GetName().Which() != goodOn.GetName().Which() ) { stat_out |= eStatus_WrongOrgname; } if( !inpOn.IsSetDiv() ) { if( goodOn.IsSetDiv() && goodOn.GetDiv().compare( "UNA" ) != 0 ) { stat_out |= eStatus_WrongDivision; } } else { if( !goodOn.IsSetDiv() ) { if( inpOn.GetDiv().compare( "UNA" ) != 0 ) { stat_out |= eStatus_WrongDivision; } } else if( inpOn.GetDiv().compare( goodOn.GetDiv() ) != 0 ) { stat_out |= eStatus_WrongDivision; } } if( goodOn.IsSetMod() ) { if( inpOn.IsSetMod() ) { const COrgName::TMod& inpMods = inpOn.GetMod(); const COrgName::TMod& goodMods = goodOn.GetMod(); for( COrgName::TMod::const_iterator gi = goodMods.begin(); gi != goodMods.end(); ++gi ) { bool bFound = false; for( COrgName::TMod::const_iterator ii = inpMods.begin(); ii != inpMods.end(); ++ii ) { if( (*gi)->GetSubtype() == (*ii)->GetSubtype() && ((*gi)->GetSubname() == (*ii)->GetSubname()) ) { bFound = true; break; } } if( !bFound ) { stat_out |= eStatus_WrongOrgmod; break; } } } else { stat_out |= eStatus_WrongOrgmod; } } } // Check taxname if( orgRef.IsSetTaxname() ) { if( !goodOr.IsSetTaxname() || orgRef.GetTaxname().compare( goodOr.GetTaxname() ) != 0 ) { stat_out |= eStatus_WrongTaxname; } } else if( goodOr.IsSetTaxname() ) { stat_out |= eStatus_WrongTaxname; } // Check common name if( orgRef.IsSetCommon() ) { if( !goodOr.IsSetCommon() || orgRef.GetCommon().compare( goodOr.GetCommon() ) != 0 ) { stat_out |= eStatus_WrongCommonName; } } else if( goodOr.IsSetCommon() ) { stat_out |= eStatus_WrongCommonName; } } else { // Internal error: Cannot find orgref by tax_id SetLastError( "No organisms found for tax id" ); ERR_POST( GetLastError() ); return false; } } return true;}END_objects_SCOPEEND_NCBI_SCOPE/* * $Log: taxon1.cpp,v $ * Revision 1000.3 2004/06/01 19:35:15 gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R6.25 * * Revision 6.25 2004/05/19 17:27:10 gorelenk * Added include of PCH - ncbi_pch.hpp * * Revision 6.24 2004/04/01 14:14:02 lavr * Spell "occurred", "occurrence", and "occurring" * * Revision 6.23 2004/03/12 20:07:24 domrach * CheckOrgRef() function added for checking the user orgref against the orgref from Taxonomy db * * Revision 6.22 2004/02/04 16:14:44 domrach * New iterator types (modes of operation) are introduced. They include: * full tree, branches'n'leaves, best, and blast. Position inquiry f-ns * IsTerminal(), IsFirstChild(), and IsLastChild() has been moved from * ITreeNode to ITreeIterator. Node loading f-ns() now return the ITreeNode * for tax id. * * Revision 6.21 2003/11/20 15:42:19 ucko * Update for new (saner) treatment of ASN.1 NULLs. * * Revision 6.20 2003/11/18 17:50:51 dicuccio * Rearranged #include statements to avoid warning on MSVC * * Revision 6.19 2003/10/23 18:52:47 domrach * Unique name bug fixed * * Revision 6.18 2003/07/09 15:41:31 domrach * SearchTaxIdByName(), GetNameClass(), and GetNodeProperty() functions added * * Revision 6.17 2003/06/23 20:42:08 domrach * New treatment of subspecies names introduced * * Revision 6.16 2003/06/05 20:44:02 domrach * Adjusted to the new CanGetXxx verification methods * * Revision 6.15 2003/05/06 19:53:54 domrach * New functions and interfaces for traversing the cached partial taxonomy tree introduced. Convenience functions GetDivisionName() and GetRankName() were added * * Revision 6.14 2003/03/10 20:59:37 ucko * ThrowError1 -> ThrowError, per the recent change to <serial/objostr.hpp>. * Explicitly cast ints to COrgMod::TSubtype when setting OrgMod.subtype. * * Revision 6.13 2003/03/05 21:33:52 domrach * Enhanced orgref processing. Orgref cache capacity control added. * * Revision 6.12 2003/01/31 03:46:46 lavr * Heed int->bool performance warnings * * Revision 6.11 2003/01/21 19:38:59 domrach * GetPopsetJoin() member function optimized to copy partial tree from cached tree * * Revision 6.10 2003/01/10 19:58:46 domrach * Function GetPopsetJoin() added to CTaxon1 class * * Revision 6.9 2002/11/08 20:55:58 ucko * CConstRef<> now requires an explicit constructor. * * Revision 6.8 2002/11/08 14:39:52 domrach * Member function GetSuperkingdom() added * * Revision 6.7 2002/11/04 21:29:18 grichenk * Fixed usage of const CRef<> and CRef<> constructor * * Revision 6.6 2002/08/06 16:12:34 domrach * Merging of modifiers is now performed in LookupMerge * * Revision 6.5 2002/07/25 15:01:56 grichenk * Replaced non-const GetXXX() with SetXXX() * * Revision 6.4 2002/02/14 22:44:50 vakatov * Use STimeout instead of time_t. * Get rid of warnings and extraneous #include's, shuffled code a little. * * Revision 6.3 2002/01/31 00:31:26 vakatov * Follow the renaming of "CTreeCont.hpp" to "ctreecont.hpp". * Get rid of "std::" which is unnecessary and sometimes un-compilable. * Also done some source identation/beautification. * * Revision 6.2 2002/01/30 16:13:38 domrach * Changes made to pass through MSVC compiler. Some src files renamed * * Revision 6.1 2002/01/28 19:56:10 domrach * Initial checkin of the library implementation files * * =========================================================================== */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -