rc_t make_trans_ctx( trans_ctx * ctx, trans_opt * opt, bool open_reference ) { rc_t rc = AlignMgrMakeRead ( &ctx->almgr ); if ( rc != 0 ) LOGERR( klogInt, rc, "AlignMgrMake() failed" ); if ( rc == 0 ) { rc = KDirectoryNativeDir( &ctx->dir ); if ( rc != 0 ) LOGERR( klogInt, rc, "KDirectoryNativeDir() failed" ); } if ( rc == 0 ) { rc = VDBManagerMakeRead ( &ctx->vdb_mgr, ctx->dir ); if ( rc != 0 ) LOGERR( klogInt, rc, "VDBManagerMakeRead() failed" ); } if ( rc == 0 ) { if ( opt->fname != NULL ) { rc = VDBManagerOpenDBRead ( ctx->vdb_mgr, &ctx->db, NULL, "%s", opt->fname ); if ( rc != 0 ) LOGERR( klogInt, rc, "VDBManagerOpenDBRead() failed" ); } else rc = RC ( rcApp, rcArgv, rcAccessing, rcParam, rcNull ); } if ( rc == 0 ) { rc = ReferenceList_MakeDatabase( &ctx->ref_list, ctx->db, ereferencelist_4na | ereferencelist_usePrimaryIds, 0, NULL, 0 ); if ( rc != 0 ) LOGERR( klogInt, rc, "ReferenceList_MakeDatabase() failed" ); } if ( rc == 0 && open_reference ) { OUTMSG(( "looking for reference '%s'\n", opt->ref_name )); rc = ReferenceList_Find( ctx->ref_list, &ctx->ref_obj, opt->ref_name, string_size( opt->ref_name ) ); if ( rc != 0 ) LOGERR( klogInt, rc, "ReferenceList_Find() failed" ); } return rc; }
static rc_t CC prepare_region_cb( const char * name, uint32_t start, uint32_t end, void * data ) { prepare_ctx * ctx = ( prepare_ctx * )data; rc_t rc = ReferenceList_Find( ctx->reflist, &ctx->refobj, name, string_size( name ) ); if ( rc != 0 ) { LOGERR( klogInt, rc, "ReferenceList_Find() failed" ); } else { rc = ctx->on_section( ctx, start, end ); if ( rc == 0 ) ReferenceObj_Release( ctx->refobj ); } return rc; }
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; }