// converts the supplied read from basespace to pseudo-colorspace
void CColorspaceUtilities::ConvertReadBasespaceToPseudoColorspace(CMosaikString& s) {

    char* pPrev   = s.Data();
    char* pString = pPrev + 1;

    // simplify various ambiguity codes
    *pPrev = GetSimplifiedBase(*pPrev);

    CS_MAP_t::const_iterator csIter;
    for(unsigned int i = 1; i < s.Length(); ++i, ++pString, ++pPrev) {

        // simplify various ambiguity codes
        *pString = GetSimplifiedBase(*pString);

        csIter = mCSMap.find(PACK_SHORT(*pPrev, *pString));
        if(csIter == mCSMap.end()) {
            printf("ERROR: Unknown combination found when converting to colorspace: [%c] & [%c]\n", *pPrev, *pString);
            exit(1);
        }

        *pPrev = csIter->second;
    }

    // adjust the read
    s.TrimEnd(1);
}
// convert cs sequence to bs sequence
// a '-' converter would produce a '-'
void CColorspaceUtilities::ConvertCs2Bs (const char* csSequence, char* bsSequence, const unsigned int start, const unsigned int end, const char startBase) {

    char lastQueryBase = startBase;
    //bsSequence[ start ] = startBase;

    BS_MAP_t::const_iterator bsIter;
    // Note: the bs sequence has one more char than cd sequence
    for ( unsigned int i = start; i < end + 1; i++ ) {
        if ( csSequence[i] != '-' ) {
            bsIter = mBSMap.find(PACK_SHORT(lastQueryBase, csSequence[i]));
            if(bsIter == mBSMap.end()) {
                printf("ERROR: Unknown combination found when converting to basespace: [%c] & [%c]\n", lastQueryBase, csSequence[i]);
                exit(1);
            }
            bsSequence[ i + 1 ] = bsIter->second;
            lastQueryBase   = bsIter->second;
        }
        else
            bsSequence[ i + 1 ] = '-';
    }
}
// converts a colorspace sequence with provided seed base into basespace
void CColorspaceUtilities::ConvertColorspaceToBasespace(char seed, const string& colorspaceSeq, string& basespaceSeq) {

    // make the basespace sequence just as long as the colorspace sequence
    const unsigned short csLen = colorspaceSeq.size();
    basespaceSeq.resize(csLen);

    // create traversal pointers to our strings
    const char* pCS = colorspaceSeq.data();
    char* pBS       = (char*)basespaceSeq.data();

    // convert each colorspace/seed combo into a basespace nucleotide
    BS_MAP_t::const_iterator bsIter;
    for(unsigned int i = 0; i < csLen; ++i, ++pCS, ++pBS) {

        // find the appropriate seed/colorspace transition combination
        bsIter = mBSMap.find(PACK_SHORT(seed, *pCS));
        if(bsIter == mBSMap.end()) {
            printf("ERROR: Unknown combination found when converting to basespace: [%c] & [%c]\n", seed, *pCS);
            exit(1);
        }

        seed = *pBS = bsIter->second;
    }
}
Exemple #4
0
STATIC int
_send_echo_pkt(int client_id,
               uint8 *payload,
               int payload_len,
               int depth,
               uint32 pkt_flags,
               int mode,
               int verbose,
               cpudb_key_t dest_key,
               void *cookie)
{
    int payload_offset = 0;
    uint32 ct_flags = 0;
    atp_tx_cb_f cb = NULL;
    int crc_payload_len;
    int rv;

    if (verbose) {
        cli_out("echo pkt: %d bytes to " CPUDB_KEY_FMT_EOLN, payload_len,
                CPUDB_KEY_DISP(dest_key));
    }
    PACK_SHORT(payload, depth);
    PACK_LONG(&payload[sizeof(uint16)], pkt_flags);

    /* There are potentially two CRCs involved here: one is the CRC
       that protects the ECHO protocol payload, which is always
       present. The other is the Ethernet FCS, which is calculated by
       the Ethernet transmitter, space for which is only allocated if
       CTE_FLAGS_CRC_REGEN is set. */
    crc_payload_len = payload_len - sizeof(uint32);
    if (pkt_flags & CTE_FLAGS_CRC_REGEN) {
        crc_payload_len -= sizeof(uint32);
    }

    PACK_LONG(payload+crc_payload_len,
              ~_shr_crc32(~0, payload, crc_payload_len));
    
    if (mode == CTE_MODE_BET_BCAST) {
        ct_flags = CPUTRANS_BCAST;
    }

    if (pkt_flags & CTE_FLAGS_ALLOC_HDR_HERE) {
        payload_offset = CPUTRANS_HEADER_BYTES;
        ct_flags |= CPUTRANS_NO_HEADER_ALLOC;
    }

    if (pkt_flags & CTE_FLAGS_CRC_REGEN) {
        ct_flags |= CPUTRANS_CRC_REGEN;
    }

    if (pkt_flags & CTE_FLAGS_ASYNC_FREE) {
        cb = _send_echo_pkt_cb;
    }

    rv = atp_tx(dest_key,
                    client_id,
                    payload - payload_offset,
                    payload_len + payload_offset,
                    ct_flags,
                    cb,
                    cookie);

    return rv;
}
Exemple #5
0
bcm_pkt_t *
cputrans_tx_pkt_list_alloc(uint8 *pkt_buf, int len, int seg_len,
                           uint32 ct_flags, int *num_segs)
{
    bcm_pkt_t *first_pkt;
    bcm_pkt_t *pkt;
    int extra_pkt_count;
    int offset;
    int i;
    int pkt_blk = 0;
    int len_fld_val = 0x601;  /* What goes in the pkt's length fld */
    int cos = -1;

    if (!_tx_setup_done) {
        return NULL;
    }

    extra_pkt_count = (len - 1) / seg_len;   /* Packets needed beyond first */

    if (ct_flags & CPUTRANS_COS_OVERRIDE) {
        cos = CPUTRANS_COS_GET(ct_flags);
    }

    /* Will return NULL if error */
    first_pkt = grab_packets(extra_pkt_count, cos, ct_flags);
    if (first_pkt == NULL) {
        return NULL;
    }

    if (num_segs != NULL) {
        *num_segs = extra_pkt_count + 1;
    }

    offset = seg_len;   /* Where second packet starts in payload */
    if (ct_flags & CPUTRANS_NO_HEADER_ALLOC) {
        /* Save header buffer in data 1 */
        sal_memcpy(&first_pkt->pkt_data[1], &first_pkt->pkt_data[0],
                   sizeof(bcm_pkt_blk_t));
        pkt_blk = 0;
        first_pkt->blk_count = 1;
        offset += CPUTRANS_HEADER_BYTES;
    } else {  /* Header in first block */
        pkt_blk = 1;
        first_pkt->blk_count = 2;
    }

    /* Put data pointers in proper place. */
    first_pkt->pkt_data[pkt_blk].data = pkt_buf;
    first_pkt->call_back = NULL;
    if (offset >= len) {  /* Only one segment needed */
        first_pkt->pkt_data[pkt_blk].len = len;
        PACK_SHORT(&first_pkt->pkt_data[0].data[CPUTRANS_LEN_OFS],
                   len_fld_val);
    } else {              /* Extra packets */
        first_pkt->pkt_data[pkt_blk].len = offset;
        PACK_SHORT(&first_pkt->pkt_data[0].data[CPUTRANS_LEN_OFS],
                   len_fld_val);
        /* Segment the rest of the packet */
        pkt = first_pkt->next;
        for (i = 0; i < extra_pkt_count - 1; i++) { /* Not first or last */
            pkt->pkt_data[1].data = &pkt_buf[offset];
            pkt->pkt_data[1].len = seg_len;
            PACK_SHORT(&first_pkt->pkt_data[0].data[CPUTRANS_LEN_OFS],
                       len_fld_val);
            pkt->blk_count = 2;
            offset += seg_len;
            pkt = pkt->next;
            pkt->call_back = NULL;
        }

        /* Take care of last pkt (pointed to by pkt) */
        pkt->pkt_data[1].data = &pkt_buf[offset];
        pkt->pkt_data[1].len = len - offset;
        PACK_SHORT(&first_pkt->pkt_data[0].data[CPUTRANS_LEN_OFS],
                   len_fld_val);
        pkt->blk_count = 2;
        pkt->call_back = NULL;
    }
    first_pkt->alloc_ptr = pkt_buf;
    if (first_pkt->next == first_pkt) {
        LOG_INFO(BSL_LS_TKS_CTPKT,
                 (BSL_META("CT pkt list alloc: Internal corruption in pointers\n")));
        CPUTRANS_ERROR_INCR;
    }

    return first_pkt;
}
// adds the basespace to pseudo-colorspace conversions
void CColorspaceUtilities::InitializeColorspaceMap(void) {

    // modified by Lee on 1/19/2009

    mCSMap[PACK_SHORT('A','A')] = 'A';
    mCSMap[PACK_SHORT('A','C')] = 'C';
    mCSMap[PACK_SHORT('A','G')] = 'G';
    mCSMap[PACK_SHORT('A','T')] = 'T';
    mCSMap[PACK_SHORT('A','N')] = 'E';
    //mCSMap[PACK_SHORT('A','-')] = 'M';

    mCSMap[PACK_SHORT('C','A')] = 'C';
    mCSMap[PACK_SHORT('C','C')] = 'A';
    mCSMap[PACK_SHORT('C','G')] = 'T';
    mCSMap[PACK_SHORT('C','T')] = 'G';
    mCSMap[PACK_SHORT('C','N')] = 'F';
    //mCSMap[PACK_SHORT('C','-')] = 'U';

    mCSMap[PACK_SHORT('G','A')] = 'G';
    mCSMap[PACK_SHORT('G','C')] = 'T';
    mCSMap[PACK_SHORT('G','G')] = 'A';
    mCSMap[PACK_SHORT('G','T')] = 'C';
    mCSMap[PACK_SHORT('G','N')] = 'I';
    //mCSMap[PACK_SHORT('G','-')] = 'D';

    mCSMap[PACK_SHORT('T','A')] = 'T';
    mCSMap[PACK_SHORT('T','C')] = 'G';
    mCSMap[PACK_SHORT('T','G')] = 'C';
    mCSMap[PACK_SHORT('T','T')] = 'A';
    mCSMap[PACK_SHORT('T','N')] = 'L';
    //mCSMap[PACK_SHORT('T','-')] = 'B';

    //mCSMap[PACK_SHORT('-','A')] = 'M';
    //mCSMap[PACK_SHORT('-','C')] = 'U';
    //mCSMap[PACK_SHORT('-','G')] = 'D';
    //mCSMap[PACK_SHORT('-','T')] = 'B';
    //mCSMap[PACK_SHORT('-','N')] = 'R';
    //mCSMap[PACK_SHORT('-','-')] = 'K';

    mCSMap[PACK_SHORT('N','A')] = 'E';
    mCSMap[PACK_SHORT('N','C')] = 'F';
    mCSMap[PACK_SHORT('N','G')] = 'I';
    mCSMap[PACK_SHORT('N','T')] = 'L';
    mCSMap[PACK_SHORT('N','N')] = 'O';
    //mCSMap[PACK_SHORT('N','X')] = 'R';
}
// adds the pseudo-colorspace to basespace conversions
void CColorspaceUtilities::InitializeBasespaceMap(void) {

    // modified by Lee on 1/19/2009

    mBSMap[PACK_SHORT('A','A')] = 'A';
    mBSMap[PACK_SHORT('A','C')] = 'C';
    mBSMap[PACK_SHORT('A','G')] = 'G';
    mBSMap[PACK_SHORT('A','T')] = 'T';
    mBSMap[PACK_SHORT('A','E')] = 'N';
    //mBSMap[PACK_SHORT('A','M')] = '-';

    mBSMap[PACK_SHORT('C','A')] = 'C';
    mBSMap[PACK_SHORT('C','C')] = 'A';
    mBSMap[PACK_SHORT('C','G')] = 'T';
    mBSMap[PACK_SHORT('C','T')] = 'G';
    mBSMap[PACK_SHORT('C','F')] = 'N';
    //mBSMap[PACK_SHORT('C','U')] = '-';

    mBSMap[PACK_SHORT('G','A')] = 'G';
    mBSMap[PACK_SHORT('G','C')] = 'T';
    mBSMap[PACK_SHORT('G','G')] = 'A';
    mBSMap[PACK_SHORT('G','T')] = 'C';
    mBSMap[PACK_SHORT('G','I')] = 'N';
    //mBSMap[PACK_SHORT('G','D')] = '-';

    mBSMap[PACK_SHORT('T','A')] = 'T';
    mBSMap[PACK_SHORT('T','C')] = 'G';
    mBSMap[PACK_SHORT('T','G')] = 'C';
    mBSMap[PACK_SHORT('T','T')] = 'A';
    mBSMap[PACK_SHORT('T','L')] = 'N';
    //mBSMap[PACK_SHORT('T','B')] = '-';

    //mBSMap[PACK_SHORT('-','M')] = 'A';
    //mBSMap[PACK_SHORT('-','U')] = 'C';
    //mBSMap[PACK_SHORT('-','D')] = 'G';
    //mBSMap[PACK_SHORT('-','B')] = 'T';
    //mBSMap[PACK_SHORT('-','R')] = 'N';
    //mBSMap[PACK_SHORT('-','K')] = '-';

    mBSMap[PACK_SHORT('N','E')] = 'A';
    mBSMap[PACK_SHORT('N','F')] = 'C';
    mBSMap[PACK_SHORT('N','I')] = 'G';
    mBSMap[PACK_SHORT('N','L')] = 'T';
    mBSMap[PACK_SHORT('N','O')] = 'N';
    //mBSMap[PACK_SHORT('N','R')] = '-';
}