/// <summary>
        /// Initializes a new instance of the <see cref="AnalyseExperiments"/> class.
        /// </summary>
        /// <param name="analyseFileContent"> instance this sample belongs to </param>
        /// <param name="filePath">Path of Analyse file</param>
        public AnalyseExperiments(AnalyseFileContent analyseFileContent, string filePath)
        {
            if (analyseFileContent == null)
            {
                throw new ArgumentNullException("analyseFileContent");
            }

            this.analyseFileHeaderObject = new AnalyseFileHeaderObject(AnalyseFileHeaderObject.AnalyseReadorWriteEnum.Read);
            this.analyseFileContent      = analyseFileContent;
            this.filePath = filePath;

            this.Initialize();
        }
Example #2
0
        /// <summary>
        /// Reads the Data file
        /// </summary>
        /// <param name="analysefilecontent">analyse file content Object</param>
        /// <param name="filepath">Path of file </param>
        /// <param name="analysefileheaderobject">Header Object</param>
        protected override void Initialise(AnalyseFileContent analysefilecontent, string filepath, AnalyseFileHeaderObject analysefileheaderobject)
        {
            this.filePath = filepath;
            this.analyseFileHeaderObject = analysefileheaderobject;

            // 1) Make sure the path file exists
            if (!File.Exists(this.filePath))
            {
                string header = "Missing File";
                string error  = string.Format("{0} is missing", this.filePath);
                MessageBox.Show(error, header);
                return;
            }

            // 2) ReadCalibrationFile (Calc MinMass, MaxMass, StepSize and MassSpecDataPoints)
            this.ReadCalibrationFile();

            // 3) Set Binsize
            this.binsize = 1;

            var  fileinfo    = new FileInfo(this.filePath);
            long imgFileSize = fileinfo.Length;

            string appPath = Application.StartupPath;

            appPath += "\\ApplicationSettings.xml";

            var filesizelimit = this.GetPathFileSizeLimit(appPath);
            var minMassDp     = 0;
            var maxMassDp     = (int)(this.massspecdatapoints - 1);

            // We only want to do binning for files bigger than 100MB filesize > pathfilesize
            if (imgFileSize != filesizelimit)
            {
                // Open up BinNumberWindow
                var binNumberWindow = new BinNumberWindow(this.analyseFileHeaderObject.NumberOfXPoints, this.analyseFileHeaderObject.NumberOfYPoints, this.MassCal);
                if (binNumberWindow.ShowDialog() == true)
                {
                    this.binsize = binNumberWindow.BinSize;
                    minMassDp    = binNumberWindow.MinMassDP;
                    maxMassDp    = binNumberWindow.MaxMassDP;
                }
            }

            this.massstepsize = 1;

            // 4) Fill out meta rawdata
            var metaData = new ImageMetaData();

            try
            {
                metaData.Add("Sample Name", typeof(string), this.analyseFileHeaderObject.Name, false);
                metaData.Add("Mass Range", typeof(string), this.massRangeName, false);
                metaData.Add("Mass Step Size", typeof(string), 1, false);
                metaData.Add("X1 (mm)", typeof(string), (Math.Abs(this.analyseFileHeaderObject.X1 - (int)this.analyseFileHeaderObject.X1) < Epsilon) ? this.analyseFileHeaderObject.X1.ToString("0.0") : this.analyseFileHeaderObject.X1.ToString(CultureInfo.InvariantCulture), false);
                metaData.Add("Y1 (mm)", typeof(string), (Math.Abs(this.analyseFileHeaderObject.Y1 - (int)this.analyseFileHeaderObject.Y1) < Epsilon) ? this.analyseFileHeaderObject.Y1.ToString("0.0") : this.analyseFileHeaderObject.Y1.ToString(CultureInfo.InvariantCulture), false);
                metaData.Add("X2 (mm)", typeof(string), (Math.Abs(this.analyseFileHeaderObject.X2 - (int)this.analyseFileHeaderObject.X2) < Epsilon) ? this.analyseFileHeaderObject.X2.ToString("0.0") : this.analyseFileHeaderObject.X2.ToString(CultureInfo.InvariantCulture), false);
                metaData.Add("Y2 (mm)", typeof(string), (Math.Abs(this.analyseFileHeaderObject.Y2 - (int)this.analyseFileHeaderObject.Y2) < Epsilon) ? this.analyseFileHeaderObject.Y2.ToString("0.0") : this.analyseFileHeaderObject.Y2.ToString(CultureInfo.InvariantCulture), false);
                metaData.Add("Data Points in X", typeof(string), this.analyseFileHeaderObject.NumberOfXPoints.ToString(CultureInfo.InvariantCulture), false);
                metaData.Add("Data Points in Y", typeof(string), this.analyseFileHeaderObject.NumberOfYPoints.ToString(CultureInfo.InvariantCulture), false);
                metaData.Add("Point Width (mm)", typeof(string), Math.Round(this.analyseFileHeaderObject.Dx, 2).ToString(CultureInfo.InvariantCulture), false);
                metaData.Add("Point Height (mm)", typeof(string), Math.Round(this.analyseFileHeaderObject.Dy, 2).ToString(CultureInfo.InvariantCulture), false);
                metaData.Add("Bin Size", typeof(string), this.binsize.ToString(CultureInfo.InvariantCulture), false);
            }
            catch (Exception e)
            {
                Util.ReportException(e);
            }

            // 5) Declare Median List
            var valuesForMedian = new List <float>();

            this.minIntensityValue = 0;
            this.maxIntensityValue = 0;

            var minIntList = new float[maxMassDp - minMassDp + 1];
            var maxIntList = new float[maxMassDp - minMassDp + 1];

            // 6) Declare and Initialise the dataTic
            var dataTic = new float[analysefileheaderobject.NumberOfXPoints][];

            for (int i = 0; i < dataTic.Length; i++)
            {
                dataTic[i] = new float[analysefileheaderobject.NumberOfYPoints];
            }

            // 7) Declare mass spectrum datat list
            this.massspecdatalist = new List <float[][]>();

            // 8) Declare and Initialise the dataList
            var data = new float[analysefileheaderobject.NumberOfXPoints][];

            for (int pointOnXAxis = 0; pointOnXAxis < analysefileheaderobject.NumberOfXPoints; pointOnXAxis++)
            {
                data[pointOnXAxis] = new float[analysefileheaderobject.NumberOfYPoints];
            }

            this.massspecdatalist.Add(data);

            // 9) Declare and populate the image data list - Fill it with some default data - this will be over written later
            Cursor.Current = Cursors.WaitCursor;
            AppContext.ProgressStart("Generating Empty Imagelist...");
            var imageDataList = new List <ImageData>();

            try
            {
                for (int massSpecDataPt = 0; massSpecDataPt < ((maxMassDp - minMassDp + 1) / this.binsize); massSpecDataPt++)
                {
                    var specData = new float[analysefileheaderobject.NumberOfXPoints][];
                    for (int i = 0; i < specData.Length; i++)
                    {
                        specData[i] = new float[analysefileheaderobject.NumberOfYPoints];
                    }

                    // ok, now create the imageData and add to list...
                    var imageData = new ImageData(
                        analysefilecontent.Document,
                        specData,
                        this.analyseFileHeaderObject.Name,
                        metaData,
                        0,
                        10000,
                        1000,
                        1000,
                        this.analyseFileHeaderObject.Dx,
                        this.analyseFileHeaderObject.Dy,
                        this.masscal,
                        this.analyseFileHeaderObject.ExperimentType);

                    // Add the imageData to the list
                    imageDataList.Add(imageData);
                    AppContext.ProgressSetValue(100.0 * massSpecDataPt / ((maxMassDp - minMassDp + 1) / this.binsize));
                }
            }
            catch (Exception e)
            {
                Util.ReportException(e);
            }
            finally
            {
                AppContext.ProgressClear();
                Cursor.Current = Cursors.Default;
            }

            // 10) Read binary file
            Cursor.Current = Cursors.WaitCursor;
            AppContext.ProgressStart("Populating ImageList...");

            using (var imgReader = new BinaryReader(File.Open(this.filePath, FileMode.Open)))
            {
                int xp = analysefileheaderobject.NumberOfXPoints;
                int yp = analysefileheaderobject.NumberOfYPoints;
                int dp = (maxMassDp - minMassDp + 1) / this.binsize;
                int dd = this.binsize;
                int dl = minMassDp;
                int xf = analysefileheaderobject.NumberOfXPoints;
                int df = this.masscal.Length;
                int ps = this.analyseFileHeaderObject.DataByteSize;
                int y;
                var meanSumList = new double[dp];

                for (int i = 0; i < dp; i++)
                {
                    minIntList[i]  = float.MaxValue;
                    maxIntList[i]  = float.MinValue;
                    meanSumList[i] = 0.0;
                }

                for (y = 0; y < yp; y++)
                {
                    // for the progress bar
                    AppContext.ProgressSetValue(y * 100 / yp);

                    // refresh counter here;
                    for (int x = 0; x < xp; x++)
                    {
                        long fp = ((((y * xf) + x) * df) + dl) * ps;
                        imgReader.BaseStream.Position = fp;

                        for (int d = 0; d < dp; d++)
                        {
                            float average = 0;

                            for (int di = 0; di < dd; di++)
                            {
                                float intensity;
                                switch (this.analyseFileHeaderObject.DataType)
                                {
                                case 4:
                                    intensity = imgReader.ReadInt16();
                                    break;

                                case 8:
                                case 16:
                                    intensity = imgReader.ReadInt32();
                                    break;

                                case 64:
                                    intensity = imgReader.ReadInt64();
                                    break;

                                default:
                                    intensity = imgReader.ReadInt32();
                                    break;
                                }

                                average += intensity;
                            }

                            average = average / dd;
                            imageDataList[d].Data[x][y] = average;
                            dataTic[x][y] += average;
                            if (average < minIntList[d])
                            {
                                minIntList[d] = average;
                            }

                            if (average > maxIntList[d])
                            {
                                maxIntList[d] = average;
                            }

                            // mean and median calculation... sum up the value to calculate the mean
                            meanSumList[d] += average;
                        }
                    }
                }

                // and cleanup
                imgReader.Close();
            }

            AppContext.ProgressClear();
            Cursor.Current = Cursors.Default;

            // 11) create new masscal array
            var newmasscal = new float[(maxMassDp - minMassDp + 1) / this.binsize];

            for (int i = 0; i < ((maxMassDp - minMassDp + 1) / this.binsize); i++)
            {
                newmasscal[i] = this.masscal[minMassDp + (i * this.binsize)];
            }

            this.masscal = newmasscal;

            // 12) Mean/Median for Tic
            double meanSum = 0.0;

            int numDataPoint = dataTic.Length;

            for (int y = 0; y < analysefileheaderobject.NumberOfYPoints; y++)
            {
                for (int x = 0; x < analysefileheaderobject.NumberOfXPoints; x++)
                {
                    float intensity = dataTic[x][y];

                    meanSum += intensity;
                    valuesForMedian.Add(intensity);

                    if (intensity < this.minIntensityValue)
                    {
                        this.minIntensityValue = intensity;
                    }

                    if (intensity > this.maxIntensityValue)
                    {
                        this.maxIntensityValue = intensity;
                    }
                }
            }

            if (numDataPoint != 0)
            {
                this.meanValue = (float)(meanSum / numDataPoint);
            }

            valuesForMedian.Sort();
            this.medianValue = ((valuesForMedian.Count % 2) == 0)
                                   ? (valuesForMedian[(valuesForMedian.Count / 2) - 1]
                                      + valuesForMedian[valuesForMedian.Count / 2]) / 2.0f
                                   : valuesForMedian[valuesForMedian.Count / 2];

            // 13) Fill out imageTic
            var imageTic = new ImageData(
                analysefilecontent.Document,
                dataTic,
                this.analyseFileHeaderObject.Name,
                metaData,
                this.minIntensityValue,
                this.maxIntensityValue,
                this.meanValue,
                this.medianValue,
                this.analyseFileHeaderObject.Dx,
                this.analyseFileHeaderObject.Dy,
                this.masscal,
                this.analyseFileHeaderObject.ExperimentType);

            // 14) Fill out ImageSpectrumData and add to analysefilecontent
            analysefilecontent.Add(
                new ImageSpectrumData(
                    analysefilecontent.Document,
                    this.analyseFileHeaderObject.Name,
                    metaData,
                    this.masscal,
                    imageDataList,
                    this.analyseFileHeaderObject.ExperimentType)
            {
                ImageTic = imageTic
            });
        }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AnalyseMsExperiment"/> class.
 /// </summary>
 /// <param name="analysefilecontent">analyseFileContent Object</param>
 /// <param name="filePath">Path of file that is being read</param>
 /// <param name="analyseFileHeaderObject">Header Object</param>
 public AnalyseMsExperiment(
     AnalyseFileContent analysefilecontent, string filePath, AnalyseFileHeaderObject analyseFileHeaderObject)
     : base(analysefilecontent, filePath, analyseFileHeaderObject)
 {
 }
Example #4
0
        /// <summary>
        /// Reads the image file for an MRM experiment
        /// </summary>
        /// <param name="analysefilecontent">analyse file content Object</param>
        /// <param name="filepath">Path of file </param>
        /// <param name="analysefileheaderobject">Header Object</param>
        protected override void Initialise(AnalyseFileContent analysefilecontent, string filepath, AnalyseFileHeaderObject analysefileheaderobject)
        {
            this.filePath = filepath;
            this.analyseFileHeaderObject = analysefileheaderobject;

            // 1) Make sure the path file exists
            if (!File.Exists(this.filePath))
            {
                MessageBox.Show(this.filePath + " is missing", "Missing File");
                return;
            }

            // 1) Use BinaryReader
            this.ReadImgFile();

            // 2) Convert data[]to ImageData[][]  & (3) And calc Mean and Median and minIntensityValue, maxIntensityValue
            var    imageData       = new float[this.analyseFileHeaderObject.NumberOfXPoints][];
            double meanSum         = 0.0;
            var    valuesForMedian = new List <float>();

            this.minIntensityValue = 0;
            this.maxIntensityValue = 0;

            int numDataPoint = this.data.Length;

            for (int i = 0; i < imageData.Length; i++)
            {
                imageData[i] = new float[this.analyseFileHeaderObject.NumberOfYPoints];
            }

            // TODO JP If data[i + j] is out of scope, exit loops and continue - remaining array points will be null
            try
            {
                for (int j = 0; j < this.analyseFileHeaderObject.NumberOfYPoints; j++)
                {
                    for (int i = 0; i < this.analyseFileHeaderObject.NumberOfXPoints; i++)
                    {
                        int index;

                        if (j == 0)
                        {
                            index = i;
                        }
                        else
                        {
                            index = i + this.analyseFileHeaderObject.NumberOfXPoints + ((j - 1) * this.analyseFileHeaderObject.NumberOfXPoints);
                        }

                        float intensity = this.data[index];
                        imageData[i][j] = intensity;
                        meanSum        += intensity;
                        valuesForMedian.Add(intensity);

                        if (intensity < this.minIntensityValue)
                        {
                            this.minIntensityValue = intensity;
                        }

                        if (intensity > this.maxIntensityValue)
                        {
                            this.maxIntensityValue = intensity;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Util.ReportException(e);
            }

            // 4) Calculate Mean And Median
            if (numDataPoint != 0)
            {
                this.meanValue = (float)(meanSum / numDataPoint);
            }

            valuesForMedian.Sort();
            this.medianValue = ((valuesForMedian.Count % 2) == 0) ? (valuesForMedian[(valuesForMedian.Count / 2) - 1] + valuesForMedian[valuesForMedian.Count / 2]) / 2.0f : valuesForMedian[valuesForMedian.Count / 2];

            // 5) Fill out meta data
            var metaData = new ImageMetaData();

            try
            {
                const float Epsilon = (float)1E-10;
                metaData.Add("Sample Name", typeof(string), this.analyseFileHeaderObject.Name, false);
                metaData.Add("X1 (mm)", typeof(string), (Math.Abs(this.analyseFileHeaderObject.X1 - (int)this.analyseFileHeaderObject.X1) < Epsilon) ? this.analyseFileHeaderObject.X1.ToString("0.0") : this.analyseFileHeaderObject.X1.ToString(CultureInfo.InvariantCulture), false);
                metaData.Add("Y1 (mm)", typeof(string), (Math.Abs(this.analyseFileHeaderObject.Y1 - (int)this.analyseFileHeaderObject.Y1) < Epsilon) ? this.analyseFileHeaderObject.Y1.ToString("0.0") : this.analyseFileHeaderObject.Y1.ToString(CultureInfo.InvariantCulture), false);
                metaData.Add("X2 (mm)", typeof(string), (Math.Abs(this.analyseFileHeaderObject.X2 - (int)this.analyseFileHeaderObject.X2) < Epsilon) ? this.analyseFileHeaderObject.X2.ToString("0.0") : this.analyseFileHeaderObject.X2.ToString(CultureInfo.InvariantCulture), false);
                metaData.Add("Y2 (mm)", typeof(string), (Math.Abs(this.analyseFileHeaderObject.Y2 - (int)this.analyseFileHeaderObject.Y2) < Epsilon) ? this.analyseFileHeaderObject.Y2.ToString("0.0") : this.analyseFileHeaderObject.Y2.ToString(CultureInfo.InvariantCulture), false);
                metaData.Add("Data Points in X", typeof(string), this.analyseFileHeaderObject.NumberOfXPoints.ToString(CultureInfo.InvariantCulture), false);
                metaData.Add("Data Points in Y", typeof(string), this.analyseFileHeaderObject.NumberOfYPoints.ToString(CultureInfo.InvariantCulture), false);
                metaData.Add("Point Width (mm)", typeof(string), Math.Round(this.analyseFileHeaderObject.Dx, 2).ToString(CultureInfo.InvariantCulture), false);
                metaData.Add("Point Height (mm)", typeof(string), Math.Round(this.analyseFileHeaderObject.Dy, 2).ToString(CultureInfo.InvariantCulture), false);
            }
            catch (Exception e)
            {
                Util.ReportException(e);
            }

            // 6) Fill out imageData
            analysefilecontent.Add(new ImageData(
                                       analysefilecontent.Document,
                                       imageData,
                                       this.analyseFileHeaderObject.Name,
                                       metaData,
                                       this.minIntensityValue,
                                       this.maxIntensityValue,
                                       this.meanValue,
                                       this.medianValue,
                                       this.analyseFileHeaderObject.Dx,
                                       this.analyseFileHeaderObject.Dy,
                                       null,
                                       this.analyseFileHeaderObject.ExperimentType));
        }