예제 #1
0
        /// <summary>
        /// Method asynchronously serializes components to memory.
        /// </summary>
        private void SerializeFqComponentToMemory()
        {
            while (toSerialize.Count != 0)
            {
                int threadId;
                FqFile_Component             component = toSerialize.Dequeue();
                ProtocolBuffersSerialization protoBuf  = new ProtocolBuffersSerialization();
                ProtocolBuffersSerialization.ProbufSerializeFqFile_AsyncMethodCaller caller
                    = new ProtocolBuffersSerialization.ProbufSerializeFqFile_AsyncMethodCaller(protoBuf.ProtobufSerializeFqFile);

                IAsyncResult result = caller.BeginInvoke(component, component.getFileName(), out threadId, null, null);

                Boolean returnValue = caller.EndInvoke(out threadId, result);
            }
        }
예제 #2
0
        /// <summary>
        /// Serializes remaining file components onto disk after task has completed.
        /// </summary>
        public void SerializeRemainingFqComponents()
        {
            ProtocolBuffersSerialization protoBuf = new ProtocolBuffersSerialization();

            while (toSerialize.Count != 0)
            {
                int threadId;
                FqFile_Component fqFileComponent = toSerialize.Dequeue();
                Boolean          result          = protoBuf.ProtobufSerializeFqFile(fqFileComponent, fqFileComponent.getFileName(), out threadId);
            }
        }
예제 #3
0
        /// <summary>
        /// The key method in the controller class, where fastqFile_components are serialized and deserialized in and out of
        /// the classes queues for processing.  The tasks are constructed through an interface - ITaskStrategy - which
        /// is designated through the task abstract factory class (TaskDiscriminator.cs).  After processing, files are deserialized and a details class
        /// for each component is populated, as are the global scores.  The use of Abstract/interface classes here allows multiple components
        /// to be processed with multiple task types within this basic code structure.
        /// </summary>
        /// <param name="worker">The backgroundworker thread</param>
        /// <param name="input">Generic inputs, including taskname and any further details necessary to complete a task such as nucleotide scores etc.</param>
        public void PerformAction(BackgroundWorker worker, GenericFastqInputs input)
        {
            BackgroundWorker loadWorker = worker;

            if (fqFileMap != null && (CONTROLLER_STATE == FastqControllerState.STATE_READY || CONTROLLER_STATE == FastqControllerState.PARSING))
            {
                sw = new Stopwatch();
                sw.Start();
                try
                {
                    toDeserialize = new Queue <String>(fqFileMap.getFileComponentDirectories());
                    PrimeFqFileComponentQueue();
                    protobufSerialization = new ProtocolBuffersSerialization();

                    ITaskStrategy task = TaskDiscrimination.getTask(input.TaskAction);
                    Console.WriteLine("Performing {0}", task.getStatement());

                    int count = 0;
                    while (toPerform.Count != 0)
                    {
                        Double progressPercent = (Double)(count / (Double)fqFileMap.getFileComponentDirectories().Count);
                        loadWorker.ReportProgress((int)(progressPercent * 100), task.getReportStatement());

                        FqFile_Component activeComponent = toPerform.Dequeue();
                        activeComponent.setFqHashMap(fqFileMap.FqReadMap);

                        if (toDeserialize.Count != 0)
                        {
                            int threadId;
                            ProtocolBuffersSerialization.ProbufDeserializeFqFile_AsyncMethodCaller caller
                                = new ProtocolBuffersSerialization.ProbufDeserializeFqFile_AsyncMethodCaller(protobufSerialization.ProtobufDerializeFqFile);
                            String       componentFileName = toDeserialize.Dequeue();
                            IAsyncResult result            = caller.BeginInvoke(componentFileName, out threadId, null, null);

                            Console.WriteLine("\n*** Processing: {0} ***\n", activeComponent.getFileName());
                            input.FastqFile = activeComponent;
                            input           = task.perform(input);
                            activeComponent = (FqFile_Component)input.FastqFile;
                            BuildFqFileMap(activeComponent);

                            FqFile_Component returnValue = caller.EndInvoke(out threadId, result);
                            toPerform.Enqueue(returnValue);
                        }
                        else if (toDeserialize.Count == 0)
                        {
                            Console.WriteLine("\n*** Processing: {0} ***\n", activeComponent.getFileName());
                            input.FastqFile = activeComponent;
                            input           = task.perform(input);
                            activeComponent = (FqFile_Component)input.FastqFile;
                            BuildFqFileMap(activeComponent);
                        }
                        toSerialize.Enqueue(activeComponent);
                        SerializeFqComponentToMemory();
                        count++;
                    }

                    SerializeRemainingFqComponents();
                    task.confirmTaskEnd();
                    Console.WriteLine("\n*********\n");
                    fqFileMap.CalculateGlobalFileScores();
                    fqFileMap.GlobalDetails.OutputToConsole();
                    loadWorker.ReportProgress(100, task.getReportStatement());

                    sw.Stop();
                    Console.WriteLine("Task: {0} Completed in Time: {1}", task.getStatement(), sw.Elapsed);

                    fqFileMap.LastTask  = input.TaskAction;
                    fqFileMap.TimeTaken = sw.Elapsed.ToString();
                    observer.UpdateGUIThread(input);
                }
                catch (IOException exception)
                {
                    ControllerStateFailureResponse(exception.ToString(), "Error");
                }
                catch (InsufficientMemoryException exception)
                {
                    ControllerStateFailureResponse(exception.ToString(), "Error");
                }
                catch (OutOfMemoryException exception)
                {
                    ControllerStateFailureResponse(exception.ToString(), "Error");
                }
                catch (ArithmeticException exception)
                {
                    ControllerStateFailureResponse(exception.ToString(), "Error");
                }
                sw.Stop();
            }
        }