CRef< CStructWrapper<BlastHSPStream> >
    x_GetSampleHspStream(CRef<CBlastOptions> opts, CSeqDB & db)
    {
        CSeq_id sid("gi|158292535");
        
        vector<int> OIDS;
        db.SeqidToOids(sid, OIDS);
        
        BOOST_REQUIRE(OIDS.size());
        
        const int k_num_hsps_start = 12;
        //const int k_num_hsps_end = 10;
        
        // Taken from traceback unit test.
        
        BlastHSPList* hsp_list = 
            (BlastHSPList*) calloc(1, sizeof(BlastHSPList)); 
        hsp_list->oid = OIDS[0];
        hsp_list->hspcnt = k_num_hsps_start;
        hsp_list->allocated = k_num_hsps_start;
        hsp_list->hsp_max = k_num_hsps_start;
        hsp_list->do_not_reallocate = FALSE;

        hsp_list->hsp_array = (BlastHSP**)
            malloc(hsp_list->allocated*sizeof(BlastHSP*));
        
	BlastHSPWriterInfo * writer_info = BlastHSPCollectorInfoNew(
	               BlastHSPCollectorParamsNew(
                                opts->GetHitSaveOpts(),
                                opts->GetExtnOpts()->compositionBasedStats,
                                opts->GetScoringOpts()->gapped_calculation));
        
        BlastHSPWriter* writer = BlastHSPWriterNew(&writer_info, NULL);
        BOOST_REQUIRE(writer_info == NULL);
        
        BlastHSPStream* hsp_stream = BlastHSPStreamNew(
                                       opts->GetProgramType(),
                                       opts->GetExtnOpts(),
                                       FALSE, 1, writer);

        const int query_offset[k_num_hsps_start] =
            { 0, 3864, 3254, 1828, 2189, 795,
              607, 1780, 1363, 2751, 3599, 242 };
        const int query_end[k_num_hsps_start] =
            { 307, 4287, 3556, 2058, 2269, 914,
              741, 1821, 1451, 2810, 3631, 285 };
        const int subject_offset[k_num_hsps_start] =
            { 1, 2723, 2267, 1028, 1292, 634,
              501, 925, 1195, 1795, 477, 1233 };
        const int subject_end[k_num_hsps_start] =
            { 321, 3171, 2537, 1243, 1371, 749,
              618, 966, 1286, 1869, 509, 1276 };
        const int score[k_num_hsps_start] =
            { 370, 319, 139, 120, 89, 84,
              75, 70, 69, 60, 47, 43 };
        const int query_gapped_start[k_num_hsps_start] =
            { 47, 4181, 3286, 2034, 2228, 871,
              632, 1798, 1383, 2759, 3606, 259 };
        const int subject_gapped_start[k_num_hsps_start] =
            { 48, 3073, 2299, 1219, 1330, 709,
              526, 943, 1215, 1803, 484, 1250 };
        
        for (int index=0; index<k_num_hsps_start; index++) {
            BlastHSP * h1
                = hsp_list->hsp_array[index]
                = (BlastHSP*) calloc(1, sizeof(BlastHSP));
            
            h1->query.offset = query_offset[index];
            h1->query.end = query_end[index];
            h1->subject.offset = subject_offset[index];
            h1->subject.end = subject_end[index];
            h1->score = score[index];
            h1->query.gapped_start = query_gapped_start[index];
            h1->subject.gapped_start = subject_gapped_start[index];
        }
        
        // needed after tie-breaking algorithm for scores was changed
        // in ScoreCompareHSP (blast_hits.c, revision 1.139)
        Blast_HSPListSortByScore(hsp_list);
        BlastHSPStreamWrite(hsp_stream, &hsp_list);
        
        CRef< CStructWrapper<BlastHSPStream> >
            hsps(WrapStruct(hsp_stream, BlastHSPStreamFree));
        
        return hsps;
    }
    CRef< CStructWrapper<BlastHSPStream> >
    x_GetSelfHitHspStream(CRef<CBlastOptions> opts, CSeqDB & db, CSeq_id& sid)
    {
        vector<int> OIDS;
        db.SeqidToOids(sid, OIDS);
        
        BOOST_REQUIRE(OIDS.size());
        
        const int k_num_hsps_start = 1;
        const int k_seq_length = db.GetSeqLength(OIDS.front());
        
        BlastHSPList* hsp_list = 
            (BlastHSPList*) calloc(1, sizeof(BlastHSPList)); 
        hsp_list->oid = OIDS.front();
        hsp_list->hspcnt = k_num_hsps_start;
        hsp_list->allocated = k_num_hsps_start;
        hsp_list->hsp_max = k_num_hsps_start;
        hsp_list->do_not_reallocate = FALSE;

        hsp_list->hsp_array = (BlastHSP**)
            malloc(hsp_list->allocated*sizeof(BlastHSP*));
        
        
        BlastHSPWriterInfo * writer_info = BlastHSPCollectorInfoNew(
                   BlastHSPCollectorParamsNew(
                                    opts->GetHitSaveOpts(),
                                    opts->GetExtnOpts()->compositionBasedStats,
                                    opts->GetScoringOpts()->gapped_calculation));

        BlastHSPWriter* writer = BlastHSPWriterNew(&writer_info, NULL);
        BOOST_REQUIRE(writer_info == NULL);
        
        BlastHSPStream* hsp_stream = BlastHSPStreamNew(
                                       opts->GetProgramType(),
                                       opts->GetExtnOpts(),
                                       FALSE, 1, writer);

        const int query_offset[k_num_hsps_start] = { 0 };
        const int query_end[k_num_hsps_start] = { k_seq_length - 1 };
        const int subject_offset[k_num_hsps_start] = { 0 };
        const int subject_end[k_num_hsps_start] = { k_seq_length - 1 };
        const int score[k_num_hsps_start] = { 0 };
        const int query_gapped_start[k_num_hsps_start] = { 0 };
        const int subject_gapped_start[k_num_hsps_start] = { 0 };
        
        for (int index=0; index<k_num_hsps_start; index++) {
            BlastHSP * h1
                = hsp_list->hsp_array[index]
                = (BlastHSP*) calloc(1, sizeof(BlastHSP));
            
            h1->query.offset = query_offset[index];
            h1->query.end = query_end[index];
            h1->subject.offset = subject_offset[index];
            h1->subject.end = subject_end[index];
            h1->score = score[index];
            h1->query.gapped_start = query_gapped_start[index];
            h1->subject.gapped_start = subject_gapped_start[index];
        }
        
        // needed after tie-breaking algorithm for scores was changed
        // in ScoreCompareHSP (blast_hits.c, revision 1.139)
        Blast_HSPListSortByScore(hsp_list);
        BlastHSPStreamWrite(hsp_stream, &hsp_list);
        
        CRef< CStructWrapper<BlastHSPStream> >
            hsps(WrapStruct(hsp_stream, BlastHSPStreamFree));
        
        return hsps;
    }