public void TestWrite()
    {
      TextFileDefinition def = new TextFileDefinition();
      def.Delimiter = '\t';
      def.Description = "Test File ...";
      def.Add(new FileDefinitionItem()
      {
        AnnotationName = "AnnoKey1",
        PropertyName = "PropName1",
        ValueType = "double",
        Format = "{0:0.0000}"
      });
      def.Add(new FileDefinitionItem()
      {
        AnnotationName = "AnnoKey2",
        PropertyName = "PropName2",
        ValueType = "int"
      });
      def.Add(new FileDefinitionItem()
      {
        AnnotationName = "AnnoKey3",
        PropertyName = "PropName3",
        ValueType = "string"
      });

      var newfile = @"../../../data/TextFileDefinition2.xml";
      def.WriteToFile(newfile);

      AssertUtils.AssertFileEqual(DefinitionFile, newfile);
      File.Delete(newfile);
    }
Beispiel #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            FormToDefinition();

            if (!dlgSaveFormatFile.FileName.Equals(lastFile))
            {
                if (File.Exists(lastFile) && !File.Exists(dlgSaveFormatFile.FileName))
                {
                    dlgSaveFormatFile.FileName = lastFile;
                }
                else
                {
                    dlgSaveFormatFile.FileName         = Path.Combine(lastDirectory, Path.GetFileName(lastDirectory) + ".siformat");
                    dlgSaveFormatFile.InitialDirectory = lastDirectory;
                }
            }

            if (dlgSaveFormatFile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                var map = headers.ToDictionary(m => m.PropertyName);
                items.ForEach(m =>
                {
                    if (!string.IsNullOrEmpty(m.PropertyName))
                    {
                        var item    = map[m.PropertyName];
                        m.ValueType = item.ValueType;
                        m.Required  = item.Required;
                        m.Format    = item.Format;
                    }
                });

                items.WriteToFile(dlgSaveFormatFile.FileName);
            }
        }
Beispiel #3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < items.Count; i++)
            {
                if (!string.IsNullOrEmpty(items[i].PropertyName))
                {
                    if (!propertyNames.Contains(items[i].PropertyName))
                    {
                        MessageBox.Show("Property " + items[i].PropertyName + " is illegal!");
                        return;
                    }

                    for (int j = i + 1; j < items.Count; j++)
                    {
                        if (items[i].PropertyName.Equals(items[j].PropertyName))
                        {
                            MessageBox.Show("Property " + items[i].PropertyName + " are multi-defined!");
                            return;
                        }
                    }
                }
            }

            dlgSaveFormatFile.InitialDirectory = FileUtils.GetTemplateDir().FullName;

            if (File.Exists(lastFile) && !File.Exists(dlgSaveFormatFile.FileName))
            {
                dlgSaveFormatFile.FileName = lastFile;
            }

            if (dlgSaveFormatFile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                var map = headers.ToDictionary(m => m.PropertyName);
                items.ForEach(m =>
                {
                    if (!string.IsNullOrEmpty(m.PropertyName))
                    {
                        var item    = map[m.PropertyName];
                        m.ValueType = item.ValueType;
                        m.Required  = item.Required;
                        m.Format    = item.Format;
                    }
                });

                items.DelimiterString = txtDelimiter.Text;
                items.Description     = txtDescription.Text;

                items.WriteToFile(dlgSaveFormatFile.FileName);

                SrmFormatFactory.Refresh();
            }
        }
Beispiel #4
0
        private void DoSaveToFile(string filename)
        {
            FormToDefinition();

            var map = headers.ToDictionary(m => m.PropertyName);

            items.ForEach(m =>
            {
                if (!string.IsNullOrEmpty(m.PropertyName))
                {
                    var item    = map[m.PropertyName];
                    m.ValueType = item.ValueType;
                    m.Required  = item.Required;
                    m.Format    = item.Format;
                }
            });

            items.WriteToFile(filename);
        }
    public void NewFromData(string subdir)
    {
      var siformat = Directory.GetFiles(subdir, "*.siformat");

      TextFileDefinition prefile = new TextFileDefinition();
      if (siformat.Length > 0)
      {
        prefile.ReadFromFile(siformat[0]);

        bool bFound = false;
        prefile.ForEach(m =>
        {
          if (m.PropertyName.Equals("TumorStage"))
          {
            m.PropertyName = "TumorStatus";
            bFound = true;
          }

          if (m.PropertyName.Equals("Metastasis"))
          {
            m.PropertyName = "MetastasisStatus";
            bFound = true;
          }
        });

        if (bFound)
        {
          prefile.WriteToFile(siformat[0]);
        }
      }

      var map = new RawSampleInfoReader().ReadDescriptionFromDirectory(subdir);

      lastDirectory = subdir;
      lastFile = String.Empty;

      var files = new HashSet<string>(from f in CelFile.GetCelFiles(subdir, false)
                                      select GeoUtils.GetGsmName(f));

      Dictionary<string, HashSet<string>> headers = new Dictionary<string, HashSet<string>>();
      foreach (var m in map)
      {
        var gsm = m.Key.ToLower();

        if (!files.Contains(gsm))
        {
          continue;
        }

        var curmap = m.Value;

        foreach (var entry in curmap)
        {
          if (!headers.ContainsKey(entry.Key))
          {
            headers[entry.Key] = new HashSet<string>();
          }
          headers[entry.Key].UnionWith(entry.Value);
        }
      }

      ClearDataSource();

      items.Clear();
      foreach (var part in headers)
      {
        items.Add(new FileDefinitionItem()
        {
          AnnotationName = part.Key,
          Example = (from v in part.Value
                     orderby v
                     select v).Merge(";")
        });
      }

      foreach (var olditem in prefile)
      {
        if (!string.IsNullOrEmpty(olditem.PropertyName))
        {
          var newitem = items.Find(m => m.AnnotationName.Equals(olditem.AnnotationName));
          if (newitem != null)
          {
            newitem.PropertyName = olditem.PropertyName;
          }
        }
      }

      items.DefaultValues.Clear();
      foreach (var olddv in prefile.DefaultValues)
      {
        if (propertyNames.Contains(olddv.PropertyName))
        {
          items.DefaultValues.Add(new DefaultValue()
          {
            PropertyName = olddv.PropertyName,
            Value = olddv.Value
          });
        }
      }

      items.Sort((m1, m2) => m1.AnnotationName.CompareTo(m2.AnnotationName));

      UpdateDataSource();

      this.Text = title + " - " + Path.GetFileName(subdir);
    }
Beispiel #6
0
        public void NewFromData(string subdir)
        {
            var siformat = Directory.GetFiles(subdir, "*.siformat");

            TextFileDefinition prefile = new TextFileDefinition();

            if (siformat.Length > 0)
            {
                prefile.ReadFromFile(siformat[0]);

                bool bFound = false;
                prefile.ForEach(m =>
                {
                    if (m.PropertyName.Equals("TumorStage"))
                    {
                        m.PropertyName = "TumorStatus";
                        bFound         = true;
                    }

                    if (m.PropertyName.Equals("Metastasis"))
                    {
                        m.PropertyName = "MetastasisStatus";
                        bFound         = true;
                    }
                });

                if (bFound)
                {
                    prefile.WriteToFile(siformat[0]);
                }
            }

            var map = new RawSampleInfoReader().ReadDescriptionFromDirectory(subdir);

            lastDirectory = subdir;
            lastFile      = String.Empty;

            var files = new HashSet <string>(from f in CelFile.GetCelFiles(subdir, false)
                                             select GeoUtils.GetGsmName(f));

            Dictionary <string, HashSet <string> > headers = new Dictionary <string, HashSet <string> >();

            foreach (var m in map)
            {
                var gsm = m.Key.ToLower();

                if (!files.Contains(gsm))
                {
                    continue;
                }

                var curmap = m.Value;

                foreach (var entry in curmap)
                {
                    if (!headers.ContainsKey(entry.Key))
                    {
                        headers[entry.Key] = new HashSet <string>();
                    }
                    headers[entry.Key].UnionWith(entry.Value);
                }
            }

            ClearDataSource();

            items.Clear();
            foreach (var part in headers)
            {
                items.Add(new FileDefinitionItem()
                {
                    AnnotationName = part.Key,
                    Example        = (from v in part.Value
                                      orderby v
                                      select v).Merge(";")
                });
            }

            foreach (var olditem in prefile)
            {
                if (!string.IsNullOrEmpty(olditem.PropertyName))
                {
                    var newitem = items.Find(m => m.AnnotationName.Equals(olditem.AnnotationName));
                    if (newitem != null)
                    {
                        newitem.PropertyName = olditem.PropertyName;
                    }
                }
            }

            items.DefaultValues.Clear();
            foreach (var olddv in prefile.DefaultValues)
            {
                if (propertyNames.Contains(olddv.PropertyName))
                {
                    items.DefaultValues.Add(new DefaultValue()
                    {
                        PropertyName = olddv.PropertyName,
                        Value        = olddv.Value
                    });
                }
            }

            items.Sort((m1, m2) => m1.AnnotationName.CompareTo(m2.AnnotationName));

            UpdateDataSource();

            this.Text = title + " - " + Path.GetFileName(subdir);
        }