示例#1
0
static rc_t walk_ref_iter( ReferenceIterator *ref_iter,
                           bool skip_empty,
                           bool nodebug )
{
    rc_t rc = 0;
    while( rc == 0 )
    {
        struct ReferenceObj const * refobj;
        INSDC_coord_zero first_pos;
        INSDC_coord_len len;
        rc = ReferenceIteratorNextReference( ref_iter, &first_pos, &len, &refobj );
        if ( rc == 0 && refobj != NULL )
        {
            const char *name;
            rc = ReferenceObj_SeqId( refobj, &name );
            if ( rc != 0 )
                LOGERR( klogInt, rc, "ReferenceObj_SeqId() failed" );
            else
            {
                OUTMSG(( "walking ref-iter on reference: >%s< ( from %u to %u )\n",
                         name, first_pos, first_pos + len - 1 ));
                rc = walk_ref_iter_reference( ref_iter, refobj, skip_empty, nodebug );
            }
        }
    }
    if ( GetRCState( rc ) == rcDone ) rc = 0;
    return rc;
}
示例#2
0
static rc_t ref_walker_walk_ref_range( struct ref_walker * self, ref_walker_data * rwd )
{
    ReferenceIterator * ref_iter;
    rc_t rc = AlignMgrMakeReferenceIterator ( self->amgr, &ref_iter, &self->cb_block, self->min_mapq ); /* align/iterator.h */
    if ( rc == 0 )
    {
        /* construct the reference iterator */

        uint32_t idx, count;
        uint32_t reflist_options = ref_walker_make_reflist_options( self ); /* above */
        Vector cur_id_vector;
        VectorInit ( &cur_id_vector, 0, 12 );

        rc = VNameListCount ( self->sources, &count );
        for ( idx = 0; idx < count && rc == 0; ++idx )
        {
            const char * src_name = NULL;
            rc = VNameListGet ( self->sources, idx, &src_name );
            if ( rc == 0 && src_name != NULL )
            {
                const VDatabase *db;
                rc = VDBManagerOpenDBRead ( self->vmgr, &db, self->vschema, "%s", src_name );
                if ( rc == 0 )
                {
                    const ReferenceList * ref_list;
                    rc = ReferenceList_MakeDatabase( &ref_list, db, reflist_options, 0, NULL, 0 );
                    if ( rc == 0 )
                    {
                        const ReferenceObj * ref_obj;
                        rc = ReferenceList_Find( ref_list, &ref_obj, rwd->ref_name, string_size( rwd->ref_name ) );
                        if ( rc == 0 )
                        {
                            INSDC_coord_len len;
                            rc = ReferenceObj_SeqLength( ref_obj, &len );
                            if ( rc == 0 )
                            {
                                if ( rwd->ref_start == 0 )
                                    rwd->ref_start = 1;
                                if ( ( rwd->ref_end == 0 )||( rwd->ref_end > len + 1 ) )
                                    rwd->ref_end = ( len - rwd->ref_start ) + 1;

                                if ( self->primary_alignments )
                                    rc = ref_walker_add_iterator( self, rwd->ref_name, rwd->ref_start, rwd->ref_end, src_name, 
                                            &cur_id_vector, db, ref_obj, ref_iter, TBL_PRIM, primary_align_ids );

                                if ( rc == 0 && self->secondary_alignments )
                                    rc = ref_walker_add_iterator( self, rwd->ref_name, rwd->ref_start, rwd->ref_end, src_name, 
                                            &cur_id_vector, db, ref_obj, ref_iter, TBL_SEC, secondary_align_ids );

                                if ( rc == 0 && self->evidence_alignments )
                                    rc = ref_walker_add_iterator( self, rwd->ref_name, rwd->ref_start, rwd->ref_end, src_name, 
                                            &cur_id_vector, db, ref_obj, ref_iter, TBL_EV, evidence_align_ids );

                            }
                            ReferenceObj_Release( ref_obj );
                        }
                        ReferenceList_Release( ref_list );
                    }
                    VDatabaseRelease( db );
                }
            }
        }

        if ( rc == 0 )
        {
            /* walk the reference iterator */
            struct ReferenceObj const * ref_obj;
            rc = ReferenceIteratorNextReference( ref_iter, NULL, NULL, &ref_obj );
            if ( rc == 0 && ref_obj != NULL )
            {
                if ( self->use_seq_name )
                    rc = ReferenceObj_Name( ref_obj, &rwd->ref_name );
                else
                    rc = ReferenceObj_SeqId( ref_obj, &rwd->ref_name );
                if ( rc == 0 )
                {
                    INSDC_coord_zero first_pos;
                    INSDC_coord_len len;
                    rc_t rc_w = ReferenceIteratorNextWindow ( ref_iter, &first_pos, &len );
                    while ( rc == 0 && rc_w == 0 )
                    {
                        rc_t rc_p = ReferenceIteratorNextPos ( ref_iter, !self->no_skip );
                        if ( rc_p == 0 )
                        {
                            rc = ReferenceIteratorPosition ( ref_iter, &rwd->pos, &rwd->depth, &rwd->bin_ref_base );
                            if ( rwd->depth > 0 && rc == 0 )
                            {
                                rc_t rc_sg = 0;
                                rwd->ascii_ref_base = _4na_to_ascii( rwd->bin_ref_base, false );
                                if ( self->on_enter_ref_pos != NULL )
                                    rc = self->on_enter_ref_pos( rwd );

                                while ( rc_sg == 0 && rc == 0 )
                                {
                                    rc_sg = ReferenceIteratorNextSpotGroup ( ref_iter, &rwd->spot_group, &rwd->spot_group_len );
                                    if ( rc_sg == 0 )
                                    {
                                        rc_t rc_pr = 0;
                                        if ( self->on_enter_spot_group != NULL )
                                            rc = self->on_enter_spot_group( rwd );

                                        while ( rc == 0 && rc_pr == 0 )
                                        {
                                            const PlacementRecord * rec;
                                            rc_pr = ReferenceIteratorNextPlacement ( ref_iter, &rec );
                                            if ( rc_pr == 0 && self->on_alignment != NULL )
                                                rc = ref_walker_walk_alignment( self, ref_iter, rec, rwd );
                                        }

                                        if ( self->on_exit_spot_group != NULL )
                                            rc = self->on_exit_spot_group( rwd );
                                    }
                                }
                                if ( self->on_exit_ref_pos != NULL )
                                    rc = self->on_exit_ref_pos( rwd );
                            }
                            rc = Quitting();
                        }
                    }
                }
            }
        }

        /* free cur_id_vector */

        ReferenceIteratorRelease ( ref_iter );
    }
    return rc;
}
示例#3
0
rc_t walk_0( walk_data * data, walk_funcs * funcs )
{
    rc_t rc;

    data->ref_start = 0;
    data->ref_len = 0;
    data->ref_name = NULL;
    data->ref_obj = NULL;
    data->ref_window_start = 0;
    data->ref_window_len = 0;
    data->ref_pos = 0;
    data->depth = 0;
    data->ref_base = 0;
    data->spotgroup = NULL;
    data->spotgroup_len = 0;
    data->rec = NULL;
    data->xrec = NULL;
    data->state = 0;
    data->seq_pos = 0;

    do
    {
        rc = ReferenceIteratorNextReference( data->ref_iter, &data->ref_start, &data->ref_len, &data->ref_obj );
        if ( GetRCState( rc ) != rcDone )
        {
            if ( rc != 0 )
            {
                LOGERR( klogInt, rc, "ReferenceIteratorNextReference() failed" );
            }
            else if ( data->ref_obj != NULL )
            {
                if ( data->options->use_seq_name )
                    rc = ReferenceObj_Name( data->ref_obj, &data->ref_name );
                else
                    rc = ReferenceObj_SeqId( data->ref_obj, &data->ref_name );

                if ( data->options->skiplist != NULL )
                    skiplist_enter_ref( data->options->skiplist, data->ref_name );

                if ( rc != 0 )
                {
                    if ( data->options->use_seq_name )
                    {
                        LOGERR( klogInt, rc, "ReferenceObj_Name() failed" );
                    }
                    else
                    {
                        LOGERR( klogInt, rc, "ReferenceObj_SeqId() failed" );
                    }
                }
                else
                {
					rc = ReferenceObj_SeqLength( data->ref_obj, &data->ref_len );
					if ( rc != 0 )
                    {
                        LOGERR( klogInt, rc, "ReferenceObj_SeqLength() failed" );
                    }
					else
					{
						if ( funcs->on_enter_ref != NULL )
							rc = funcs->on_enter_ref( data );
						if ( rc == 0 )
							rc = walk_ref_window( data, funcs );
						if ( rc == 0 && funcs->on_exit_ref != NULL )
							rc = funcs->on_exit_ref( data );
					}
                }
            }
        }
    } while ( rc == 0 );
    if ( GetRCState( rc ) == rcDone ) { rc = 0; }
    if ( GetRCState( rc ) == rcCanceled ) { rc = 0; }
    return rc;
}