示例#1
0
    public void Test()
    {
      GenebankFeature cds = new GenebankFeature();

      cds.Location = "141..539";
      Assert.IsFalse(cds.IsComplement);
      Assert.AreEqual(141, cds.Start);
      Assert.AreEqual(539, cds.End);

      cds.Location = "complement(141..539)";
      Assert.IsTrue(cds.IsComplement);
      Assert.AreEqual(141, cds.Start);
      Assert.AreEqual(539, cds.End);

      cds.Context = new List<string>();

      cds.FeatureName = "CDS";
      List<string> paragraph = cds.GetParagraph(false);
      Assert.AreEqual("     CDS             complement(141..539)", paragraph[0]);
      paragraph = cds.GetParagraph(true);
      Assert.AreEqual("FT   CDS             complement(141..539)", paragraph[0]);

      cds.FeatureName = "Contig";
      paragraph = cds.GetParagraph(false);
      Assert.AreEqual("     Contig          complement(141..539)", paragraph[0]);
      paragraph = cds.GetParagraph(true);
      Assert.AreEqual("FT   Contig          complement(141..539)", paragraph[0]);
    }
示例#2
0
        public List <GenebankItem> ReadFromFile(string fileName)
        {
            List <GenebankItem> result = new List <GenebankItem>();

            using (StreamReader sr = new StreamReader(fileName))
            {
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    if (line.StartsWith("LOCUS"))
                    {
                        GenebankItem item = new GenebankItem();
                        result.Add(item);
                        item.Accession = line.StringAfter("LOCUS").Trim().StringBefore(" ");

                        while ((line = sr.ReadLine()) != null)
                        {
                            if (line.StartsWith("FEATURES"))
                            {
                                GenebankFeature feature = null;
                                while ((line = sr.ReadLine()) != null)
                                {
                                    if (line[0] != ' ')
                                    {
                                        break;
                                    }

                                    if (line[5] != ' ')
                                    {
                                        feature = new GenebankFeature();
                                        item.Features.Add(feature);
                                        feature.FeatureName = line.Substring(5).StringBefore(" ");
                                        feature.Location    = line;
                                    }
                                    else
                                    {
                                        feature.Context.Add(line.Substring(3).Trim());
                                    }
                                }
                            }

                            if (line.Equals("//"))
                            {
                                break;
                            }
                        }
                    }
                }
            }

            return(result);
        }