Example #1
0
        /// <summary>
        /// Returns list of citation references in this metadata which are referred in the specified feature.
        /// </summary>
        /// <param name="item">Feature Item.</param>
        public List <CitationReference> GetCitationsReferredInFeature(FeatureItem item)
        {
            List <CitationReference> list = new List <CitationReference>();

            if (item == null || !item.Qualifiers.ContainsKey(StandardQualifierNames.Citation))
            {
                return(list);
            }

            foreach (string str in item.Qualifiers[StandardQualifierNames.Citation])
            {
                if (!string.IsNullOrEmpty(str))
                {
                    string strCitationNumber = str.Replace("[", string.Empty).Replace("]", string.Empty);
                    int    citationNumber    = -1;
                    if (int.TryParse(strCitationNumber, out citationNumber))
                    {
                        CitationReference citation = References.FirstOrDefault(F => F.Number == citationNumber);
                        if (citation != null && !list.Contains(citation))
                        {
                            list.Add(citation);
                        }
                    }
                }
            }

            return(list);
        }
Example #2
0
        /// <summary>
        /// Parses the GenBank Reference information from the GenBank file.
        /// </summary>
        /// <param name="line">parse line</param>
        /// <param name="sequence">The sequence.</param>
        /// <param name="stream">The stream reader.</param>
        /// <returns>The parsed line.</returns>
        private string ParseReferences(string line, ref Sequence sequence, StreamReader stream)
        {
            GenBankMetadata           metadata      = (GenBankMetadata)sequence.Metadata[Helper.GenBankMetadataKey];
            IList <CitationReference> referenceList = metadata.References;
            CitationReference         reference     = null;

            while (line != null)
            {
                string lineHeader = GetLineHeader(line, DataIndent);
                if (lineHeader == "REFERENCE")
                {
                    // add previous reference
                    if (reference != null)
                    {
                        referenceList.Add(reference);
                    }

                    // check for start/end e.g. (bases 1 to 118), or prose notes
                    string lineData = GetLineData(line, DataIndent);

                    Match m = Regex.Match(lineData, @"^(?<number>\d+)(\s+\((?<location>.*)\))?");
                    if (!m.Success)
                    {
                        string message = String.Format(
                            CultureInfo.CurrentCulture,
                            Properties.Resource.ParserReferenceError,
                            lineData);
                        Trace.Report(message);
                        throw new InvalidDataException(message);
                    }

                    // create new reference
                    string number   = m.Groups["number"].Value;
                    string location = m.Groups["location"].Value;
                    reference = new CitationReference();
                    int outValue;
                    if (!int.TryParse(number, out outValue))
                    {
                        throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Properties.Resource.InvalidRefNumber, number));
                    }
                    reference.Number   = outValue;
                    reference.Location = location;
                    line = GoToNextLine(line, stream);
                }
                else if (line.StartsWith(" ", StringComparison.Ordinal))
                {
                    switch (lineHeader)
                    {
                    // all the following are extracted the same way - possibly multiline
                    case "AUTHORS":
                        reference.Authors = ParseMultiLineData(ref line, " ", DataIndent, stream);
                        break;

                    case "CONSRTM":
                        reference.Consortiums = ParseMultiLineData(ref line, " ", DataIndent, stream);
                        break;

                    case "TITLE":
                        reference.Title = ParseMultiLineData(ref line, " ", DataIndent, stream);
                        break;

                    case "JOURNAL":
                        reference.Journal = ParseMultiLineData(ref line, " ", DataIndent, stream);
                        break;

                    case "REMARK":
                        reference.Remarks = ParseMultiLineData(ref line, " ", DataIndent, stream);
                        break;

                    case "MEDLINE":
                        reference.Medline = ParseMultiLineData(ref line, " ", DataIndent, stream);
                        break;

                    case "PUBMED":
                        reference.PubMed = ParseMultiLineData(ref line, " ", DataIndent, stream);
                        break;

                    default:
                        string message = String.Format(
                            CultureInfo.CurrentCulture,
                            Properties.Resource.ParserInvalidReferenceField,
                            lineHeader);
                        Trace.Report(message);
                        throw new InvalidDataException(message);
                    }
                }
                else
                {
                    // add last reference
                    if (reference != null)
                    {
                        referenceList.Add(reference);
                    }

                    // don't go to next line; current line still needs to be processed
                    break;
                }
            }

            return(line);
        }
Example #3
0
        /// <summary>
        /// Parses reference info.
        /// </summary>
        /// <param name="metadata">Metadata object</param>
        /// <param name="cellRange">Range of cells</param>
        /// <param name="rowIndex">Current index of row</param>
        /// <returns>Index of row</returns>
        private static int ParseReference(GenBankMetadata metadata, object[,] cellRange, int rowIndex)
        {
            string Key;
            string subKey;
            string value;
            string message;

            value = cellRange[rowIndex, ValueColumnIndex] != null ? cellRange[rowIndex, ValueColumnIndex].ToString() : string.Empty;
            rowIndex++;
            CitationReference reference = new CitationReference();
            if (!string.IsNullOrWhiteSpace(value))
            {
                // check for start/end e.g. (bases 1 to 118), or prose notes
                Match m = Regex.Match(value,
                    @"^(?<number>\d+)(\s+\((?<location>.*)\))?");
                if (m.Success)
                {
                    // create new reference
                    string number = m.Groups["number"].Value;
                    string location = m.Groups["location"].Value;
                    int outValue;
                    if (!int.TryParse(number, out outValue))
                    {
                        message = String.Format(
                         CultureInfo.InvariantCulture,
                         Resources.UnrecognizedGenBankMetadataFormat,
                         REFERENCE);
                        throw new FormatException(message);
                    }

                    reference.Number = outValue;
                    reference.Location = location;
                }
            }

            while (rowIndex < cellRange.GetLength(0))
            {
                if (3 > cellRange.GetLength(1))
                {
                    message = String.Format(
                                CultureInfo.InvariantCulture,
                                Resources.UnrecognizedGenBankMetadataFormat,
                                REFERENCE);
                    throw new FormatException(message);
                }

                if (null != cellRange[rowIndex, KeyColumnIndex])
                {
                    Key = cellRange[rowIndex, KeyColumnIndex].ToString();
                    if (!string.IsNullOrWhiteSpace(Key))
                    {
                        break;
                    }
                }

                if (null == cellRange[rowIndex, SubKeyColumnIndex] || string.IsNullOrWhiteSpace(cellRange[rowIndex, SubKeyColumnIndex].ToString()))
                {
                    message = String.Format(
                              CultureInfo.InvariantCulture,
                              Resources.UnrecognizedGenBankMetadataFormat,
                              REFERENCE);
                    throw new FormatException(message);
                }

                subKey = cellRange[rowIndex, SubKeyColumnIndex].ToString().ToUpperInvariant();
                value = cellRange[rowIndex, ValueColumnIndex] != null ? cellRange[rowIndex, ValueColumnIndex].ToString() : string.Empty;
                if (string.IsNullOrWhiteSpace(value))
                {
                    continue;
                }

                switch (subKey)
                {
                    case REFERENCE_AUTHORS:
                        reference.Authors = value;
                        break;
                    case REFERENCE_CONSORTIUMS:
                        reference.Consortiums = value;
                        break;
                    case REFERENCE_JOURNAL:
                        reference.Journal = value;
                        break;
                    case REFERENCE_MEDLINE:
                        reference.Medline = value;
                        break;
                    case REFERENCE_PUBMED:
                        reference.PubMed = value;
                        break;
                    case REFERENCE_REMARK:
                        reference.Remarks = value;
                        break;
                    case REFERENCE_TITLE:
                        reference.Title = value;
                        break;
                }

                rowIndex++;
            }

            metadata.References.Add(reference);

            return rowIndex;
        }
Example #4
0
        /// <summary>
        /// Parses the GenBank Reference information from the GenBank file.
        /// </summary>
        /// <param name="line">parse line</param>
        /// <param name="sequence">The sequence.</param>
        /// <param name="stream">The stream reader.</param>
        /// <returns>The parsed line.</returns>
        private string ParseReferences(string line, ref Sequence sequence, StreamReader stream)
        {
            GenBankMetadata metadata = (GenBankMetadata)sequence.Metadata[Helper.GenBankMetadataKey];
            IList<CitationReference> referenceList = metadata.References;
            CitationReference reference = null;

            while (line != null)
            {
                string lineHeader = GetLineHeader(line, DataIndent);
                if (lineHeader == "REFERENCE")
                {
                    // add previous reference
                    if (reference != null)
                    {
                        referenceList.Add(reference);
                    }

                    // check for start/end e.g. (bases 1 to 118), or prose notes
                    string lineData = GetLineData(line, DataIndent);

                    Match m = Regex.Match(lineData, @"^(?<number>\d+)(\s+\((?<location>.*)\))?");
                    if (!m.Success)
                    {
                        string message = String.Format(
                                CultureInfo.CurrentCulture,
                                Properties.Resource.ParserReferenceError,
                                lineData);
                        Trace.Report(message);
                        throw new InvalidDataException(message);
                    }

                    // create new reference
                    string number = m.Groups["number"].Value;
                    string location = m.Groups["location"].Value;
                    reference = new CitationReference();
                    int outValue;
                    if (!int.TryParse(number, out outValue))
                        throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Properties.Resource.InvalidRefNumber, number));
                    reference.Number = outValue;
                    reference.Location = location;
                    line = GoToNextLine(line, stream);
                }
                else if (line.StartsWith(" ", StringComparison.Ordinal))
                {
                    switch (lineHeader)
                    {
                        // all the following are extracted the same way - possibly multiline
                        case "AUTHORS":
                            reference.Authors = ParseMultiLineData(ref line, " ", DataIndent, stream);
                            break;
                        case "CONSRTM":
                            reference.Consortiums = ParseMultiLineData(ref line, " ", DataIndent, stream);
                            break;
                        case "TITLE":
                            reference.Title = ParseMultiLineData(ref line, " ", DataIndent, stream);
                            break;
                        case "JOURNAL":
                            reference.Journal = ParseMultiLineData(ref line, " ", DataIndent, stream);
                            break;
                        case "REMARK":
                            reference.Remarks = ParseMultiLineData(ref line, " ", DataIndent, stream);
                            break;
                        case "MEDLINE":
                            reference.Medline = ParseMultiLineData(ref line, " ", DataIndent, stream);
                            break;
                        case "PUBMED":
                            reference.PubMed = ParseMultiLineData(ref line, " ", DataIndent, stream);
                            break;

                        default:
                            string message = String.Format(
                                    CultureInfo.CurrentCulture,
                                    Properties.Resource.ParserInvalidReferenceField,
                                    lineHeader);
                            Trace.Report(message);
                            throw new InvalidDataException(message);
                    }
                }
                else
                {
                    // add last reference
                    if (reference != null)
                    {
                        referenceList.Add(reference);
                    }

                    // don't go to next line; current line still needs to be processed
                    break;
                }
            }

            return line;
        }