/// <summary> /// Flushes memory of fqprotobin files /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void flushMemoryToolStripMenuItem_Click(object sender, EventArgs e) { if (FastqController.getInstance().FlushMemoryOfProtobinFiles() == true) { UserResponse.InformationResponse("Protobin directory cleaned."); } }
/// <summary> /// Resets the state of a controller for loading a new file /// </summary> public void PrimeForNewFile() { fqFileMap = null; if (FlushMemoryOfProtobinFiles() == true) { UserResponse.InformationResponse("Protobin directory cleaned."); } }
/// <summary> /// Method allows the cancellation of backgroundworker thread for loading and processing files. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void loadWorker_Completed(object sender, RunWorkerCompletedEventArgs e) { if (e.Error != null) { UserResponse.ErrorResponse(e.Error.Message, "Load Error"); } if (e.Cancelled) { UserResponse.InformationResponse("Loading cancelled at request"); } FastqController.CONTROLLER_STATE = FastqController.FastqControllerState.STATE_READY; Console.WriteLine("Process ended."); }
/// <summary> /// Parses file into component chunks through the parseFastq class before handing component details to FastqController /// for processing. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void loadWorker_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; InputFq input = (InputFq)e.Argument; FileStream fileStream = input.fileStream; String fileName = input.fileName; ParseFastq parseFq; if ((worker.CancellationPending == true)) { e.Cancel = true; } else { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); try { worker.ReportProgress(3, "[PARSING FILE]"); parseFq = new ParseFastq(fileStream, fileName); if (parseFq.getFastqFileCheck() == true && FastqController.CONTROLLER_STATE == FastqController.FastqControllerState.STATE_READY) { //Create new fqFileMap in controller and prime state for load FastqController.CONTROLLER_STATE = FastqController.FastqControllerState.PARSING; FastqController.getInstance().CreateNewFastqFile(fileName, parseFq.GetFastqFileLength()); FastqController.getInstance().GetFqFileMap().InitializeReadMap(); int fqFileComponentNumber = 1; ProtocolBuffersSerialization protoBuf = new ProtocolBuffersSerialization(); GenericFastqInputs processInputs = new GenericFastqInputs(); processInputs.TaskAction = Task_LoadTask.statement; ITaskStrategy task = TaskDiscrimination.getTask(processInputs.TaskAction); // Uses IEnummerable yield return to parse components back to this class via this foreach loop foreach (FqFile_Component fqFileComponent in parseFq.ParseComponents()) { Double progressPercent = (Double)(((fqFileComponentNumber - 1) * FqFileMap.FQ_BLOCK_LIMIT) / (Double)(parseFq.GetLineCount() / 4)); worker.ReportProgress((int)(progressPercent * 100), ParseFastq.REPORT_STATEMENT); if (fqFileComponent.getFastqArraySize() >= 1) { int threadId; String componentFileName = FastqController.getInstance().GetFqFileMap().FileGUID + "_" + Path.GetFileNameWithoutExtension(fileName) + "_" + fqFileComponentNumber + ProtocolBuffersSerialization.PROTOBUF_FILE_EXTENSION; fqFileComponent.setFastqFileName(componentFileName); fqFileComponent.setComponentNumber(fqFileComponentNumber); fqFileComponent.setFqHashMap(FastqController.getInstance().GetFqFileMap().FqReadMap); processInputs.FastqFile = fqFileComponent; processInputs = task.perform(processInputs); FastqController.getInstance().BuildFqFileMap(processInputs.FastqFile); ProtocolBuffersSerialization.ProbufSerializeFqFile_AsyncMethodCaller caller = new ProtocolBuffersSerialization.ProbufSerializeFqFile_AsyncMethodCaller(protoBuf.ProtobufSerializeFqFile); IAsyncResult result = caller.BeginInvoke((processInputs.FastqFile as FqFile_Component), componentFileName, out threadId, null, null); Boolean returnValue = caller.EndInvoke(out threadId, result); if (returnValue == false) { UserResponse.ErrorResponse("File serialization methods failed, please check you have hard disk space and restart the application", "File Error"); Console.WriteLine("Serialization failed"); loadWorker.CancelAsync(); } else { FastqController.getInstance().addFqFileComponentDirectory(componentFileName); } fqFileComponentNumber++; } } parseFq.CloseReader(); task.confirmTaskEnd(); Console.WriteLine("\n*********\n"); FastqController.getInstance().GetFqFileMap().CalculateGlobalFileScores(); FastqController.getInstance().GetFqFileMap().GlobalDetails.OutputToConsole(); loadWorker.ReportProgress(100, task.getReportStatement()); stopwatch.Stop(); Console.WriteLine("Task: {0} Completed in Time: {1}", task.getStatement(), stopwatch.Elapsed); FastqController.getInstance().GetFqFileMap().LastTask = processInputs.TaskAction; FastqController.getInstance().GetFqFileMap().TimeTaken = stopwatch.Elapsed.ToString(); this.UpdateGUIThread(processInputs); } else { worker.ReportProgress(0, ""); UserResponse.InformationResponse("File does not conform to standard format.", "File Error"); parseFq.CloseReader(); } } catch (IOException exception) { Console.Write(exception.StackTrace); UserResponse.ErrorResponse(exception.ToString()); } catch (InsufficientMemoryException exception) { Console.Write(exception.StackTrace); UserResponse.ErrorResponse(exception.ToString()); } catch (OutOfMemoryException exception) { Console.Write(exception.StackTrace); UserResponse.ErrorResponse(exception.ToString()); } catch (ArithmeticException exception) { Console.Write(exception.StackTrace); UserResponse.ErrorResponse(exception.ToString()); } FastqController.CONTROLLER_STATE = FastqController.FastqControllerState.STATE_READY; stopwatch.Stop(); } }