public static string GetText(DocumentType helpType, Section section)
        {
            IList<ParameterDescription> list = Read();
            if (list == null){
                return null;
            }
            list = list.Where(x => x.Section.Name == section.Name).ToList();

            StringBuilder builder = new StringBuilder();
            if (helpType == DocumentType.Rtf){
                builder.Append("{\rtf1\ansi");
            }
            foreach (ParameterDescription descripition in list){
                switch (helpType){
                    case DocumentType.Html:
                        descripition.ToHtml(builder);
                        break;
                    case DocumentType.PlainText:
                        descripition.ToPlainText(builder);
                        break;
                    case DocumentType.Rtf:
                        descripition.ToRichText(builder);
                        break;
                }
            }
            if (helpType == DocumentType.Rtf){
                builder.Append("}");
            }

            return builder.ToString();
        }
 private ParameterDescription(string name, Section section, string definition, string multiplicity,
                              IList<string> example, FieldType fieldType)
 {
     Name = name;
     Section = section;
     Definition = definition;
     Multiplicity = multiplicity;
     Example = example;
     _fieldType = fieldType;
 }
        /**
         * {position}{Parameter}-{Type:accession}|{neutral loss}
         */
        public Modification(Section section, ModificationType type, string accession)
        {
            if (! section.isData()){
                throw new ArgumentException("Section should use Protein, Peptide, PSM or SmallMolecule.");
            }
            _section = section;
            _type = type;

            if (accession == null){
                throw new NullReferenceException("Modification accession can not null!");
            }
            _accession = accession;
        }
        public static SortedDictionary<string, MZTabColumn> createOptionalColumns(Section section,
                                                                                  StudyVariable studyVariable,
                                                                                  int offset)
        {
            SortedDictionary<string, MZTabColumn> columns = new SortedDictionary<string, MZTabColumn>();
            Section dataSection = Section.toDataSection(section);

            AbundanceColumn column = new AbundanceColumn(dataSection, Field.ABUNDANCE, studyVariable, offset);
            columns.Add(column.LogicPosition, column);
            column = new AbundanceColumn(dataSection, Field.ABUNDANCE_STDEV, studyVariable, offset);
            columns.Add(column.LogicPosition, column);
            column = new AbundanceColumn(dataSection, Field.ABUNDANCE_STD_ERROR, studyVariable, offset);
            columns.Add(column.LogicPosition, column);

            return columns;
        }
        /**
        * We assume that user before call this method, have parse the raw line
        * is not empty line and start with section prefix.
        */
        protected void Parse(int lineNumber, string line, MZTabErrorList errorList)
        {
            _lineNumber = lineNumber;
            _line = line;
            _errorList = errorList ?? new MZTabErrorList();

            _items = line.Split(MZTabConstants.TAB);
            _items[0] = _items[0].Trim();
            _items[_items.Length - 1] = _items[_items.Length - 1].Trim();

            _section = Section.findSection(_items[0]);

            if (_section == null){
                MZTabError error = new MZTabError(FormatErrorType.LinePrefix, lineNumber, _items[0]);
                _errorList.Add(error);
            }
        }
        /**
         * Translate the data line to a {@link MZTabRecord}.
         *
         * NOTICE: Normally, we suggest user do convert operation after validate successfully.
         *
         * @see #parse(int, string, uk.ac.ebi.pride.jmztab.utils.errors.MZTabErrorList)
         */
        protected MZTabRecord getRecord(Section section, string line)
        {
            MZTabRecord record = null;

            if (section.Equals(Section.Protein)){
                record = new Protein(factory);
            }
            else if (section.Equals(Section.Peptide)){
                record = new Peptide(factory, metadata);
            }
            else if (section.Equals(Section.PSM)){
                record = new PSM(factory, metadata);
            }
            else if (section.Equals(Section.Small_Molecule)){
                record = new SmallMolecule(factory, metadata);
            }

            int offset = loadStableData(record, line);
            if (offset == _items.Length - 1){
                return record;
            }

            loadOptionalData(record, offset);

            return record;
        }
        /**
         * Check and translate target string into {@link Modification} list which split by ',' character..
         * If parse incorrect, raise {@link FormatErrorType#ModificationList} error.
         * Normally, ambiguityMembers can set "null", but in "Complete" file, in general "null" values SHOULD not be given.
         *
         * If software cannot determine protein-level modifications, "null" MUST be used.
         * If the software has determined that there are no modifications to a given protein "0" MUST be used.
         *
         * @param section SHOULD NOT set null
         * @param column SHOULD NOT set null
         * @param modificationsLabel SHOULD NOT be empty.
         */
        protected SplitList<Modification> checkModifications(Section section, MZTabColumn column,
                                                             string modificationsLabel)
        {
            string result_modifications = checkData(column, modificationsLabel, true);

            if (result_modifications == null ||
                result_modifications.Equals("NULL", StringComparison.CurrentCultureIgnoreCase) ||
                result_modifications.Equals("0")){
                return new SplitList<Modification>(MZTabConstants.COMMA);
            }

            SplitList<Modification> modificationList = MZTabUtils.ParseModificationList(section, modificationsLabel);
            if (modificationList.Count == 0){
                _errorList.Add(new MZTabError(FormatErrorType.ModificationList, _lineNumber, column.Header,
                                              result_modifications));
            }

            return modificationList;
        }
        internal static MZTabColumn CreateOptionalColumn(Section section, MZTabColumn column, Integer id, IndexedElement element)
        {
            if (! column.isOptional()){
                throw new ArgumentException(column + " is not optional column!");
            }

            MZTabColumn optionColumn = null;

            if (section.Equals(Section.Protein_Header)){
                optionColumn = new ProteinColumn(column.Name, column.Type, column.isOptional(), column.Order, id);
            }
            else if (section.Equals(Section.Peptide_Header)){
                optionColumn = new PeptideColumn(column.Name, column.Type, column.isOptional(), column.Order, id);
            }
            else if (section.Equals(Section.PSM_Header)){
                optionColumn = new PSMColumn(column.Name, column.Type, column.isOptional(), column.Order, id);
            }
            else if (section.Equals(Section.Small_Molecule_Header)){
                optionColumn = new SmallMoleculeColumn(column.Name, column.Type, column.isOptional(), column.Order, id);
            }

            if (optionColumn != null && element != null){
                optionColumn.Element = element;
            }

            return optionColumn;
        }
 private AbundanceColumn(Section section, Field field, IndexedElement element, int offset)
     : base(translate(section.Name) + "_" + field.name, field.columnType, true, offset + field.position + "")
 {
     Element = element;
 }
 public static MZTabColumn createOptionalColumn(Section section, Assay assay, int offset)
 {
     return new AbundanceColumn(Section.toDataSection(section), Field.ABUNDANCE, assay, offset);
 }
Beispiel #11
0
        private static Modification ParseModification(Section section, string target)
        {
            target = ParseString(target);
            // no modification
            if (target.Equals("0")){
                return Modification.CreateNoModification(section);
            }
            target = translateMinusToUnicode(target);
            if (target == null){
                return null;
            }

            target = translateTabToComma(target);
            string[] items = target.Split("\\-".ToCharArray());
            string modLabel;
            string positionLabel;
            if (items.Length > 2){
                // error
                return null;
            }
            if (items.Length == 2){
                positionLabel = items[0];
                modLabel = items[1];
            }
            else{
                positionLabel = null;
                modLabel = items[0];
            }

            Modification modification = null;

            modLabel = translateUnicodeToMinus(modLabel);
            Regex regex = new Regex("(MOD|UNIMOD|CHEMMOD|SUBST):([^\\|]+)(\\|\\[([^,]+)?,([^,]+)?,([^,]+),([^,]*)\\])?");

            if (regex.IsMatch(modLabel)){
                Modification.ModificationType type = Modification.FindType(regex.Match(target).Groups[1].Value);
                string accession = regex.Match(target).Groups[2].Value;
                modification = new Modification(section, type, accession);
                if (positionLabel != null){
                    parsePosition(positionLabel, modification);
                }

                CVParam neutralLoss = string.IsNullOrEmpty(regex.Match(target).Groups[6].Value)
                                          ? null
                                          : new CVParam(regex.Match(target).Groups[4].Value,
                                                        regex.Match(target).Groups[5].Value,
                                                        regex.Match(target).Groups[6].Value,
                                                        regex.Match(target).Groups[7].Value);
                modification.NeutralLoss = neutralLoss;
            }

            return modification;
        }
Beispiel #12
0
        public static SplitList<Modification> ParseModificationList(Section section, string target)
        {
            target = ParseString(target);
            if (target == null){
                return null;
            }

            SplitList<Modification> modList = new SplitList<Modification>(MZTabConstants.COMMA);
            if (target.Equals("0")){
                modList.Add(Modification.CreateNoModification(section));
                return modList;
            }

            target = translateCommaToTab(target);

            SplitList<string> list = ParseStringList(MZTabConstants.COMMA, target);

            foreach (string item in list){
                Modification mod = ParseModification(section, item.Trim());
                if (mod == null){
                    modList.Clear();
                    break;
                }
                modList.Add(mod);
            }

            return modList;
        }
 public Modification(Section section, ModificationType type, int accession)
     : this(section, type, accession.ToString(CultureInfo.InvariantCulture))
 {
 }
 /**
  *. If the software has determined that there are no modifications to a given protein “0” MUST be used.
  */
 public static Modification CreateNoModification(Section section)
 {
     return new Modification(section, ModificationType.UNKNOWN, "0");
 }
        /**
         * Based on {@link #section} to generate stable columns, and store them into {@link #stableColumnMapping} and
         * {@link #columnMapping} which maintain all columns in the factory.
         *
         * @param section SHOULD be {@link Section#Protein_Header}, {@link Section#Peptide_Header} {@link Section#PSM_Header}
         *                or {@link Section#Small_Molecule_Header}.
         */
        public static MZTabColumnFactory GetInstance(Section section)
        {
            section = Section.toHeaderSection(section);

            if (section == null){
                throw new ArgumentException(
                    "Section should use Protein_Header, Peptide_Header, PSM_Header or Small_Molecule_Header.");
            }

            MZTabColumnFactory factory = new MZTabColumnFactory();

            if (section.Equals(Section.Protein_Header)){
                AddStableColumn(factory, ProteinColumn.ACCESSION);
                AddStableColumn(factory, ProteinColumn.DESCRIPTION);
                AddStableColumn(factory, ProteinColumn.TAXID);
                AddStableColumn(factory, ProteinColumn.SPECIES);
                AddStableColumn(factory, ProteinColumn.DATABASE);
                AddStableColumn(factory, ProteinColumn.DATABASE_VERSION);
                AddStableColumn(factory, ProteinColumn.SEARCH_ENGINE);
                AddStableColumn(factory, ProteinColumn.AMBIGUITY_MEMBERS);
                AddStableColumn(factory, ProteinColumn.MODIFICATIONS);
                AddStableColumn(factory, ProteinColumn.PROTEIN_COVERAGE);
            }
            else if (section.Equals(Section.Peptide_Header)){
                AddStableColumn(factory, PeptideColumn.SEQUENCE);
                AddStableColumn(factory, PeptideColumn.ACCESSION);
                AddStableColumn(factory, PeptideColumn.UNIQUE);
                AddStableColumn(factory, PeptideColumn.DATABASE);
                AddStableColumn(factory, PeptideColumn.DATABASE_VERSION);
                AddStableColumn(factory, PeptideColumn.SEARCH_ENGINE);
                AddStableColumn(factory, PeptideColumn.MODIFICATIONS);
                AddStableColumn(factory, PeptideColumn.RETENTION_TIME);
                AddStableColumn(factory, PeptideColumn.RETENTION_TIME_WINDOW);
                AddStableColumn(factory, PeptideColumn.CHARGE);
                AddStableColumn(factory, PeptideColumn.MASS_TO_CHARGE);
                AddStableColumn(factory, PeptideColumn.SPECTRA_REF);
            }
            else if (section.Equals(Section.PSM_Header)){
                AddStableColumn(factory, PSMColumn.SEQUENCE);
                AddStableColumn(factory, PSMColumn.PSM_ID);
                AddStableColumn(factory, PSMColumn.ACCESSION);
                AddStableColumn(factory, PSMColumn.UNIQUE);
                AddStableColumn(factory, PSMColumn.DATABASE);
                AddStableColumn(factory, PSMColumn.DATABASE_VERSION);
                AddStableColumn(factory, PSMColumn.SEARCH_ENGINE);
                AddStableColumn(factory, PSMColumn.MODIFICATIONS);
                AddStableColumn(factory, PSMColumn.RETENTION_TIME);
                AddStableColumn(factory, PSMColumn.CHARGE);
                AddStableColumn(factory, PSMColumn.EXP_MASS_TO_CHARGE);
                AddStableColumn(factory, PSMColumn.CALC_MASS_TO_CHARGE);
                AddStableColumn(factory, PSMColumn.SPECTRA_REF);
                AddStableColumn(factory, PSMColumn.PRE);
                AddStableColumn(factory, PSMColumn.POST);
                AddStableColumn(factory, PSMColumn.START);
                AddStableColumn(factory, PSMColumn.END);
            }
            else if (section.Equals(Section.Small_Molecule_Header)){
                AddStableColumn(factory, SmallMoleculeColumn.IDENTIFIER);
                AddStableColumn(factory, SmallMoleculeColumn.CHEMICAL_FORMULA);
                AddStableColumn(factory, SmallMoleculeColumn.SMILES);
                AddStableColumn(factory, SmallMoleculeColumn.INCHI_KEY);
                AddStableColumn(factory, SmallMoleculeColumn.DESCRIPTION);
                AddStableColumn(factory, SmallMoleculeColumn.EXP_MASS_TO_CHARGE);
                AddStableColumn(factory, SmallMoleculeColumn.CALC_MASS_TO_CHARGE);
                AddStableColumn(factory, SmallMoleculeColumn.CHARGE);
                AddStableColumn(factory, SmallMoleculeColumn.RETENTION_TIME);
                AddStableColumn(factory, SmallMoleculeColumn.TAXID);
                AddStableColumn(factory, SmallMoleculeColumn.SPECIES);
                AddStableColumn(factory, SmallMoleculeColumn.DATABASE);
                AddStableColumn(factory, SmallMoleculeColumn.DATABASE_VERSION);
                AddStableColumn(factory, SmallMoleculeColumn.SPECTRA_REF);
                AddStableColumn(factory, SmallMoleculeColumn.SEARCH_ENGINE);
                AddStableColumn(factory, SmallMoleculeColumn.BEST_SEARCH_ENGINE_SCORE);
                AddStableColumn(factory, SmallMoleculeColumn.MODIFICATIONS);
            }
            else{
                throw new NotImplementedException("Section should be Protein, Peptide or " +
                                                  "Small_Molecule. Others can not setting. ");
            }

            foreach (var column in factory.StableColumnMapping){
                factory.ColumnMapping.Add(column.Key, column.Value);
            }
            factory.section = section;

            return factory;
        }