Ejemplo n.º 1
0
        public IList <PeakData> ImportFile(TextReader peakViewReader)
        {
            var peakDatas   = new List <PeakData>();
            var msFileNames = new List <string>();
            var fileReader  = new DsvFileReader(peakViewReader, TextUtil.SEPARATOR_TSV);

            Assert.AreEqual(fileReader.GetFieldIndex(PROTEIN), 0);
            Assert.AreEqual(fileReader.GetFieldIndex(PEPTIDE), 1);
            Assert.AreEqual(fileReader.GetFieldIndex(LABEL), 2);
            Assert.AreEqual(fileReader.GetFieldIndex(PRECURSOR), 3);
            Assert.AreEqual(fileReader.GetFieldIndex(CHARGE), 4);
            Assert.AreEqual(fileReader.GetFieldIndex(RT), 5);
            Assert.AreEqual(fileReader.GetFieldIndex(DECOY), 6);
            for (int i = 7; i < fileReader.NumberOfFields; ++i)
            {
                msFileNames.Add(fileReader.FieldNames[i]);
            }
            while (fileReader.ReadLine() != null)
            {
                string modifiedSequence = fileReader.GetFieldByName(PEPTIDE);
                string decoyString      = fileReader.GetFieldByName(DECOY);
                bool   decoy;
                Assert.IsTrue(bool.TryParse(decoyString, out decoy));
                foreach (var msFileName in msFileNames)
                {
                    string dataFieldString = fileReader.GetFieldByName(msFileName);
                    double dataField;
                    Assert.IsTrue(double.TryParse(dataFieldString, out dataField));
                    var peakData = new PeakData(dataField, modifiedSequence, msFileName, decoy);
                    peakDatas.Add(peakData);
                }
            }
            return(peakDatas);
        }
Ejemplo n.º 2
0
        public void DsvHeadersTest()
        {
            // test reading DSV files with and without headers
            string[]   lines          = { "dog,1.1,cat,2.2", "pony,3.3,fish,4.4" };                                                     // Not L10N
            const char csvSeperator   = ',';
            var        withheaders    = new DsvFileReader(new StringReader("0,1,2,3\n" + String.Join("\n", lines)), csvSeperator);      // Not L10N
            var        withoutheaders = new DsvFileReader(new StringReader(String.Join("\n", lines)), csvSeperator, hasHeaders: false); // Not L10N

            Assert.AreEqual(withheaders.NumberOfFields, withoutheaders.NumberOfFields);
            for (int h = 0; h < withoutheaders.NumberOfFields; h++)
            {
                var f = String.Format("{0}", h); // verify that a headerless CSV file will pretend to have a header of form "0,1,2,..."  // Not L10N
                Assert.AreEqual(withheaders.GetFieldIndex(f), withoutheaders.GetFieldIndex(f));
            }
            int linenumber = 0;

            while (true)
            {
                var fields     = withoutheaders.ReadLine();
                var fieldsTest = withheaders.ReadLine();
                Assert.IsTrue((fields == null) == (fieldsTest == null));

                if (fields == null)
                {
                    break;
                }
                for (int f = 0; f < withoutheaders.NumberOfFields; f++)
                {
                    Assert.AreEqual(fields[f], fieldsTest[f]); // quick string compare
                    Assert.AreEqual(lines[linenumber].Split(csvSeperator)[f], fields[f]);
                }
                linenumber++;
            }
            Assert.AreEqual(2, linenumber);

            // let's also check the precision handling and field exception in AssertEx.FieldsEqual
            var A = String.Join("\n", lines).Replace("cat", "hamster"); // change col 2, then ignore it // Not L10N
            var B = String.Join("\n", lines).Replace("1.1", "1.09");    // add error at limits of precision, then allow for it // Not L10N

            AssertEx.FieldsEqual(A, B, 4, 2, true);
        }