Skip to content

Commit

Permalink
update formatting to split else clause onto next line after brace
Browse files Browse the repository at this point in the history
  • Loading branch information
Sawwave committed Dec 18, 2021
1 parent 83fdf98 commit 308541b
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 45 deletions.
10 changes: 6 additions & 4 deletions src/AwFmFile.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@ enum AwFmReturnCode awFmReadIndexFromFile(
fclose(fileHandle);
awFmDeallocIndex(indexData);
return AwFmAllocationFailure;
} else {
}
else {
elementsRead = fread(indexData->suffixArray.values, 1, compressedSuffixArrayByteLength, fileHandle);
if(elementsRead != compressedSuffixArrayByteLength) {
fclose(fileHandle);
Expand Down Expand Up @@ -408,8 +409,8 @@ enum AwFmReturnCode awFmReadSequenceFromFile(const struct AwFmIndex *restrict co
// null terminate the string
sequenceBuffer[sequenceSegmentLength] = 0;
return AwFmFileReadOkay;

} else {
}
else {

return AwFmUnsupportedVersionError;
}
Expand Down Expand Up @@ -467,7 +468,8 @@ size_t awFmGetSequenceFileOffset(const struct AwFmIndex *restrict const index) {
size_t awFmGetSuffixArrayFileOffset(const struct AwFmIndex *restrict const index) {
if(index->config.storeOriginalSequence) {
return awFmGetSequenceFileOffset(index) + ((index->bwtLength - 1) * sizeof(char));
} else {
}
else {
return awFmGetSequenceFileOffset(index);
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/AwFmKmerTable.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ static inline struct AwFmSearchRange awFmNucleotidePartialKmerSeedRangeFromTable
if(__builtin_expect((kmer[kmerLength - 1] | 0x20) == 't', 0)) {
// lookup kmer from scratch
awFmNucleotideNonSeededSearch(index, kmer, kmerLength, &range);
} else {
}
else {

const uint64_t endSequenceKmerTableIndex = 0; // index->endSequenceKmerTableIndex;
const uint8_t kmerLengthInSeedTable = index->config.kmerLengthInSeedTable;
Expand Down Expand Up @@ -141,7 +142,8 @@ inline struct AwFmSearchRange awFmAminoPartialKmerSeedRangeFromTable(
if(__builtin_expect((kmer[kmerLength - 1] | 0x20) == 'y', 0)) {
// lookup kmer from scratch
awFmAminoNonSeededSearch(index, kmer, kmerLength, &range);
} else {
}
else {

const uint64_t endSequenceKmerTableIndex = 0; // index->endSequenceKmerTableIndex;
const uint8_t kmerLengthInSeedTable = index->config.kmerLengthInSeedTable;
Expand Down
6 changes: 4 additions & 2 deletions src/AwFmLetter.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ uint8_t awFmNucleotideCompressedVectorToLetterIndex(const uint8_t compressedVect
uint8_t awFmAsciiAminoAcidToLetterIndex(const uint8_t asciiLetter) {
if(__builtin_expect(asciiLetter == '$', 0)) {
return 21;
} else {
}
else {
static const uint8_t letterEncodings[32] = {20, 0, 20, 1, 2, 3, 4, 5, 6, 7, 20, 8, 9, 10, 11, 20, 12, 13, 14, 15,
16, 20, 17, 18, 20, 19, 20, 20, 20, 20, 20, 20};
// find the index and mod (to prevent array out of bounds for weird ascii inputs)
Expand All @@ -63,7 +64,8 @@ uint8_t awFmAsciiAminoLetterSanitize(const uint8_t asciiLetter) {

if(__builtin_expect(letterIsAmbiguityChar, 0)) {
return 'z';
} else {
}
else {
return asciiLetter;
}
}
Expand Down
25 changes: 16 additions & 9 deletions src/AwFmParallelSearch.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ void awFmParallelSearchLocate(const struct AwFmIndex *restrict const index,
parallelSearchExtendKmersInBlock(index, searchList, ranges, threadBlockStartIndex, threadBlockEndIndex);
parallelSearchTracebackPositionLists(index, searchList, ranges, threadBlockStartIndex, threadBlockEndIndex);
}
} else {
}
else {
// exact duplicate of above code, without the omp pragma, so it doesn't kill performance with only 1 thread.
for(size_t threadBlockStartIndex = 0; threadBlockStartIndex < searchListCount;
threadBlockStartIndex += AW_FM_NUM_CONCURRENT_QUERIES) {
Expand Down Expand Up @@ -147,7 +148,8 @@ void awFmParallelSearchCount(const struct AwFmIndex *restrict const index,
searchList->kmerSearchData[i].count = awFmSearchRangeLength(&ranges[i - threadBlockStartIndex]);
}
}
} else {
}
else {
// exact duplicate of above code, without the omp pragma, so it doesn't kill performance with only 1 thread.
for(size_t threadBlockStartIndex = 0; threadBlockStartIndex < searchListCount;
threadBlockStartIndex += AW_FM_NUM_CONCURRENT_QUERIES) {
Expand Down Expand Up @@ -183,14 +185,16 @@ void parallelSearchFindKmerSeedsForBlock(const struct AwFmIndex *restrict const
// TODO: reimplement partial seeded search when it's implementable
if(kmerLength < index->config.kmerLengthInSeedTable) {
awFmNucleotideNonSeededSearch(index, kmerString, kmerLength, &ranges[rangesIndex]);
} else {
}
else {
ranges[rangesIndex] = awFmNucleotideKmerSeedRangeFromTable(index, kmerString, kmerLength);
}
} else {
}
else {
if(kmerLength < index->config.kmerLengthInSeedTable) {
awFmAminoNonSeededSearch(index, kmerString, kmerLength, &ranges[rangesIndex]);

} else {
}
else {
ranges[rangesIndex] = awFmAminoKmerSeedRangeFromTable(index, kmerString, kmerLength);
}
}
Expand Down Expand Up @@ -221,7 +225,8 @@ void parallelSearchExtendKmersInBlock(const struct AwFmIndex *restrict const ind
if(index->config.alphabetType == AwFmAlphabetNucleotide) {
const uint8_t queryLetterIndex = awFmAsciiNucleotideToLetterIndex(kmerString[currentQueryLetterIndex]);
awFmNucleotideIterativeStepBackwardSearch(index, &ranges[rangesIndex], queryLetterIndex);
} else {
}
else {
const uint8_t queryLetterIndex = awFmAsciiAminoAcidToLetterIndex(kmerString[currentQueryLetterIndex]);
awFmAminoIterativeStepBackwardSearch(index, &ranges[rangesIndex], queryLetterIndex);
}
Expand Down Expand Up @@ -256,7 +261,8 @@ void parallelSearchTracebackPositionLists(const struct AwFmIndex *restrict const
backtrace.position = awFmNucleotideBacktraceBwtPosition(index, backtrace.position);
backtrace.offset++;
}
} else {
}
else {
while(!awFmBwtPositionIsSampled(index, backtrace.position)) {
backtrace.position = awFmAminoBacktraceBwtPosition(index, backtrace.position);
backtrace.offset++;
Expand All @@ -273,7 +279,8 @@ void parallelSearchTracebackPositionLists(const struct AwFmIndex *restrict const
bool setPositionListCount(struct AwFmKmerSearchData *restrict const searchData, uint32_t newCount) {
if(__builtin_expect(searchData->capacity >= newCount, 1)) {
searchData->count = newCount;
} else {
}
else {
const size_t newCapacity = newCount;
const size_t newLengthInBytes = newCapacity * sizeof(uint64_t);
void *tmpPtr = realloc(searchData->positionList, newLengthInBytes);
Expand Down
18 changes: 12 additions & 6 deletions src/AwFmSearch.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ struct AwFmSearchRange awFmCreateInitialQueryRange(
uint8_t finalLetterIndexInQuery;
if(index->config.alphabetType == AwFmAlphabetNucleotide) {
finalLetterIndexInQuery = awFmAsciiNucleotideToLetterIndex(query[queryLength - 1]);
} else {
}
else {
finalLetterIndexInQuery = awFmAsciiAminoAcidToLetterIndex(query[queryLength - 1]);
}

Expand Down Expand Up @@ -167,7 +168,8 @@ uint64_t *awFmFindDatabaseHitPositions(const struct AwFmIndex *restrict const in
backtracePosition = awFmNucleotideBacktraceBwtPosition(index, backtracePosition);
databaseSequenceOffset++;
}
} else {
}
else {
while(!awFmBwtPositionIsSampled(index, backtracePosition)) {
backtracePosition = awFmAminoBacktraceBwtPosition(index, backtracePosition);
databaseSequenceOffset++;
Expand Down Expand Up @@ -203,7 +205,8 @@ enum AwFmReturnCode awFmGetLocalSequencePositionFromIndexPosition(const struct A
size_t globalPosition, size_t *sequenceNumber, size_t *localSequencePosition) {
if(!index->fastaVector) {
return AwFmUnsupportedVersionError;
} else {
}
else {
if(globalPosition >= index->bwtLength) {
return AwFmIllegalPositionError;
}
Expand All @@ -216,7 +219,8 @@ enum AwFmReturnCode awFmGetLocalSequencePositionFromIndexPosition(const struct A
size_t sequenceStartPosition;
if(sequenceIndex == 0) {
sequenceStartPosition = 0;
} else {
}
else {
sequenceStartPosition = index->fastaVector->metadata.data[sequenceIndex - 1].sequenceEndPosition;
}
*sequenceNumber = sequenceIndex;
Expand Down Expand Up @@ -257,7 +261,8 @@ struct AwFmSearchRange awFmDatabaseSingleKmerExactMatch(
if(index->config.alphabetType == AwFmAlphabetNucleotide) {
bwtBlockWidth = sizeof(struct AwFmNucleotideBlock);
kmerLetterIndex = awFmAsciiNucleotideToLetterIndex(kmer[kmerLetterPosition]);
} else {
}
else {
bwtBlockWidth = sizeof(struct AwFmAminoBlock);
kmerLetterIndex = awFmAsciiAminoAcidToLetterIndex(kmer[kmerLetterPosition]);
}
Expand All @@ -273,7 +278,8 @@ struct AwFmSearchRange awFmDatabaseSingleKmerExactMatch(
kmerLetterIndex = awFmAsciiNucleotideToLetterIndex(kmer[kmerLetterPosition]);
awFmNucleotideIterativeStepBackwardSearch(index, &range, kmerLetterIndex);
}
} else {
}
else {
while(__builtin_expect(awFmSearchRangeIsValid(&range) && (kmerLetterPosition--), 1)) {
kmerLetterIndex = awFmAsciiAminoAcidToLetterIndex(kmer[kmerLetterPosition]);
awFmAminoIterativeStepBackwardSearch(index, &range, kmerLetterIndex);
Expand Down
7 changes: 4 additions & 3 deletions src/AwFmSuffixArray.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ enum AwFmReturnCode awFmReadPositionsFromSuffixArray(const struct AwFmIndex *res
}

return AwFmSuccess;
} else {
}
else {
for(size_t i = 0; i < positionArrayLength; i++) {
size_t indexInSuffixArray = positionArray[i] / index->config.suffixArrayCompressionRatio;
enum AwFmReturnCode rc = awFmGetSuffixArrayValueFromFile(index, indexInSuffixArray, &positionArray[i]);
Expand All @@ -160,8 +161,8 @@ enum AwFmReturnCode awFmSuffixArrayReadPositionParallel(
size_t saValue = awFmGetValueFromCompressedSuffixArray(&index->suffixArray, suffixArrayPosition);
backtracePtr->position = (saValue + backtracePtr->offset) % index->bwtLength;
return AwFmSuccess;

} else {
}
else {
uint64_t suffixArrayPosition = backtracePtr->position / index->config.suffixArrayCompressionRatio;
size_t saValue;
enum AwFmReturnCode rc = awFmGetSuffixArrayValueFromFile(index, suffixArrayPosition, &saValue);
Expand Down
9 changes: 6 additions & 3 deletions test/kmerSeedTableTests/kmerSeedTableTests.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ void checkRangeForCorrectness(const struct AwFmSearchRange *restrict const range

sprintf(buffer, "range had position %zu for kmer %s, but that position holds kmer %s.\n", position, kmerBuffer,
sequenceBuffer);
} else {
}
else {
sprintf(buffer, "position %zu matches kmer %s, but was not represented in the range.\n", position, kmerBuffer);
}
testAssertString((kmerFoundAtPosition == positionFoundInRange), buffer);
Expand Down Expand Up @@ -160,7 +161,8 @@ void testAllKmerRanges(struct AwFmIndexConfiguration *config, uint64_t sequenceL
char *kmer2 = "agaaa";
if(config->alphabetType == AwFmAlphabetNucleotide) {
awFmNucleotideNonSeededSearch(index, kmer2, 5, &range);
} else {
}
else {
awFmAminoNonSeededSearch(index, kmer2, 5, &range);
}
printf("range for agaaa: %zu, %zu\n", range.startPtr, range.endPtr);
Expand Down Expand Up @@ -193,7 +195,8 @@ void testAllKmerRanges(struct AwFmIndexConfiguration *config, uint64_t sequenceL
if(index->config.alphabetType == AwFmAlphabetNucleotide) {
kmer[letterInKmer] = nucleotideLookup[(kmerIndexCopy % 4)];
kmerIndexCopy /= 4;
} else {
}
else {
kmer[letterInKmer] = aminoLookup[(kmerIndexCopy % 20)];
kmerIndexCopy /= 20;
}
Expand Down
9 changes: 6 additions & 3 deletions test/multiSequenceIndexTest/AwFmMultiSequenceTest.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,14 +318,16 @@ void testAwFmIndexGivesCorrectHeaders(void) {
char *headerBufferPtrFromFastaVector;
if(sequenceIndex == 0) {
headerBufferPtrFromFastaVector = fastaVector->header.charData;
} else {
}
else {
size_t headerOffset = fastaVector->metadata.data[sequenceIndex - 1].headerEndPosition;
headerBufferPtrFromFastaVector = fastaVector->header.charData + headerOffset;
}
size_t headerLengthFromFastaVector;
if(sequenceIndex == 0) {
headerLengthFromFastaVector = fastaVector->metadata.data[0].headerEndPosition;
} else {
}
else {
size_t startPosition = fastaVector->metadata.data[sequenceIndex - 1].headerEndPosition;
size_t endPosition = fastaVector->metadata.data[sequenceIndex].headerEndPosition;
headerLengthFromFastaVector = endPosition - startPosition;
Expand Down Expand Up @@ -411,7 +413,8 @@ void compareIndicesForEqualityIgnoreVersion(const struct AwFmIndex *index1, cons
}
}
}
} else {
}
else {
bool blocksAreEqual = memcmp(&index1->bwtBlockList.asAmino[blockIndex], &index2->bwtBlockList.asAmino[blockIndex],
sizeof(struct AwFmAminoBlock)) == 0;
sprintf(buffer, "index 1 bwt block %zu did not compare equal to matching index 2 block.", blockIndex);
Expand Down
3 changes: 2 additions & 1 deletion test/occupancyPerformanceTest/occSpeedTest.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ void performDbQueries(const struct AwFmIndex *restrict const index, uint64_t pos
ptrs[1] = ptrs[1] % positionsInDb;
awFmOccupancyDataPrefetch(index, ptrs[1]);
}
} else {
}
else {
for(uint32_t i = 0; i < numQueries; i++) {
uint8_t letter = rand() % 20;
ptrs[0] = awFmGetOccupancy(index, ptrs[0], letter) + index->rankPrefixSums[letter];
Expand Down
6 changes: 4 additions & 2 deletions test/parallelSearch/parallelSearchTest.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ void testParallelSearchAmino(void) {
sequence + sequencePosition, sequencePosition);
testAssertString(false, buffer);
exit(-1);
} else if(!kmerFoundAtThisPosition && thisPositionInList) {
}
else if(!kmerFoundAtThisPosition && thisPositionInList) {
printf("kmer %zu has count %u\n", kmerIndex, searchData->count);
printf("position list: ");
for(size_t i = 0; i < searchData->count; i++) {
Expand Down Expand Up @@ -296,7 +297,8 @@ void testParallelSearchNucleotide() {

testAssertString(false, buffer);
exit(-2);
} else if(!kmerFoundAtThisPosition && thisPositionInList) {
}
else if(!kmerFoundAtThisPosition && thisPositionInList) {
printf("kmer %zu has count %u\n", kmerIndex, searchData->count);
printf("position list: ");
for(size_t i = 0; i < searchData->count; i++) {
Expand Down
7 changes: 4 additions & 3 deletions test/searchTest/searchTest.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ void generateRandomIndex(struct AwFmIndex **index, uint8_t **sequence, size_t se
if(sequence == NULL) {
printf("critical failure: could not allocate sequence in unit test.");
exit(-1);
} else if(suffixArray == NULL) {
}
else if(suffixArray == NULL) {
printf("critical failure: could not allocate suffix array in unit test.");
exit(-2);
}
Expand Down Expand Up @@ -162,8 +163,8 @@ void testRangeForCorrectness(const struct AwFmSearchRange *range, const uint8_t
printf("%zu, ", suffixArray[i]);
}
printf("]\n");

} else if(!kmerFoundAtPosition && kmerExpectedAtPosition) {
}
else if(!kmerFoundAtPosition && kmerExpectedAtPosition) {
sprintf(buffer,
"kmer \"%.*s\" returned range [%zu, %zu], which contains position %zu, but that position was not in range:",
kmerLength, kmer, range->startPtr, range->endPtr, position);
Expand Down
10 changes: 6 additions & 4 deletions tuning/build/buildIndex.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ int main(int argc, char **argv) {
if(chromosomeNumber == -1 && !fullGenomeIndexRequested) {
printf("no chromosome or full genome specified, defaulting to chromosome 21.\n");
chromosomeNumber = 21;
} else if(chromosomeNumber != -1 && fullGenomeIndexRequested) {
}
else if(chromosomeNumber != -1 && fullGenomeIndexRequested) {
printf(
"the full genome flag was set, but a specific chromosome was also requested. Ignoring full genome and making "
"index on chromosome %i\n",
Expand All @@ -67,7 +68,8 @@ int main(int argc, char **argv) {
// build the index using the parsed settings
if(fullGenomeIndexRequested) {
buildFullGenomeIndex(suffixArrayCompressionRatio, kmerLengthInSeedTable, indexFilenameBuffer);
} else {
}
else {
buildChromosomeIndex(chromosomeNumber, suffixArrayCompressionRatio, kmerLengthInSeedTable, indexFilenameBuffer);
}
}
Expand Down Expand Up @@ -111,8 +113,8 @@ void buildChromosomeIndex(
if(sequenceLength > 1000) {
printf("for reference, here's the first 1000 characters in the sequence: %.*s\n", 1000, sequenceBuffer);
printf("...and the last 10 characters: %.*s\n", 10, &sequenceBuffer[sequenceLength - 10]);

} else {
}
else {
printf("for reference, here's all %zu characters in the sequence: %.*s\n", sequenceLength, (int)sequenceLength,
sequenceBuffer);
}
Expand Down
9 changes: 6 additions & 3 deletions tuning/search/timeSearch.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ int main(int argc, char **argv) {
// search for the kmers
if(useCountFunction) {
awFmParallelSearchCount(index, searchList, numThreadsInParallelQuery);
} else {
}
else {
awFmParallelSearchLocate(index, searchList, numThreadsInParallelQuery);
}
clock_t searchEndTime = clock();
Expand Down Expand Up @@ -128,7 +129,8 @@ bool charIsAmbiguous(char c, enum AwFmAlphabetType alphabet) {
return false;
}
}
} else {
}
else {
for(uint8_t i = 0; i < 20; i++) {
if(tolower(c) == aminoLookup[i]) {
return false;
Expand Down Expand Up @@ -167,7 +169,8 @@ bool getStringFromSequenceFile(
if(charFromFile >= 'A' && charFromFile < 'z') {
if(charIsAmbiguous(charFromFile, alphabet)) {
return false;
} else {
}
else {
buffer[charactersGrabbed++] = charFromFile;
}
}
Expand Down

0 comments on commit 308541b

Please sign in to comment.