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
        private static void ParseReferences(MBFTextReader mbfReader, ref Sequence sequence)
        {
            GenBankMetadata           metadata      = (GenBankMetadata)sequence.Metadata[Helper.GenBankMetadataKey];
            IList <CitationReference> referenceList = metadata.References;
            CitationReference         reference     = null;

            //List<MetadataListItem<string>> referenceList = new List<MetadataListItem<string>>();
            //MetadataListItem<string> reference = null;

            while (mbfReader.HasLines)
            {
                if (mbfReader.LineHeader == "REFERENCE")
                {
                    // add previous reference
                    if (reference != null)
                    {
                        referenceList.Add(reference);
                    }

                    // check for start/end e.g. (bases 1 to 118), or prose notes
                    Match m = Regex.Match(mbfReader.LineData,
                                          @"^(?<number>\d+)(\s+\((?<location>.*)\))?");
                    if (!m.Success)
                    {
                        string message = String.Format(
                            CultureInfo.CurrentCulture,
                            Properties.Resource.ParserReferenceError,
                            mbfReader.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();
                    }
                    reference.Number   = outValue;
                    reference.Location = location;
                    mbfReader.GoToNextLine();
                }
                else if (mbfReader.Line.StartsWith(" ", StringComparison.Ordinal))
                {
                    switch (mbfReader.LineHeader)
                    {
                    // all the following are extracted the same way - possibly multiline
                    case "AUTHORS":
                        reference.Authors = ParseMultiLineData(mbfReader, " ");
                        break;

                    case "CONSRTM":
                        reference.Consortiums = ParseMultiLineData(mbfReader, " ");
                        break;

                    case "TITLE":
                        reference.Title = ParseMultiLineData(mbfReader, " ");
                        break;

                    case "JOURNAL":
                        reference.Journal = ParseMultiLineData(mbfReader, " ");
                        break;

                    case "REMARK":
                        reference.Remarks = ParseMultiLineData(mbfReader, " ");
                        break;

                    case "MEDLINE":
                        reference.Medline = ParseMultiLineData(mbfReader, " ");
                        break;

                    case "PUBMED":
                        reference.PubMed = ParseMultiLineData(mbfReader, " ");
                        break;

                    default:
                        string message = String.Format(
                            CultureInfo.CurrentCulture,
                            Properties.Resource.ParserInvalidReferenceField,
                            mbfReader.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;
                }
            }
        }