public static UserResponse getInstance() { if (uniqueInstance == null) { lock (syncLock) { uniqueInstance = new UserResponse(); } } return uniqueInstance; }
private void SaveFastqAction(IFqFile fq, String fileName) { StreamWriter writer; try { writer = new StreamWriter(@fileName); saveWorker.ReportProgress(40, "[CREATING FASTQ FORMAT]"); for (int i = 0; i < fqFile.getFastqArraySize(); i++) { writer.Write(fqFile.getFastqSequenceByPosition(i).createFastqBlock(fqFile.getMap())); } saveWorker.ReportProgress(100, "[FASTQ FORMAT CREATED]"); writer.Flush(); writer.Close(); } catch (IOException exception) { Console.WriteLine(exception.ToString()); UserResponse.ErrorResponse(exception.ToString()); } }
private void SaveCSVAction(IFqFile fq, String fileName) { StreamWriter writer; string COMMA_DELIMITER = ","; string[] output; try { writer = new StreamWriter(@fileName); saveWorker.ReportProgress(30, "[CREATING CSV FORMAT]"); output = new string[] { "Sequence Index", "Header", "Total Nucleotides", "G Count", "C Count", "Misread Count", "Lower Threshold", "First Quartile", "Median", "Mean", "Third Quartile", "Upper Threshold" }; writer.WriteLine(string.Join(COMMA_DELIMITER, output)); for (int i = 0; i < fqFile.getFastqArraySize(); i++) { FqSequence fqSeq = fqFile.getFastqSequenceByPosition(i); output = new string[] { fqSeq.getSeqIndex().ToString(), fqSeq.getSequenceHeader(), fqSeq.getFastqSeqSize().ToString(), fqSeq.getGCount().ToString(), fqSeq.getCCount().ToString(), fqSeq.getNCount().ToString(), fqSeq.getLowerThreshold().ToString(), fqSeq.getFirstQuartile().ToString(), fqSeq.getMedian().ToString(), fqSeq.getMean().ToString(), fqSeq.getThirdQuartile().ToString(), fqSeq.getUpperThreshold().ToString(), fqSeq.createSequenceString(fqFile.getMap()) }; writer.WriteLine(string.Join(COMMA_DELIMITER, output)); } saveWorker.ReportProgress(100, "[FASTQ FORMAT CREATED]"); writer.Flush(); writer.Close(); } catch (IOException exception) { Console.WriteLine(exception.ToString()); UserResponse.ErrorResponse(exception.ToString()); } }
private void SaveFastaAction(IFqFile fq, String fileName) { saveWorker.ReportProgress(40, "[CREATING FASTA FORMAT]"); String output = fqFile.createFastaFormat(""); saveWorker.ReportProgress(100, "[FASTA FORMAT CREATED]"); StreamWriter writer; try { writer = new StreamWriter(@fileName); writer.Write(output); writer.Flush(); writer.Close(); } catch (IOException exception) { Console.WriteLine(exception.ToString()); UserResponse.ErrorResponse(exception.ToString()); } }
/// <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(); } }