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

📄 cn3d_app.cpp

📁 ncbi源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    SetDiagPostLevel(eDiag_Info);    if (!okay) {        ERRORMSG("This file is not a valid Biostruc");        return NULL;    }    // remove all but desired model coordinates    CRef < CBiostruc_model > desiredModel;    CBiostruc::TModel::const_iterator m, me = biostruc->GetModel().end();    for (m=biostruc->GetModel().begin(); m!=me; ++m) {        if ((*m)->GetType() == model) {            desiredModel = *m;            break;        }    }    if (desiredModel.Empty()) {        ERRORMSG("Ack! There's no appropriate model in this Biostruc");        return NULL;    }    biostruc->ResetModel();    biostruc->SetModel().push_back(desiredModel);    // package Biostruc inside a mime object    CRef < CNcbi_mime_asn1 > mime(new CNcbi_mime_asn1());    CRef < CBiostruc_seq > strucseq(new CBiostruc_seq());    mime->SetStrucseq(*strucseq);    strucseq->SetStructure(*biostruc);    // get list of gi's to import    vector < int > gis;    CBiostruc_graph::TMolecule_graphs::const_iterator g,        ge = biostruc->GetChemical_graph().GetMolecule_graphs().end();    for (g=biostruc->GetChemical_graph().GetMolecule_graphs().begin(); g!=ge; ++g) {        if ((*g)->IsSetSeq_id() && (*g)->GetSeq_id().IsGi())            gis.push_back((*g)->GetSeq_id().GetGi());    }    if (gis.size() == 0) {        ERRORMSG("Can't find any sequence gi identifiers in this Biostruc");        return NULL;    }    // fetch sequences and store in mime    CRef < CSeq_entry > seqs(new CSeq_entry());    strucseq->SetSequences().push_back(seqs);    CRef < CBioseq_set > seqset(new CBioseq_set());    seqs->SetSet(*seqset);    for (int i=0; i<gis.size(); ++i) {        wxString id;        id.Printf("%i", gis[i]);        CRef < CBioseq > bioseq = FetchSequenceViaHTTP(id.c_str());        if (bioseq.NotEmpty()) {            CRef < CSeq_entry > seqentry(new CSeq_entry());            seqentry->SetSeq(*bioseq);            seqset->SetSeq_set().push_back(seqentry);        } else {            ERRORMSG("Failed to retrieve all Bioseqs");            return NULL;        }    }    return mime.Release();}bool Cn3DApp::OnInit(void){    INFOMSG("Welcome to Cn3D " << CN3D_VERSION_STRING << "!");    INFOMSG("built " << __DATE__ << " with wxWidgets " << wxVERSION_NUM_DOT_STRING);    // set up command line parser    static const wxCmdLineEntryDesc cmdLineDesc[] = {        { wxCMD_LINE_SWITCH, "h", "help", "show this help message",            wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },        { wxCMD_LINE_SWITCH, "r", "readonly", "message file is read-only",            wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL },        { wxCMD_LINE_SWITCH, "i", "imports", "show imports window on startup",            wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL },        { wxCMD_LINE_SWITCH, "n", "noalign", "do not show alignment window on startup",            wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL },        { wxCMD_LINE_SWITCH, "f", "force", "force saves to same file",            wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL },        { wxCMD_LINE_OPTION, "m", "message", "message file",            wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_NEEDS_SEPARATOR },        { wxCMD_LINE_OPTION, "a", "targetapp", "messaging target application name",            wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_NEEDS_SEPARATOR },        { wxCMD_LINE_OPTION, "o", "model", "model choice: alpha, single, or PDB",            wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_NEEDS_SEPARATOR },        { wxCMD_LINE_OPTION, "d", "id", "MMDB/PDB ID to load via network",            wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_NEEDS_SEPARATOR },        { wxCMD_LINE_PARAM, NULL, NULL, "input file",            wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL},        { wxCMD_LINE_NONE }    };    commandLine.SetSwitchChars("-");    commandLine.SetDesc(cmdLineDesc);    commandLine.SetCmdLine(argc, argv);    switch (commandLine.Parse()) {        case 0: TRACEMSG("command line parsed successfully"); break;        default: return false;  // exit upon either help or syntax error    }    // help system loads from zip file    wxFileSystem::AddHandler(new wxZipFSHandler);    // set up working directories    workingDir = wxGetCwd().c_str();#ifdef __WXGTK__    if (getenv("CN3D_HOME") != NULL)        programDir = getenv("CN3D_HOME");    else#endif    if (wxIsAbsolutePath(argv[0]))        programDir = wxPathOnly(argv[0]).c_str();    else if (wxPathOnly(argv[0]) == "")        programDir = workingDir;    else        programDir = workingDir + wxFILE_SEP_PATH + wxPathOnly(argv[0]).c_str();    workingDir = workingDir + wxFILE_SEP_PATH;    programDir = programDir + wxFILE_SEP_PATH;    // find or create preferences folder    wxString localDir;    wxSplitPath((wxFileConfig::GetLocalFileName("unused")).c_str(), &localDir, NULL, NULL);    wxString prefsDirLocal = localDir + wxFILE_SEP_PATH + "Cn3D_User";    wxString prefsDirProg = wxString(programDir.c_str()) + wxFILE_SEP_PATH + "Cn3D_User";    if (wxDirExists(prefsDirLocal))        prefsDir = prefsDirLocal.c_str();    else if (wxDirExists(prefsDirProg))        prefsDir = prefsDirProg.c_str();    else {        // try to create the folder        if (wxMkdir(prefsDirLocal) && wxDirExists(prefsDirLocal))            prefsDir = prefsDirLocal.c_str();        else if (wxMkdir(prefsDirProg) && wxDirExists(prefsDirProg))            prefsDir = prefsDirProg.c_str();    }    if (prefsDir.size() == 0)        WARNINGMSG("Can't create Cn3D_User folder at either:"            << "\n    " << prefsDirLocal            << "\nor  " << prefsDirProg);    else        prefsDir += wxFILE_SEP_PATH;    // set data dir, and register the path in C toolkit registry (mainly for BLAST code)#ifdef __WXMAC__    dataDir = programDir + "../Resources/data/";#else    dataDir = programDir + "data" + wxFILE_SEP_PATH;#endif    Nlm_TransientSetAppParam("ncbi", "ncbi", "data", dataDir.c_str());    INFOMSG("working dir: " << workingDir.c_str());    INFOMSG("program dir: " << programDir.c_str());    INFOMSG("data dir: " << dataDir.c_str());    INFOMSG("prefs dir: " << prefsDir.c_str());    // read dictionary    wxString dictFile = wxString(dataDir.c_str()) + "bstdt.val";    LoadStandardDictionary(dictFile.c_str());    // set up registry and favorite styles (must be done before structure window creation)    InitRegistry();    // create the main frame window - must be first window created by the app    structureWindow = new StructureWindow(        wxString("Cn3D ") + CN3D_VERSION_STRING, wxPoint(0,0), wxSize(500,500));    SetTopWindow(structureWindow);    SetExitOnFrameDelete(true); // exit app when structure window is closed    topWindow = structureWindow;    // show log if set to do so    bool showLog = false;    RegistryGetBoolean(REG_CONFIG_SECTION, REG_SHOW_LOG_ON_START, &showLog);    if (showLog) RaiseLogWindow();    // get model type from -o    EModel_type model = eModel_type_other;    wxString modelStr;    if (commandLine.Found("o", &modelStr)) {        if (modelStr == "alpha")            model = eModel_type_ncbi_backbone;        else if (modelStr == "single")            model = eModel_type_ncbi_all_atom;        else if (modelStr == "PDB")            model = eModel_type_pdb_model;        else            ERRORMSG("Model type (-o) must be one of alpha|single|PDB");    }    // load file given on command line    if (commandLine.GetParamCount() == 1) {        wxString filename = commandLine.GetParam(0).c_str();        INFOMSG("command line file: " << filename.c_str());        // if -o is present, assume param is a Biostruc file        if (model != eModel_type_other) {   // -o present            CNcbi_mime_asn1 *mime = CreateMimeFromBiostruc(filename, model);            if (mime)                structureWindow->LoadData(NULL, commandLine.Found("f"), mime);        } else {            structureWindow->LoadData(filename.c_str(), commandLine.Found("f"));        }    }    // if no file passed but there is -o, see if there's a -d parameter (MMDB/PDB ID to fetch)    else if (model != eModel_type_other) {  // -o present        wxString id;        if (commandLine.Found("d", &id)) {            CNcbi_mime_asn1 *mime = LoadStructureViaCache(id.c_str(), model);            if (mime)                structureWindow->LoadData(NULL, commandLine.Found("f"), mime);        } else {            ERRORMSG("-o requires either -d or Biostruc file name");        }    }    // if no structure loaded, show the logo    if (!structureWindow->glCanvas->structureSet) {        structureWindow->glCanvas->renderer->AttachStructureSet(NULL);        structureWindow->glCanvas->Refresh(false);    }    // set up messaging file communication    wxString messageFilename;    if (commandLine.Found("m", &messageFilename)) {        wxString messageApp;        if (!commandLine.Found("a", &messageApp))            messageApp = "Listener";        structureWindow->SetupFileMessenger(            messageFilename.c_str(), messageApp.c_str(), commandLine.Found("r"));    }    // optionally show alignment window    if (!commandLine.Found("n") && structureWindow->glCanvas->structureSet)        structureWindow->glCanvas->structureSet->alignmentManager->ShowSequenceViewer();    // optionally open imports window, but only if any imports present    if (commandLine.Found("i") && structureWindow->glCanvas->structureSet &&            structureWindow->glCanvas->structureSet->alignmentManager->NUpdates() > 0)        structureWindow->glCanvas->structureSet->alignmentManager->ShowUpdateWindow();    // give structure window initial focus    structureWindow->Raise();    structureWindow->SetFocus();    return true;}int Cn3DApp::OnExit(void){    SetDiagHandler(NULL, NULL, NULL);    SetDiagStream(&cout);    // save registry    SaveRegistry();    // remove dictionary    DeleteStandardDictionary();    // destroy log    if (logFrame) logFrame->Destroy();    return 0;}void Cn3DApp::OnIdle(wxIdleEvent& event){    // process pending redraws    GlobalMessenger()->ProcessRedraws();    // call base class OnIdle to continue processing any other system idle-time stuff    wxApp::OnIdle(event);}#ifdef __WXMAC__// special handler for open file apple eventvoid Cn3DApp::MacOpenFile(const wxString& filename){    if (filename.size() > 0) {        INFOMSG("apple open event file: " << filename);        structureWindow->LoadData(filename, false);    }}#endifEND_SCOPE(Cn3D)/** ---------------------------------------------------------------------------* $Log: cn3d_app.cpp,v $* Revision 1000.3  2004/06/01 18:28:05  gouriano* PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.21** Revision 1.21  2004/05/22 15:33:41  thiessen* fix scrolling bug in log frame** Revision 1.20  2004/05/21 21:41:39  gorelenk* Added PCH ncbi_pch.hpp** Revision 1.19  2004/04/19 19:36:07  thiessen* fix frame switch bug when no structures present** Revision 1.18  2004/03/15 18:19:23  thiessen* prefer prefix vs. postfix ++/-- operators** Revision 1.17  2004/03/10 23:15:51  thiessen* add ability to turn off/on error dialogs; group block aligner errors in message log** Revision 1.16  2004/02/19 17:04:47  thiessen* remove cn3d/ from include paths; add pragma to disable annoying msvc warning** Revision 1.15  2004/01/28 19:27:54  thiessen* add input asn stream verification** Revision 1.14  2004/01/17 02:11:27  thiessen* mac fix** Revision 1.13  2004/01/17 01:47:26  thiessen* add network load** Revision 1.12  2004/01/17 00:17:28  thiessen* add Biostruc and network structure load** Revision 1.11  2004/01/08 15:31:02  thiessen* remove hard-coded CDTree references in messaging; add Cn3DTerminated message upon exit** Revision 1.10  2003/12/03 15:46:36  thiessen* adjust so spin increment is accurate** Revision 1.9  2003/12/03 15:07:09  thiessen* add more sophisticated animation controls** Revision 1.8  2003/11/15 16:08:35  thiessen* add stereo** Revision 1.7  2003/10/13 14:16:31  thiessen* add -n option to not show alignment window** Revision 1.6  2003/10/13 13:23:31  thiessen* add -i option to show import window** Revision 1.5  2003/07/17 18:47:01  thiessen* add -f option to force save to same file** Revision 1.4  2003/06/21 20:54:03  thiessen* explicitly show bottom of log when new text appended** Revision 1.3  2003/05/29 14:34:19  thiessen* force serial object verification** Revision 1.2  2003/03/13 16:57:14  thiessen* fix favorites load/save problem** Revision 1.1  2003/03/13 14:26:18  thiessen* add file_messaging module; split cn3d_main_wxwin into cn3d_app, cn3d_glcanvas, structure_window, cn3d_tools**/

⌨️ 快捷键说明

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