bool psEffect::Load(iDocumentNode * node, iView * parentView, psEffect2DRenderer * renderer2d, iLoaderContext * ldr_context) { csRef<iDocumentNodeIterator> xmlbinds; // get the attributes name.Clear(); csRef<iDocumentAttributeIterator> attribIter = node->GetAttributes(); while (attribIter->HasNext()) { csRef<iDocumentAttribute> attr = attribIter->Next(); csString attrName = attr->GetName(); attrName.Downcase(); if (attrName == "name") name = attr->GetValue(); } if (name.IsEmpty()) { csReport(psCSSetup::object_reg, CS_REPORTER_SEVERITY_ERROR, "planeshift_effects", "Attempting to create an effect with no name.\n"); return false; } // anchors xmlbinds = node->GetNodes("anchor"); csRef<iDocumentNode> anchorNode; while (xmlbinds->HasNext()) { anchorNode = xmlbinds->Next(); psEffectAnchor * anchor = 0; // create a anchor from the given type string anchor = CreateAnchor(anchorNode->GetAttributeValue("type")); if (anchor) { if (anchor->Load(anchorNode)) AddAnchor(anchor); else { csReport(psCSSetup::object_reg, CS_REPORTER_SEVERITY_ERROR, "planeshift_effects", "Problem with an effect anchor in: %s\n", name.GetData()); } } else { csReport(psCSSetup::object_reg, CS_REPORTER_SEVERITY_ERROR, "planeshift_effects", "Couldn't create anchor.\n"); } } // Check if sound is available csRef<iSndSysRenderer> sndRender = csQueryRegistry<iSndSysRenderer> (psCSSetup::object_reg); bool sound = ( sndRender != NULL ); // objs xmlbinds = node->GetNodes("obj"); csRef<iDocumentNode> objNode; while (xmlbinds->HasNext()) { objNode = xmlbinds->Next(); psEffectObj *obj = 0; csString type = objNode->GetAttributeValue("type"); type.Downcase(); if (type == "quad") { obj = new psEffectObjQuad(parentView, renderer2d); } else if (type == "spire") { obj = new psEffectObjSpire(parentView, renderer2d); } else if (type == "mesh") { obj = new psEffectObjMesh(parentView, renderer2d); } else if (type == "simpmesh") { obj = new psEffectObjSimpMesh(parentView, renderer2d); } else if (type == "particles") { obj = new psEffectObjParticles(parentView, renderer2d); } else if (type == "sound") { if (sound) { obj = new psEffectObjSound(parentView, renderer2d); } else { continue; // Sound is off; ignore this obj } } else if (type == "star") { obj = new psEffectObjStar(parentView, renderer2d); } else if (type == "text") { obj = new psEffectObjText(parentView, renderer2d); } else if (type == "label") { obj = new psEffectObjLabel(parentView, renderer2d); } else if (type == "trail") { obj = new psEffectObjTrail(parentView, renderer2d); } #ifdef PS_EFFECT_ENABLE_DECAL else if (type == "decal") { obj = new psEffectObjDecal(parentView, renderer2d); #endif // PS_EFFECT_ENABLE_DECAL } else if (type == "text2d") { obj = new psEffectObjText2D(parentView, renderer2d); } if (obj) { if (obj->Load(objNode, ldr_context)) { effectObjs.Push(obj); if (mainTextObj == (size_t)(-1)) { psEffectObjTextable * textObj = dynamic_cast<psEffectObjTextable *>(obj); if (textObj) mainTextObj = effectObjs.GetSize()-1; } } else { csReport(psCSSetup::object_reg, CS_REPORTER_SEVERITY_ERROR, "planeshift_effects", "Problem with an effect obj in: %s/%s\n", type.GetData(), name.GetData()); delete obj; } } else { csReport(psCSSetup::object_reg, CS_REPORTER_SEVERITY_ERROR, "planeshift_effects", "Unknown effect obj type: %s\n", type.GetData()); } } return true; }
int ErrorCorrection( char *read, char *qual, KmerCode& kmerCode, int maxCorrection, char badQuality, Store *kmers, int &badPrefix, int &badSuffix ) { int i, j, k ; bool storedKmer[MAX_READ_LENGTH] ; int kmerCnt = 0 ; int readLength = 0 ; int fix[MAX_READ_LENGTH] ; // The fixed character for each untrusted position. bool trusted[MAX_READ_LENGTH] ; // Do not correct these makred positions. int tag ; int from, to ; int trimStart = -1 ; int ambiguousCnt = 0 ; int alternativeCnt = 0 ; bool hasAnchor = false ; int createAnchorPos = -1 ; // KmerCode kmerCode( inCode ) ; KmerCode tmpKmerCode( 0 ) ; badPrefix = badSuffix = 0 ; int kmerLength = kmerCode.GetKmerLength() ; kmerCode.Restart() ; for ( i = 0 ; i < kmerLength && read[i] ; ++i ) { kmerCode.Append( read[i] ) ; } if ( !kmers->IsIn( kmerCode ) ) storedKmer[0] = false ; else storedKmer[0] = true ; kmerCnt = 1 ; for ( ; read[i] ; ++i, ++kmerCnt ) { kmerCode.Append( read[i] ) ; if ( !kmers->IsIn( kmerCode ) ) storedKmer[ kmerCnt ] = false ; else { storedKmer[ kmerCnt ] = true ; hasAnchor = true ; } } readLength = i ; if ( readLength < kmerLength ) return 0 ; trimStart = readLength ; for ( i = 0 ; i < readLength ; ++i ) fix[i] = -1 ; for ( i = 0 ; i < readLength ; ++i ) trusted[i] = false ; tag = -1 ; for ( i = 0 ; i < kmerCnt ; ++i ) { if ( storedKmer[i] ) { if ( tag == -1 ) tag = i ; } else { if ( tag != -1 )// && i - tag >= 3 ) { for ( j = tag ; j < i + kmerLength - 1 ; ++j ) trusted[j] = true ; } tag = -1 ; } } if ( !hasAnchor ) { createAnchorPos = CreateAnchor( read, qual, fix, storedKmer, kmerCode, kmers ) ; if ( createAnchorPos == -1 ) return -1 ; ++alternativeCnt ; } //printf( "%d %d %d\n", kmerLength, kmerCnt, i ) ; #ifdef DEBUG printf( "%s\n", read ) ; for ( i = 0 ; i < kmerCnt ; ++i ) printf( "%d", storedKmer[i] ) ; printf( "\n" ) ; #endif //exit( 1 ) ; // All the kmers are reliable. for ( i = 0 ; i < kmerCnt ; ++i ) { if ( storedKmer[i] == false ) break ; } /*if ( !strcmp( read, "TTGCGTAAGATGGGGGTACCCACGTGGTGTCAGAGTGTCTCTCATTTCGGTTTGATCTACGCAGATCTACAAAAAATGCGGGAGAATAGACGCAGAGTTCT" ) ) { printf( "## %d\n", i ) ; exit( 1 ) ; }*/ if ( i >= kmerCnt ) return 0 ; // Find the first trusted kmer int longestStoredKmerCnt = 0, storedKmerCnt = 0 ; tag = -1 ; for ( i = 0 ; i < kmerCnt ; ++i ) { if ( storedKmer[i] ) { ++storedKmerCnt ; } else { if ( storedKmerCnt > longestStoredKmerCnt ) { longestStoredKmerCnt = storedKmerCnt ; tag = i - storedKmerCnt ; } storedKmerCnt = 0 ; } } if ( storedKmerCnt > longestStoredKmerCnt ) { longestStoredKmerCnt = storedKmerCnt ; tag = i - storedKmerCnt ; } if ( longestStoredKmerCnt == 0 ) { return -1 ; } if ( longestStoredKmerCnt >= kmerCnt ) { //printf( "0%s\n", read ) ; return 0 ; } //if ( tag > 0 ) // return 0 ; for ( k = tag + 1 ; k < kmerCnt ; ++k ) if ( !storedKmer[k] ) break ; // Scan towards right kmerCode.Restart() ; if ( k >= kmerCnt ) // The kmers are all correct after tag, so force skip the correction. i = readLength + 1 ; else { char backupC = '\0' ; if ( createAnchorPos != -1 ) { backupC = read[ createAnchorPos ] ; read[ createAnchorPos ] = numToNuc[ fix[ createAnchorPos ] ] ; } if ( longestStoredKmerCnt < kmerLength ) { for ( i = k - 1 + 1 ; i < k - 1 + kmerLength - 1 + 1 ; ++i ) { kmerCode.Append( read[i] ) ; } } else { // Adjust the anchor if necessary // Test whether the current anchor is good for ( i = k ; i < k + kmerLength ; ++i ) kmerCode.Append( read[i] ) ; int c ; for ( c = 0 ; c < 4 ; ++c ) { if ( numToNuc[c] == read[i - 1] ) continue ; if ( numToNuc[c] == read[i - 1] ) continue ; tmpKmerCode = kmerCode ; tmpKmerCode.ShiftRight( 1 ) ; tmpKmerCode.Append( numToNuc[c] ) ; if ( kmers->IsIn( tmpKmerCode ) ) { // Test whether this branch makes sense int t = 0 ; for ( t = 0 ; t < kmerLength && read[i + t] ; ++t ) // and it is should be a very good fix { tmpKmerCode.Append( read[i + t] ) ; if ( !kmers->IsIn( tmpKmerCode ) ) break ; } if ( !read[i + t] || t >= kmerLength ) break ; } } if ( c < 4 ) { //kmerCode.ShiftRight( 1 ) ; Seems wrong for ( i = k - 1 ; i < k + kmerLength - 1 ; ++i ) kmerCode.Append( read[i] ) ; } else { // Adjust the right side for ( j = kmerLength / 2 - 1 ; j >= 0 ; --j ) { int c ; KmerCode tmpKmerCode( kmerLength ) ; for ( i = k - j - 1 ; i < k - j + kmerLength - 1 ; ++i ) kmerCode.Append( read[i] ) ; //printf( "%d %d %c\n", j, i, read[i - 1] ) ; for ( c = 0 ; c < 4 ; ++c ) { if ( numToNuc[c] == read[i - 1] ) continue ; tmpKmerCode = kmerCode ; tmpKmerCode.ShiftRight( 1 ) ; tmpKmerCode.Append( numToNuc[c] ) ; if ( kmers->IsIn( tmpKmerCode ) ) { ++alternativeCnt ; // Test whether this branch makes sense int t = 0 ; for ( t = 0 ; t <= kmerLength / 2 && read[i + t] ; ++t ) // and it is should be a very good fix { tmpKmerCode.Append( read[i + t] ) ; if ( !kmers->IsIn( tmpKmerCode ) ) break ; } if ( t > kmerLength / 2 ) break ; } } if ( c < 4 ) { // adjust the anchor --i ; kmerCode.ShiftRight( 1 ) ; break ; } } } } if ( createAnchorPos != -1 ) { read[ createAnchorPos ] = backupC ; } } /*for ( i = k ; i < k + kmerLength - 1 ; ++i ) { kmerCode = ( kmerCode << (uint64_t)2 ) & mask ; kmerCode = kmerCode | (uint64_t)nucToNum[ read[i] - 'A' ] ; }*/ for ( ; i < readLength ; ) { KmerCode fixedKmerCode( kmerCode ) ; int maxTo = -1 ; int maxChange = -1 ; int maxCnt = 0 ; int testCnt = 0 ; from = i + 1 ; to = ( i + kmerLength - 1 < readLength ) ? i + kmerLength - 1 : readLength - 1 ; for ( j = 0 ; j < 4 ; ++j ) { //kmerCode = ( fixedKmerCode << (uint64_t)2 ) & mask ; //kmerCode = kmerCode | (uint64_t)j ; kmerCode = fixedKmerCode ; kmerCode.Append( numToNuc[j] ) ; //printf( "?code=%llu\n", kmerCode.GetCode() ) ; if ( !kmers->IsIn( kmerCode ) ) continue ; if ( maxTo == -1 ) maxTo = i ; ++testCnt ; // How many kmers this change can fix for ( k = from ; k <= to ; ++k ) { kmerCode.Append( read[k] ) ; if ( !kmers->IsIn( kmerCode ) ) break ; } // Try to extend 1 position if ( k > to && to == readLength - 1 ) { int l, m ; for ( m = 0 ; m < kmerLength - 1 - ( to - from + 1 ) ; ++m ) { for ( l = 0 ; l < 4 ; ++l ) { KmerCode tmpKmerCode( kmerCode ) ; tmpKmerCode.Append( numToNuc[l] ) ; if ( kmers->IsIn( tmpKmerCode ) ) break ; } if ( l < 4 ) { //printf( "hi\n" ) ; kmerCode.Append( numToNuc[l] ) ; ++k ; } } } //printf( "hi %d %d\n", k, maxTo ) ; if ( k > maxTo ) { /*if ( maxTo - from + 1 >= kmerLength / 2 ) { ++maxCnt ; } else*/ maxCnt = 1 ; maxTo = k ; maxChange = j ; tmpKmerCode = kmerCode ; } /*else if ( k - from + 1 >= kmerLength / 2 ) { ++maxCnt ; }*/ else if ( k == maxTo ) { ++maxCnt ; if ( k == i + 1 && j == nucToNum[ read[i] - 'A' ] ) { maxCnt = 1 ; maxChange = j ; tmpKmerCode = kmerCode ; } else if ( k == i + 1 && maxChange == nucToNum[ read[i] - 'A' ] ) { maxCnt = 1 ; } } //printf( "%d\n", j ) ; } #ifdef DEBUG printf( "+hi %d: %d %d=>%d, (%d): code=%llu\n", i, maxTo, to, maxChange, maxCnt, tmpKmerCode.GetCode() ) ; #endif if ( testCnt > 1 ) alternativeCnt += ( testCnt - 1 ) ; // TODO: if maxTo is far from i, then we may in a repeat. Try keep this base unfixed // see whether the next fixing makes sense. if ( maxTo == -1 || ( maxCnt > 1 && ( maxTo <= to || to - i + 1 < kmerLength ) ) ) { //printf( "+%s\n", read ) ; // trim //if ( maxCnt > 1 ) //{ trimStart = i ; break ; //} //else //return 0 ; } fix[i] = maxChange ; if ( maxCnt > 1 ) { // Remove the effect of the ambiguous fixing fix[i] = -2 ; ++ambiguousCnt ; } if ( maxTo >= readLength ) break ; if ( maxTo <= to ) { // There are multiple errors in the region if ( 0 ) //maxTo > i + 1 ) { // The next start search can start one place earlier //uint64_t tmp ; /*kmerCode.ShiftRi ; if ( fix[maxTo - kmerLength + 1] != -1 ) kmerCode |= ( (uint64_t)fix[maxTo - kmerLength + 1] << ( 2ull * ( kmerLength - 2 ) ) ) ; else kmerCode |= ( (uint64_t)nucToNum[ read[maxTo - kmerLength + 1] - 'A' ] << ( 2ull * ( kmerLength -2 ) ) ) ; i = maxTo - 1 ;*/ } else { kmerCode = tmpKmerCode ; kmerCode.ShiftRight( 1 ) ; i = maxTo ; } continue ; } else { // Search for next error. for ( k = to - kmerLength + 2 ; k < kmerCnt ; ++k ) if ( !storedKmer[k] ) break ; if ( k >= kmerCnt ) break ; kmerCode.Restart() ; for ( i = k - 1 + 1 ; i < k - 1 + kmerLength - 1 + 1 ; ++i ) { if ( fix[i] < 0 ) kmerCode.Append( read[i] ) ; else kmerCode.Append( numToNuc[ fix[i] ] ) ; } continue ; } } // Scan towards left //printf( "%d\n", tag ) ; if ( tag == 0 ) { // Force skip tag = -1 ; } else { if ( longestStoredKmerCnt < kmerLength ) { kmerCode.Restart() ; for ( i = tag + 1 - 1 ; i < tag + kmerLength - 1 ; ++i ) { kmerCode.Append( read[i] ) ; } kmerCode.Append( 'A' ) ; } else { // Test whether the current anchor is good int c ; j = -1 ; for ( i = tag -1 ; i < tag - 1 + kmerLength ; ++i ) kmerCode.Append( read[i] ) ; for ( c = 0 ; c < 4 ; ++c ) { if ( numToNuc[c] == read[tag + j] ) continue ; tmpKmerCode = kmerCode ; tmpKmerCode.Append( 'A' ) ; tmpKmerCode.Prepend( numToNuc[c] ) ; if ( kmers->IsIn( tmpKmerCode ) ) { // Test whether this branch makes sense int t = 0 ; for ( t = 0 ; t <= kmerLength - 1 && tag + j - t - 1 >= 0 ; ++t ) // and it is should be a very good fix { tmpKmerCode.Prepend( read[tag + j - t - 1] ) ; if ( !kmers->IsIn( tmpKmerCode ) ) break ; } if ( t > kmerLength - 1 || tag + j -t -1 < 0 ) break ; } } if ( c < 4 ) { j = 0 ; kmerCode.Restart() ; for ( i = tag + j ; i < tag + j + kmerLength ; ++i ) kmerCode.Append( read[i] ) ; } else { // Adjust the left side of the anchor for ( j = kmerLength / 2 - 1 ; j >= 0 ; --j ) { int c ; KmerCode tmpKmerCode( kmerLength ) ; kmerCode.Restart() ; for ( i = tag + j ; i < tag + j + kmerLength ; ++i ) kmerCode.Append( read[i] ) ; //printf( "%d %d %c\n", j, i, read[i - 1] ) ; for ( c = 0 ; c < 4 ; ++c ) { if ( numToNuc[c] == read[tag + j] ) continue ; tmpKmerCode = kmerCode ; tmpKmerCode.Append( 'A' ) ; tmpKmerCode.Prepend( numToNuc[c] ) ; if ( kmers->IsIn( tmpKmerCode ) ) { ++alternativeCnt ; // Test whether this branch makes sense int t = 0 ; for ( t = 0 ; t <= kmerLength / 2 && tag + j - t - 1 >= 0 ; ++t ) // and it is should be a very good fix { tmpKmerCode.Prepend( read[tag + j - t - 1] ) ; if ( !kmers->IsIn( tmpKmerCode ) ) break ; } if ( t > kmerLength / 2 ) break ; } } if ( c < 4 ) { // adjust the anchor tag = tag + j + 1 ; kmerCode.Append( 'A' ) ; break ; } } } } } //kmerCode = ( kmerCode << (uint64_t)2 ) & mask ; for ( i = tag - 1 ; i >= 0 ; ) { KmerCode fixedKmerCode( kmerCode ) ; int minTo = readLength + 1 ; int minChange = -1 ; int minCnt = 0 ; int testCnt = 0 ; from = i - 1 ; to = ( i - kmerLength + 1 < 0 ) ? 0 : ( i - kmerLength + 1 ) ; for ( j = 0 ; j < 4 ; ++j ) { //kmerCode = ( fixedKmerCode >> (uint64_t)2 ) & ( mask >> 2ull ) ; //printf( "1.%llu\n", kmerCode.GetCode() ) ; //kmerCode = kmerCode | ( ((uint64_t)j) << (uint64_t)(2 * kmerLength - 2 ) ) ; kmerCode = fixedKmerCode ; kmerCode.Prepend( numToNuc[j] ) ; //printf( "2.%llu\n", kmerCode.GetCode() ) ; //printf( "%d %lld %lld\n", j, (long long int)kmerCode, (long long int)fixedKmerCode ) ; if ( !kmers->IsIn( kmerCode ) ) continue ; if ( minTo == tag + 1 ) minTo = i ; ++testCnt ; // How many kmers this change can fix for ( k = from ; k >= to ; --k ) { kmerCode.Prepend( read[k] ) ; if ( !kmers->IsIn( kmerCode ) ) break ; } // try extension if ( k < to && to == 0 ) { int l, m ; for ( m = 0 ; m < kmerLength - 1 - ( from - to + 1 ) ; ++m ) { for ( l = 0 ; l < 4 ; ++l ) { KmerCode tmpKmerCode( kmerCode ) ; tmpKmerCode.Prepend( numToNuc[l] ) ; if ( kmers->IsIn( tmpKmerCode ) ) break ; } if ( l < 4 ) { //printf( "hi\n" ) ; kmerCode.Prepend( numToNuc[l] ) ; --k ; } } } if ( k < minTo ) { minCnt = 1 ; minTo = k ; minChange = j ; tmpKmerCode = kmerCode ; } else if ( k == minTo ) { ++minCnt ; if ( k == i - 1 && j == nucToNum[ read[i] - 'A' ] ) { minCnt = 1 ; minChange = j ; tmpKmerCode = kmerCode ; } else if ( k == i -1 && minChange == nucToNum[ read[i] - 'A' ] ) { minCnt = 1 ; } } } #ifdef DEBUG printf( "-hi %d: %d %d=>%d, (%d)\n", i, minTo, to, minChange, minCnt ) ; #endif if ( testCnt > 1 ) alternativeCnt += ( testCnt - 1 ) ; if ( minTo == readLength + 1 || ( minCnt > 1 && ( minTo >= to || i - to + 1 < kmerLength ) ) ) { //printf( "-%s\n", read ) ; //return -1 ; badPrefix = i + 1 ; break ; } //printf( "---%d %d\n", minChange, nucToNum[read[0] - 'A'] ) ; fix[i] = minChange ; if ( minCnt > 1 ) { fix[i] = -2 ; ++ambiguousCnt ; } if ( minTo < 0 ) break ; if ( minTo >= to ) { /*if ( maxTo > i + 1 ) { // The next start search can start one place earlier kmerCode = tmpKmerCode >> 2ull ; i = maxTo - 1 ; } else*/ //kmerCode = tmpKmerCode << 2ull ; kmerCode = tmpKmerCode ; kmerCode.Append( 'A' ) ; //printf( "i=>minTo: %d=>%d\n", i, minTo ) ; i = minTo ; continue ; } else { // Search for next error. for ( k = to - 1 ; k >= 0 ; --k ) if ( !storedKmer[k] ) break ; if ( k < 0 ) break ; kmerCode.Restart() ; for ( i = k + 2 - 1 ; i < k + 2 + kmerLength - 1 - 1 ; ++i ) { if ( fix[i] < 0 ) kmerCode.Append( read[i] ) ; else kmerCode.Append( numToNuc[ fix[i] ] ) ; } i = k + 1 - 1 ; kmerCode.Append( 'A' ) ; continue ; } /*{ // This happens when the distance between two errors is just of kmerLength //printf( "%llu\n", tmpKmerCode.GetCode() ) ; kmerCode = tmpKmerCode ; i = minTo ; }*/ } #ifdef DEBUG printf( "fix: ") ; for ( i = 0 ; i < readLength; ++i ) { if ( fix[i] == -1 ) printf( "5" ) ; else if ( fix[i] == -2 ) printf( "6" ) ; else printf( "%d", fix[i] ) ; } printf( "\n" ) ; #endif int ret = 0 ; double correctCnt = 0 ; //printf( "%s\n%d\n", read, ret ) ; /*for ( i = badPrefix ; i < trimStart ; ++i ) { if ( trusted[i] && fix[i] != -1 ) return -1 ; if ( fix[i] == -1 || read[i] == numToNuc[ fix[i] ] || read[i] == 'N' ) continue ; ++correctCnt ; if ( correctCnt > maxCorrection ) { // There are too many corrections, adjust the trimStart for ( j = i - 1 ; j >= badPrefix ; --j ) { if ( fix[j] == -1 || read[j] == numToNuc[ fix[j] ] ) break ; } trimStart = j + 1 ; if ( trimStart == badPrefix ) return -1 ; correctCnt = 0 ; for ( i = badPrefix ; i < trimStart ; ++i ) { if ( fix[i] == -1 || read[i] == numToNuc[ fix[i] ] ) continue ; ++correctCnt ; } if ( correctCnt > maxCorrection - 1 ) return -1 ; break ; } }*/ bool overCorrected = false ; int adjustMaxCor = 0 ; for ( i = 0 ; i < readLength ; ++i ) if ( trusted[i] && fix[i] != -1 ) break ; if ( alternativeCnt == 0 && i >= readLength ) adjustMaxCor = 1 ; for ( i = 0 ; i < readLength ; ++i ) { if ( i >= kmerLength && ( fix[i - kmerLength] >= 0 && read[i - kmerLength] != 'N' ) ) { if ( qual[0] != '\0' && qual[i - kmerLength] <= badQuality ) correctCnt -= 0.5 ; else --correctCnt ; } if ( fix[i] >= 0 && read[i] != 'N' ) { if ( qual[0] != '\0' && qual[i] <= badQuality ) correctCnt += 0.5 ; else ++correctCnt ; } int tmp = maxCorrection ; if ( i >= kmerLength && i + kmerLength - 1 < readLength ) tmp += adjustMaxCor ; if ( correctCnt > tmp ) //maxCorrection ) { if ( fix[i] >= 0 ) { fix[i] = 4 ; overCorrected = true ; } } } if ( overCorrected ) { for ( i = 0 ; i < readLength ; ++i ) { if ( fix[i] == 4 ) { fix[i] = -1 ; int tag = i ; for ( j = i - 1 ; j >= 0 && j >= tag - kmerLength + 1 ; --j ) if ( fix[j] >= 0 ) { fix[j] = -1 ; tag = j ; } tag = i ; for ( j = i + 1 ; j < readLength && j <= tag + kmerLength - 1 ; ++j ) if ( fix[j] >= 0 ) { fix[j] = -1 ; tag = j ; } i = j ; } } } /*if ( correctCnt > MAX_CORRECTION ) { // Find the point where the correct count become to increase rapidly. //return 0 ; int correctPartialSum[1000] ; correctPartialSum[0] = 0 ; for ( i = 0 ; i < trimStart ; ++i ) { correctPartialSum[i + 1] = correctPartialSum[i - 1] + ( ( fix[i] == -1 || read[i] == numToNuc[ fix[i] ] ) ? 0 : 1 ) ; } for ( i = trimStart - 1 ; i >= 0 ; --i ) { } //int cnt = 0 ; //for ( i = 0 ; i < trimStart ; ++i ) }*/ #ifdef DEBUG printf( "prefix=%d suffix=%d\n", badPrefix, trimStart ) ; printf( "fix: ") ; for ( i = 0 ; i < readLength; ++i ) { if ( fix[i] == -1 ) printf( "5" ) ; else if ( fix[i] == -2 ) printf( "6" ) ; else printf( "%d", fix[i] ) ; } printf( "\n" ) ; #endif for ( i = badPrefix ; i < trimStart ; ++i ) { if ( fix[i] < 0 ) continue ; if ( read[i] != numToNuc[ fix[i] ] ) { read[i] = numToNuc[ fix[i] ] ; //if ( read[i] != 'N' ) if ( qual[0] != '\0' && SET_NEW_QUAL >= 0 ) qual[i] = (char)SET_NEW_QUAL ; ++ret ; } } //printf( "%d %d\n", ret, trimStart ) ; //badPrefix = 0 ; badSuffix = readLength - trimStart ; //if ( ALLOW_TRIMMING ) // else we do partial correction // read[ trimStart ] = '\0' ; //ret += trimmed ; /*if ( !strcmp( read, "GTAAACGCCTTATCCGGCCTACGGAGGGTGCGGGAATTTGTAGGCCTGATAAGACGCGCAAGCGTCGCATCAGGCAGTCGGCACGGTTGCCGGATGCAGCG" ) ) { printf( "## %d\n", i ) ; exit( 1 ) ; }*/ if ( ret == 0 && badPrefix == 0 && badSuffix == 0 && ambiguousCnt > 0 ) return -1 ; if ( ret == 0 && badPrefix == 0 && badSuffix == 0 && overCorrected ) return -1 ; return ret ; }
void MainScene::onEnter() { CCScene::onEnter(); // Create physical world CreatePhysics(); // Add a color background. This will make it easier on the eyes. addChild(SunBackgroundLayer::create()); // Adding the debug lines so that we can draw the path followed. DebugLinesLayer* linesLayer = DebugLinesLayer::create(); assert(linesLayer != NULL); addChild(DebugLinesLayer::create()); linesLayer->setTag(TAG_DEBUG_LINES); addChild(linesLayer); // Grid // This should be at the bottom of the layer stack. GridLayer* gridLayer = GridLayer::create(5); assert(gridLayer != NULL); gridLayer->setTag(TAG_DEBUG_GRID); addChild(gridLayer); // Box2d Debug Box2DDebugDrawLayer* debugLayer = Box2DDebugDrawLayer::create(_world); assert(debugLayer != NULL); debugLayer->setTag(TAG_DEBUG_BOX2D); addChild(debugLayer); // Asteroids _asteroidLayer = SpriteBatchLayer::create("Asteroids_ImgData.png", "Asteroids_ImgData.plist"); assert(_asteroidLayer != NULL); addChild(_asteroidLayer); // Space Ships _shipLayer = SpriteBatchLayer::create("EntitySpriteImages.png", "EntitySpriteImages.plist"); assert(_shipLayer != NULL); addChild(_shipLayer); // Touch Input addChild(TapDragPinchInput::create(this)); // User Controls addChild(PlayerGameControlsLayer::create()); // Create the Anchor CreateAnchor(); // Asteroids CreateAsteroids(); // Populate physical world CreateEntity(); // Create the sensor grid CreateSensors(); // Contact Counts // addChild(GraphSensorContactLayer::create()); // Register for events Notifier::Instance().Attach(this, NE_VIEWPORT_CHANGED); Notifier::Instance().Attach(this, NE_GAME_COMMAND_ZOOM_IN); Notifier::Instance().Attach(this, NE_GAME_COMMAND_ZOOM_OUT); Notifier::Instance().Attach(this, NE_GAME_COMMAND_TRACK); // Kickstart all sizes ViewportChanged(); }