Exemple #1
0
static rc_t print_edge( struct rna_splice_log * sl,
                        INSDC_coord_zero pos,
                        bool const reverse_complement,
                        bool const add_newline )
{
    rc_t rc;
    INSDC_coord_len from_ref_obj, to_read;
    uint8_t buffer[ EDGE_LEN + 1 ];
    INSDC_coord_zero rd_pos = 0;
    uint32_t pre_len = PRE_POST_LEN;
    uint32_t post_len = PRE_POST_LEN;

    if ( pos >= PRE_POST_LEN )
        rd_pos = ( pos - PRE_POST_LEN ); /* in the rare case the delete is at the very beginning of the alignment */
    else
        pre_len = pos; /* rd_pos is still 0, what we want*/

    to_read = pre_len + post_len + 2;
    rc = ReferenceObj_Read( sl->ref_obj, rd_pos, to_read, buffer, &from_ref_obj );
    if ( rc == 0 )
    {
        uint8_t complement[ EDGE_LEN + 1 ];
        uint8_t to_write[ EDGE_LEN + 5 ];
        uint8_t * ref_bytes = buffer;

        if ( from_ref_obj < to_read )
            post_len -= ( to_read - from_ref_obj );

        if ( reverse_complement )
        {
            copy_read_and_reverse_complement( complement, buffer, from_ref_obj );
            ref_bytes = complement;
        }
        memmove( to_write, ref_bytes, pre_len );
        to_write[ pre_len ] = '\t';
        to_write[ pre_len + 1 ] = ref_bytes[ pre_len ];
        to_write[ pre_len + 2 ] = ref_bytes[ pre_len + 1 ];
        to_write[ pre_len + 3 ] = '\t';
        memmove( &( to_write[ pre_len + 4 ] ), &( ref_bytes[ pre_len + 2 ] ), post_len );

        if ( add_newline )
            to_write[ pre_len + post_len + 4 ] = '\n';
        else
            to_write[ pre_len + post_len + 4 ] = '\t';

        rc = write_to_file( sl, to_write, pre_len + post_len + 5 );
    }
    return rc;
}
LIB_EXPORT rc_t CC ReferenceIteratorPosition ( const ReferenceIterator *self,
    INSDC_coord_zero *pos, uint32_t * depth, INSDC_4na_bin * base )
{
    rc_t rc = 0;
    if ( self == NULL )
        rc = RC( rcAlign, rcIterator, rcAccessing, rcSelf, rcNull );
    else
    {
        /* return position, many records our record-list, and the base at this position */
        if ( pos != NULL )
        {
            *pos = self->current_pos;
        }

        if ( depth != NULL )
        {
            *depth = self->depth;
        }

        if ( base != NULL )
        {
            uint32_t written;
            *base = 0;
            /* problem! how to get the base if depth == 0 */
            if ( self->current_rec != NULL )
            {
                rc = ReferenceObj_Read( self->current_rec->ref, self->current_pos, 1, base, &written );
            }
            else if ( self->refobj != NULL )
            {
                rc = ReferenceObj_Read( self->refobj, self->current_pos, 1, base, &written );
            }
        }
    }
    return rc;
}
LIB_EXPORT uint32_t CC ReferenceIteratorBasesDeleted ( const ReferenceIterator *self,
    INSDC_coord_zero *pos, const INSDC_4na_bin **bases )
{
    uint32_t res = align_iter_invalid;
    if ( bases != NULL )
    {
        *bases = NULL;
    }
    if ( self != NULL )
    {
        /* PlacementRecordCast returns NULL if self->current_rec is NULL */
        AlignmentIterator * al_iter = PlacementRecordCast ( self->current_rec, placementRecordExtension0 );
        if ( al_iter != NULL )
        {
            INSDC_coord_zero temp_pos;
            res = AlignmentIteratorBasesDeleted( al_iter, &temp_pos );
            if ( ( res & align_iter_invalid ) != align_iter_invalid )
            {
                if ( pos != NULL ) { *pos = temp_pos; }
                /* where to get the reference-bases from ? PlacementRecord.ref ! */
                if ( res > 0 && bases != NULL )
                {
                    uint8_t * buffer = malloc( res );
                    if ( buffer != NULL )
                    {
                        INSDC_coord_len written;
                        rc_t rc = ReferenceObj_Read( self->current_rec->ref, temp_pos, res, buffer, &written );
                        if ( rc == 0 )
                        {
                            *bases = buffer;
                        }
                    }
                }
            }
        }
    }
    return res;
}