Пример #1
0
        public DFile ParseDFile(string file, string gelName, int gelSize)
        {
            int inc = 1;

            DFile result = new DFile();

            using (var fs = File.OpenRead(file))
            {
                using (var br = new BinaryReader(fs))
                {
                    bool isIFE = gelName == "IFE";
                    result.Scans = new List <ScanCommon>();
                    for (int i = 0; i < gelSize; i++)
                    {
                        string name     = ConvertToString(br.ReadBytes(8));
                        int    gelSize1 = br.ReadInt16();

                        // 跳过ScanCommon信息解析
                        br.ReadBytes(842 - 10);
                        //scan.Patient;
                        //scan.Status
                        //scan.DateTimeStam;
                        //scan.SampleNumbe;
                        //scan.TestIdentit;
                        //scan.RunIdentity
                        //scan.Comments
                        //scan.Characteristic
                        //scan.ImageContras;

                        if (isIFE)
                        {
                            var scan = new IFEScan();
                            // 解析units
                            scan.Units = new List <float>();
                            for (int u = 0; u < 9 + 1; u++)
                            {
                                scan.Units.Add(br.ReadSingle());
                            }

                            //
                            scan.ImageAspectRatio = br.ReadSingle();
                            scan.Image            = br.ReadBytes(50400); // 6 * 140 * 20 *3

                            List <Bitmap> parts     = new List <Bitmap>();
                            List <string> bandNames = new List <string> {
                                "SP", "G", "A", "M", "K", "L"
                            };
                            for (int v = 0; v < 6; v++)
                            {
                                var temp = new byte[8400];
                                Array.Copy(scan.Image, v * 8400, temp, 0, 8400);

                                var part = BitmapImageHelper.CreateBitmap(140, 20, temp, true);
                                parts.Add(part);
                            }
                            var bitMap = BitmapImageHelper.FixImageMerge(parts, bandNames);
                            //var outFileName = "E:\\export\\" + ginc + "_" + inc++ + ".bmp";
                            //bitMap.Save(outFileName);

                            scan.DestBytes = BitmapImageHelper.GetBytes(bitMap);

                            result.Scans.Add(scan);
                        }
                        else
                        {
                            var scan = new StdScan();

                            // 解析ScanIdentifier
                            scan.Reference = new List <ScanIdentifier>();
                            for (int s = 0; s < 4; s++)
                            {
                                var reference = new ScanIdentifier();
                                reference.TimeStamp    = br.ReadUInt32();
                                reference.SampleNumber = br.ReadByte();
                                reference.Instrument   = ConvertToString(br.ReadBytes(11));
                                scan.Reference.Add(reference);
                            }

                            // skip
                            // br.ReadBytes(894);
                            scan.FractionIdentity = br.ReadUInt16();
                            // 解析data
                            scan.Data = new List <short>();
                            int dcount = br.ReadInt16();
                            var pos    = 910 + i * 21150;
                            var pos1   = fs.Position;
                            for (int d = 0; d < dcount; d++)
                            {
                                scan.Data.Add(br.ReadInt16());
                            }
                            // skip
                            br.ReadBytes(2090 - (dcount + 1) * 2);
                            // 解析rawdata
                            scan.RawData = new List <ushort>();
                            int rdcount  = br.ReadInt16();
                            int rdcount1 = rdcount * 3 / 4;
                            for (int r = 0; r < rdcount1; r++)
                            {
                                scan.RawData.Add(br.ReadUInt16());
                            }
                            // skip
                            br.ReadBytes(1568 - (rdcount1 + 1) * 2);
                            // 解析fraction
                            scan.Fraction = new List <short>();
                            for (int r = 0; r < 10 + 1; r++)
                            {
                                scan.Fraction.Add(br.ReadInt16());
                            }
                            // 解析rawfraction
                            scan.RawFraction = new List <short>();
                            for (int r = 0; r < 10 + 1; r++)
                            {
                                scan.RawFraction.Add(br.ReadInt16());
                            }

                            // union 1
                            br.ReadInt16();

                            // union 2
                            br.ReadBytes(20);

                            // todo:fix count
                            //scan.OverlayAdjust = new List<short>();
                            //for (int o = 0; o < 16; o++)
                            //{
                            //    scan.OverlayAdjust.Add(br.ReadInt16());
                            //}
                            scan.Sensitivity = br.ReadInt16();

                            scan.Amplification    = br.ReadSingle();
                            scan.DspScaleFactor   = br.ReadSingle();
                            scan.NumScaleFactor   = br.ReadSingle();
                            scan.ImageAspectRatio = br.ReadSingle();

                            scan.Image = br.ReadBytes(16500); // 220*25*3

                            //var outFileName = "E:\\export\\" + ginc + "_" + inc++ + ".bmp";
                            //BitmapImageHelper.SaveBitmap(220, 25, scan.Image, outFileName);
                            scan.DestBytes = BitmapImageHelper.GetBytes(220, 25, scan.Image);

                            result.Scans.Add(scan);
                        }
                    }
                }
            }
            ginc++;
            return(result);
        }
Пример #2
0
        public DFile ParseDFile(string file, string gelName, int gelSize)
        {
            int inc = 1;

            DFile result = new DFile();
            using (var fs = File.OpenRead(file))
            {
                using (var br = new BinaryReader(fs))
                {
                    bool isIFE = gelName == "IFE";
                    result.Scans = new List<ScanCommon>();
                    for (int i = 0; i < gelSize; i++)
                    {
                        string name = ConvertToString(br.ReadBytes(8));
                        int gelSize1 = br.ReadInt16();

                        // 跳过ScanCommon信息解析                            
                        br.ReadBytes(842 - 10);
                        //scan.Patient;
                        //scan.Status
                        //scan.DateTimeStam;
                        //scan.SampleNumbe;
                        //scan.TestIdentit;
                        //scan.RunIdentity
                        //scan.Comments
                        //scan.Characteristic
                        //scan.ImageContras;

                        if (isIFE)
                        {
                            var scan = new IFEScan();
                            // 解析units
                            scan.Units = new List<float>();
                            for (int u = 0; u < 9 + 1; u++)
                            {
                                scan.Units.Add(br.ReadSingle());
                            }

                            // 
                            scan.ImageAspectRatio = br.ReadSingle();
                            scan.Image = br.ReadBytes(50400); // 6 * 140 * 20 *3 

                            List<Bitmap> parts = new List<Bitmap>();
                            List<string> bandNames = new List<string> { "SP", "G", "A", "M", "K", "L" };
                            for (int v = 0; v < 6; v++)
                            {
                                var temp = new byte[8400];
                                Array.Copy(scan.Image, v * 8400, temp, 0, 8400);

                                var part = BitmapImageHelper.CreateBitmap(140, 20, temp, true);
                                parts.Add(part);
                            }
                            var bitMap = BitmapImageHelper.FixImageMerge(parts, bandNames);
                            //var outFileName = "E:\\export\\" + ginc + "_" + inc++ + ".bmp";
                            //bitMap.Save(outFileName);

                            scan.DestBytes = BitmapImageHelper.GetBytes(bitMap);

                            result.Scans.Add(scan);
                        }
                        else
                        {
                            var scan = new StdScan();

                            // 解析ScanIdentifier
                            scan.Reference = new List<ScanIdentifier>();
                            for (int s = 0; s < 4; s++)
                            {
                                var reference = new ScanIdentifier();
                                reference.TimeStamp = br.ReadUInt32();
                                reference.SampleNumber = br.ReadByte();
                                reference.Instrument = ConvertToString(br.ReadBytes(11));
                                scan.Reference.Add(reference);
                            }

                            // skip
                            // br.ReadBytes(894);
                            scan.FractionIdentity = br.ReadUInt16();
                            // 解析data
                            scan.Data = new List<short>();
                            int dcount = br.ReadInt16();
                            var pos = 910 + i * 21150;
                            var pos1 = fs.Position;
                            for (int d = 0; d < dcount; d++)
                            {
                                scan.Data.Add(br.ReadInt16());
                            }
                            // skip
                            br.ReadBytes(2090 - (dcount + 1) * 2);
                            // 解析rawdata
                            scan.RawData = new List<ushort>();
                            int rdcount = br.ReadInt16();
                            int rdcount1 = rdcount * 3 / 4;
                            for (int r = 0; r < rdcount1; r++)
                            {
                                scan.RawData.Add(br.ReadUInt16());
                            }
                            // skip
                            br.ReadBytes(1568 - (rdcount1 + 1) * 2);
                            // 解析fraction
                            scan.Fraction = new List<short>();
                            for (int r = 0; r < 10 + 1; r++)
                            {
                                scan.Fraction.Add(br.ReadInt16());
                            }
                            // 解析rawfraction
                            scan.RawFraction = new List<short>();
                            for (int r = 0; r < 10 + 1; r++)
                            {
                                scan.RawFraction.Add(br.ReadInt16());
                            }

                            // union 1
                            br.ReadInt16();

                            // union 2
                            br.ReadBytes(20);

                            // todo:fix count
                            //scan.OverlayAdjust = new List<short>();
                            //for (int o = 0; o < 16; o++)
                            //{
                            //    scan.OverlayAdjust.Add(br.ReadInt16());
                            //}
                            scan.Sensitivity = br.ReadInt16();

                            scan.Amplification = br.ReadSingle();
                            scan.DspScaleFactor = br.ReadSingle();
                            scan.NumScaleFactor = br.ReadSingle();
                            scan.ImageAspectRatio = br.ReadSingle();

                            scan.Image = br.ReadBytes(16500); // 220*25*3

                            //var outFileName = "E:\\export\\" + ginc + "_" + inc++ + ".bmp";
                            //BitmapImageHelper.SaveBitmap(220, 25, scan.Image, outFileName);
                            scan.DestBytes = BitmapImageHelper.GetBytes(220, 25, scan.Image);

                            result.Scans.Add(scan);
                        }

                    }
                }
            }
            ginc++;
            return result;
        }