Beispiel #1
0
        /**
         * Create a MZTabFile with defined metadata.
         *
         * @param metadata SHOULD NOT set null.
         */
        public MZTabFile(Metadata metadata)
        {
            if (metadata == null){
                throw new NullReferenceException("Metadata should be created first.");
            }

            this.metadata = metadata;
        }
        /**
         * Parse a header line into {@link MZTabColumnFactory} structure.
         *
         * @param factory SHOULD NOT set null
         * @param metadata SHOULD NOT set null
         */
        protected MZTabHeaderLineParser(MZTabColumnFactory factory, Metadata metadata)
        {
            if (factory == null){
                throw new NullReferenceException("Header line should be parse first!");
            }
            this.factory = factory;

            if (metadata == null){
                throw new NullReferenceException("Metadata should be create first!");
            }
            this.metadata = metadata;
        }
        /**
         * Generate a mzTab data line parser. A couple of common method used to parse a data line into
         * {@link MZTabRecord} structure.
         *
         * NOTICE: {@link MZTabColumnFactory} maintain a couple of {@link MZTabColumn} which have internal logical
         * position and order. In physical mzTab file, we allow user not obey this logical position organized way,
         * and provide their date with own order. In order to distinguish them, we use physical position (a positive
         * integer) to record the column location in mzTab file. And use {@link PositionMapping} structure the maintain
         * the mapping between them.
         *
         * @param factory SHOULD NOT set null
         * @param positionMapping SHOULD NOT set null
         * @param metadata SHOULD NOT set null
         */
        protected MZTabDataLineParser(MZTabColumnFactory factory, PositionMapping positionMapping,
                                      Metadata metadata, MZTabErrorList errorList)
        {
            if (factory == null){
                throw new NullReferenceException("Column header factory should be create first.");
            }
            this.factory = factory;

            this.positionMapping = positionMapping;
            exchangeMapping = positionMapping.exchange();

            mapping = factory.GetOffsetColumnsMap();

            if (metadata == null){
                throw new NullReferenceException("Metadata should be parser first.");
            }
            this.metadata = metadata;
            _errorList = errorList ?? new MZTabErrorList();
        }
        private void addPeptideValue()
        {
            MsRun msRun1 = new MsRun(1);
            Assay assay1 = new Assay(1);
            Assay assay2 = new Assay(2);
            StudyVariable studyVariable1 = new StudyVariable(1);

            MZTabColumnFactory factory = MZTabColumnFactory.GetInstance(Section.Peptide_Header);
            factory.AddOptionalColumn(PeptideColumn.SEARCH_ENGINE_SCORE, msRun1);
            factory.AddAbundanceOptionalColumn(assay1);
            factory.AddAbundanceOptionalColumn(studyVariable1);
            factory.AddAbundanceOptionalColumn(assay2);
            factory.AddOptionalColumn(msRun1, "my_value", typeof (string));
            CVParam param = new CVParam("MS", "MS:1002217", "decoy peptide", null);
            factory.AddOptionalColumn(param, typeof (string));

            Metadata metadata = new Metadata();
            metadata.AddMsRunLocation(2, new Url("file://C:\\path\\to\\my\\file"));

            Console.WriteLine(factory);

            Peptide peptide = new Peptide(factory, metadata);

            peptide.Sequence = "KVPQVSTPTLVEVSR";
            peptide.Accession = "P02768";
            peptide.SetUnique("0");
            peptide.Database = "UniProtKB";
            peptide.DatabaseVersion = "2011_11";
            peptide.SetSearchEngine("[MS,MS:1001207,Mascot,]|[MS,MS:1001208,Sequest,]");
            peptide.SetBestSearchEngineScore("[MS,MS:1001155,Sequest:xcorr,2]");
            peptide.Reliability = Reliability.findReliability("3");
            peptide.SetModifications(
                "3[MS,MS:1001876, modification probability, 0.8]|4[MS,MS:1001876, modification probability, 0.2]-MOD:00412,8[MS,MS:1001876, modification probability, 0.3]-MOD:00412");
            peptide.AddRetentionTime(10.2);
            peptide.AddRetentionTimeWindow(1123.2);
            peptide.AddRetentionTimeWindow(1145.3);
            peptide.Charge = new Integer(2);
            peptide.MassToCharge = 1234.4;
            peptide.URI = new Uri("http://www.ebi.ac.uk/pride/link/to/peptide");
            peptide.SetSpectraRef("ms_run[2]:index=7|ms_run[2]:index=9");
            Console.WriteLine(peptide);
        }
Beispiel #5
0
 public Peptide(Metadata metadata)
     : base(MZTabColumnFactory.GetInstance(Section.Peptide))
 {
     this.metadata = metadata;
 }
 public PEHLineParser(Metadata metadata)
     : base(MZTabColumnFactory.GetInstance(Section.Peptide_Header), metadata)
 {
 }
 public PRHLineParser(Metadata metadata)
     : base(MZTabColumnFactory.GetInstance(Section.Protein_Header), metadata)
 {
 }
        public static void main(string[] args)
        {
            MZTabDescription tabDescription = new MZTabDescription(MzTabMode.Summary, MzTabType.Identification){
                Id = "PRIDE_1234"
            };
            Metadata mtd = new Metadata(tabDescription);

            mtd.Title = "My first test experiment";
            mtd.Description = "An experiment investigating the effects of Il-6.";

            mtd.AddSampleProcessingParam(1, new CVParam("SEP", "SEP:00173", "SDS PAGE", null));
            mtd.AddSampleProcessingParam(2, new CVParam("SEP", "SEP:00142", "enzyme digestion", null));
            mtd.AddSampleProcessingParam(2, new CVParam("MS", "MS:1001251", "Trypsin", null));

            mtd.AddInstrumentName(1, new CVParam("MS", "MS:100049", "LTQ Orbitrap", null));
            mtd.AddInstrumentName(2,
                                  new CVParam("MS", "MS:1000031", "Instrument model",
                                              "name of the instrument not included in the CV"));
            mtd.AddInstrumentSource(1, new CVParam("MS", "MS:1000073", "ESI", null));
            mtd.AddInstrumentSource(2, new CVParam("MS", "MS:1000598", "ETD", null));
            mtd.AddInstrumentAnalyzer(1, new CVParam("MS", "MS:1000291", "linear ion trap", null));
            mtd.AddInstrumentAnalyzer(2, new CVParam("MS", "MS:1000484", "orbitrap", null));
            mtd.AddInstrumentDetector(1, new CVParam("MS", "MS:1000253", "electron multiplier", null));
            mtd.AddInstrumentDetector(2, new CVParam("MS", "MS:1000348", "focal plane collector", null));

            mtd.AddSoftwareParam(1, new CVParam("MS", "MS:1001207", "Mascot", "2.3"));
            mtd.AddSoftwareParam(2, new CVParam("MS", "MS:1001561", "Scaffold", "1.0"));
            mtd.AddSoftwareSetting(1, "Fragment tolerance = 0.1Da");
            mtd.AddSoftwareSetting(1, "Parent tolerance = 0.5Da");

            mtd.AddFalseDiscoveryRateParam(new CVParam("MS", "MS:1001364", "pep:global FDR", "0.01"));
            mtd.AddFalseDiscoveryRateParam(new CVParam("MS", "MS:1001214", "pep:global FDR", "0.08"));

            mtd.AddPublicationItem(1, PublicationType.PUBMED, "21063943");
            mtd.AddPublicationItem(1, PublicationType.DOI, "10.1007/978-1-60761-987-1_6");
            mtd.AddPublicationItem(2, PublicationType.PUBMED, "20615486");
            mtd.AddPublicationItem(2, PublicationType.DOI, "10.1016/j.jprot.2010.06.008");

            mtd.AddContactName(1, "James D. Watson");
            mtd.AddContactName(2, "Francis Crick");
            mtd.AddContactAffiliation(1, "Cambridge University, UK");
            mtd.AddContactAffiliation(2, "Cambridge University, UK");
            mtd.AddContactEmail(1, "*****@*****.**");
            mtd.AddContactEmail(2, "*****@*****.**");

            mtd.AddUri(new Uri("http://www.ebi.ac.uk/pride/url/to/experiment"));
            mtd.AddUri(new Uri("http://proteomecentral.proteomexchange.org/cgi/GetDataset"));

            mtd.AddFixedModParam(1, new CVParam("UNIMOD", "UNIMOD:4", "Carbamidomethyl", null));
            mtd.AddFixedModSite(1, "M");
            mtd.AddFixedModParam(2, new CVParam("UNIMOD", "UNIMOD:35", "Oxidation", null));
            mtd.AddFixedModSite(2, "N-term");
            mtd.AddFixedModParam(3, new CVParam("UNIMOD", "UNIMOD:1", "Acetyl", null));
            mtd.AddFixedModPosition(3, "Protein C-term");

            mtd.AddVariableModParam(1, new CVParam("UNIMOD", "UNIMOD:21", "Phospho", null));
            mtd.AddVariableModSite(1, "M");
            mtd.AddVariableModParam(2, new CVParam("UNIMOD", "UNIMOD:35", "Oxidation", null));
            mtd.AddVariableModSite(2, "N-term");
            mtd.AddVariableModParam(3, new CVParam("UNIMOD", "UNIMOD:1", "Acetyl", null));
            mtd.AddVariableModPosition(3, "Protein C-term");

            mtd.QuantificationMethod = new CVParam("MS", "MS:1001837", "iTRAQ quantitation analysis", null);
            mtd.ProteinQuantificationUnit = new CVParam("PRIDE", "PRIDE:0000395", "Ratio", null);
            mtd.PeptideQuantificationUnit = new CVParam("PRIDE", "PRIDE:0000395", "Ratio", null);
            mtd.SmallMoleculeQuantificationUnit = new CVParam("PRIDE", "PRIDE:0000395", "Ratio", null);

            mtd.AddMsRunFormat(1, new CVParam("MS", "MS:1000584", "mzML file", null));
            mtd.AddMsRunFormat(2, new CVParam("MS", "MS:1001062", "Mascot MGF file", null));
            mtd.AddMsRunLocation(1, new Url("file://C:\\path\\to\\my\\file"));
            mtd.AddMsRunLocation(2, new Url("ftp://ftp.ebi.ac.uk/path/to/file"));
            mtd.AddMsRunIdFormat(1, new CVParam("MS", "MS:1001530", "mzML unique identifier", null));
            mtd.AddMsRunFragmentationMethod(1, new CVParam("MS", "MS:1000133", "CID", null));
            mtd.AddMsRunFragmentationMethod(2, new CVParam("MS", "MS:1000422", "HCD", null));

            mtd.AddCustom(new UserParam("MS operator", "Florian"));

            mtd.AddSampleSpecies(1, new CVParam("NEWT", "9606", "H**o sapiens (Human)", null));
            mtd.AddSampleSpecies(1, new CVParam("NEWT", "573824", "Human rhinovirus 1", null));
            mtd.AddSampleSpecies(2, new CVParam("NEWT", "9606", "H**o sapiens (Human)", null));
            mtd.AddSampleSpecies(2, new CVParam("NEWT", "12130", "Human rhinovirus 2", null));
            mtd.AddSampleTissue(1, new CVParam("BTO", "BTO:0000759", "liver", null));
            mtd.AddSampleCellType(1, new CVParam("CL", "CL:0000182", "hepatocyte", null));
            mtd.AddSampleDisease(1, new CVParam("DOID", "DOID:684", "hepatocellular carcinoma", null));
            mtd.AddSampleDisease(1, new CVParam("DOID", "DOID:9451", "alcoholic fatty liver", null));
            mtd.AddSampleDescription(1, "Hepatocellular carcinoma samples.");
            mtd.AddSampleDescription(2, "Healthy control samples.");
            mtd.AddSampleCustom(1, new UserParam("Extraction date", "2011-12-21"));
            mtd.AddSampleCustom(1, new UserParam("Extraction reason", "liver biopsy"));

            Sample sample1 = mtd.SampleMap[1];
            Sample sample2 = mtd.SampleMap[2];
            mtd.AddAssayQuantificationReagent(1, new CVParam("PRIDE", "PRIDE:0000114", "iTRAQ reagent", "114"));
            mtd.AddAssayQuantificationReagent(2, new CVParam("PRIDE", "PRIDE:0000115", "iTRAQ reagent", "115"));
            mtd.AddAssayQuantificationReagent(1, new CVParam("PRIDE", "MS:1002038", "unlabeled sample", null));
            mtd.AddAssaySample(1, sample1);
            mtd.AddAssaySample(2, sample2);

            mtd.AddAssayQuantificationModParam(2, 1, new CVParam("UNIMOD", "UNIMOD:188", "Label:13C(6)", null));
            mtd.AddAssayQuantificationModParam(2, 2, new CVParam("UNIMOD", "UNIMOD:188", "Label:13C(6)", null));
            mtd.AddAssayQuantificationModSite(2, 1, "R");
            mtd.AddAssayQuantificationModSite(2, 2, "K");
            mtd.AddAssayQuantificationModPosition(2, 1, "Anywhere");
            mtd.AddAssayQuantificationModPosition(2, 2, "Anywhere");

            MsRun msRun1 = mtd.MsRunMap[1];
            mtd.AddAssayMsRun(1, msRun1);

            Assay assay1 = mtd.AssayMap[1];
            Assay assay2 = mtd.AssayMap[2];
            mtd.AddStudyVariableAssay(1, assay1);
            mtd.AddStudyVariableAssay(1, assay2);

            mtd.AddStudyVariableSample(1, sample1);
            mtd.AddStudyVariableDescription(1, "description Group B (spike-in 0.74 fmol/uL)");

            mtd.AddCVLabel(1, "MS");
            mtd.AddCVFullName(1, "MS");
            mtd.AddCVVersion(1, "3.54.0");
            mtd.AddCVURL(1,
                         "http://psidev.cvs.sourceforge.net/viewvc/psidev/psi/psi-ms/mzML/controlledVocabulary/psi-ms.obo");

            mtd.AddProteinColUnit(ProteinColumn.RELIABILITY,
                                  new CVParam("MS", "MS:00001231", "PeptideProphet:Score", null));

            MZTabColumnFactory peptideFactory = MZTabColumnFactory.GetInstance(Section.Peptide);
            PeptideColumn peptideColumn = (PeptideColumn) peptideFactory.FindColumnByHeader("retention_time");
            mtd.AddPeptideColUnit(peptideColumn, new CVParam("UO", "UO:0000031", "minute", null));

            mtd.AddPSMColUnit(PSMColumn.RETENTION_TIME, new CVParam("UO", "UO:0000031", "minute", null));
            mtd.AddSmallMoleculeColUnit(SmallMoleculeColumn.RETENTION_TIME,
                                        new CVParam("UO", "UO:0000031", "minute", null));

            Console.WriteLine(mtd);
        }
 public SmallMolecule(Metadata metadata)
     : base(MZTabColumnFactory.GetInstance(Section.Small_Molecule))
 {
     this.metadata = metadata;
 }
        private void addPSMValue()
        {
            Assay assay1 = new Assay(1);

            MZTabColumnFactory factory = MZTabColumnFactory.GetInstance(Section.PSM_Header);
            factory.AddOptionalColumn(assay1, "my_value", typeof (string));
            CVParam param = new CVParam("MS", "MS:1002217", "decoy peptide", null);
            factory.AddOptionalColumn(param, typeof (string));

            Metadata metadata = new Metadata();
            metadata.AddMsRunLocation(2, new Url("file://C:\\path\\to\\my\\file"));

            Console.WriteLine(factory);
            PSM psm = new PSM(factory, metadata);

            psm.Sequence = "KVPQVSTPTLVEVSR";
            psm.SetPSM_ID("1");
            psm.Accession = "P02768";
            psm.Unique = MZBoolean.False;
            psm.Database = "UniProtKB";
            psm.DatabaseVersion = "2011_11";
            psm.setSearchEngine("[MS,MS:1001207,Mascot,]|[MS,MS:1001208,Sequest,]");
            psm.setSearchEngineScore("[MS,MS:1001155,Sequest:xcorr,2]");
            psm.setReliability("3");
            psm.setModifications("CHEMMOD:+159.93");
            psm.AddRetentionTime(10.2);
            psm.Charge = new Integer(2);
            psm.SetExpMassToCharge("1234.4");
            psm.SetCalcMassToCharge("123.4");
            psm.SetUri("http://www.ebi.ac.uk/pride/link/to/peptide");
            psm.SetSpectraRef("ms_run[2]:index=7|ms_run[2]:index=9");
            psm.Pre = "K";
            psm.Post = "D";
            psm.Start = "45";
            psm.End = "57";
            Console.WriteLine(psm);
        }
 private void AddTitleParameter(IList<Parameter> list, IList<ParameterDescription> help, Metadata mtd)
 {
     string name = MetadataElement.TITLE.Name;
     string desc = null;
     name = CheckIfDescriptionExists(help, name, ref desc, mtd);
     StringParam id = new StringParam(name){Value = mtd.Title, Help = desc};
     list.Add(id);
 }
        private void AddMzParameters(IList<Parameter> list, IList<ParameterDescription> help, Metadata mtd)
        {
            string name = string.Format("{0}{1}{2}", MetadataElement.MZTAB, MZTabConstants.MINUS,
                                        MetadataProperty.MZTAB_VERSION);
            string desc = null;
            name = CheckIfDescriptionExists(help, name, ref desc, mtd);
            StringParam version = new StringParam(name, Constants.versions.Last()){
                Help = desc
            };
            list.Add(version);

            IList<string> values = Enum.GetNames(typeof (MzTabMode));
            name = string.Format("{0}{1}{2}", MetadataElement.MZTAB, MZTabConstants.MINUS, MetadataProperty.MZTAB_MODE);
            desc = null;
            name = CheckIfDescriptionExists(help, name, ref desc, mtd);
            SingleChoiceParam mode = new SingleChoiceParam(name){
                Values = values,
                Value = values.IndexOf(mtd.TabDescription.MzTabMode.ToString()),
                Help = desc
            };
            list.Add(mode);

            values = Enum.GetNames(typeof (MzTabType));
            name = string.Format("{0}{1}{2}", MetadataElement.MZTAB, MZTabConstants.MINUS, MetadataProperty.MZTAB_TYPE);
            desc = null;
            name = CheckIfDescriptionExists(help, name, ref desc, mtd);
            SingleChoiceParam type = new SingleChoiceParam(name){
                Values = values,
                Value = values.IndexOf(mtd.TabDescription.MzTabType.ToString()),
                Help = desc
            };
            list.Add(type);

            name = string.Format("{0}{1}{2}", MetadataElement.MZTAB, MZTabConstants.MINUS, MetadataProperty.MZTAB_ID);
            desc = null;
            name = CheckIfDescriptionExists(help, name, ref desc, mtd);
            StringParam id = new StringParam(name){Value = mtd.TabDescription.Id, Help = desc};
            list.Add(id);
        }
        public override IMatrixData ProcessData(IMatrixData[] inputData, Parameters param, ref IMatrixData[] supplTables,
                                                ref IDocumentData[] documents, ProcessInfo processInfo)
        {
            Metadata mtd = new Metadata();

            string name = string.Format("{0}{1}{2}", MetadataElement.MZTAB, MZTabConstants.MINUS,
                                        MetadataProperty.MZTAB_VERSION);
            StringParam stringParam = FindParam(param, name) as StringParam;
            if (stringParam != null && !string.IsNullOrEmpty(stringParam.Value)){
                mtd.MZTabVersion = stringParam.Value;
            }

            name = string.Format("{0}{1}{2}", MetadataElement.MZTAB, MZTabConstants.MINUS, MetadataProperty.MZTAB_MODE);
            SingleChoiceParam single = FindParam(param, name) as SingleChoiceParam;
            if (single != null && !string.IsNullOrEmpty(single.SelectedValue)){
                MzTabMode mode;
                if (Enum.TryParse(single.SelectedValue, true, out mode)){
                    mtd.MzTabMode = mode;
                }
            }

            name = string.Format("{0}{1}{2}", MetadataElement.MZTAB, MZTabConstants.MINUS, MetadataProperty.MZTAB_TYPE);
            single = FindParam(param, name) as SingleChoiceParam;
            if (single != null && !string.IsNullOrEmpty(single.SelectedValue)){
                MzTabType type;
                if (Enum.TryParse(single.SelectedValue, true, out type)){
                    mtd.MzTabType = type;
                }
            }

            name = string.Format("{0}{1}{2}", MetadataElement.MZTAB, MZTabConstants.MINUS, MetadataProperty.MZTAB_ID);
            stringParam = FindParam(param, name) as StringParam;
            if (stringParam != null && !string.IsNullOrEmpty(stringParam.Value)){
                mtd.MZTabID = stringParam.Value;
            }

            stringParam = FindParam(param, MetadataElement.TITLE.Name) as StringParam;
            if (stringParam != null && !string.IsNullOrEmpty(stringParam.Value)){
                mtd.SetTitle(stringParam.Value);
            }

            stringParam = FindParam(param, MetadataElement.DESCRIPTION.Name) as StringParam;
            if (stringParam != null && !string.IsNullOrEmpty(stringParam.Value)){
                mtd.SetDescription(stringParam.Value);
            }

            SingleChoiceWithSubParams singleSub =
                FindParam(param, MetadataElement.SAMPLE_PROCESSING.Name) as SingleChoiceWithSubParams;
            if (singleSub != null){
                SampleProcessingParam sub =
                    singleSub.SubParams[singleSub.Value].GetAllParameters().FirstOrDefault() as SampleProcessingParam;
                if (sub != null){
                    if (sub.Value != null){
                        for (int j = 0; j < sub.Value.Length; j++){
                            mtd.SampleProcessingMap.Add(j + 1, sub.Value[j]);
                        }
                    }
                }
            }

            singleSub = FindParam(param, MetadataElement.INSTRUMENT.Name) as SingleChoiceWithSubParams;
            if (singleSub != null){
                InstrumentParam sub =
                    singleSub.SubParams[singleSub.Value].GetAllParameters().FirstOrDefault() as InstrumentParam;
                if (sub != null){
                    if (sub.Value != null){
                        for (int j = 0; j < sub.Value.Length; j++){
                            mtd.InstrumentMap.Add(j + 1, sub.Value[j]);
                        }
                    }
                }
            }

            singleSub = FindParam(param, MetadataElement.SOFTWARE.Name) as SingleChoiceWithSubParams;
            if (singleSub != null){
                SoftwareParam sub =
                    singleSub.SubParams[singleSub.Value].GetAllParameters().FirstOrDefault() as SoftwareParam;
                if (sub != null){
                    if (sub.Value != null){
                        for (int j = 0; j < sub.Value.Length; j++){
                            mtd.SoftwareMap.Add(j + 1, sub.Value[j]);
                        }
                    }
                }
            }

            MultiChoiceParam multi = FindParam(param, MetadataElement.FALSE_DISCOVERY_RATE.Name) as MultiChoiceParam;
            if (multi != null && multi.SelectedValues != null && multi.SelectedValues.Any()){
                foreach (string sel in multi.SelectedValues){
                    string[] items = sel.Split('=');
                    if (items.Length != 2){
                        continue;
                    }
                    string key = items[0];
                    string value = items[1];

                    if (ContainsParameterKey(parameters.protein_fdr, key)){
                        key = "prot:global FDR";
                    } else if (ContainsParameterKey(parameters.psm_fdr, key)) {
                        key = "pep:global FDR";
                    } else if (ContainsParameterKey(parameters.site_fdr, key)) {
                        key = "site:global FDR";
                    }

                    Lib.Model.Param p = cv.GetParam(key, "MS", value);
                    if (p != null){
                        mtd.FalseDiscoveryRate.Add(p);
                    }
                }
            }

            singleSub = FindParam(param, MetadataElement.PUBLICATION.Name) as SingleChoiceWithSubParams;
            if (singleSub != null){
                PublicationParam sub =
                    singleSub.SubParams[singleSub.Value].GetAllParameters().FirstOrDefault() as PublicationParam;
                if (sub != null){
                    if (sub.Value != null){
                        for (int j = 0; j < sub.Value.Length; j++){
                            mtd.PublicationMap.Add(j + 1, sub.Value[j]);
                        }
                    }
                }
            }

            singleSub = FindParam(param, MetadataElement.CONTACT.Name) as SingleChoiceWithSubParams;
            if (singleSub != null){
                ContactParam sub =
                    singleSub.SubParams[singleSub.Value].GetAllParameters().FirstOrDefault() as ContactParam;
                if (sub != null){
                    if (sub.Value != null){
                        for (int j = 0; j < sub.Value.Length; j++){
                            mtd.ContactMap.Add(j + 1, sub.Value[j]);
                        }
                    }
                }
            }

            singleSub = FindParam(param, MetadataElement.FIXED_MOD.Name) as SingleChoiceWithSubParams;
            if (singleSub != null){
                ModificationParam sub =
                    singleSub.SubParams[singleSub.Value].GetAllParameters().FirstOrDefault() as ModificationParam;
                if (sub != null){
                    if (sub.Value != null){
                        for (int j = 0; j < sub.Value.Length; j++){
                            mtd.FixedModMap.Add(j + 1, (FixedMod) sub.Value[j]);
                        }
                    }
                }
            }

            singleSub = FindParam(param, MetadataElement.VARIABLE_MOD.Name) as SingleChoiceWithSubParams;
            if (singleSub != null){
                ModificationParam sub =
                    singleSub.SubParams[singleSub.Value].GetAllParameters().FirstOrDefault() as ModificationParam;
                if (sub != null){
                    if (sub.Value != null){
                        for (int j = 0; j < sub.Value.Length; j++){
                            mtd.VariableModMap.Add(j + 1, (VariableMod) sub.Value[j]);
                        }
                    }
                }
            }

            single = FindParam(param, MetadataElement.QUANTIFICATION_METHOD.Name) as SingleChoiceParam;
            if (single != null && !string.IsNullOrEmpty(single.SelectedValue)){
                Lib.Model.Param temp;
                mtd.QuantificationMethod = Lib.Model.Param.TryParse(single.SelectedValue, out temp)
                                               ? temp
                                               : cv.GetParam(single.SelectedValue, "MS");
            }

            name = string.Format("{0}{1}{2}", MetadataElement.PROTEIN, MZTabConstants.MINUS,
                                 MetadataProperty.PROTEIN_QUANTIFICATION_UNIT);
            single = FindParam(param, name) as SingleChoiceParam;
            if (single != null && !string.IsNullOrEmpty(single.SelectedValue)){
                Lib.Model.Param temp;
                mtd.ProteinQuantificationUnit = Lib.Model.Param.TryParse(single.SelectedValue, out temp)
                                                    ? temp
                                                    : cv.GetParam(single.SelectedValue, "PRIDE");
            }

            name = string.Format("{0}{1}{2}", MetadataElement.PEPTIDE, MZTabConstants.MINUS,
                                 MetadataProperty.PROTEIN_QUANTIFICATION_UNIT);
            single = FindParam(param, name) as SingleChoiceParam;
            if (single != null && !string.IsNullOrEmpty(single.SelectedValue)){
                Lib.Model.Param temp;
                mtd.PeptideQuantificationUnit = Lib.Model.Param.TryParse(single.SelectedValue, out temp)
                                                    ? temp
                                                    : cv.GetParam(single.SelectedValue, "PRIDE");
            }

            Regex regex = new Regex("[A-Z]{1}:/");
            MsRunParam msrunParam = FindParam(param, MetadataElement.MS_RUN.Name) as MsRunParam;
            if (msrunParam != null){
                if (msrunParam.Value != null){
                    for (int j = 0; j < msrunParam.Value.Length; j++){
                        MsRunImpl runImpl = msrunParam.Value[j];
                        if (regex.IsMatch(runImpl.Location.Value)){
                            runImpl.Location = new Url("file:\\\\\\" + runImpl.Location.Value);
                        }
                        mtd.MsRunMap.Add(j + 1, runImpl);
                    }
                }
            }

            SampleParam sampleParam = FindParam(param, MetadataElement.SAMPLE.Name) as SampleParam;
            if (sampleParam != null){
                if (sampleParam.Value != null){
                    for (int j = 0; j < sampleParam.Value.Length; j++){
                        mtd.SampleMap.Add(j + 1, sampleParam.Value[j]);
                    }
                }
            }

            AssayParam assayParam = FindParam(param, MetadataElement.ASSAY.Name) as AssayParam;
            if (assayParam != null){
                if (assayParam.Value != null){
                    for (int j = 0; j < assayParam.Value.Length; j++){
                        mtd.AssayMap.Add(j + 1, assayParam.Value[j]);
                    }
                }
            }

            StudyVariableParam studyVariableParam =
                FindParam(param, MetadataElement.STUDY_VARIABLE.Name) as StudyVariableParam;
            if (studyVariableParam != null){
                if (studyVariableParam.Value != null){
                    for (int j = 0; j < studyVariableParam.Value.Length; j++){
                        mtd.StudyVariableMap.Add(j + 1, studyVariableParam.Value[j]);
                    }
                }
            }

            multi = FindParam(param, MetadataElement.CV.Name) as MultiChoiceParam;
            if (multi != null && multi.SelectedValues != null){
                var headers = cv.Headers;
                foreach (string value in multi.SelectedValues){
                    var temp = headers.FirstOrDefault(x => x.FullName.Equals(value));
                    if (temp == null){
                        continue;
                    }
                    int id = mtd.CvMap.Count + 1;
                    mtd.CvMap.Add(id,
                                  new CV(id){
                                      FullName = temp.FullName,
                                      Label = temp.Label,
                                      Url = temp.Url,
                                      Version = temp.Version
                                  });
                }
            }

            string mtdString = mtd.ToString();
            string[] lines = mtdString.Split(new[]{"\n"}, StringSplitOptions.RemoveEmptyEntries);

            List<string> columnames = new List<string>{"MTH", "key", "value"};
            List<string[]> columns = columnames.Select(columname => new string[lines.Length]).ToList();

            for (int n = 0; n < lines.Length; n++){
                string[] items = lines[n].Split(new[]{"\t", "\n", "\r"}, StringSplitOptions.None);
                if (items.Length < 3){
                    continue;
                }
                columns[0][n] = items[0];
                columns[1][n] = items[1];
                columns[2][n] = items[2];
            }
            int nrows = lines.Length;
            int ncols = columnames.Count;
            IMatrixData data = (IMatrixData) inputData[0].CreateNewInstance(DataType.Matrix);
            data.SetData(Matrix.MetadataSection, new List<string>(), new float[nrows,ncols], columnames, columns,
                         new List<string>(), new List<string[][]>(), new List<string>(), new List<double[]>(),
                         new List<string>(), new List<double[][]>(), new List<string>(), new List<string[][]>(),
                         new List<string>(), new List<double[]>());

            return data;
        }
        public Metadata CreateMetadataDefault(IMatrixData parameters, IMatrixData experiment, IMatrixData search)
        {
            Metadata mtd = new Metadata(new MZTabDescription(MzTabMode.Complete, MzTabType.Quantification));

            List<MsRunImpl> runs = null;
            List<StudyVariable> studyvariables = null;
            List<Assay> assays = null;
            List<Sample> samples = null;
            List<Instrument> instruments = null;
            GetExperminetValues(null, null, experiment, search, ref runs, ref studyvariables, ref assays, ref samples,
                                ref instruments);

            foreach (var msRun in runs){
                mtd.MsRunMap.Add(msRun.Id, msRun);
            }

            foreach (var studyvariable in studyvariables){
                mtd.StudyVariableMap.Add(studyvariable.Id, studyvariable);
            }

            foreach (var sample in samples){
                mtd.SampleMap.Add(sample.Id, sample);
            }

            foreach (var assay in assays){
                mtd.AssayMap.Add(assay.Id, assay);
            }

            foreach (var instrument in instruments){
                mtd.InstrumentMap.Add(instrument.Id, instrument);
            }

            SplitList<Lib.Model.Param> sampleProcessing = new SplitList<Lib.Model.Param>{
                cv.GetParam("enzyme digestion", "SEP"),
                cv.GetParam("reversed-phase chromatography", "SEP")
            };
            //sampleProcessing.Add(_cv.GetParam("ion-exchange chromatography", "SEP"));

            mtd.SampleProcessingMap.Add(1, sampleProcessing);

            var paramDict = MzTabMatrixUtils.ConvertToParamDict(parameters);

            string key = Constants.GetKeywordName(Utils.parameters.fixedMod, paramDict.Keys.ToArray());
            if (key != null){
                string[] values = paramDict[key].Split(';');
                foreach (var mod in values.Select(x => BaseLib.Mol.Tables.Modifications[x])){
                    int id = mtd.FixedModMap.Count + 1;
                    mtd.AddFixedModParam(id, cv.GetModificationParam(mod));
                    mtd.AddFixedModPosition(id, mod.Position.ToString());
                    mtd.AddFixedModSite(id, StringUtils.Concat(", ", mod.GetSiteArray()));
                }
            }

            key = Constants.GetKeywordName(Utils.parameters.variableMod, paramDict.Keys.ToArray());
            if (key != null){
                string[] values = paramDict[key].Split(';');
                foreach (var mod in values.Select(x => BaseLib.Mol.Tables.Modifications[x])){
                    int id = mtd.VariableModMap.Count + 1;
                    mtd.AddVariableModParam(id, cv.GetModificationParam(mod));
                    mtd.AddVariableModPosition(id, mod.Position.ToString());
                    mtd.AddVariableModSite(id, StringUtils.Concat(", ", mod.GetSiteArray()));
                }
            }

            string version = Constants.GetKeywordName(Utils.parameters.version, paramDict.Keys.ToArray());
            Software software = new Software(1){
                Param = cv.GetParam("MaxQuant", "MS", GetParameterString(parameters, version, null))
            };
            mtd.SoftwareMap.Add(software.Id, software);

            software = new Software(2){
                Param = cv.GetParam("Andromeda", "MS", GetParameterString(parameters, version, null))
            };
            mtd.SoftwareMap.Add(software.Id, software);

            if (assays.Count > 0){
                var tmp = ArrayUtils.UniqueValues(assays.Select(x => x.QuantificationReagent.Name).ToArray());
                if (tmp.Length == 1 && tmp.First().Equals("Unlabeled sample")){
                    mtd.QuantificationMethod = cv.GetParam("label-free proteingroup level quantitation", "MS");
                }
                else if (tmp.Any(x => x.Contains("SILAC"))){
                    mtd.QuantificationMethod = cv.GetParam("SILAC quantitation analysis", "MS");
                }
            }

            return mtd;
        }
Beispiel #15
0
 public Peptide(MZTabColumnFactory factory, Metadata metadata)
     : base(factory)
 {
     this.metadata = metadata;
 }
Beispiel #16
0
        public static SplitList<SpectraRef> ParseSpectraRefList(Metadata metadata, string target)
        {
            SplitList<string> list = ParseStringList(MZTabConstants.BAR, target);
            SplitList<SpectraRef> refList = new SplitList<SpectraRef>(MZTabConstants.BAR);

            Regex regex = new Regex("ms_run\\[(\\d+)\\]:(.*)");

            foreach (string item in list){
                if (regex.IsMatch(item.Trim())){
                    int ms_file_id = int.Parse(regex.Match(item.Trim()).Groups[1].Value);
                    string reference = regex.Match(item.Trim()).Groups[2].Value;

                    MsRun msRun = metadata.MsRunMap[ms_file_id];
                    SpectraRef sref = msRun == null ? null : new SpectraRef(msRun, reference);

                    if (sref == null){
                        refList.Clear();
                        break;
                    }
                    refList.Add(sref);
                }
            }

            return refList;
        }
        private void addSmallMoleculeValue()
        {
            MsRun msRun1 = new MsRun(1);
            Assay assay1 = new Assay(1);
            Assay assay2 = new Assay(2);
            StudyVariable studyVariable1 = new StudyVariable(1);

            MZTabColumnFactory factory = MZTabColumnFactory.GetInstance(Section.Small_Molecule);
            factory.AddAbundanceOptionalColumn(assay1);
            factory.AddAbundanceOptionalColumn(studyVariable1);
            factory.AddAbundanceOptionalColumn(assay2);
            factory.AddOptionalColumn(msRun1, "my_value", typeof (string));
            CVParam param = new CVParam("MS", "MS:1002217", "decoy peptide", null);
            factory.AddOptionalColumn(param, typeof (string));

            Metadata metadata = new Metadata();
            metadata.AddMsRunLocation(2, new Url("file://C:\\path\\to\\my\\file"));

            Console.WriteLine(factory);
            /*TODO: SmallMolecule sm = new SmallMolecule(factory, metadata);
            sm.setIdentifier("CID:00027395");
            sm.setChemicalFormula("C17H20N4O2");
            sm.setSmiles("C1=CC=C(C=C1)CCNC(=O)CCNNC(=O)C2=CC=NC=C2");
            sm.setInchiKey("QXBMEGUKVLFJAM-UHFFFAOYSA-N");
            sm.setDescription("N-(2-phenylethyl)-3-[2-(pyridine-4-carbonyl)hydrazinyl]propanamide");
            sm.setExpMassToCharge("1234.4");
            sm.setCalcMassToCharge("1234.5");
            sm.setCharge("2");
            sm.setRetentionTime("10.2|11.5");
            sm.setTaxid("10116");
            sm.setSpecies("Rattus norvegicus (Rat)");
            sm.setDatabase("UniProtKB");
            sm.setDatabaseVersion("2011_11");
            sm.setReliability("2");
            sm.setURI("http://www.ebi.ac.uk/pride/link/to/identification");
            sm.setSpectraRef("ms_run[2]:index=7|ms_run[2]:index=9");
            sm.setSearchEngine("[MS, MS:1001477, SpectraST,]");
            sm.setBestSearchEngineScore("[MS, MS:1001419, SpectraST:discriminant score F, 0.7]");
            sm.setModifications("CHEMMOD:+Na-H");

            Console.WriteLine(sm);*/
        }
 public SmallMolecule(MZTabColumnFactory factory, Metadata metadata)
     : base(factory)
 {
     this.metadata = metadata;
 }
 internal static string CheckIfDescriptionExists(IList<ParameterDescription> help, string title, ref string desc,
                                                 Metadata mtd)
 {
     string shortName = ParameterDescription.Shorten(title);
     if (help != null && help.Count > 0) {
         ParameterDescription parameterDescription = help.FirstOrDefault(x => x.Match(shortName));
         if (parameterDescription != null) {
             if (mtd != null) {
                 string type = parameterDescription.GetFieldType(mtd.TabDescription.MzTabType,
                                                                 mtd.TabDescription.MzTabMode);
                 if (type != null) {
                     if (type.Equals("mandatory")) {
                         title += "*";
                     } else if (type.Equals("(mandatory)")) {
                         title += "(*)";
                     } else if (type.Equals("optional")) {
                         title += "(optional)";
                     } else if (type.Equals("none")) {
                         //TODO:
                     }
                 }
             }
             desc = parameterDescription.Definition;
         }
     }
     return title;
 }
 public PSMLineParser(MZTabColumnFactory factory, PositionMapping positionMapping, Metadata metadata,
                      MZTabErrorList errorList)
     : base(factory, positionMapping, metadata, errorList)
 {
 }
 public SMHLineParser(Metadata metadata)
     : base(MZTabColumnFactory.GetInstance(Section.Small_Molecule_Header), metadata)
 {
 }