Example #1
0
static
rc_t SRFAbsolidLoaderFmt_Whack(SRFAbsolidLoaderFmt* self, SRATable** table)
{
    SRAWriteAbsolid_Whack(self->fe.writer, table);
    free(self);
    return 0;
}
Example #2
0
rc_t SRAWriteAbsolid_Make(const SRAWriteAbsolid** cself, const SRALoaderConfig* config)
{
    rc_t rc = 0;
    SRAWriteAbsolid* self;
    const PlatformXML* platform;
    const ReadSpecXML_read* read;
    uint32_t sequence_length;
    uint8_t nreads;

    if( cself == NULL || config == NULL ) {
        return RC(rcSRA, rcFormatter, rcConstructing, rcParam, rcNull);
    }
    if( (rc = Experiment_GetPlatform(config->experiment, &platform)) != 0 ||
        (rc = Experiment_GetSpotLength(config->experiment, &sequence_length)) != 0 ||
        (rc = Experiment_GetReadNumber(config->experiment, &nreads)) != 0 ) {
        return rc;
    }
    if( platform->id != SRA_PLATFORM_ABSOLID ) {
        rc = RC(rcSRA, rcFormatter, rcParsing, rcData, rcInvalid);
        LOGERR(klogErr, rc, "platform type");
        return rc;
    }
    if( nreads > ABSOLID_FMT_MAX_NUM_READS ) {
        rc = RC(rcSRA, rcFormatter, rcConstructing, rcData, rcUnsupported);
        PLOGERR(klogErr, (klogErr, rc, "expected up to $(max) reads", "max=%u", ABSOLID_FMT_MAX_NUM_READS));
        return rc;
    }
    self = calloc(1, sizeof(*self));
    if( self == NULL ) {
        rc = RC(rcSRA, rcFormatter, rcConstructing, rcMemory, rcExhausted);
        return rc;
    }
    if( (rc = SRAWriter_Make(&self->base, config)) != 0 ) {
        LOGERR(klogInt, rc, "failed to initialize base writer");
    } else if( (rc = Experiment_GetRead(config->experiment, 0, &read)) != 0 ) {
        LOGERR(klogInt, rc, "failed to get read 1 descriptor");
    } else if( read->coord_type != rdsp_RelativeOrder_ct && read->coord_type != rdsp_BaseCoord_ct ) {
        rc = RC(rcSRA, rcFormatter, rcConstructing, rcData, rcInvalid);
        LOGERR(klogErr, rc, "1st read can be BASE_COORD or RELATIVE_ORDER only");
    } else if( read->read_type != rdsp_Forward_rt && read->read_type != rdsp_Reverse_rt ) {
        LOGMSG(klogWarn, "expected 1st read to be of type 'Forward' or 'Reverse'");
    }
    self->read_seg[0].start = 0;
    self->read_seg[0].len = sequence_length;

    if( rc == 0 && nreads >= ABSOLID_FMT_MAX_NUM_READS ) {
        if( nreads > ABSOLID_FMT_MAX_NUM_READS ) {
            rc = RC(rcSRA, rcFormatter, rcConstructing, rcData, rcUnsupported);
            LOGERR(klogErr, rc, "more than 2 reads");
        } else if( (rc = Experiment_GetRead(config->experiment, 1, &read)) != 0 ) {
            LOGERR(klogErr, rc, "failed to get read 2 descriptor");
        } else if( read->coord_type != rdsp_BaseCoord_ct ) {
            rc = RC(rcSRA, rcFormatter, rcConstructing, rcData, rcInvalid);
            LOGERR(klogErr, rc, "2nd read can be BASE_COORD only");
        } else if( read->read_type != rdsp_Forward_rt && read->read_type != rdsp_Reverse_rt ) {
            LOGMSG(klogWarn, "expected 2ndt read to be of type 'Forward' or 'Reverse'");
        }
		if( rc == 0 ) {
			self->read_seg[1].start = read->coord.start_coord - 1;
			self->read_seg[1].len = sequence_length - self->read_seg[1].start;
			self->read_seg[0].len = self->read_seg[1].start;
		}
    }
#if _DEBUGGING
    DEBUG_MSG(3, ("%s READ_SEG[%hu,%hu]\n", __func__, self->read_seg[0].start, self->read_seg[0].len));
    if( nreads > 1 ) {
        DEBUG_MSG(3, ("%s READ_SEG[%hu,%hu]\n", __func__, self->read_seg[1].start, self->read_seg[1].len));
    }
#endif
    if( rc == 0 ) {
        self->platform = platform;
        self->nreads = nreads;
        *cself = self;
    } else {
        SRAWriteAbsolid_Whack(self, NULL);
    }
    return rc;
}