Region* Instrument::GetFirstRegion() { if (!pRegions) LoadRegions(); if (!pRegions) return NULL; RegionsIterator = pRegions->begin(); return (RegionsIterator != pRegions->end()) ? *RegionsIterator : NULL; }
void CConsole::Process( int c ) { char outputline[128], temp[1024]; bool kill = false; int indexcount = 0; int j; int keyresp; CSocket *tSock = NULL; if( c == '*' ) { if( cwmWorldState->GetSecure() ) messageLoop << "Secure mode disabled. Press ? for a commands list"; else messageLoop << "Secure mode re-enabled"; cwmWorldState->SetSecure( !cwmWorldState->GetSecure() ); return; } else { if( cwmWorldState->GetSecure() ) { messageLoop << "Secure mode prevents keyboard commands! Press '*' to disable"; return; } JSCONSOLEKEYMAP_ITERATOR toFind = JSKeyHandler.find( c ); if( toFind != JSKeyHandler.end() ) { if( toFind->second.isEnabled ) { cScript *toExecute = JSMapping->GetScript( toFind->second.scriptID ); if( toExecute != NULL ) { // All commands that execute are of the form: command_commandname (to avoid possible clashes) #if defined( UOX_DEBUG_MODE ) Print( "Executing JS keystroke %c %s\n", c, toFind->second.cmdName.c_str() ); #endif toExecute->CallParticularEvent( toFind->second.cmdName.c_str(), NULL, 0 ); } return; } } switch( c ) { case '!': // Force server to save accounts file messageLoop << "CMD: Saving Accounts... "; Accounts->Save(); messageLoop << MSG_PRINTDONE; break; case '@': // Force server to save all files.(Manual save) messageLoop << MSG_WORLDSAVE; break; case 'Y': std::cout << "System: "; while( !kill ) { keyresp = cl_getch(); switch( keyresp ) { case -1: // no key pressed case 0: break; case 0x1B: memset( outputline, 0x00, sizeof( outputline ) ); indexcount = 0; kill = true; std::cout << std::endl; messageLoop << "CMD: System broadcast canceled."; break; case 0x08: --indexcount; if( indexcount < 0 ) indexcount = 0; else std::cout << "\b \b"; break; case 0x0A: case 0x0D: outputline[indexcount] = 0; messageLoop.NewMessage( MSG_CONSOLEBCAST, outputline ); indexcount = 0; kill = true; std::cout << std::endl; sprintf( temp, "CMD: System broadcast sent message \"%s\"", outputline ); memset( outputline, 0x00, sizeof( outputline ) ); messageLoop << temp; break; default: if( static_cast<size_t>(indexcount) < sizeof( outputline ) ) { outputline[indexcount++] = (UI08)(keyresp); std::cout << (char)keyresp; } break; } keyresp = 0x00; } break; case '[': { // We want to group all the contents of the multimap container numerically by group. We rely on the self ordering in the multimap implementation to do this. messageLoop << " "; messageLoop << "Auto-AddMenu Statistics"; messageLoop << " "; char szBuffer[128]; // We need to get an iteration into the map first of all the top level ULONGs then we can get an equal range. std::map< UI32, UI08 > localMap; localMap.clear(); for( ADDMENUMAP_CITERATOR CJ = g_mmapAddMenuMap.begin(); CJ != g_mmapAddMenuMap.end(); CJ++ ) { // check to see if the group id has been checked already if( localMap.find( CJ->first ) == localMap.end() ) { localMap.insert( std::make_pair( CJ->first, 0 ) ); memset( szBuffer, 0x00, sizeof( szBuffer ) ); sprintf( szBuffer, "AddMenuGroup %lu:", CJ->first ); messageLoop << szBuffer; std::pair< ADDMENUMAP_CITERATOR, ADDMENUMAP_CITERATOR > pairRange = g_mmapAddMenuMap.equal_range( CJ->first ); int count = 0; for( ADDMENUMAP_CITERATOR CI=pairRange.first;CI != pairRange.second; CI++ ) { count++; } memset( szBuffer, 0x00, sizeof( szBuffer ) ); sprintf( szBuffer, " Found %i Auto-AddMenu Item(s).", count ); messageLoop << szBuffer; } } messageLoop << MSG_SECTIONBEGIN; break; } case '<': messageLoop << "Function not implemented."; break; case '>': messageLoop << "Function not implemented."; break; case 0x1B: case 'Q': messageLoop << MSG_SECTIONBEGIN; messageLoop << "CMD: Immediate Shutdown initialized!"; messageLoop << MSG_SHUTDOWN; break; case '0': if( !cwmWorldState->GetReloadingScripts() ) { cwmWorldState->SetReloadingScripts( true ); // Reload all the files. If there are issues with these files change the order reloaded from here first. cwmWorldState->ServerData()->Load(); messageLoop << "CMD: Loading All"; messageLoop << " Server INI... "; // Reload accounts, and update Access.adm if new accounts available. messageLoop << " Loading Accounts... "; Accounts->Load(); messageLoop << MSG_PRINTDONE; // Reload Region Files messageLoop << " Loading Regions... "; UnloadRegions(); LoadRegions(); messageLoop << MSG_PRINTDONE; // Reload the serve spawn regions messageLoop << " Loading Spawn Regions... "; UnloadSpawnRegions(); LoadSpawnRegions(); messageLoop << MSG_PRINTDONE; // Reload the server command list messageLoop << " Loading commands... "; Commands->Load(); messageLoop << MSG_PRINTDONE; // Reload DFN's messageLoop << " Loading Server DFN... "; FileLookup->Reload(); LoadTeleportLocations(); messageLoop << MSG_PRINTDONE; // messageLoop access is REQUIRED, as this function is executing in a different thread, so we need thread safety messageLoop << " Loading JSE Scripts... "; // Reload the current Spells messageLoop << " Loading spells... "; Magic->LoadScript(); messageLoop << MSG_PRINTDONE; // Reload the HTML output templates messageLoop << " Loading HTML Templates... "; HTMLTemplates->Unload(); HTMLTemplates->Load(); cwmWorldState->SetReloadingScripts( false ); messageLoop << MSG_PRINTDONE; } else messageLoop << "Server can only load one script at a time"; break; case 'T': // Timed shut down(10 minutes) messageLoop << "CMD: 10 Minute Server Shutdown Announced(Timed)"; cwmWorldState->SetEndTime( BuildTimeValue( 600 ) ); endmessage(0); break; case 'D': // Disconnect account 0 (useful when client crashes) for( tSock = Network->LastSocket(); tSock != NULL; tSock = Network->PrevSocket() ) { if( tSock->AcctNo() == 0 ) Network->Disconnect( tSock ); } messageLoop << "CMD: Socket Disconnected(Account 0)."; break; case 'K': { for( tSock = Network->FirstSocket(); !Network->FinishedSockets(); tSock = Network->NextSocket() ) { Network->Disconnect( tSock ); } messageLoop << "CMD: All Connections Closed."; } break; case 'P': { UI32 networkTimeCount = cwmWorldState->ServerProfile()->NetworkTimeCount(); UI32 timerTimeCount = cwmWorldState->ServerProfile()->TimerTimeCount(); UI32 autoTimeCount = cwmWorldState->ServerProfile()->AutoTimeCount(); UI32 loopTimeCount = cwmWorldState->ServerProfile()->LoopTimeCount(); // 1/13/2003 - Dreoth - Log Performance Information enhancements LogEcho( true ); Log( "--- Starting Performance Dump ---", "performance.log"); Log( "\tPerformace Dump:", "performance.log"); Log( "\tNetwork code: %.2fmsec [%i samples]", "performance.log", (R32)((R32)cwmWorldState->ServerProfile()->NetworkTime()/(R32)networkTimeCount), networkTimeCount); Log( "\tTimer code: %.2fmsec [%i samples]", "performance.log", (R32)((R32)cwmWorldState->ServerProfile()->TimerTime()/(R32)timerTimeCount), timerTimeCount); Log( "\tAuto code: %.2fmsec [%i samples]", "performance.log", (R32)((R32)cwmWorldState->ServerProfile()->AutoTime()/(R32)autoTimeCount), autoTimeCount); Log( "\tLoop Time: %.2fmsec [%i samples]", "performance.log", (R32)((R32)cwmWorldState->ServerProfile()->LoopTime()/(R32)loopTimeCount), loopTimeCount); ObjectFactory *ourFac = ObjectFactory::getSingletonPtr(); Log( "\tCharacters: %i/%i - Items: %i/%i (Dynamic)", "performance.log", ourFac->CountOfObjects( OT_CHAR ), ourFac->SizeOfObjects( OT_CHAR ), ourFac->CountOfObjects( OT_ITEM ), ourFac->SizeOfObjects( OT_ITEM ) ); Log( "\tSimulation Cycles: %f per sec", "performance.log", (1000.0*(1.0/(R32)((R32)cwmWorldState->ServerProfile()->LoopTime()/(R32)loopTimeCount)))); Log( "\tBytes sent: %i", "performance.log", cwmWorldState->ServerProfile()->GlobalSent()); Log( "\tBytes Received: %i", "performance.log", cwmWorldState->ServerProfile()->GlobalReceived()); Log( "--- Performance Dump Complete ---", "performance.log"); LogEcho( false ); break; } case 'W': // Display logged in chars messageLoop << "CMD: Current Users in the World:"; j = 0; CSocket *iSock; Network->PushConn(); for( iSock = Network->FirstSocket(); !Network->FinishedSockets(); iSock = Network->NextSocket() ) { ++j; CChar *mChar = iSock->CurrcharObj(); sprintf( temp, " %i) %s [%x %x %x %x]", j - 1, mChar->GetName().c_str(), mChar->GetSerial( 1 ), mChar->GetSerial( 2 ), mChar->GetSerial( 3 ), mChar->GetSerial( 4 ) ); messageLoop << temp; } Network->PopConn(); sprintf( temp, " Total users online: %i", j ); messageLoop << temp; break; case 'M': size_t tmp, total; total = 0; tmp = 0; messageLoop << "CMD: UOX Memory Information:"; messageLoop << " Cache:"; sprintf( temp, " Tiles: %u bytes", Map->GetTileMem() ); messageLoop << temp; sprintf( temp, " Multis: %u bytes", Map->GetMultisMem() ); messageLoop << temp; size_t m, n; m = ObjectFactory::getSingleton().SizeOfObjects( OT_CHAR ); total += tmp = m + m*sizeof( CTEffect ) + m*sizeof(char) + m*sizeof(int)*5; sprintf( temp, " Characters: %u bytes [%u chars ( %u allocated )]", tmp, ObjectFactory::getSingleton().CountOfObjects( OT_CHAR ), m ); messageLoop << temp; n = ObjectFactory::getSingleton().SizeOfObjects( OT_ITEM ); total += tmp = n + n * sizeof( int ) * 4; sprintf( temp, " Items: %u bytes [%u items ( %u allocated )]", tmp, ObjectFactory::getSingleton().CountOfObjects( OT_ITEM ), n ); messageLoop << temp; sprintf( temp, " You save I: %i & C: %i bytes!", m * sizeof(CItem) - ObjectFactory::getSingleton().CountOfObjects( OT_ITEM ), m * sizeof( CChar ) - ObjectFactory::getSingleton().CountOfObjects( OT_CHAR ) ); total += tmp = 69 * sizeof( SpellInfo ); sprintf( temp, " Spells: %i bytes", tmp ); messageLoop << " Sizes:"; sprintf( temp, " CItem : %i bytes", sizeof( CItem ) ); messageLoop << temp; sprintf( temp, " CChar : %i bytes", sizeof( CChar ) ); messageLoop << temp; sprintf( temp, " TEffect: %i bytes (%i total)", sizeof( CTEffect ), sizeof( CTEffect ) * cwmWorldState->tempEffects.Num() ); messageLoop << temp; total += tmp = Map->GetTileMem() + Map->GetMultisMem(); sprintf( temp, " Approximate Total: %i bytes", total ); messageLoop << temp; break; case '?': messageLoop << MSG_SECTIONBEGIN; messageLoop << "Console commands:"; messageLoop << MSG_SECTIONBEGIN; messageLoop << " ShardOP:"; messageLoop << " * - Lock/Unlock Console ? - Commands list(this)"; messageLoop << " C - Configuration H - Unused"; messageLoop << " Y - Console Broadcast Q - Quit/Exit "; messageLoop << " Load Commands:"; messageLoop << " 1 - Ini 2 - Accounts"; messageLoop << " 3 - Regions 4 - Spawn Regions"; messageLoop << " 5 - Spells 6 - Commands"; messageLoop << " 7 - Dfn's 8 - JavaScript"; messageLoop << " 9 - HTML Templates 0 - ALL(1-9)"; messageLoop << " Save Commands:"; messageLoop << " ! - Accounts @ - World(w/AccountImport)"; messageLoop << " # - Unused $ - Unused"; messageLoop << " % - Unused ^ - Unused"; messageLoop << " & - Unused ( - Unused"; messageLoop << " ) - Unused"; messageLoop << " Server Maintenence:"; messageLoop << " P - Performance W - Characters Online"; messageLoop << " M - Memory Information T - 10 Minute Shutdown"; messageLoop << " V - Dump Lookups(Devs) F - Display Priority Maps"; messageLoop << " Network Maintenence:"; messageLoop << " D - Disconnect Acct0 K - Disconnect All"; messageLoop << " Z - Socket Logging "; messageLoop << MSG_SECTIONBEGIN; break; case 'v': case 'V': // Dump look up data to files so developers working with extending the ini will have a table to use messageLoop << "| CMD: Creating Server.scp and Uox3.ini Tag Lookup files(For Developers)...."; cwmWorldState->ServerData()->dumpLookup( 0 ); cwmWorldState->ServerData()->save( "./uox.tst.ini" ); messageLoop << MSG_PRINTDONE; break; case 'z': case 'Z': { // Log socket activity Network->PushConn(); bool loggingEnabled = false; CSocket *snSock = Network->FirstSocket(); if( snSock != NULL ) loggingEnabled = !snSock->Logging(); for( ; !Network->FinishedSockets(); snSock = Network->NextSocket() ) { if( snSock != NULL ) snSock->Logging( !snSock->Logging() ); } Network->PopConn(); if( loggingEnabled ) messageLoop << "CMD: Network Logging Enabled."; else messageLoop << "CMD: Network Logging Disabled."; break; } case 'c': case 'C': // Shows a configuration header DisplaySettings(); break; case 'f': case 'F': FileLookup->DisplayPriorityMap(); break; default: sprintf( temp, "Key \'%c\' [%i] does not perform a function", (char)c, c ); messageLoop << temp; break; } } }
void GCContent::OutputGCContent(String & reference, int windowSize, String &gcContentFile, String ®ionFile, bool invertRegion) { GenomeSequence genome; bool memoryMap = false; genome.setReferenceName(reference.c_str()); if (genome.open()) { fprintf(stderr, "Failed to open reference index and is creating one...\n"); if(genome.create()) error("Failed to create reference index!\n"); } genome.useMemoryMap(memoryMap); if(genome.open()) error("Open reference failed...!\n"); LoadRegions(regionFile, genome, invertRegion); if (regionIndicator.size() == 0) { printf("Calculate GC file for whole genome; "); } else { printf("Calculate GC file for specified region ( %u bp ); ", (unsigned int) regionIndicator.size()); } printf("reference genome has %u bp\n", genome.sequenceLength()); FILE * fh = fopen(gcContentFile.c_str(), "wb"); int gccnt = 0; int atcnt = 0; uint8_t gc = 0; uint32_t gcContentDist[101]; for(int i=0; i<101; i++) gcContentDist[i] = 0; for(int i=0; i<windowSize; i++) { if(toupper((genome)[i]) == 'G' || toupper((genome)[i]) == 'C') gccnt++; if(toupper((genome)[i]) == 'A' || toupper((genome)[i]) == 'T') atcnt++; } for(int i=0; i<windowSize/2; i++) { fwrite(&gc, 1, sizeof(uint8_t), fh); gcContentDist[gc]++; } for(uint32_t i=windowSize; i<genome.sequenceLength(); i++) { if(toupper((genome)[i])=='G' || toupper((genome)[i]) == 'C') gccnt++; if(toupper((genome)[i-windowSize]) == 'G' ||toupper((genome)[i-windowSize]) == 'C') gccnt--; if(toupper((genome)[i])=='A' || toupper((genome)[i]) == 'T') atcnt++; if(toupper((genome)[i-windowSize]) == 'A' ||toupper((genome)[i-windowSize]) == 'T') atcnt--; if(gccnt+atcnt<windowSize) gc = 0; else gc = floor(double(gccnt)/(gccnt+atcnt)*100+0.5); fwrite(&gc, 1, sizeof(uint8_t), fh); if(regionIndicator.size() > 0 && regionIndicator[i]==false) gc = 0; gcContentDist[gc]++; } gc = 0; for(int i=0; i<windowSize/2; i++) { fwrite(&gc, 1, sizeof(uint8_t), fh); gcContentDist[gc]++; } fwrite(&gcContentDist, 1, sizeof(gcContentDist), fh); printf("GCPercentage\tFrequency\n"); for(int i=0; i<101; i++) printf("%d\t%u\n", i, gcContentDist[i]); fclose(fh); }
int Process(etPMode PMode, // processing mode etFMode FMode, // output format mode int MovAvgFilter, // apply this moving average window size filter int BaselineFilter, // baseline normalisation window size char *pszTrackName, // UCSC track name double DyadratioThres, // dyad grooves must be at least this ratio to background double Dyad2ratioThres, // immediately flanking grooves must be at least this ratio to background double Dyad3ratioThres, // remainder of flanking grooves must be at least this ration to background char *pszInGenomefile, // bioseq genome file char *pszInConfFile, // file containing conformation characteristics char *pszOutFile, // where to write nucleosome predictions char *pszInclRegionFile, // only report predicted nucleosomes if intersecting with regions in this file int OfsLoci, // offset region start loci by this many nt int DeltaLen, // change region length by this many nt int TruncLength) // truncate regions to be a maximum of this length { int Rslt = 0; bool bRegionFilter; // set true if region filtering int SeqIdx; int WindLen = 147; // nucleosomes are this length - agreed :-) int ChkGroove[13]; // to hold dyad (ChkGroove[6]) and +/- 6 at approx decimer (depends on twist) offsets int DecIdx; // index into ChkGroove, incr/decr every 360 degree twist int GrooveCnt; // to hold number of groove values contributing to current ChkGroove[DecIdx] so average can be calculated int AccumTwist; // to hold accumulated twist relative to dyad int ChkTwist; // AccumTwist % 360 used to determine if minor groove back on same plane as at dyad int BaseLineValueSum; double BaseLineAv; double ChromBaseLineSum; int NumBaseLines; Init(); m_PMode = PMode; m_FMode = FMode; strcpy(m_szTrackName,pszTrackName); m_DyadratioThres = DyadratioThres; m_Dyad2ratioThres = Dyad2ratioThres; m_Dyad3ratioThres = Dyad3ratioThres; if((m_pszOutBuff = new char [cAllocOutBuff])==NULL) { gDiagnostics.DiagOut(eDLFatal,gszProcName,"Unable to alloc memory (%d bytes requested) for bufering output results",cAllocOutBuff); Reset(); return(eBSFerrMem); } m_AllocdOutBuff = cAllocOutBuff; if((m_pBioSeqFile = new CBioSeqFile) == NULL) { gDiagnostics.DiagOut(eDLFatal,gszProcName,"Unable to instantiate CBioSeqFile object"); Reset(); return(eBSFerrObj); } if((Rslt = m_pBioSeqFile->Open(pszInGenomefile))!=eBSFSuccess) { while(m_pBioSeqFile->NumErrMsgs()) gDiagnostics.DiagOut(eDLFatal,gszProcName,m_pBioSeqFile->GetErrMsg()); gDiagnostics.DiagOut(eDLFatal,gszProcName,"Unable to open genome assembly sequence file '%s'",pszInGenomefile); Reset(); return(Rslt); } if(pszInclRegionFile != NULL && pszInclRegionFile[0] != '\0') { if((Rslt = LoadRegions(pszInclRegionFile,OfsLoci,DeltaLen,TruncLength))!=eBSFSuccess) { Reset(); return(Rslt); } bRegionFilter = true; } else bRegionFilter = false; if((m_pTwister = new CTwister)==NULL) { gDiagnostics.DiagOut(eDLFatal,"ProcessFastaStruct","Unable to create CTwister object"); Reset(); return(eBSFerrObj); } if((Rslt = m_pTwister->LoadStructParams(pszInConfFile)) < eBSFSuccess) { while(m_pTwister->NumErrMsgs()) gDiagnostics.DiagOut(eDLFatal,gszProcName,m_pTwister->GetErrMsg()); gDiagnostics.DiagOut(eDLFatal,"ProcessFastaStruct","LoadStructParams(%s) failed",pszInConfFile); Reset(); return(Rslt); } #ifdef _WIN32 if((m_hOutFile = open(pszOutFile, _O_RDWR | _O_BINARY | _O_SEQUENTIAL | _O_CREAT | _O_TRUNC, _S_IREAD | _S_IWRITE ))==-1) #else if((m_hOutFile = open(pszOutFile, O_RDWR | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE ))==-1) #endif { gDiagnostics.DiagOut(eDLFatal,gszProcName,"Unable to create predicted nucleosome output file: %s - %s",pszOutFile,strerror(errno)); Reset(); return(eBSFerrCreateFile); } if(FMode == eFMbedGraphDyads || FMode == eFMbedGraphNucs) { m_UsedOutBuff = sprintf(m_pszOutBuff, "track type=bedGraph name=\"%s\" description=\"%s\" visibility=full color=200,100,0 altColor=0,100,200 priority=20 autoScale=on alwaysZero=on graphType=bar smoothingWindow=4\n", pszTrackName,pszTrackName); CUtility::SafeWrite(m_hOutFile,m_pszOutBuff,m_UsedOutBuff); m_UsedOutBuff = 0; } // iterate over chromosomes tBSFEntryID ChromID = 0; while((ChromID = m_pBioSeqFile->Next(ChromID))>0) { m_pBioSeqFile->GetName(ChromID,sizeof(m_szCurChrom),m_szCurChrom); gDiagnostics.DiagOut(eDLInfo,gszProcName,"Processing %s...",m_szCurChrom); m_ChromSeqLen = m_pBioSeqFile->GetDataLen(ChromID); if(m_pChromSeq == NULL || m_ChromSeqLen > m_AllocdChromSeq) { if(m_pChromSeq != NULL) { delete m_pChromSeq; m_pChromSeq = NULL; } int AllocLen = m_ChromSeqLen + m_ChromSeqLen/10; if((m_pChromSeq = new unsigned char [AllocLen])==NULL) { gDiagnostics.DiagOut(eDLFatal,gszProcName,"Unable to alloc memory (%d requested) for holding raw sequence data",AllocLen); Reset(); return(eBSFerrMem); } m_AllocdChromSeq = AllocLen; if(m_pScores != NULL) { delete m_pScores; m_pScores = NULL; } if((m_pScores = new int [AllocLen])==NULL) { gDiagnostics.DiagOut(eDLFatal,gszProcName,"Unable to allocate memory (%d bytes) for holding scores",AllocLen); Reset(); return(eBSFerrMem); } if(m_pConfGroove != NULL) { delete m_pConfGroove; m_pConfGroove = NULL; } if((m_pConfGroove = new int [AllocLen])==NULL) { gDiagnostics.DiagOut(eDLFatal,gszProcName,"Unable to allocate memory (%d bytes) for holding minor groove conformation values",AllocLen); Reset(); return(eBSFerrMem); } if(m_pConfTwist != NULL) { delete m_pConfTwist; m_pConfTwist = NULL; } if((m_pConfTwist = new int [AllocLen])==NULL) { gDiagnostics.DiagOut(eDLFatal,gszProcName,"Unable to allocate memory (%d bytes) for holding rotational twist conformation values",AllocLen); Reset(); return(eBSFerrMem); } } if((Rslt=m_pBioSeqFile->GetData(ChromID,eSeqBaseType,0,m_pChromSeq,m_ChromSeqLen)) != m_ChromSeqLen) { gDiagnostics.DiagOut(eDLFatal,gszProcName,"Loading sequence of length %d failed from chrom: %s file: '%s'",m_ChromSeqLen,m_szCurChrom,pszInGenomefile); Reset(); return(Rslt); } // remove any repeat masking and randomly substitute bases for eBaseN's - not expecting too many of these say's he hopefully! etSeqBase *pSeq = m_pChromSeq; for(SeqIdx = 0; SeqIdx < m_ChromSeqLen; SeqIdx++,pSeq++) if((*pSeq &= ~cRptMskFlg) > eBaseT) *pSeq = rand() % 4; if((Rslt = m_pTwister->GetSequenceConformation(eSSminorgroove, // process for this conformational parameter 0, // initial starting offset (0..n) in pSeq 0, // number of steps (0 for all) to process starting at pSeq[iStartPsn]|pSeq[iStartPsn+1] m_ChromSeqLen, // total length of sequence m_pChromSeq, // sequence to be processed m_pConfGroove))!=eBSFSuccess) // where to return step conformational values { gDiagnostics.DiagOut(eDLFatal,"GetSequenceConformation","minor groove failed"); Reset(); return(Rslt); } if((Rslt = m_pTwister->GetSequenceConformation(eSStwist, // process for this conformational parameter 0, // initial starting offset (0..n) in pSeq 0, // number of steps (0 for all) to process starting at pSeq[iStartPsn]|pSeq[iStartPsn+1] m_ChromSeqLen, // total length of sequence m_pChromSeq, // sequence to be processed m_pConfTwist))!=eBSFSuccess) // where to return step conformational values { gDiagnostics.DiagOut(eDLFatal,"GetSequenceConformation","rotational twist failed"); Reset(); return(Rslt); } memset(m_pScores,0,m_ChromSeqLen * sizeof(int)); // reset all scores back to minimum // establish the baseline conformational characteristic value over initial window which is centered around the WindLen window // the baseline will be updated as the putative dyad is slid along the chromosome int *pConfGroove; int *pBaseLineWin5; int *pBaseLineWin3; int *pConfTwist; int BaseLineWin = min(5 * WindLen,m_ChromSeqLen); BaseLineValueSum = 0; pBaseLineWin3 = m_pConfGroove; for(SeqIdx = 0; SeqIdx < BaseLineWin; SeqIdx++) BaseLineValueSum += *pBaseLineWin3++; double BestMaxRatio = 0.0f; double BestMinRatio = 10000.0f; int DyadFirstOfs = 73; int DyadLastOfs = m_ChromSeqLen - 73; m_ChromPutDyads = 0; ChromBaseLineSum = 0.0; NumBaseLines = 0; pBaseLineWin5 = m_pConfGroove; for(SeqIdx = DyadFirstOfs; SeqIdx < DyadLastOfs; SeqIdx++) { if(SeqIdx > BaseLineWin/2 && SeqIdx < (m_ChromSeqLen - (BaseLineWin+1)/2)) { BaseLineValueSum -= *pBaseLineWin5++; BaseLineValueSum += *pBaseLineWin3++; } BaseLineAv = (double)BaseLineValueSum/BaseLineWin; ChromBaseLineSum += BaseLineAv/10000.0f; NumBaseLines += 1; if(bRegionFilter && !InAnyRegion(ChromID,SeqIdx-74,SeqIdx+73,0)) continue; DecIdx = 6; pConfGroove = &m_pConfGroove[SeqIdx]; ChkGroove[DecIdx++] = *pConfGroove++; m_DyadRatio = (double)ChkGroove[6]/BaseLineAv; if(m_DyadRatio < DyadratioThres) continue; pConfTwist = &m_pConfTwist[SeqIdx+1]; AccumTwist = *pConfTwist; ChkGroove[DecIdx] = 0; GrooveCnt = 0; // iterate over bases to right of putative dyad and every rotation of the dsDNA get the minor groove int Bases = 1; while(DecIdx <= 12) { Bases += 1; pConfTwist += 1; pConfGroove += 1; AccumTwist += *pConfTwist; ChkTwist = AccumTwist % 3600000; if(ChkTwist >= 3300000 || ChkTwist <= 300000) { ChkGroove[DecIdx] += *pConfGroove; GrooveCnt += 1; } else { if(GrooveCnt > 0) { ChkGroove[DecIdx] /= GrooveCnt; GrooveCnt = 0; if(DecIdx++ < 12) ChkGroove[DecIdx]= 0; } } } // now iterate over bases to left of putative dyad and every rotation of the dsDNA get the minor groove DecIdx = 5; pConfGroove = &m_pConfGroove[SeqIdx-1]; pConfTwist = &m_pConfTwist[SeqIdx-1]; AccumTwist = *pConfTwist; ChkGroove[DecIdx] = 0; GrooveCnt = 0; Bases = 1; while(DecIdx >= 0) { Bases += 1; pConfTwist -= 1; pConfGroove -= 1; AccumTwist += *pConfTwist; ChkTwist = AccumTwist % 3600000; if(ChkTwist >= 3300000 || ChkTwist <= 300000) { ChkGroove[DecIdx] += *pConfGroove; GrooveCnt += 1; } else { if(GrooveCnt > 0) { ChkGroove[DecIdx] /= GrooveCnt; GrooveCnt = 0; if(DecIdx-- > 0) ChkGroove[DecIdx] = 0; } } } m_Dyad2Ratio = (double)(ChkGroove[5] + ChkGroove[7])/(2*BaseLineAv); m_Dyad3Ratio = (double)(ChkGroove[0] + ChkGroove[1] + ChkGroove[2] + ChkGroove[3] + ChkGroove[4] + ChkGroove[8] + ChkGroove[9] + ChkGroove[10] + ChkGroove[11] + ChkGroove[12])/(10*BaseLineAv); if(m_Dyad2Ratio < Dyad2ratioThres || m_Dyad3Ratio < Dyad3ratioThres) continue; if(bRegionFilter) InAnyRegion(ChromID,SeqIdx-74,SeqIdx+73,1); int LocScore = (int)(1000 * ((m_DyadRatio - 1.0f) + ((m_Dyad2Ratio - 1.0f) * 0.85) + ((m_Dyad3Ratio - 1.0f) * 0.75))); if(LocScore < 0) printf("\nHave an issue!"); m_pScores[SeqIdx] = LocScore; } OutputDyads(m_hOutFile, // results file FMode, // output format mode MovAvgFilter, // apply this width moving average filter BaselineFilter, // use this window size when normalising for baseline pszTrackName, // track name m_szCurChrom, // dyads on this chromosome m_ChromSeqLen, // last dyad loci m_pScores); // dyad scores gDiagnostics.DiagOut(eDLInfo,gszProcName,"On chromosome '%s' (length %d), %d putative nucleosome dyads were identified - running total: %d",m_szCurChrom,m_ChromSeqLen,m_ChromPutDyads,m_NumPutDyads); gDiagnostics.DiagOut(eDLInfo,gszProcName,"On chromosome '%s' (length %d), averaged minor groove baseline was %1.6f",m_szCurChrom,m_ChromSeqLen,ChromBaseLineSum/NumBaseLines); } if(m_UsedOutBuff) { if((Rslt=write(m_hOutFile,m_pszOutBuff,m_UsedOutBuff))!=m_UsedOutBuff) Rslt = eBSFerrWrite; m_UsedOutBuff = 0; } gDiagnostics.DiagOut(eDLInfo,gszProcName,"After processing a total of %d putative nucleosome dyads have been identified",m_NumPutDyads); DumpRegionHitStats(); Reset(); return(Rslt); }