int main() { int i,n,counter = 0; char str[100],*p,*q; scanf("%s",str); n = strlen(str); //printf("%d",n); for(i = 0; i<=n/2;++i) { //printf("str[%d]=%c str[%d]=%c \n",i,str[i],(n-1)-i,str[(n-1)-i]); if(str[i]==str[(n-1)-i]) { counter++; //printf("str[%d]=%c str[%d]=%c \n",i,str[i],(n-1)-i,str[(n-1)-i]); } else break; } //printf("%d",counter); p = str; if(counter == 0) { p = NULL; } q = p+counter-1; printChars(p,q); }
void Individual::printDetail(ofstream &ofs){ ofs << "Chars:\n"; printChars(ofs); ofs << "Words:\n"; printWords(ofs); }
void Individual::printDetail(){ cout << "Chars:\n"; printChars(); cout << "Words:\n"; printWords(); }
int main(){ int c, i, p = 0, n = 0; while(EOF != (c = getchar())){ if(' ' == c){ ++n; if(TABINC - 1 == p % TABINC){ #if D_S printf("*%d*", n); #endif (n > 0)? putchar((1 == n)? ' ': '\t'): 0; n = 0; } }else{ if('\t' == c) p = (p / TABINC + 1) * TABINC - 1; else{ ('\n' == c)? (p = 0): 0; printChars(n, ' '); #if D_S printf("%d", n); #endif } n = 0, putchar(c); } ++p; } return 0; }
/* Prints an upright triangle with a given number as height * on the screen. * Parameter: size - the height of the triangle * Parameter: printChar - the character to print * Return: void */ void printTri(int size, int printChar) { int row = 1; // size of the row is increased by 1 as it moves down for ( ; row <= size; row++) { printChars(row, printChar); printf("\n"); } }
void * processQueries(void * QSptr) { setupTimers(); defineTimer(setupSecs); defineTimer(findDiagonals); defineTimer(findClumps); defineTimer(filterClumps); defineTimer(processClumps); defineTimer(printClumpss); defineTimer(totalTimer); // Use skipDist of 1 for query, regardless of what was used to create the hash table. int skipDist = 1; // Cache the wordLen on the stack to speed loop access. QueryState_t * QS = (QueryState_t *) QSptr; AlignmentArgs_t * AAs = QS->AAs; int wordLen = AAs->wordLen; int maxHits = AAs->maxHits; ROFF *startingOffs = AAs->startingOffs; #ifdef STATS // Let's keep some statistics about the queries we process. int queryCount = 0; int totalQueryLength = 0; uint64_t totalTotalCount = 0; int minQLength = 1000000000; int maxQLength = 0; int minTotalCount = 1000000000; int maxTotalCount = 0; uint64_t totalClumpsOut = 0; int minClumpsPerQuery = 1000000000; int maxClumpsPerQuery = -1; int totalNonAlignedQueries = 0; #endif ///// // Now we are ready to go into the main query read loop. ///// // Calculate some masks for use later. UINT hashMask = ((UINT)0xFFFFFFFF) >> (32 - 2*wordLen); int hashSaveLength = wordLen - skipDist; startTime(); // To get started, make sure we have read a first query. // This is a partial unwind of the first time through the loop. // It allows the main thread to read the first query to get a query length estimate to use to create the other threads. if (QS->queryLen == 0) readNextQuery(AAs, QS); while (QS->queryLen > 0) { /////// // First Phase. Read in the query, reverse it, and do the initial hashing. /////// // See if we need to reallocate the query length dependent structures. if (QS->queryLen > QS->maxQueryLength) reallocNewMaxQueryLength(QS); QOFF qbaseCount = QS->queryLen; #ifdef STATS fprintQueryId(QS, stderr); #endif #ifdef QUERYSTATS struct timeval starttime, endtime; if (AAs->queryStats) { QS->alignCount = 0; QS->alignOutCount = 0; QS->DPCount = 0; QS->usec = 0; QS->seedMatches = 0; QS->diagRegionCount = 0; QS->diagRegionTotal = 0; gettimeofday(&starttime, NULL); } #endif ///// // Now match the query against both the reference DNA and its reverse-complement strand. // Therefore the bases in the reversed query are also complemented. ///// // Do the forward query first. int offsetCount = ((qbaseCount - wordLen)/skipDist) + 1; for (int rev=0; rev<=1; rev++) { QS->reversed = (BOOL)rev; if (QS->reversed) { QS->queryCodeBuf = QS->reverseCodeBuf; QS->queryBuf = QS->reverseBuf; } else { QS->queryCodeBuf = QS->forwardCodeBuf; QS->queryBuf = QS->forwardBuf; } ///// // Find the hash seeds, filter overhits, and fill in structures from the hash table. ///// #ifdef STATS UINT maxHitsOverCount = 0; #endif // The loop complication is because we want to both encode each base once, and skip over non-ACGT codes. UINT totalCount = 0; int baseOff = 0; int endingOffset = qbaseCount - wordLen; UINT hashCode = 0; UINT partialHashCode = 0; int badOffset = generateMatches4UNPto2Fast(QS->queryCodeBuf, baseOff, wordLen, &hashCode); while (TRUE) { if (badOffset != 0) { // Get rid of all the bad ones in a row. while (badOffset <= endingOffset && QS->queryCodeBuf[badOffset] > 3) badOffset += 1; // Make sure the ones we skipped over have their count set to zero. // We need to handle the case where the above has gone too far. badOffset = MIN(badOffset, endingOffset + 1); // fprintf(stderr, "After throwing away bases, badOffset %d baseOff %d endingOffset %d \n", badOffset, baseOff, endingOffset); for (int i=baseOff; i<badOffset; i++) QS->offsetCounts[i].count = 0; // Move forward on the query. baseOff = badOffset; if (baseOff > endingOffset) break; // Try to load entire word. badOffset = generateMatches4UNPto2Fast(QS->queryCodeBuf, baseOff, wordLen, &hashCode); continue; } // The previous read was good, so process it. // Max out before we overflow. UINT count = startingOffs[hashCode+1] - startingOffs[hashCode]; if (count <= maxHits) { totalCount += count; QS->offsetCounts[baseOff].count = count; QS->offsetCounts[baseOff].sOffset = startingOffs[hashCode]; QS->offsetCounts[baseOff].newCount = 0; } else { #ifdef STATS maxHitsOverCount += 1; #endif QS->offsetCounts[baseOff].count = 0; } // and just get the next skipDist worth baseOff += 1; if (baseOff > endingOffset) break; badOffset = generateMatches4UNPto2Fast(QS->queryCodeBuf, baseOff + hashSaveLength, 1, &partialHashCode); // and tack it on to the rest from the previous get. hashCode = ((hashCode << 2) | partialHashCode) & hashMask; } #ifdef STATS fprintf(stderr, "K-mers above maxHits %u\n", maxHitsOverCount); totalTotalCount += totalCount; if (totalCount > 0 && totalCount < minTotalCount) minTotalCount = totalCount; if (totalCount > maxTotalCount) maxTotalCount = totalCount; #endif #ifdef QUERYSTATS if (AAs->queryStats)QS->seedMatches += totalCount; #endif addToTimer(setupSecs); // If the totalCount is zero, we have no hits to process. if (totalCount == 0) continue; ///// // Second Phase. Go through all hash matches, and look for diagonal fragments. ///// int fragCount = findFragmentsSort(AAs, QS, offsetCount); addToTimer(findDiagonals); ///// // Third Phase. Put Fragments into potential alignments (clumps). ///// processFragmentsGapped(AAs, QS, fragCount); addToTimer(findClumps); } // Align and Score clumps, filtering those that don't meet thresholds. postProcessClumps(QS, AAs); addToTimer(processClumps); // Run OQC algorithm if requested. // If not, at least get rid of duplicates. if (AAs->OQC) postFilterBySimilarity(AAs, QS); else postFilterRemoveDups(AAs, QS); addToTimer(filterClumps); // The file lock and unlock here act as the thread synchromization mechanism. // This will ensure that all alignments for a given query are in contiguous lines in the output file. // Otherwise, many downstream tools such as samtools will be unhappy. flockfile(AAs->outFile); // This is to avoid compiler warning when STATS not on. #ifdef STATS int tempClumpsPerQuery = printClumps(QS, AAs); #else printClumps(QS, AAs); #endif funlockfile(AAs->outFile); addToTimer(printClumpss); #ifdef STATS queryCount += 1; totalQueryLength += qbaseCount; if (qbaseCount < minQLength) minQLength = qbaseCount; if (qbaseCount > maxQLength) maxQLength = qbaseCount; totalClumpsOut += tempClumpsPerQuery; if (tempClumpsPerQuery > maxClumpsPerQuery) maxClumpsPerQuery = tempClumpsPerQuery; if (tempClumpsPerQuery > 0 && tempClumpsPerQuery < minClumpsPerQuery) minClumpsPerQuery = tempClumpsPerQuery; if (tempClumpsPerQuery == 0) totalNonAlignedQueries += 1; #endif #ifdef QUERYSTATS if (AAs->queryStats) { gettimeofday(&endtime, NULL); QS->usec = ((endtime.tv_sec - starttime.tv_sec) * 1000000 + (endtime.tv_usec - starttime.tv_usec)); printChars(AAs->qsFile, QS->queryID, 0, QS->queryIDLen); double avgDiagRegionSize = (QS->diagRegionCount > 0) ? (((double)QS->diagRegionTotal/(double)QS->diagRegionCount)+0.0) : 0; fprintf(AAs->qsFile, "\t%u\t%u\t%f\t%u\t%u\t%u\t%u\n", QS->queryLen, QS->seedMatches, avgDiagRegionSize, QS->alignCount, QS->DPCount, QS->alignOutCount, QS->usec); } #endif // Clear query state to get ready for next query. resetQueryState(QS); // Read the next query to setup for next iteration. readNextQuery(AAs, QS); } ////////////////////// // Done with processing the query file. // Close files and clean up storage. ///////////////////// #ifdef TIMING addToTimer(setupSecs); endTime(totalTimer); flockfile(stderr); // if (AAs->threadCount > 1) fprintf(stderr, "Thread %d statistics.\n", QS->threadNum); fprintTimerWithTotalPercent(stderr, "Query setup and hashing took: ", setupSecs, totalTimer); fprintTimerWithTotalPercent(stderr, "Sorting k-mers and forming fragments took: ", findDiagonals, totalTimer); fprintTimerWithTotalPercent(stderr, "Collecting fragments into clumps (using graph) took: ", findClumps, totalTimer); fprintTimerWithTotalPercent(stderr, "Aligning and scoring clumps took: ", processClumps, totalTimer); fprintTimerWithTotalPercent(stderr, "Filtering clumps took: ", filterClumps, totalTimer); fprintTimerWithTotalPercent(stderr, "Printing clumps took: ", printClumpss, totalTimer); funlockfile(stderr); #endif #ifdef STATS if (AAs->verbose) { fprintf(stderr, "%d queries processed.\n", queryCount); fprintf(stderr, "Query Lengths vary from %d to %d with average %d.\n", minQLength, maxQLength, (totalQueryLength/queryCount)); fprintf(stderr, "Total Counts vary from %d to %d with average %"PRIu64".\n", minTotalCount, maxTotalCount, (totalTotalCount/(2 * queryCount))); fprintf(stderr, "There were %d queries with no Alignment.\n", totalNonAlignedQueries); if (totalClumpsOut <= 0) fprintf(stderr, "No Alignments found.\n"); else { fprintf(stderr, "Total Alignments Output = %"PRIu64", average %4.2f per non-zero query.\n", totalClumpsOut, ((double)totalClumpsOut/(queryCount-totalNonAlignedQueries))); fprintf(stderr, "Of those queries with an alignment, the min number of alignments was %d.\n", minClumpsPerQuery); fprintf(stderr, "The max number of alignments per query was %d.\n", maxClumpsPerQuery); } } #endif // Deallocate thread local structures. finalizeQueries(QS); disposeQueryState(QS); return NULL; }
char* Stream::decompress(int tableId, int recordNumber) { char *data; short *q, *limit; int run = 0; decompressedLength = 0; for (Segment *segment = segments; segment; segment = segment->next) { if (segment->length == 0) continue; const short* p = (short*) segment->address; const short* end = (short*) (segment->address + segment->length); if (decompressedLength == 0) { decompressedLength = *p++; if (decompressedLength <= 0) { Log::log ("corrupted record, table %d, record %d, decompressed length %d\n", tableId, recordNumber, decompressedLength); throw SQLEXCEPTION (RUNTIME_ERROR, "corrupted record, table %d, record %d, decompressed length %d", tableId, recordNumber, decompressedLength); } int len = ((decompressedLength + 1) / 2) * 2; //data = new char [len]; data = ALLOCATE_RECORD (len); limit = (short*) (data + decompressedLength); if (decompressedLength & 1) ++limit; q = (short*) data; } while (p < end) { const short n = *p++; //#ifdef ENGINE if (n == 0 && run == 0) { Log::log ("corrupted record (zero run), table %d, record %d\n", tableId, recordNumber); printShorts ("Zero run", (segment->length + 1) / 2, (short*) segment->address); printChars ("Zero run", segment->length, segment->address); } //#endif if (run > 0) { for (; run; --run) *q++ = n; } else if (run < 0) { *q++ = n; ++run; } else { run = n; if (q + run > limit) { //#ifdef ENGINE Log::log ("corrupted record (overrun), table %d, record %d\n", tableId, recordNumber); printShorts ("Compressed", (segment->length + 1)/2, (short*) segment->address); printChars ("Compressed", segment->length, segment->address); //#endif if (q == limit) return data; throw SQLEXCEPTION (RUNTIME_ERROR, "corrupted record, table %d, record %d", tableId, recordNumber); } } } } //printShorts ("Decompressed", (decompressedLength + 1) / 2, (short*) data); return data; }
void fprintQueryId(QueryState_t * QS, FILE * out) { printChars(out, QS->queryID, 0, QS->queryIDLen); fprintf(out, " has length=%d, and strand=%c", QS->queryLen, (QS->reversed ? '-' : '+')); }
/* ************************************************************************* NAME: test2_float2char USAGE: test2_float2char(); returns: void DESCRIPTION: convert floats to ints to shorts to chars to test rounding/truncating REFERENCES: Ian Ollmann's Altivec Tutorial LIMITATIONS: GLOBAL VARIABLES: accessed: none modified: none FUNCTIONS CALLED: fprintf vec_st - store a vector to memory vec_ctu - convert to fixed point vec_pack - narrow 2 vectors and pack them into one vector REVISION HISTORY: STR Description of Revision Author 08-Feb-2011 Based off of test_float2char but kaj changing set of vec functions called ************************************************************************* */ void test2_float2char(void) { vector float floatVec1 = {0.0, -50.14455, 21.7790, 100.0 }; vector float floatVec2 = {-100.4567, 250.14455, -210.7790, 170.0 }; vector float floatVec3 = {0.09876, -150.55, 1.7790, -120.0 }; vector float floatVec4 = {-90.234, -30.9455, -205.90, 199.9 }; vector unsigned int intVec1, intVec2, intVec3, intVec4; vector unsigned short shortVec1, shortVec2; vector unsigned char charVec; unsigned char printchar[CHAR_ARRAYSIZE] __attribute__ ((aligned (16))); float printfloat[FLOAT_ARRAYSIZE] __attribute__ ((aligned (16))); unsigned short printshort[SHORT_ARRAYSIZE] __attribute__ ((aligned (16))); unsigned int printint[INT_ARRAYSIZE] __attribute__ ((aligned (16))); int i; fprintf(stderr, "--- function %s ------\n", __FUNCTION__); /* print out floats */ vec_st(floatVec1,0,printfloat); printFloats(printfloat); vec_st(floatVec2,0,printfloat); printFloats(printfloat); vec_st(floatVec3,0,printfloat); printFloats(printfloat); vec_st(floatVec4,0,printfloat); printFloats(printfloat); /* convert from float to unsigned int and print */ intVec1 = vec_ctu(floatVec1,0); vec_st(intVec1,0,printint); printUInts(printint); intVec2 = vec_ctu(floatVec2,0); vec_st(intVec2,0,printint); printUInts(printint); intVec3 = vec_ctu(floatVec3,0); vec_st(intVec3,0,printint); printUInts(printint); intVec4 = vec_ctu(floatVec4,0); vec_st(intVec4,0,printint); printInts(printint); /* convert from unsigned int to unsigned short and print */ shortVec1 = vec_pack(intVec1,intVec2); vec_st(shortVec1,0,printshort); printUShorts(printshort); shortVec2 = vec_pack(intVec3,intVec4); vec_st(shortVec2,0,printshort); printUShorts(printshort); /* convert from unsigned short to unsigned char and print */ charVec = vec_pack(shortVec1, shortVec2); vec_st(charVec,0,printchar); printChars(printchar); } /* test2_float2char */
void ColumnPrinter::print(std::ostream& out) const { // stringstream::str() copies the string, so we need // to extract all the strings and store them to avoid copying // at every access. std::vector<std::string> texts(getColumnCount()); for (size_t col = 0; col < getColumnCount(); ++col) texts[col] = _cols[col]->text.str(); // Calculate the width of each column. std::vector<size_t> widths(getColumnCount()); for (size_t col = 0; col < getColumnCount(); ++col) { const auto& text = texts[col]; size_t maxWidth = 0; size_t pos = 0; while (pos < text.size()) { size_t width = getLineWidth(text, pos); if (width > maxWidth) maxWidth = width; // We can't just increment pos unconditionally by width + 1, as // that could result in an overflow. pos += width; if (pos == text.size()) break; if (text[pos] == '\0') { ++pos; if (pos == text.size()) break; ++pos; } else if (text[pos] == '\n') ++pos; } widths[col] = maxWidth; } // Print each row std::vector<size_t> poses(getColumnCount()); while (true) { bool done = true; for (size_t col = 0; col < getColumnCount(); ++col) { if (poses[col] < texts[col].size()) { done = false; break; } } if (done) break; out << _prefix; for (size_t col = 0; col < getColumnCount(); ++col) { out << _cols[col]->prefix; const std::string& text = texts[col]; size_t& pos = poses[col]; size_t width = getLineWidth(text, pos); char padChar = ' '; if ( pos + width < text.size() && text[pos + width] == '\0' && pos + width + 1 < text.size() ) { padChar = text[pos + width + 1]; } if (!_cols[col]->flushLeft) printChars(out, widths[col] - width, padChar); while (pos < text.size()) { if (text[pos] == '\n') { ++pos; break; } if (text[pos] == '\0') { ++pos; if (pos < text.size()) { MATHIC_ASSERT(text[pos] == padChar); ++pos; } break; } out << text[pos]; ++pos; } if (_cols[col]->flushLeft) printChars(out, widths[col] - width, padChar); out << _cols[col]->suffix; } out << '\n'; } }
int main(int argc, char *argv[]) { // Lists SortedListPtr integers = SLCreate(compareIntegers, destroyList); SortedListPtr doubles = SLCreate(compareDoubles, destroyList); SortedListPtr characters = SLCreate(compareStrings, destroyList); SortedListPtr strings = SLCreate(compareStrings, destroyList); // Insertions int a = 7, b = 7, c = 8, d = 1; double h = 22.3, i = 98.2, j = 1.2; char s = 's', w = 'a', v = 'c'; char word1[10] = "Hello"; char word2[10] = "World"; // ========================== Case 1 ========================== printf("\nIntegers:\n"); SLInsert(integers, (void*)&a); SLInsert(integers, (void*)&b); SLInsert(integers, (void*)&c); SLInsert(integers, (void*)&d); SortedListIteratorPtr itr1 = SLCreateIterator(integers); printIntegers(itr1); printf("\n"); SLRemove(integers, (void*)&c); SortedListIteratorPtr itr2 = SLCreateIterator(integers); printIntegers(itr2); printf("\n"); // ========================== Case 2 ========================== printf("\nDoubles:\n"); SLInsert(doubles, (void*)&h); SLInsert(doubles, (void*)&i); SLInsert(doubles, (void*)&j); SortedListIteratorPtr itr3 = SLCreateIterator(doubles); printDoubles(itr3); printf("\n"); SLRemove(doubles, (void*)&h); SortedListIteratorPtr itr4 = SLCreateIterator(doubles); printDoubles(itr4); printf("\n"); // ========================== Case 3 ========================== printf("\nCharacters:\n"); SLInsert(characters, (void*)&s); SLInsert(characters, (void*)&w); SLInsert(characters, (void*)&v); SortedListIteratorPtr itr5 = SLCreateIterator(characters); printChars(itr5); printf("\n"); SLRemove(characters, (void*)&v); SLRemove(characters, (void*)&s); SortedListIteratorPtr itr6 = SLCreateIterator(characters); printChars(itr6); printf("\n"); // ========================== Case 4 ========================== printf("\nStrings:\n"); SLInsert(strings, (void*)word1); SLInsert(strings, (void*)word2); SortedListIteratorPtr itr7 = SLCreateIterator(strings); printStrings(itr7); printf("\n"); SLRemove(strings, (void*)word1); SortedListIteratorPtr itr8 = SLCreateIterator(strings); printStrings(itr8); printf("\n\n"); return 0; }