public static InterpolatedTimeIntensities ReadFromStream(Stream stream, ChromGroupHeaderInfo chromGroupHeaderInfo, ChromTransition[] chromTransitions) { Dictionary <ChromSource, int[]> scanIds = new Dictionary <ChromSource, int[]>(); int numTrans = chromTransitions.Length; Assume.IsTrue(numTrans == chromGroupHeaderInfo.NumTransitions); int numPoints = chromGroupHeaderInfo.NumPoints; var sharedTimes = PrimitiveArrays.Read <float>(stream, numPoints); var transitionIntensities = new IList <float> [numTrans]; for (int i = 0; i < numTrans; i++) { transitionIntensities[i] = PrimitiveArrays.Read <float>(stream, numPoints); } IList <float>[] transitionMassErrors = new IList <float> [numTrans]; if (chromGroupHeaderInfo.HasMassErrors) { for (int i = 0; i < numTrans; i++) { transitionMassErrors[i] = ReadMassErrors(stream, numPoints); } } if (chromGroupHeaderInfo.HasFragmentScanIds) { scanIds.Add(ChromSource.fragment, PrimitiveArrays.Read <int>(stream, numPoints)); } if (chromGroupHeaderInfo.HasSimScanIds) { scanIds.Add(ChromSource.sim, PrimitiveArrays.Read <int>(stream, numPoints)); } if (chromGroupHeaderInfo.HasMs1ScanIds) { scanIds.Add(ChromSource.ms1, PrimitiveArrays.Read <int>(stream, numPoints)); } List <TimeIntensities> listOfTimeIntensities = new List <TimeIntensities>(); for (int i = 0; i < numTrans; i++) { var chromSource = chromTransitions[i].Source; int[] transitionScanIds; scanIds.TryGetValue(chromSource, out transitionScanIds); var timeIntensities = new TimeIntensities(sharedTimes, transitionIntensities[i], transitionMassErrors[i], transitionScanIds); listOfTimeIntensities.Add(timeIntensities); } return(new InterpolatedTimeIntensities(listOfTimeIntensities, chromTransitions.Select(chromTransition => chromTransition.Source))); }
public static ChromLibSpectrumInfo Read(Stream stream) { LibKey key = LibKey.Read(stream); int id = PrimitiveArrays.ReadOneValue <int>(stream); double peakArea = PrimitiveArrays.ReadOneValue <double>(stream); var retentionTimesByFileId = IndexedRetentionTimes.Read(stream); int mzCount = PrimitiveArrays.ReadOneValue <int>(stream); var mzs = PrimitiveArrays.Read <double>(stream, mzCount); var areas = PrimitiveArrays.Read <float>(stream, mzCount); var mzAreas = ImmutableList.ValueOf(Enumerable.Range(0, mzCount) .Select(index => new SpectrumPeaksInfo.MI { Mz = mzs[index], Intensity = areas[index] })); return(new ChromLibSpectrumInfo(key, id, peakArea, retentionTimesByFileId, mzAreas)); }
private static float[] ReadMassErrors(Stream stream, int count) { return(PrimitiveArrays.Read <short>(stream, count).Select(value => value / 10f).ToArray()); }
protected void Complete(Exception x) { lock (this) { ChromatogramCache result = null; try { if (x == null && !_status.IsFinal) { long locationScanIds = 0, countBytesScanIds = 0; if (_fs.Stream != null) { try { locationScanIds = _fs.Stream.Position; countBytesScanIds = _fsScans.Stream.Position; ChromatogramCache.WriteStructs(_fs.Stream, _fsScans.Stream, _fsPeaks.Stream, _fsScores.Stream, _listCachedFiles, _listGroups, _listTransitions, _listTextIdBytes, _listScoreTypes, _scoreCount, _peakCount); _loader.StreamManager.Finish(_fs.Stream); _fs.Stream = null; // Allow cancelation right up to the final commit if (!_loader.IsCanceled) { _fs.Commit(_destinationStream); } else { _loader.UpdateProgress(_status = _status.Cancel()); } } catch (Exception xWrite) { throw new IOException(TextUtil.LineSeparate(string.Format(Resources.ChromCacheWriter_Complete_Failure_attempting_to_write_the_file__0_, _fs.RealName), xWrite.Message)); } } if (!_status.IsCanceled) { // Create stream identifier, but do not open. The stream will be opened // the first time the document uses it. var readStream = _loader.StreamManager.CreatePooledStream(CachePath, false); // DebugLog.Info("{0}. {1} - created", readStream.GlobalIndex, CachePath); _fsPeaks.Stream.Seek(0, SeekOrigin.Begin); _fsScores.Stream.Seek(0, SeekOrigin.Begin); var rawData = new ChromatogramCache.RawData { FormatVersion = ChromatogramCache.FORMAT_VERSION_CACHE, ChromCacheFiles = _listCachedFiles.ToArray(), ChromatogramEntries = _listGroups.ToArray(), ChromTransitions = _listTransitions.ToArray(), ChromatogramPeaks = new BlockedArray <ChromPeak>( count => ChromPeak.ReadArray(_fsPeaks.FileStream, count), _peakCount, ChromPeak.SizeOf, ChromPeak.DEFAULT_BLOCK_SIZE), ScoreTypes = _listScoreTypes.ToArray(), Scores = new BlockedArray <float>( count => PrimitiveArrays.Read <float>(_fsScores.FileStream, count), _scoreCount, sizeof(float), ChromatogramCache.DEFAULT_SCORES_BLOCK_SIZE), TextIdBytes = _listTextIdBytes.ToArray(), LocationScanIds = locationScanIds, CountBytesScanIds = countBytesScanIds, }; result = new ChromatogramCache(CachePath, rawData, readStream); _status = _status.Complete(); _loader.UpdateProgress(_status); } } } catch (Exception x2) { x = x2; } finally { Dispose(); } try { _completed(result, x == null ? _status : _status.ChangeErrorException(x)); } catch (Exception x2) { _completed(null, _status.ChangeErrorException(x2)); } } }
protected void Complete(Exception x) { lock (this) { ChromatogramCache result = null; try { if (x == null && !_status.IsFinal) { long locationScanIds = 0, countBytesScanIds = 0; if (_fs.Stream != null) { locationScanIds = _fs.Stream.Position; countBytesScanIds = _fsScans.Stream.Position; ChromatogramCache.WriteStructs(_fs.Stream, _fsScans.Stream, _fsPeaks.Stream, _fsScores.Stream, _listCachedFiles, _listGroups, _listTransitions, _listTextIdBytes, _listScoreTypes, _scoreCount, _peakCount); _loader.StreamManager.Finish(_fs.Stream); _fs.Stream = null; _fs.Commit(_destinationStream); } // Create stream identifier, but do not open. The stream will be opened // the first time the document uses it. var readStream = _loader.StreamManager.CreatePooledStream(CachePath, false); _fsPeaks.Stream.Seek(0, SeekOrigin.Begin); _fsScores.Stream.Seek(0, SeekOrigin.Begin); var rawData = new ChromatogramCache.RawData { FormatVersion = ChromatogramCache.FORMAT_VERSION_CACHE, ChromCacheFiles = _listCachedFiles.ToArray(), ChromatogramEntries = _listGroups.ToArray(), ChromTransitions = _listTransitions.ToArray(), ChromatogramPeaks = new BlockedArray <ChromPeak>( count => ChromPeak.ReadArray(_fsPeaks.FileStream.SafeFileHandle, count), _peakCount, ChromPeak.SizeOf, ChromPeak.DEFAULT_BLOCK_SIZE), ScoreTypes = _listScoreTypes.ToArray(), Scores = new BlockedArray <float>( count => PrimitiveArrays.Read <float>(_fsScores.FileStream, count), _scoreCount, sizeof(float), ChromatogramCache.DEFAULT_SCORES_BLOCK_SIZE), TextIdBytes = _listTextIdBytes.ToArray(), LocationScanIds = locationScanIds, CountBytesScanIds = countBytesScanIds, }; result = new ChromatogramCache(CachePath, rawData, readStream); _loader.UpdateProgress(_status.Complete()); } } catch (Exception x2) { x = x2; } finally { Dispose(); } try { _completed(result, x); } catch (Exception x2) { _completed(null, x2); } } }