public void TestCommandLineImportAnnotations()
        {
            var         testFilesDir   = new TestFilesDir(TestContext, @"TestA\CommandLineImportAnnotationsTest.zip");
            var         inDocPath      = testFilesDir.GetTestPath("original.sky");
            var         outDocPath     = testFilesDir.GetTestPath("AnnotatedDocument.sky");
            var         annotationPath = testFilesDir.GetTestPath("annotations.csv");
            SrmDocument originalDocument;

            using (var stream = new FileStream(inDocPath, FileMode.Open))
            {
                originalDocument = (SrmDocument) new XmlSerializer(typeof(SrmDocument)).Deserialize(stream);
            }
            Assert.IsTrue(originalDocument.Settings.HasResults);
            var replicateAnnotation =
                originalDocument.Settings.DataSettings.AnnotationDefs.First(
                    def => def.Name == REPLICATE_ANNOTATION);

            Assert.IsNotNull(replicateAnnotation);
            Assert.IsTrue(replicateAnnotation.AnnotationTargets.Contains(AnnotationDef.AnnotationTarget.replicate));
            Assert.AreEqual(AnnotationDef.AnnotationType.text, replicateAnnotation.Type);
            var chromatograms = originalDocument.MeasuredResults.Chromatograms.ToArray();

            Assert.AreNotEqual(0, chromatograms.Length);
            for (int i = 0; i < chromatograms.Length; i++)
            {
                var chromSet = chromatograms[i];
                chromSet = chromSet.ChangeAnnotations(
                    chromSet.Annotations.ChangeAnnotation(replicateAnnotation, "Replicate" + i));
                chromatograms[i] = chromSet;
            }
            SrmDocument annotatedDocument = originalDocument.ChangeMeasuredResults(
                originalDocument.MeasuredResults.ChangeChromatograms(chromatograms));

            Assert.AreNotEqual(originalDocument, annotatedDocument);
            var documentAnnotations = new DocumentAnnotations(annotatedDocument);

            documentAnnotations.WriteAnnotationsToFile(CancellationToken.None, ExportAnnotationSettings.AllAnnotations(annotatedDocument), annotationPath);
            Assert.IsTrue(File.Exists(annotationPath));
            RunCommand("--in=" + inDocPath, "--out=" + outDocPath, "--import-annotations=" + annotationPath);
            Assert.IsTrue(File.Exists(outDocPath));
            SrmDocument outputDocument;

            using (var stream = new FileStream(outDocPath, FileMode.Open))
            {
                outputDocument = (SrmDocument) new XmlSerializer(typeof(SrmDocument)).Deserialize(stream);
            }
            Assert.AreEqual(annotatedDocument.Settings.MeasuredResults.Chromatograms,
                            outputDocument.Settings.MeasuredResults.Chromatograms);
        }
Example #2
0
        protected override void DoTest()
        {
            RunUI(() => SkylineWindow.OpenFile(TestFilesDir.GetTestPath("ImportAnnotationsTest.sky")));
            WaitForDocumentLoaded();
            var annotationAdder = new AnnotationAdder();

            Assert.IsTrue(SkylineWindow.SetDocument(annotationAdder.DefineTestAnnotations(SkylineWindow.Document), SkylineWindow.Document));
            var annotatedDocument  = annotationAdder.AddAnnotationTestValues(SkylineWindow.Document);
            var annotationSettings = ExportAnnotationSettings.AllAnnotations(annotatedDocument)
                                     .ChangeRemoveBlankRows(true);

            var    documentAnnotations = new DocumentAnnotations(annotatedDocument);
            string annotationPath      = TestFilesDir.GetTestPath("annotations.csv");

            documentAnnotations.WriteAnnotationsToFile(CancellationToken.None, annotationSettings, annotationPath);
            RunUI(() => SkylineWindow.ImportAnnotations(annotationPath));
            Assert.AreEqual(annotatedDocument, SkylineWindow.Document);
            using (var reader = new StreamReader(annotationPath))
            {
                var lines = reader.ReadToEnd().Split('\n').Where(line => !string.IsNullOrEmpty(line)).ToArray();
                Assert.AreEqual(annotationAdder.ElementCount + 1, lines.Length);
            }
        }