Exemplo n.º 1
0
Arquivo: chain.c Projeto: 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;
}
Exemplo 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;
}
Exemplo n.º 3
0
extern Chain* chainCreateReverse(Chain* chain) {

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

    reverse->subchain = 1;
    reverse->length = chain->length;

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

    if (chain->reverseCodes == NULL) {
        addReversedChain(chain);
    }

    reverse->codes = chain->reverseCodes;
    reverse->items = chain->reverseItems;
    reverse->reverseCodes = chain->codes;
    reverse->reverseItems = chain->items;

    return reverse;
}