public Qs2000State GetState(TFileData query) { string testsFile = GlobalConfigVars.DbPath + "\\" + "Tests.qsd"; TestsFile test = ParseTestsFile(testsFile); string tfile = GlobalConfigVars.DbPath + "\\" + GetTFile(query.SeqNum); TFile tFile = ParseTFile(tfile); string dfile = GlobalConfigVars.DbPath + "\\" + GetDFile(query.SeqNum); DFile dFile = ParseDFile(dfile, tFile.Header.Identity.Name, tFile.Header.Identity.GelSize); // 查找配置 TestProperties tp = test.Tests.Where(t => t.Identity.Equals(tFile.Header.Identity)).First(); int idx = query.Id - 1; Qs2000State state = new Qs2000State { SeqNum = query.SeqNum.ToString(), SampleNum = query.Id.ToString(), SampleId = tFile.Datas[idx].Patient.Demographic[0], ScannedDate = tFile.Datas[idx].ScanDate.ToString("yyyy/MM/dd HH:mm:ss"), Scan = dFile.Scans[idx].DestBytes, TestType = tFile.Header.Identity.Name }; if (!tp.bIFE) { StdScan scan = dFile.Scans[idx] as StdScan; state.Result = new Qs2000Result(scan.Data, scan.Fraction, tp.Fraction); } return(state); }
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); }
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; }