test_getalignments.cpp
上传用户:yhdzpy8989
上传日期:2007-06-13
资源大小:13604k
文件大小:7k
- /*
- * ===========================================================================
- * PRODUCTION $Log: test_getalignments.cpp,v $
- * PRODUCTION Revision 1000.0 2004/06/01 21:22:07 gouriano
- * PRODUCTION PRODUCTION: IMPORTED [GCC34_MSVC7] Dev-tree R1.3
- * PRODUCTION
- * ===========================================================================
- */
- /* $Id: test_getalignments.cpp,v 1000.0 2004/06/01 21:22:07 gouriano Exp $
- * ===========================================================================
- *
- * PUBLIC DOMAIN NOTICE
- * National Center for Biotechnology Information
- *
- * This software/database is a "United States Government Work" under the
- * terms of the United States Copyright Act. It was written as part of
- * the author's official duties as a United States Government employee and
- * thus cannot be copyrighted. This software/database is freely available
- * to the public for use. The National Library of Medicine and the U.S.
- * Government have not placed any restriction on its use or reproduction.
- *
- * Although all reasonable efforts have been taken to ensure the accuracy
- * and reliability of the software and data, the NLM and the U.S.
- * Government do not and cannot warrant the performance or results that
- * may be obtained by using this software or data. The NLM and the U.S.
- * Government disclaim all warranties, express or implied, including
- * warranties of performance, merchantability or fitness for any particular
- * purpose.
- *
- * Please cite the author in any work or product based on this material.
- *
- * ===========================================================================
- *
- * Authors: Mike DiCuccio
- *
- * File Description:
- * Test application for plugins
- */
- #include <ncbi_pch.hpp>
- #include <corelib/ncbiapp.hpp>
- #include <corelib/ncbiargs.hpp>
- #include <corelib/ncbienv.hpp>
- #include <corelib/ncbireg.hpp>
- #include <gui/objutils/utils.hpp>
- #include <gui/objutils/mate_pair.hpp>
- #include <gui/objutils/alignment.hpp>
- #include <gui/objutils/pw_alignment.hpp>
- #include <gui/objutils/label.hpp>
- #include <objmgr/object_manager.hpp>
- #include <objmgr/scope.hpp>
- #include <objtools/data_loaders/genbank/gbloader.hpp>
- #include <objects/seqalign/Seq_align.hpp>
- #include <serial/objostr.hpp>
- #include <serial/serial.hpp>
- USING_NCBI_SCOPE;
- USING_SCOPE(objects);
- class CTestGetAlignments : public CNcbiApplication
- {
- public:
- virtual void Init(void);
- virtual int Run(void);
- virtual void Exit(void);
- };
- void CTestGetAlignments::Init(void)
- {
- // Create command-line argument descriptions class
- auto_ptr<CArgDescriptions> arg_desc(new CArgDescriptions);
- // Specify USAGE context
- arg_desc->SetUsageContext(GetArguments().GetProgramBasename(),
- "Test: CSeqUtils::GetAlignments()");
- arg_desc->AddKey("acc", "Accession",
- "Accession to test",
- CArgDescriptions::eString);
- // Setup arg.descriptions for this application
- SetupArgDescriptions(arg_desc.release());
- }
- int CTestGetAlignments::Run(void)
- {
- // Get arguments
- CArgs args = GetArgs();
- string id_str = args["acc"].AsString();
- CSeq_id id(id_str);
- if ( id.Which() == CSeq_id::e_not_set) {
- LOG_POST(Fatal << "don't understand accession: " << id_str);
- }
- CRef<CObjectManager> obj_mgr(new CObjectManager());
- obj_mgr->RegisterDataLoader(*new CGBDataLoader(),
- CObjectManager::eDefault);
- CRef<CScope> scope(new CScope(*obj_mgr));
- scope->AddDefaults();
- CBioseq_Handle handle = scope->GetBioseqHandle(id);
- if ( !handle ) {
- LOG_POST(Fatal << "failed to retrieve sequence for: " << id_str);
- }
- CLayoutEngine::TObjects objs;
- CSeqUtils::GetAlignments(handle,
- TSeqRange(0, handle.GetBioseqLength()),
- objs);
- cout << "got " << objs.size() << " alignments:" << endl;
- auto_ptr<CObjectOStream> os(CObjectOStream::Open(eSerial_AsnText, cout));
- ITERATE (CLayoutEngine::TObjects, iter, objs) {
- const CLayoutObject& obj = **iter;
- if (dynamic_cast<const CLayoutPWAlign*>(&obj)) {
- const CLayoutPWAlign& pwalign =
- dynamic_cast<const CLayoutPWAlign&>(obj);
- const CSeq_align& align = pwalign.GetAlignment();
- string label;
- CLabel::GetLabel(align, &label, CLabel::eDefault, scope);
- cout << string(72, '-') << endl;
- cout << "pairwise alignment: " << label << endl;
- *os << align;
- } else if (dynamic_cast<const CLayoutMatePair*>(&obj)) {
- const CLayoutMatePair& mpalign =
- dynamic_cast<const CLayoutMatePair&>(obj);
- const CLayoutMatePair::TAlignList& aligns =
- mpalign.GetSeqAligns();
- cout << string(72, '-') << endl;
- cout << "mate pair alignment: " << aligns.size()
- << " alignments" << endl;
- cout << "mate pair library: " << mpalign.GetLibraryId() << endl;
- cout << "mate pair error code: " << mpalign.GetError() << endl;
- ITERATE (CLayoutMatePair::TAlignList, iter, aligns) {
- *os << (*iter)->GetAlignment();
- }
- } else if (dynamic_cast<const CLayoutAlign*>(&obj)) {
- const CLayoutAlign& aobj =
- dynamic_cast<const CLayoutAlign&>(obj);
- const CSeq_align& align = aobj.GetAlignment();
- string label;
- CLabel::GetLabel(align, &label, CLabel::eDefault, scope);
- cout << string(72, '-') << endl;
- cout << "pairwise alignment: " << label << endl;
- *os << align;
- } else {
- LOG_POST(Error << "unhandled alignment object");
- }
- }
- return 0;
- }
- /////////////////////////////////////////////////////////////////////////////
- // Cleanup
- void CTestGetAlignments::Exit(void)
- {
- SetDiagStream(0);
- }
- /////////////////////////////////////////////////////////////////////////////
- // MAIN
- int main(int argc, const char* argv[])
- {
- // Execute main application function
- return CTestGetAlignments().AppMain(argc, argv, 0, eDS_Default, 0);
- }
- /*
- * ===========================================================================
- * $Log: test_getalignments.cpp,v $
- * Revision 1000.0 2004/06/01 21:22:07 gouriano
- * PRODUCTION: IMPORTED [GCC34_MSVC7] Dev-tree R1.3
- *
- * Revision 1.3 2004/05/21 22:27:44 gorelenk
- * Added PCH ncbi_pch.hpp
- *
- * Revision 1.2 2004/05/10 18:23:53 dicuccio
- * Dump pairwise alignments. Added tracing of mate pair specifics
- *
- * Revision 1.1 2004/05/09 23:59:55 dicuccio
- * Standardized names of demo and test applications. Cleaned up LIB
- * specifications to eliminate unneeded libraries after splitting libgui_utils
- * into libgui_utils and libgui_objutils
- *
- * ===========================================================================
- */