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; }
static void readFromBuffer(Chain* chain, char* fileBuffer, SWPrefs* swPrefs) { Matcher* matcher = swPrefsGetMatcher(swPrefs); int shotgun = swPrefsShotgun(swPrefs); int fileLength = strlen(fileBuffer); // Maximum chain length is equal to input file length. chain->items = (ChainItem*) malloc(sizeof(ChainItem) * fileLength); chain->codes = (ChainCode*) malloc(sizeof(ChainCode) * fileLength); chain->length = 0; int fileCharIdx; int isSpace; // boolean ChainItem chainItem; ChainItem chainCode; int fillItems = (matcherGetType(matcher) == MATCHER_MATCH_MISMATCH); int start = 0; while (fileBuffer[start] != '\n') start++; chain->name = malloc((start + 1) * sizeof(char)); chain->name = strncpy(chain->name, fileBuffer, start); chain->name[start] = '\0'; // Read all items into the item array. Use matcher object to get the item // codes and write them to code array. for (fileCharIdx = start; fileCharIdx < fileLength; ++fileCharIdx) { isSpace = isspace(fileBuffer[fileCharIdx]); if (isSpace) { continue; } chainItem = (ChainItem) toupper(fileBuffer[fileCharIdx]); chain->items[chain->length] = chainItem; if (fillItems) matcherAddItem(matcher, chainItem); chainCode = (ChainCode) matcherGetCode(matcher, chainItem, shotgun); chain->codes[chain->length] = chainCode; if (chain->codes[chain->length] == MATCHER_CODE_NOT_FOUND) { printf("Item not in matching table %c.\n", chainItem); exit(-1); } chain->length++; } if (!TEST_MODE) { printf("%.55s... length:%14d\n", chain->name, chain->length); } }
extern SWData* swSolveGPU(Chain* rowChain, Chain* columnChain, SWPrefs* swPrefs) { int matcherType = matcherGetType(swPrefsGetMatcher(swPrefs)); if (matcherType == MATCHER_MATRIX) { return swSolveGPUSM(rowChain, columnChain, swPrefs); } else { return swSolveGPUMM(rowChain, columnChain, swPrefs); } }
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; }