示例#1
0
 public void ValidateErrorIndexingUnsortedBAM()
 {
     //samtools throws the following error, we should do the same
     //[bam_index_core] the alignment is not sorted (H0KTMADXX130517:2:1111:17648:28366): 12370 > 12324 in 25-th chr
     
     // Get filepath from xml config file.
     string bamFilePath = this.utilityObj.xmlUtil.GetTextValue(
         Constants.BAMUnsortedFilePath, Constants.FilePathNode);
     using (Stream bamStream = new FileStream(bamFilePath, FileMode.Open, FileAccess.Read))
     {
         BAMParser parser = new BAMParser();
         BAMIndex bamIndex;
         try
         {
             bamIndex = parser.GetIndexFromBAMStorage(bamStream);
             Assert.Fail();
         }    
         catch(InvalidDataException)
         {
             
         }
         catch(Exception) {
         Assert.Fail();
         }
         finally
         {
             parser.Dispose();
         }
     }
     // Log message to VSTest GUI.
     ApplicationLog.WriteLine(string.Format(null,
                                            "BAM Parser BVT : Validated error is thrown on indexing unsorted file"));
 }
示例#2
0
 public void InvalidateGetIndexFromBAMFileUsingStream()
 {
     // Create BAM Parser object
     using (var bamParserObj = new BAMParser())
     {
         try
         {
             bamParserObj.GetIndexFromBAMStorage(null);
             Assert.Fail();
         }
         catch (ArgumentNullException ex)
         {
             string exceptionMessage = ex.Message;
             ApplicationLog.WriteLine(string.Format(null,
                                                    "BAM Parser P2 : Validated Exception {0} successfully",
                                                    exceptionMessage));
         }
     }
 }
示例#3
0
 /// <summary>
 /// Creates BAMIndex object from the specified BAM file and writes to specified BAMIndex file.
 /// </summary>
 /// <param name="compressedBAMStream"></param>
 /// <param name="indexStorage"></param>
 private static void CreateBAMIndexFile(Stream compressedBAMStream, BAMIndexStorage indexStorage)
 {
     var parser = new BAMParser();
     BAMIndex bamIndex = parser.GetIndexFromBAMStorage(compressedBAMStream);
     indexStorage.Write(bamIndex);
 }
示例#4
0
        public void ValidateBAMIndexMatchesExpectation()
        {
            // Get input and output values from xml node.
            string BAMStoragePath = this.utilityObj.xmlUtil.GetTextValue(
                Constants.BAMHumanLargeNode, Constants.FilePathNode);
            string expectedIndexPath= this.utilityObj.xmlUtil.GetTextValue(
                Constants.BAMHumanLargeNode, Constants.BAMIndexFileNode);
            var bp = new BAMParser();
            //get observed index file
            BAMIndex bi;
            using (Stream bamStream = new FileStream(BAMStoragePath, FileMode.Open, FileAccess.Read))
            {
               bi = bp.GetIndexFromBAMStorage(bamStream);
            }
            //get expected
            var bi2 = new BAMIndexStorage(File.OpenRead(expectedIndexPath)).Read();
            //now verify
            Assert.AreEqual(bi2.RefIndexes.Count, bi.RefIndexes.Count);
            for (int i = 0; i < bi.RefIndexes.Count; i++)
            {
                var obs = bi.RefIndexes[i];
                var exp = bi2.RefIndexes[i];
                Assert.AreEqual(obs.Bins.Count, exp.Bins.Count);
                Assert.AreEqual(obs.LinearIndex.Count, exp.LinearIndex.Count);
                Assert.AreEqual(obs.MappedReadsCount, exp.MappedReadsCount);
                Assert.AreEqual(obs.UnMappedReadsCount, exp.UnMappedReadsCount);
                var ob = obs.Bins.ToList();
                var eb = exp.Bins.ToList();
                ob.Sort((x, y) => x.BinNumber.CompareTo(y.BinNumber));
                eb.Sort((x, y) => x.BinNumber.CompareTo(y.BinNumber));
                for (int j = 0; j < ob.Count; j++)
                {
                    var obb=ob[0];
                    var ebb=eb[0];
                    Assert.AreEqual(obb.BinNumber, ebb.BinNumber);
                    Assert.AreEqual(obb.Chunks.Count, ebb.Chunks.Count);
                    var c1 = obb.Chunks.ToList();
                    var c2 = ebb.Chunks.ToList();
                    c1.Sort((x, y) => x.ChunkStart.CompareTo(y.ChunkStart));
                    c2.Sort((x, y) => x.ChunkStart.CompareTo(y.ChunkStart));

                    for (int k = 0; k < c1.Count; k++)
                    {
                        var co = c1[k];
                        var eo = c2[k];
                        Assert.AreEqual(eo.ChunkStart, co.ChunkStart);
                        Assert.AreEqual(eo.ChunkEnd, co.ChunkEnd);


                    }
                }


            }
        }