SCompartmentData(const CSeq_align_set &compartment)
 : num_alignments(compartment.Get().size())
 {
    CSeq_align align;
    align.SetSegs().SetDisc(const_cast<CSeq_align_set &>(compartment));
    query_range = align.GetSeqRange(0);
    subject_range = align.GetSeqRange(1);
 }
int CTestCompartApplication::Run(void)
{
    // Get arguments
    const CArgs& args = GetArgs();

    CRef<CObjectManager> om(CObjectManager::GetInstance());
    CGBDataLoader::RegisterInObjectManager(*om);
    CRef<CScope> scope(new CScope(*om));
    scope->AddDefaults();

    list< CRef<CSeq_align> > aligns;
    {{
         CNcbiIstream& istr = args["i"].AsInputFile();
         auto_ptr<CObjectIStream> is
             (CObjectIStream::Open(eSerial_AsnText, istr));
         while ( !is->EndOfData() ) {
             CRef<CSeq_align> align(new CSeq_align);
             *is >> *align;
             aligns.push_back(align);
         }
     }}

    CNcbiOstream& ostr = args["o"].AsOutputFile();

    TCompartOptions opts = fCompart_Defaults;
    if (args["allow-intersect"]) {
        opts |= fCompart_AllowIntersections;
    }
    if (args["allow-intersect-query"]) {
        opts |= fCompart_AllowIntersectionsQuery;
    }
    if (args["allow-intersect-subject"]) {
        opts |= fCompart_AllowIntersectionsSubject;
    }
    if (args["allow-intersect-both"]) {
        opts |= fCompart_AllowIntersectionsBoth;
    }

    list< CRef<CSeq_align_set> > compartments;
    FindCompartments(aligns, compartments, opts);

    LOG_POST(Error << "input alignments: " << aligns.size());
    LOG_POST(Error << "output compartments: " << compartments.size());

    size_t count = 0;
    NON_CONST_ITERATE (list< CRef<CSeq_align_set> >, i, compartments) {
        ++count;
        CSeq_align align;
        align.SetSegs().SetDisc(**i);

        TSeqRange r1 = align.GetSeqRange(0);
        TSeqRange r2 = align.GetSeqRange(1);
        CSeq_id_Handle id1 = CSeq_id_Handle::GetHandle(align.GetSeq_id(0));
        CSeq_id_Handle id2 = CSeq_id_Handle::GetHandle(align.GetSeq_id(1));

        LOG_POST(Error << "compartment " << count << ":");
        LOG_POST(Error << "  query   = " << id1 << " (" << r1.GetFrom() + 1 << ".." << r1.GetTo() + 1 << ")");
        LOG_POST(Error << "  subject = " << id2 << " (" << r2.GetFrom() + 1 << ".." << r2.GetTo() + 1 << ")");
        LOG_POST(Error << "  alignments = " << (*i)->Get().size());

        string title("Compartment ");
        title += NStr::NumericToString(count);
        CSeq_annot annot;
        annot.SetNameDesc(title);
        annot.SetTitleDesc(title);
        annot.SetData().SetAlign() = (*i)->Get();
        ostr << MSerial_AsnText << annot;
    }