Exemplo n.º 1
0
        public void WriteDataWithAnnotationColumnsTest()
        {
            // main data
            IDataWithAnnotationColumns mdata = PerseusFactory.CreateDataWithAnnotationColumns();

            // annotation columns
            mdata.AddStringColumn("strcol1", "this is stringcol1", new[] { "1", "2" });
            mdata.AddStringColumn("strcol2", "", new[] { "", "hallo" });
            mdata.AddNumericColumn("numcol", "", new[] { 1.0, 2.0 });
            mdata.AddMultiNumericColumn("multnumcol", "this is multnumcol", new[] { new[] { -2.0, 2.0 }, new double[] {} });
            mdata.AddCategoryColumn("catcol", "", new[] { new[] { "cat1", "cat1.1" }, new[] { "cat2", "cat1" } });
            string mdataStr;

            using (MemoryStream memstream = new MemoryStream())
                using (StreamWriter writer = new StreamWriter(memstream)) {
                    PerseusUtils.WriteDataWithAnnotationColumns(mdata, writer);
                    writer.Flush();
                    mdataStr = Encoding.UTF8.GetString(memstream.ToArray());
                }
            IMatrixData mdata3 = PerseusFactory.CreateMatrixData();

            PerseusUtils.ReadMatrix(mdata3, new ProcessInfo(new Settings(), status => { }, progress => { }, 1, i => { }),
                                    () => {
                StreamReader tmpStream = new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(mdataStr)));
                return(tmpStream);
            }, "matrix1", '\t');
            IDataWithAnnotationColumns mdata2 = mdata3;

            Assert.AreEqual(2, mdata2.RowCount);
            Assert.AreEqual(2, mdata2.StringColumnCount);
            Assert.AreEqual(1, mdata2.NumericColumnCount);
            Assert.AreEqual(1, mdata2.CategoryColumnCount);
            Assert.AreEqual(1, mdata2.MultiNumericColumnCount);
            Assert.AreEqual("hallo", mdata2.StringColumns[mdata2.StringColumnNames.FindIndex(col => col.Equals("strcol2"))][1]);
        }
Exemplo n.º 2
0
        public void TestWriteMultiNumericColumnWithNulls()
        {
            var data = PerseusFactory.CreateDataWithAnnotationColumns();

            data.AddMultiNumericColumn("Test", "", new double[1][]);
            data.AddStringColumn("Test2", "", new string[1]);
            Assert.AreEqual(1, data.RowCount);
            var writer = new StreamWriter(new MemoryStream());

            PerseusUtils.WriteDataWithAnnotationColumns(data, writer);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Write the fiven network to the specified folder.
 /// </summary>
 public static void Write(INetworkDataAnnColumns ndata, string folder)
 {
     if (!Directory.Exists(folder))
     {
         Directory.CreateDirectory(folder);
     }
     PerseusUtils.WriteDataWithAnnotationColumns(ndata, Path.Combine(folder, "networks.txt"));
     foreach (var network in ndata)
     {
         PerseusUtils.WriteDataWithAnnotationColumns(network.NodeTable, Path.Combine(folder, $"{network.Guid}_nodes.txt"));
         PerseusUtils.WriteDataWithAnnotationColumns(network.EdgeTable, Path.Combine(folder, $"{network.Guid}_edges.txt"));
     }
 }