Exemplo n.º 1
0
 public void Open()
 {
     if (File.Exists(FilePath))
     {
         _connection = MzIdentMLType.LoadFromFile(FilePath);
     }
     else
     {
         // Create a new file
         _connection = new MzIdentMLType();
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Write the provided data to the file
        /// </summary>
        /// <param name="identData"></param>
        /// <param name="filePath">Path to file to be written, with extension of .mzid[.gz]</param>
        /// <param name="bufferSize">File stream buffer size</param>
        public static void Write(MzIdentMLType identData, string filePath, int bufferSize = 65536)
        {
            var xRoot = new XmlRootAttribute()
            {
                ElementName = "MzIdentML",
                Namespace   = "http://psidev.info/psi/pi/mzIdentML/1.1",
                IsNullable  = false,
            };
            var serializer = new XmlSerializer(typeof(MzIdentMLType), xRoot);

            using (var writer = CreateWriter(filePath, bufferSize))
            {
                serializer.Serialize(writer, identData);
            }
        }
        /// <summary>
        /// Write the provided data to the file
        /// </summary>
        /// <param name="identData"></param>
        /// <param name="filePath">Path to file to be written, with extension of .mzid[.gz]</param>
        /// <param name="bufferSize">File stream buffer size</param>
        public static void Write(MzIdentMLType identData, string filePath, int bufferSize = 65536)
        {
            XmlSerializer serializer;

            if (identData.version.StartsWith("1.2"))
            {
                var overrides = GetMzIdentMl12Overrides(out var ns, out var xsdUrl);
                identData.xsiSchemaLocation = $"{ns} {xsdUrl}";
                serializer = new XmlSerializer(typeof(MzIdentMLType), overrides);
            }
            else
            {
                serializer = new XmlSerializer(typeof(MzIdentMLType), "http://psidev.info/psi/pi/mzIdentML/1.1");
            }

            using (var writer = CreateWriter(filePath, bufferSize))
            {
                serializer.Serialize(writer, identData);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Create an IdentDataObj directly from an MzIdentMLType object - fully cascades for the entire contents of
        /// MzIdentMLType
        /// </summary>
        /// <param name="mzid"></param>
        public IdentDataObj(MzIdentMLType mzid)
        {
            Id                    = mzid.id;
            Name                  = mzid.name;
            Version               = mzid.version;
            _creationDate         = mzid.creationDate;
            CreationDateSpecified = mzid.creationDateSpecified;

            CvTranslator                = new CVTranslator();
            _cvList                     = null;
            _analysisSoftwareList       = null;
            _provider                   = null;
            _auditCollection            = null;
            _analysisSampleCollection   = null;
            _sequenceCollection         = null;
            _analysisCollection         = null;
            _analysisProtocolCollection = null;
            _dataCollection             = null;
            _bibliographicReferences    = null;

            CVList = new IdentDataList <CVInfo>(1);
            BibliographicReferences  = new IdentDataList <BibliographicReferenceObj>(1);
            AuditCollection          = new IdentDataList <AbstractContactObj>(1);
            AnalysisSampleCollection = new IdentDataList <SampleObj>(1);
            AnalysisSoftwareList     = new IdentDataList <AnalysisSoftwareObj>(1);

            // Referenced by anything using CV/User params
            if (mzid.cvList?.Count > 0)
            {
                CVList.AddRange(mzid.cvList, cv => new CVInfo(cv, this));
                CvTranslator = new CVTranslator(_cvList);
            }
            // Referenced by nothing
            if (mzid.BibliographicReference?.Count > 0)
            {
                BibliographicReferences.AddRange(mzid.BibliographicReference, br => new BibliographicReferenceObj(br, this));
            }
            // Referenced by anything using organization, person, contactRoleInfo - SampleInfo, ProviderInfo, AnalysisSoftwareInfo
            if (mzid.AuditCollection?.Count > 0)
            {
                AuditCollection.AddRange(mzid.AuditCollection, ac =>
                {
                    if (ac is PersonType p)
                    {
                        return(new PersonObj(p, this));
                    }

                    if (ac is OrganizationType o)
                    {
                        return(new OrganizationObj(o, this));
                    }

                    return(null);
                });
            }
            // Referenced by anything using SampleInfo: SubSample, SpectrumIdentificationItem
            if (mzid.AnalysisSampleCollection?.Count > 0)
            {
                AnalysisSampleCollection.AddRange(mzid.AnalysisSampleCollection, asc => new SampleObj(asc, this));
            }
            // Referenced by ProviderInfo, ProteinDetectionProtocol, SpectrumIdentificationProtocol, references AbstractContactInfo through ContactRoleInfo
            if (mzid.AnalysisSoftwareList?.Count > 0)
            {
                AnalysisSoftwareList.AddRange(mzid.AnalysisSoftwareList, asl => new AnalysisSoftwareObj(asl, this));
            }
            // Referenced by nothing, references AnalysisSoftwareInfo
            if (mzid.Provider != null)
            {
                _provider = new ProviderObj(mzid.Provider, this);
            }
            // Referenced by SpectrumIdentification, ProteinDetection, SpectrumIdentificationItem, PeptideEvidence, references AnalysisSoftwareInfo
            if (mzid.AnalysisProtocolCollection != null)
            {
                _analysisProtocolCollection = new AnalysisProtocolCollectionObj(mzid.AnalysisProtocolCollection, this);
            }
            // InputsInfo referenced by DBSequence, SpectrumIdentification.SearchDatabaseRefInfo, SpectrumIdentificationResult, SpectrumIdentification.InputSpectraRef
            if (mzid.DataCollection != null)
            {
                //this._dataCollection = new DataCollection(mzid.DataCollection, this);
                _dataCollection = new DataCollectionObj {
                    Inputs = new InputsObj(mzid.DataCollection.Inputs, this)
                };
            }
            // Referenced by SpectrumIdentificationItem, ProteinDetectionHypothesis, PeptideHypothesis
            // References InputsInfo.DBSequence, AnalysisProtocolCollection.SoftwareIdentificationProtocol.DatabaseTranslation.TranslationTable
            if (mzid.SequenceCollection != null)
            {
                _sequenceCollection = new SequenceCollectionObj(mzid.SequenceCollection, this);
            }
            // AnalysisData referenced by SpectrumIdentification, InputSpectrumIdentifications, ProteinDetection, references Peptides, PeptideEvidence, SampleInfo, MassTable,
            if (mzid.DataCollection != null && _dataCollection != null)
            {
                _dataCollection.AnalysisData = new AnalysisDataObj(mzid.DataCollection.AnalysisData, this);
            }
            // References SpectrumIdentificationProtocol, SpectrumIdentificationList, SpectraData, SearchDatabaseInfo, ProteinDetectionList, ProteinDetectionProtocol
            if (mzid.AnalysisCollection != null)
            {
                _analysisCollection = new AnalysisCollectionObj(mzid.AnalysisCollection, this);
            }

            // Reduce memory footprint by removing IdentDataList IdMaps that are created during the translation process
            SequenceCollection?.DBSequences?.RemoveIdMap();
            SequenceCollection?.PeptideEvidences?.RemoveIdMap();
            SequenceCollection?.Peptides?.RemoveIdMap();
        }
Exemplo n.º 5
0
        /// <summary>
        ///     Create an IdentDataObj directly from an MzIdentMLType object - fully cascades for the entire contents of
        ///     MzIdentMLType
        /// </summary>
        /// <param name="mzid"></param>
        public IdentDataObj(MzIdentMLType mzid)
        {
            Id                    = mzid.id;
            Name                  = mzid.name;
            Version               = mzid.version;
            _creationDate         = mzid.creationDate;
            CreationDateSpecified = mzid.creationDateSpecified;

            CvTranslator                = new CVTranslator();
            _cvList                     = null;
            _analysisSoftwareList       = null;
            _provider                   = null;
            _auditCollection            = null;
            _analysisSampleCollection   = null;
            _sequenceCollection         = null;
            _analysisCollection         = null;
            _analysisProtocolCollection = null;
            _dataCollection             = null;
            _bibliographicReferences    = null;

            // Referenced by anything using CV/User params
            if (mzid.cvList != null && mzid.cvList.Count > 0)
            {
                CVList = new IdentDataList <CVInfo>();
                foreach (var cv in mzid.cvList)
                {
                    CVList.Add(new CVInfo(cv, this));
                }
                CvTranslator = new CVTranslator(_cvList);
            }
            // Referenced by nothing
            if (mzid.BibliographicReference != null && mzid.BibliographicReference.Count > 0)
            {
                BibliographicReferences = new IdentDataList <BibliographicReferenceObj>();
                foreach (var br in mzid.BibliographicReference)
                {
                    BibliographicReferences.Add(new BibliographicReferenceObj(br, this));
                }
            }
            // Referenced by anything using organization, person, contactRoleInfo - SampleInfo, ProviderInfo, AnalysisSoftwareInfo
            if (mzid.AuditCollection != null && mzid.AuditCollection.Count > 0)
            {
                AuditCollection = new IdentDataList <AbstractContactObj>();
                foreach (var ac in mzid.AuditCollection)
                {
                    if (ac is PersonType)
                    {
                        AuditCollection.Add(new PersonObj(ac as PersonType, this));
                    }
                    else if (ac is OrganizationType)
                    {
                        AuditCollection.Add(new OrganizationObj(ac as OrganizationType, this));
                    }
                }
            }
            // Referenced by anything using SampleInfo: SubSample, SpectrumIdentificationItem
            if (mzid.AnalysisSampleCollection != null && mzid.AnalysisSampleCollection.Count > 0)
            {
                AnalysisSampleCollection = new IdentDataList <SampleObj>();
                foreach (var asc in mzid.AnalysisSampleCollection)
                {
                    AnalysisSampleCollection.Add(new SampleObj(asc, this));
                }
            }
            // Referenced by ProviderInfo, ProteinDetectionProtocol, SpectrumIdentificationProtocol, references AbstractContactInfo through ContactRoleInfo
            if (mzid.AnalysisSoftwareList != null && mzid.AnalysisSoftwareList.Count > 0)
            {
                AnalysisSoftwareList = new IdentDataList <AnalysisSoftwareObj>();
                foreach (var asl in mzid.AnalysisSoftwareList)
                {
                    AnalysisSoftwareList.Add(new AnalysisSoftwareObj(asl, this));
                }
            }
            // Referenced by nothing, references AnalysisSoftwareInfo
            if (mzid.Provider != null)
            {
                _provider = new ProviderObj(mzid.Provider, this);
            }
            // Referenced by SpectrumIdentification, ProteinDetection, SpectrumIdentificationItem, PeptideEvidence, references AnalysisSoftwareInfo
            if (mzid.AnalysisProtocolCollection != null)
            {
                _analysisProtocolCollection = new AnalysisProtocolCollectionObj(mzid.AnalysisProtocolCollection, this);
            }
            // InputsInfo referenced by DBSequence, SpectrumIdentification.SearchDatabaseRefInfo, SpectrumIdentificationResult, SpectrumIdentification.InputSpectraRef
            if (mzid.DataCollection != null)
            {
                //this._dataCollection = new DataCollection(mzid.DataCollection, this);
                _dataCollection = new DataCollectionObj {
                    Inputs = new InputsObj(mzid.DataCollection.Inputs, this)
                };
            }
            // Referenced by SpectrumIdentificationItem, ProteinDetectionHypothesis, PeptideHypothesis
            // References InputsInfo.DBSequence, AnalysisProtocolCollection.SoftwareIdentificationProtocol.DatabaseTranslation.TranslationTable
            if (mzid.SequenceCollection != null)
            {
                _sequenceCollection = new SequenceCollectionObj(mzid.SequenceCollection, this);
            }
            // AnalysisData referenced by SpectrumIdentification, InputSpectrumIdentifications, ProteinDetection, references Peptides, PeptideEvidence, SampleInfo, MassTable,
            if (mzid.DataCollection != null)
            {
                _dataCollection.AnalysisData = new AnalysisDataObj(mzid.DataCollection.AnalysisData, this);
            }
            // References SpectrumIdentificationProtocol, SpectrumIdentificationList, SpectraData, SeqrchDatabaseInfo, ProteinDetectionList, ProteinDetectionProtocol
            if (mzid.AnalysisCollection != null)
            {
                _analysisCollection = new AnalysisCollectionObj(mzid.AnalysisCollection, this);
            }
        }