/// <summary> /// Specific API /// 从Aird文件中读取,但是不要将m/z数组的从Integer改为Float /// <para> /// Read from aird, but not convert the m/z array from integer to float /// /// </para> /// </summary> /// <param name="index"> 索引序列号 block index </param> /// <param name="rt"> 光谱产出时刻 retention time for the spectrum </param> /// <param name="compressor"> 压缩方式 compression method 0: ZDPD 1: S-ZDPD, default compressor = 0 </param> /// <returns> 该时刻产生的光谱信息, 其中mz数据以int类型返回 the target rt's spectrum with integer mz array </returns> public virtual MzIntensityPairs getSpectrumAsInteger(BlockIndex index, float rt, int compressor) { if (compressor == 0) { return(getSpectrumAsInteger(index, rt)); } else if (compressor == 1) { IList <float> rts = index.rts; int position = rts.IndexOf(rt); MzIntensityPairs mzIntensityPairs = getSpectrumByIndex(index, position); int[] mzArray = new int[mzIntensityPairs.getMzArray().Length]; for (int i = 0; i < mzArray.Length; i++) { mzArray[i] = (int)(mzIntensityPairs.getMzArray()[i] * mzPrecision); } return(new MzIntensityPairs(mzArray, mzIntensityPairs.getIntensityArray())); } else { Console.WriteLine("No such compressor."); } return(null); }
public virtual SpectrumDetail getSpectrumDetail(int index) { IList <BlockIndex> indexList = getAirdInfo().indexList; for (int i = 0; i < indexList.Count; i++) { BlockIndex blockIndex = indexList[i]; if (blockIndex.nums.Contains(index)) { int targetIndex = blockIndex.nums.IndexOf(index); MzIntensityPairs pairs = getSpectrumByIndex(blockIndex, targetIndex); } } return(null); }
/// <summary> /// 返回值是一个map,其中key为rt,value为这个rt对应点原始谱图信息 /// 特别需要注意的是,本函数在使用完raf对象以后并不会直接关闭该对象,需要使用者在使用完DIAParser对象以后手动关闭该对象 /// <para> /// the result key is rt,value is the spectrum(mz-intensity pairs) /// In particular, this function will not close the RAF object directly after using it. /// Users need to close the object manually after using the diaparser object /// /// </para> /// </summary> /// <param name="startPtr"> 起始指针位置 start point </param> /// <param name="endPtr"> 结束指针位置 end point </param> /// <param name="rtList"> rt列表,包含所有的光谱产出时刻 the retention time list </param> /// <param name="mzSizeList"> mz块的大小列表 the mz block size list </param> /// <param name="intSizeList"> intensity块的大小列表 the intensity block size list </param> /// <returns> 每一个时刻对应的光谱信息 the spectrum of the target retention time </returns> public virtual SortedDictionary <float, MzIntensityPairs> getSpectrums(long startPtr, long endPtr, IList <float> rtList, IList <long> mzSizeList, IList <long> intSizeList) { try { SortedDictionary <float, MzIntensityPairs> map = new SortedDictionary <float, MzIntensityPairs>(); airdFile.Seek(startPtr, SeekOrigin.Begin); long delta = endPtr - startPtr; byte[] result = new byte[(int)delta]; airdFile.Read(result, 0, (int)delta); Debug.Assert(rtList.Count == mzSizeList.Count); Debug.Assert(mzSizeList.Count == intSizeList.Count); int start = 0; for (int i = 0; i < rtList.Count; i++) { float[] intensityArray = null; float[] mzArray = getMzValues(result, start, ((int)mzSizeList[i])); start = start + ((int)mzSizeList[i]); if (intCompressor.methods.Contains(Compressor.METHOD_LOG10)) { intensityArray = getLogedIntValues(result, start, ((int)intSizeList[i])); } else { intensityArray = getIntValues(result, start, ((int)intSizeList[i])); } start = start + ((int)intSizeList[i]); map[rtList[i]] = new MzIntensityPairs(mzArray, intensityArray); } return(map); } catch (Exception e) { Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); } return(null); }
/// <summary> /// 根据特定BlockIndex取出对应SortedDictionary /// </summary> /// <param name="file">filereader</param> /// <param name="blockIndex"> the block index read from the index file </param> /// <returns> 解码内容, key为rt, value为光谱中的键值对 </returns> /// <exception cref="Exception"> 读取文件异常 </exception> public virtual SortedDictionary <double, MzIntensityPairs> parseBlockValue(FileStream file, BlockIndex blockIndex) { SortedDictionary <double, MzIntensityPairs> map = new SortedDictionary <double, MzIntensityPairs>(); IList <float> rts = blockIndex.rts; file.Seek(blockIndex.startPtr, SeekOrigin.Begin); long delta = blockIndex.endPtr - blockIndex.startPtr; byte[] result = new byte[(int)delta]; file.Read(result, 0, (int)delta); IList <long> mzSizes = blockIndex.mzs; IList <long> intensitySizes = blockIndex.ints; int start = 0; for (int i = 0; i < mzSizes.Count; i++) { var mz = new byte[(int)mzSizes[i]]; Buffer.BlockCopy(result, start, mz, 0, ((int)mzSizes[i])); start = start + ((int)mzSizes[i]); var intensity = new byte[(int)intensitySizes[i]]; Buffer.BlockCopy(result, start, intensity, 0, ((int)intensitySizes[i])); start = start + ((int)intensitySizes[i]); try { MzIntensityPairs pairs = new MzIntensityPairs(getMzValues(mz), getIntValues(intensity)); map[rts[i] / 60d] = pairs; } catch (Exception e) { throw e; } } return(map); }
/// <summary> /// 返回值是一个map,其中key为rt,value为这个rt对应点原始谱图信息 /// 特别需要注意的是,本函数在使用完raf对象以后并不会直接关闭该对象,需要使用者在使用完DIAParser对象以后手动关闭该对象 /// <para> /// the result key is rt,value is the spectrum(mz-intensity pairs) /// In particular, this function will not close the RAF object directly after using it. /// Users need to close the object manually after using the diaparser object /// /// </para> /// </summary> /// <param name="startPtr"> 起始指针位置 start point </param> /// <param name="endPtr"> 结束指针位置 end point </param> /// <param name="rtList"> rt列表,包含所有的光谱产出时刻 the retention time list </param> /// <param name="mzSizeList"> mz块的大小列表 the mz block size list </param> /// <param name="tagSizeList"> tag块的大小列表 the tag block size list </param> /// <param name="intSizeList"> intensity块的大小列表 the intensity block size list </param> /// <returns> 每一个时刻对应的光谱信息 the spectrum of the target retention time </returns> public virtual SortedDictionary <float, MzIntensityPairs> getSpectrums(long startPtr, long endPtr, IList <float> rtList, IList <long> mzSizeList, IList <long> tagSizeList, IList <long> intSizeList) { try { SortedDictionary <float, MzIntensityPairs> map = new SortedDictionary <float, MzIntensityPairs>(); airdFile.Seek(startPtr, SeekOrigin.Begin); long delta = endPtr - startPtr; byte[] result = new byte[(int)delta]; airdFile.Read(result, 0, (int)delta); Debug.Assert(tagSizeList.Count == mzSizeList.Count); Debug.Assert(mzSizeList.Count == intSizeList.Count); int start = 0; int maxTag = (int)Math.Pow(2, mzCompressor.digit); for (int i = 0; i < mzSizeList.Count; i++) { float[] mzArray = getMzValues(result, start, ((int)mzSizeList[i])); start = start + ((int)mzSizeList[i]); int[] tagArray = getTags(result, start, ((int)tagSizeList[i])); start += ((int)tagSizeList[i]); Dictionary <int, int> tagMap = new Dictionary <int, int>(); foreach (int tag in tagArray) { if (tagMap.ContainsKey(tag)) { tagMap[tag]++; } else { tagMap.Add(tag, 1); } } IList <float[]> mzGroup = new List <float[]>(); int layerNum = tagMap.Keys.Count; for (int j = 0; j < layerNum; j++) { mzGroup.Add(new float[tagMap[j]]); } int[] p = new int[layerNum]; for (int j = 0; j < tagArray.Length; j++) { mzGroup[tagArray[j]][p[tagArray[j]]++] = mzArray[j]; } float[] intensityArray = null; if (intCompressor.methods.Contains(Compressor.METHOD_LOG10)) { intensityArray = getLogedIntValues(result, start, ((int)intSizeList[i])); } else { intensityArray = getIntValues(result, start, ((int)intSizeList[i])); } start = start + ((int)intSizeList[i]); IList <float[]> intensityGroup = new List <float[]>(); int initFlag = 0; for (int j = 0; j < layerNum; j++) { intensityGroup.Add(intensityArray.Skip(initFlag).Take(tagMap[j]).ToArray()); initFlag += tagMap[j]; } for (int j = 0; j < layerNum; j++) { map[rtList[i * maxTag + j]] = new MzIntensityPairs(mzGroup[j], intensityGroup[j]); } } return(map); } catch (Exception e) { Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); } return(null); }