internal static ulong GetMinOffset(ReferenceSequence refSeq, int begin) { int bin = BinUtilities.FirstBin(Constants.NumLevels) + (begin >> Constants.MinShift); do { if (refSeq.IdToChunks.ContainsKey(bin)) { break; } int firstBin = (BinUtilities.ParentBin(bin) << 3) + 1; if (bin > firstBin) { bin--; } else { bin = BinUtilities.ParentBin(bin); } } while (bin != 0); int bottomBin = BinUtilities.BottomBin(bin); return(refSeq.LinearFileOffsets[bottomBin]); }
public void GetMaxOffset_MissingAllOverlappingBins_ReturnMaxOffset() { const ulong expectedResults = ulong.MaxValue; var idToChunks = new Dictionary <int, Interval[]>(); var refSeq = new ReferenceSequence(Chr2, idToChunks, null); ulong observedResults = SearchUtilities.GetMaxOffset(refSeq, 243171329); Assert.Equal(expectedResults, observedResults); }
public void GetMaxOffset_MissingFirstBin() { const ulong expectedResults = 3724908138137; var idToChunks = new Dictionary <int, Interval[]> { [860] = new[] { new Interval(3724908138137, 3724908155075) } }; var refSeq = new ReferenceSequence(Chr2, idToChunks, null); ulong observedResults = SearchUtilities.GetMaxOffset(refSeq, 36028417); Assert.Equal(expectedResults, observedResults); }
public void GetMaxOffset_Nominal() { const ulong expectedResults = 3591443312067; var idToChunks = new Dictionary <int, Interval[]> { [6311] = new[] { new Interval(3591443312067, 3592132724129) } }; var refSeq = new ReferenceSequence(Chr2, idToChunks, null); ulong observedResults = SearchUtilities.GetMaxOffset(refSeq, 26699126); Assert.Equal(expectedResults, observedResults); }
public void GetMaxOffset_MissingBin() { const ulong expectedResults = 3724057593420; var idToChunks = new Dictionary <int, Interval[]> { [6878] = new[] { new Interval(3724057593420, 3724057615020) } }; var refSeq = new ReferenceSequence(Chr2, idToChunks, null); ulong observedResults = SearchUtilities.GetMaxOffset(refSeq, 35962881); Assert.Equal(expectedResults, observedResults); }
public void GetMinOffset_MissingFirstBin() { const ulong expectedResults = 4351134646660; var linearFileOffsets = new ulong[5353]; linearFileOffsets[5352] = expectedResults; var idToChunks = new Dictionary <int, Interval[]> { [1254] = new[] { new Interval(1, 1) } }; var refSeq = new ReferenceSequence(Chr2, idToChunks, linearFileOffsets); ulong observedResults = SearchUtilities.GetMinOffset(refSeq, 87687168); Assert.Equal(expectedResults, observedResults); }
public void GetMinOffset_Nominal() { const ulong expectedResults = 3591443256775; var linearFileOffsets = new ulong[1630]; linearFileOffsets[1629] = expectedResults; var idToChunks = new Dictionary <int, Interval[]> { [6310] = new[] { new Interval(1, 1) } }; var refSeq = new ReferenceSequence(Chr2, idToChunks, linearFileOffsets); ulong observedResults = SearchUtilities.GetMinOffset(refSeq, 26699125); Assert.Equal(expectedResults, observedResults); }
public void GetOffset_Nominal() { var linearFileOffsets = new ulong[1630]; linearFileOffsets[1629] = 3591443256775; var idToChunks = GetIdToChunks(); var refSeqs = new ReferenceSequence[2]; refSeqs[1] = new ReferenceSequence(Chr2, idToChunks, linearFileOffsets); var index = new Index(Constants.VcfFormat, 0, 0, 0, '#', 0, refSeqs, _refNameToTabixIndex); long observedResult = index.GetOffset("chr2", 26699126); Assert.Equal(3591443256857, observedResult); }
public void GetMinOffset_MissingBin() { const ulong expectedResults = 3723191187417; var linearFileOffsets = new ulong[2196]; linearFileOffsets[2195] = expectedResults; var idToChunks = new Dictionary <int, Interval[]> { [6876] = new[] { new Interval(1, 1) } }; var refSeq = new ReferenceSequence(Chr2, idToChunks, linearFileOffsets); ulong observedResults = SearchUtilities.GetMinOffset(refSeq, 35979265); Assert.Equal(expectedResults, observedResults); }
public void GetTabixReferenceSequence_NullChromosome_ReturnNull() { var linearFileOffsets = new ulong[1630]; linearFileOffsets[1629] = 3591443256775; var idToChunks = GetIdToChunks(); var refSeqs = new ReferenceSequence[2]; refSeqs[1] = new ReferenceSequence(Chr2, idToChunks, linearFileOffsets); var index = new Index(Constants.VcfFormat, 0, 0, 0, '#', 0, refSeqs, _refNameToTabixIndex); var refSeq = index.GetTabixReferenceSequence(null); Assert.Null(refSeq); }
public void GetTabixReferenceSequence_Nominal() { var linearFileOffsets = new ulong[1630]; linearFileOffsets[1629] = 3591443256775; var idToChunks = GetIdToChunks(); var refSeqs = new ReferenceSequence[2]; refSeqs[1] = new ReferenceSequence(Chr2, idToChunks, linearFileOffsets); var index = new Index(Constants.VcfFormat, 0, 0, 0, '#', 0, refSeqs, _refNameToTabixIndex); var refSeq = index.GetTabixReferenceSequence("chr2"); Assert.Equal("chr2", refSeq.Chromosome.UcscName); }
public void GetOffset_NoOverlappingBins_UseLinearIndex_WithTruncatedIndex_ReturnMinusOne() { var chr1 = new Chromosome("chr1", "1", 0); var linearFileOffsets = new ulong[1]; linearFileOffsets[0] = 11418; var idToChunks = new Dictionary <int, Interval[]>(); var refSeqs = new ReferenceSequence[2]; refSeqs[0] = new ReferenceSequence(chr1, idToChunks, linearFileOffsets); var index = new Index(Constants.VcfFormat, 0, 0, 0, '#', 0, refSeqs, _refNameToTabixIndex); long observedResult = index.GetOffset("chr1", 100_000); Assert.Equal(-1, observedResult); }
public void GetOffset_HandleDiff_TabixIndex_And_RefIndex() { var linearFileOffsets = new ulong[1630]; linearFileOffsets[1629] = 3591443256775; var idToChunks = GetIdToChunks(); // tabix index 10 = chr2 = ref index 1 var refSeqs = new ReferenceSequence[11]; refSeqs[10] = new ReferenceSequence(Chr2, idToChunks, linearFileOffsets); var refNameToTabixIndex = new Dictionary <string, ushort> { ["chr2"] = 10 }; var index = new Index(Constants.VcfFormat, 0, 0, 0, '#', 0, refSeqs, refNameToTabixIndex); long observedResult = index.GetOffset("chr2", 26699126); Assert.Equal(3591443256857, observedResult); }
public void GetOffset_FixNegativeBeginCoordinate() { var linearFileOffsets = new ulong[1]; linearFileOffsets[0] = 3213608733669; var idToChunks = new Dictionary <int, Interval[]> { [585] = new[] { new Interval(3213608740412, 3213608740487) }, [4681] = new[] { new Interval(3213608733669, 3213608740412) }, [4682] = new[] { new Interval(3213608740487, 3214303562687) } }; var refSeqs = new ReferenceSequence[2]; refSeqs[1] = new ReferenceSequence(Chr2, idToChunks, linearFileOffsets); var index = new Index(Constants.VcfFormat, 0, 0, 0, '#', 0, refSeqs, _refNameToTabixIndex); long observedResult = index.GetOffset("chr2", 0); Assert.Equal(3213608733669, observedResult); }
public ReferenceSequence GetReferenceSequence() { string input = _reader.ReadLine(); if (input == null) { return(null); } if (!input.StartsWith(">")) { throw new UserErrorException($"Encountered a FASTA header that did not start with '>': {input}"); } var match = _nameRegex.Match(input); var referenceSequence = new ReferenceSequence { Name = match.Groups[1].Value }; _sb.Clear(); for (int index = _reader.Peek(); index != -1 && index != 62; index = _reader.Peek()) { string str = _reader.ReadLine(); if (str != null) { _sb.Append(str); } else { break; } } referenceSequence.Bases = _sb.ToString(); return(referenceSequence); }
internal static ulong GetMaxOffset(ReferenceSequence refSeq, int end) { int bin = BinUtilities.FirstBin(Constants.NumLevels) + ((end - 1) >> Constants.MinShift) + 1; while (true) { while (bin % 8 == 1) { bin = BinUtilities.ParentBin(bin); } if (bin == 0) { return(ulong.MaxValue); } if (refSeq.IdToChunks.TryGetValue(bin, out var chunks) && chunks.Length > 0) { return(chunks[0].Begin); } bin++; } }
/// <summary> /// Convert the delta alignment object to its sequence representation /// </summary> /// <returns>Reference sequence alignment at 0th index and /// Query sequence alignment at 1st index</returns> internal PairwiseAlignedSequence ConvertDeltaToSequences() { PairwiseAlignedSequence alignedSequence = new PairwiseAlignedSequence(); Sequence referenceSequence = null; Sequence querySequence = null; int gap = 0; int length = 0; List <int> startOffsets = new List <int>(2); List <int> endOffsets = new List <int>(2); List <int> insertions = new List <int>(2); startOffsets.Add(FirstSequenceStart); startOffsets.Add(SecondSequenceStart); endOffsets.Add(FirstSequenceEnd); endOffsets.Add(SecondSequenceEnd); insertions.Add(0); insertions.Add(0); // Create the new sequence object with given start and end indices referenceSequence = new Sequence(ReferenceSequence.Alphabet); referenceSequence.IsReadOnly = false; length = FirstSequenceEnd - FirstSequenceStart + 1; referenceSequence.InsertRange( 0, ReferenceSequence.Range(FirstSequenceStart, length).ToString()); querySequence = new Sequence(QuerySequence.Alphabet); querySequence.IsReadOnly = false; length = SecondSequenceEnd - SecondSequenceStart + 1; querySequence.InsertRange( 0, QuerySequence.Range(SecondSequenceStart, length).ToString()); // Insert the Alignment character at delta position // +ve delta: Insertion in reference sequence // -ve delta: Insertion in query sequence (deletion in reference sequence) foreach (int delta in Deltas) { gap += Math.Abs(delta); if (delta < 0) { referenceSequence.Insert(gap - 1, DnaAlphabet.Instance.Gap.Symbol); insertions[0]++; } else { querySequence.Insert(gap - 1, DnaAlphabet.Instance.Gap.Symbol); insertions[1]++; } } alignedSequence.FirstSequence = referenceSequence; alignedSequence.SecondSequence = querySequence; alignedSequence.Metadata["StartOffsets"] = startOffsets; alignedSequence.Metadata["EndOffsets"] = endOffsets; alignedSequence.Metadata["Insertions"] = insertions; return(alignedSequence); }
public override void WriteOpenXml(OpenXmlWriter writer) { X14.ConditionalFormatting cf = new X14.ConditionalFormatting(); cf.AddNamespaceDeclaration("xm", "http://schemas.microsoft.com/office/excel/2006/main"); ReferenceSequence referenceSequence = new ReferenceSequence(); referenceSequence.Text = $"{SpreadsheetHelper.ExcelColumnFromNumber(RangeStart.ColumnIndex)}{RangeStart.RowIndex}:{SpreadsheetHelper.ExcelColumnFromNumber(RangeEnd.ColumnIndex)}{RangeEnd.RowIndex}"; X14.ConditionalFormattingRule conditionalFormattingRule = new X14.ConditionalFormattingRule() { Type = ConditionalFormatValues.IconSet, Priority = 1, Id = Guid.NewGuid().ToString("B").ToUpper() }; X14.IconSet iconSet1 = new X14.IconSet() { IconSetTypes = new EnumValue <IconSetTypeValues>(IconSetTypeValues.FourTrafficLights), ShowValue = false, Custom = true }; //ConditionalFormattingIcon var conditionalFormattingIcon1 = new X14.ConditionalFormattingIcon() { IconSet = X14.IconSetTypeValues.NoIcons, IconId = (UInt32Value)0U }; var conditionalFormattingIcon2 = new X14.ConditionalFormattingIcon() { IconSet = X14.IconSetTypeValues.ThreeSymbols2, IconId = (UInt32Value)2U }; var conditionalFormattingIcon3 = new X14.ConditionalFormattingIcon() { IconSet = X14.IconSetTypeValues.ThreeSymbols, IconId = (UInt32Value)1U }; var conditionalFormattingIcon4 = new X14.ConditionalFormattingIcon() { IconSet = X14.IconSetTypeValues.ThreeSymbols, IconId = (UInt32Value)0U }; X14.ConditionalFormattingValueObject conditionalFormattingValueObject1 = new X14.ConditionalFormattingValueObject() { Type = X14.ConditionalFormattingValueObjectTypeValues.Numeric }; Formula formula1 = new Formula(); formula1.Text = "0"; conditionalFormattingValueObject1.Append(formula1); X14.ConditionalFormattingValueObject conditionalFormattingValueObject2 = new X14.ConditionalFormattingValueObject() { Type = X14.ConditionalFormattingValueObjectTypeValues.Numeric }; Formula formula2 = new Formula(); formula2.Text = "1"; conditionalFormattingValueObject2.Append(formula2); X14.ConditionalFormattingValueObject conditionalFormattingValueObject3 = new X14.ConditionalFormattingValueObject() { Type = X14.ConditionalFormattingValueObjectTypeValues.Numeric }; Formula formula3 = new Formula(); formula3.Text = "2"; conditionalFormattingValueObject3.Append(formula3); X14.ConditionalFormattingValueObject conditionalFormattingValueObject4 = new X14.ConditionalFormattingValueObject() { Type = X14.ConditionalFormattingValueObjectTypeValues.Numeric }; Formula formula4 = new Formula(); formula4.Text = "3"; conditionalFormattingValueObject4.Append(formula4); iconSet1.Append( conditionalFormattingValueObject1 , conditionalFormattingValueObject2 , conditionalFormattingValueObject3 , conditionalFormattingValueObject4 , conditionalFormattingIcon1 , conditionalFormattingIcon2 , conditionalFormattingIcon3 , conditionalFormattingIcon4 ); conditionalFormattingRule.Append(iconSet1); cf.Append(conditionalFormattingRule); cf.Append(referenceSequence); writer.WriteElement(cf); }
private void CreateResourcesWorksheet(Dictionary <string, object[]> fieldDictionary, DataTable dataTable, WorkbookPart workbookPart, Dictionary <string, int> sharedStringIndices) { var worksheetPart = workbookPart.AddNewPart <WorksheetPart>("rId1"); var worksheet = new Worksheet(new SheetProperties { CodeName = "Sheet1" }, new SheetDimension { Reference = string.Format("A1:{0}{1}", GetColId(fieldDictionary.Count - 1), dataTable.Rows.Count + 2) }, new SheetViews( new SheetView( new Pane { VerticalSplit = 1D, TopLeftCell = "A3", ActivePane = PaneValues.BottomLeft, State = PaneStateValues.Frozen }, new Selection { ActiveCell = "A2", SequenceOfReferences = new ListValue <StringValue> { InnerText = "A2" } }, new Selection { Pane = PaneValues.BottomLeft }) { TabSelected = true, TopLeftCell = "A2", WorkbookViewId = (UInt32Value)0U })) { MCAttributes = new MarkupCompatibilityAttributes { Ignorable = "x14ac" } }; worksheet.AddNamespaceDeclaration("r", R_SCHEMA); worksheet.AddNamespaceDeclaration("mc", MC_SCHEMA); worksheet.AddNamespaceDeclaration("x14ac", X14_AC_SCHEMA); var columns = new Columns(); UInt32Value colIndex = 1U; foreach (var pair in fieldDictionary) { var column = new Column { Min = colIndex, Max = colIndex, Width = 9.140625D, Style = 1U, BestFit = true, CustomWidth = true }; if (pair.Key.Equals("ID") || pair.Key.Equals("Title")) { column.Style = 5U; } if (pair.Key.Equals("SharePointAccount") && new Act(_spWeb).IsOnline) { column.Hidden = true; } columns.AppendChild(column); colIndex++; } columns.AppendChild(new Column { Min = colIndex, Max = 16384U, Width = 9.140625D, Style = 1U }); var sheetData = new SheetData(); for (UInt32Value i = 1; i <= dataTable.Rows.Count + 2; i++) { var row = new Row { RowIndex = i }; if (i == 1) { row.Hidden = true; } else if (i == 2) { row.StyleIndex = 4U; row.CustomFormat = true; } var rowId = (int)(i - 1); for (int j = 0; j < fieldDictionary.Count; j++) { var cellValue = new CellValue(); KeyValuePair <string, object[]> pair = fieldDictionary.ElementAt(j); object oValue = null; string value = string.Empty; if (rowId > 1) { oValue = dataTable.Rows[rowId - 2][pair.Key]; if (pair.Key.Equals("ResourceLevel")) { foreach (var l in ((IList <string>)pair.Value[2]) .Select(level => level.Split('|')) .Where(l => l[0].Equals(oValue.ToString()))) { oValue = l[1]; break; } } value = oValue.ToString(); } switch (rowId) { case 0: cellValue.Text = sharedStringIndices[pair.Key].ToString(CultureInfo.InvariantCulture); break; case 1: cellValue.Text = sharedStringIndices[pair.Value[0].ToString()].ToString(CultureInfo.InvariantCulture); break; default: cellValue.Text = sharedStringIndices[value].ToString(CultureInfo.InvariantCulture); break; } var cell = new Cell { CellReference = GetColId(j) + i, StyleIndex = 1U }; if (rowId > 1) { switch ((SPFieldType)pair.Value[1]) { case SPFieldType.Counter: case SPFieldType.Integer: case SPFieldType.Number: cellValue.Text = value; break; case SPFieldType.DateTime: cell.StyleIndex = 3U; cellValue.Text = oValue != null && oValue != DBNull.Value ? ((DateTime)oValue).ToOADate() .ToString(CultureInfo.InvariantCulture) : null; break; case SPFieldType.Currency: cell.StyleIndex = 2U; cellValue.Text = value; break; case SPFieldType.Boolean: cell.DataType = CellValues.Boolean; cellValue.Text = value; break; default: cell.DataType = CellValues.SharedString; break; } switch (pair.Key) { case "ID": case "Title": case "Generic": case "SharePointAccount": case "Email": cell.StyleIndex = 5U; break; } } else { cell.DataType = CellValues.SharedString; } if (i == 2) { cell.StyleIndex = 4U; } cell.AppendChild(cellValue); row.AppendChild(cell); } sheetData.AppendChild(row); } var worksheetExtensionList = new WorksheetExtensionList(); var worksheetExtension = new WorksheetExtension { Uri = "{CCE6A557-97BC-4b89-ADB6-D9C93CAAB3DF}" }; worksheetExtension.AddNamespaceDeclaration("x14", X14_SCHEMA); var dataValidations = new X14.DataValidations { Count = 0U }; dataValidations.AddNamespaceDeclaration("xm", XM_SCHEMA); for (int i = 0; i < fieldDictionary.Count; i++) { string colId = GetColId(i); KeyValuePair <string, object[]> pair = fieldDictionary.ElementAt(i); var spFieldType = (SPFieldType)pair.Value[1]; if (spFieldType != SPFieldType.Boolean && spFieldType != SPFieldType.Lookup && spFieldType != SPFieldType.User && spFieldType != SPFieldType.Choice) { continue; } if (pair.Key.Equals("SharePointAccount")) { continue; } if ((bool)pair.Value[3]) { continue; } dataValidations.Count++; var dataValidation = new X14.DataValidation { Type = DataValidationValues.List, AllowBlank = true, ShowInputMessage = true, ShowErrorMessage = true }; string formulaValue = string.Empty; switch (spFieldType) { case SPFieldType.Boolean: formulaValue = "BValues!$A$1:$A$2"; break; case SPFieldType.Lookup: case SPFieldType.Choice: int count = ((List <string>)pair.Value[2]).Count(); formulaValue = pair.Key.Replace("_x0020_", "__") + "Values!$A$1" + (count > 1 ? ":$A$" + count : string.Empty); break; case SPFieldType.User: formulaValue = "DNValues!$D:$D"; break; } var dataValidationForumla = new X14.DataValidationForumla1(); var formula = new Formula { Text = formulaValue }; dataValidationForumla.AppendChild(formula); var refSeq = new ReferenceSequence { Text = string.Format("{0}3:{0}1048576", colId) }; dataValidation.Append(dataValidationForumla, refSeq); dataValidations.AppendChild(dataValidation); } worksheetExtension.AppendChild(dataValidations); worksheetExtensionList.AppendChild(worksheetExtension); worksheet.Append(columns, sheetData, worksheetExtensionList); worksheetPart.Worksheet = worksheet; }