Beispiel #1
0
        public static void ExportMsMs(this UMCClusterLight cluster, string path, List <DatasetInformation> datasets,
                                      IMsMsSpectraWriter writer)
        {
            // Let's map the datasets first.
            var readers     = new Dictionary <int, ISpectraProvider>();
            var information = new Dictionary <int, DatasetInformation>();

            datasets.ForEach(x => information.Add(x.DatasetId, x));

            // We are only loading what datasets we have to here!
            // The point is, each cluster or feature may have come from a different raw data source...
            // since we dont store all of the data in memory, we have to fetch it from the appropriate source.
            // This means that we have to go into the raw data and get the scans for an MSMS spectra.
            foreach (var feature in cluster.Features)
            {
                if (!readers.ContainsKey(feature.GroupId))
                {
                    if (information.ContainsKey(feature.GroupId))
                    {
                        var singleInfo = information[feature.GroupId];

                        if (singleInfo.RawFile != null)
                        {
                            // Make sure that we have a file.
                            if (!File.Exists(singleInfo.RawFile.Path))
                            {
                                continue;
                            }
Beispiel #2
0
 /// <summary>
 ///     Default constructor.
 /// </summary>
 /// <param name="path"></param>
 public UMCClusterMsmsSpectraWriter(string name, IMsMsSpectraWriter spectraWriter, string extension)
     : base(true)
 {
     m_spectraWriter = spectraWriter;
     Extension       = extension;
     Name            = name;
     Description     = "Writes the a cluster and the associated MS/MS meta-data.";
 }
 /// <summary>
 ///     Default constructor.
 /// </summary>
 /// <param name="path"></param>
 public UMCClusterMsmsSpectraWriter(string name, IMsMsSpectraWriter spectraWriter, string extension)
     : base(true)
 {
     m_spectraWriter = spectraWriter;
     Extension = extension;
     Name = name;
     Description = "Writes the a cluster and the associated MS/MS meta-data.";
 }
Beispiel #4
0
        /// <summary>
        /// Creates a spectra writer based on the file type.
        /// </summary>
        /// <param name="writerType"></param>
        /// <returns></returns>
        public static IMsMsSpectraWriter CreateSpectraWriter(string extension)
        {
            IMsMsSpectraWriter writer = null;

            switch (extension)
            {
            case ".dta":
                writer = CreateSpectraWriter(MsMsWriterType.DTA);
                break;

            case ".mgf":
                writer = CreateSpectraWriter(MsMsWriterType.MGF);
                break;
            }
            return(writer);
        }
Beispiel #5
0
        /// <summary>
        /// Creates a spectra writer based on the file type.
        /// </summary>
        /// <param name="writerType"></param>
        /// <returns></returns>
        public static IMsMsSpectraWriter CreateSpectraWriter(MsMsWriterType writerType)
        {
            IMsMsSpectraWriter writer = null;

            switch (writerType)
            {
            case MsMsWriterType.DTA:
                writer = new DtaFileWriter();
                break;

            case MsMsWriterType.MGF:
                writer = new MgfFileWriter();
                break;

            default:
                break;
            }
            return(writer);
        }
Beispiel #6
0
        public static void ExportMsMs(this UMCClusterLight cluster, string path, List<DatasetInformation> datasets,
            IMsMsSpectraWriter writer)
        {
            // Let's map the datasets first.
            var readers = new Dictionary<int, ISpectraProvider>();
            var information = new Dictionary<int, DatasetInformation>();

            datasets.ForEach(x => information.Add(x.DatasetId, x));

            // We are only loading what datasets we have to here!
            // The point is, each cluster or feature may have come from a different raw data source...
            // since we dont store all of the data in memory, we have to fetch it from the appropriate source.
            // This means that we have to go into the raw data and get the scans for an MSMS spectra.
            foreach (var feature in cluster.Features)
            {
                if (!readers.ContainsKey(feature.GroupId))
                {
                    if (information.ContainsKey(feature.GroupId))
                    {
                        var singleInfo = information[feature.GroupId];

                        if (singleInfo.Raw != null && singleInfo.RawPath != null)
                        {
                            // Make sure that we have a file.
                            if (!File.Exists(singleInfo.RawPath))
                                continue;

                            // Here we create a data file reader for the file we want to access.
                            var provider = RawLoaderFactory.CreateFileReader(singleInfo.RawPath);
                            // Then we make sure we key it to the provider.
                            provider.AddDataFile(singleInfo.RawPath, feature.GroupId);
                            // Then make sure we map it for a dataset, so when we sort through a cluster
                            // we make sure that we can access in O(1) time.
                            readers.Add(feature.GroupId, provider);
                        }
                    }
                }
            }

            // We flag the first write, so that if the file exists, we overwrite.  They should have done
            // checking to make sure that the file was already created...we dont care.
            var firstWrite = true;
            foreach (var feature in cluster.Features)
            {
                if (readers.ContainsKey(feature.GroupId))
                {
                    var provider = readers[feature.GroupId];
                    foreach (var msFeature in feature.MsFeatures)
                    {
                        foreach (var spectrum in msFeature.MSnSpectra)
                        {
                            var summary = new ScanSummary();
                            var data = provider.GetRawSpectra(spectrum.Scan, spectrum.GroupId, out summary);
                            spectrum.Peaks = data;
                            spectrum.ScanMetaData = summary;
                        }
                        if (firstWrite)
                        {
                            writer.Write(path, msFeature.MSnSpectra);
                        }
                        else
                        {
                            writer.Append(path, msFeature.MSnSpectra);
                        }
                    }
                }
            }
        }