Esempio n. 1
0
File: chain.c Progetto: Zuza/swSharp
extern Chain* chainCreateComplement(Chain* chain, SWPrefs* swPrefs) {

    Chain* complement = (Chain*) malloc(sizeof(struct Chain));

    complement->subchain = 0;
    complement->length = chain->length;

    int nameLen = strlen(chain->name) + strlen(COMPLEMENT_LABEL) + 1;
    complement->name = (char*) malloc(nameLen * sizeof(char));
    sprintf(complement->name, "%s%s", COMPLEMENT_LABEL, chain->name);

    complement->codes = (ChainCode*) malloc(complement->length * sizeof(ChainCode));
    complement->items = (ChainItem*) malloc(complement->length * sizeof(ChainItem));

    int normal;
    int reverse;
    ChainItem item;
    ChainItem newItem;

    Matcher* matcher = swPrefsGetMatcher(swPrefs);

    for (
        normal = 0, reverse = chain->length - 1; 
        normal < chain->length; 
        ++normal, --reverse
    ) {

        item = chain->items[reverse];
        
        switch (item) {
        case 'A':
            newItem = 'T';
            break;
        case 'C':
            newItem = 'G';
            break;
        case 'T':
            newItem = 'A';
            break;
        case 'G':
            newItem = 'C';
            break;
        default:
            newItem = item;
        }

        complement->items[normal] = newItem;
        complement->codes[normal] = matcherGetCode(matcher, newItem, 
            swPrefsShotgun(swPrefs));
    }

    if (swPrefsSolveOnly(swPrefs)) {
        complement->reverseCodes = NULL;
        complement->reverseItems = NULL;
    } else {
        addReversedChain(complement);
    }

    return complement;
}
Esempio n. 2
0
extern Chain* chainCreateFromBuffer(char* fileBuffer, SWPrefs* swPrefs) {

    Chain* chain = (Chain*) malloc(sizeof(struct Chain));
    chain->subchain = 0;

    readFromBuffer(chain, fileBuffer, swPrefsGetMatcher(swPrefs));

    if (swPrefsSolveOnly(swPrefs)) {
        chain->reverseCodes = NULL;
        chain->reverseItems = NULL;
    } else {
        addReversedChain(chain);
    }

    return chain;
}