/// <summary> /// returns the desired JSON transcript given an annotated variant, a transcript ID, and an alt allele /// </summary> public static IAnnotatedTranscript GetTranscript(IAnnotatedVariant annotatedVariant, string transcriptId, string altAllele, string refAllele = null) { foreach (var variant in annotatedVariant.AnnotatedAlternateAlleles) { if (altAllele != null && variant.AltAllele != altAllele) { continue; } if (refAllele != null && variant.RefAllele != refAllele) { continue; } foreach (var transcript in variant.EnsemblTranscripts.Where( transcript => FormatUtilities.SplitVersion(transcript.TranscriptID).Item1 == transcriptId)) { return(transcript); } foreach (var transcript in variant.RefSeqTranscripts.Where( transcript => FormatUtilities.SplitVersion(transcript.TranscriptID).Item1 == transcriptId)) { return(transcript); } } return(null); }
private void AddSmallAnnotations(IAnnotatedVariant annotatedVariant) { foreach (INsaReader nsaReader in _nsaReaders) { var variant = annotatedVariant.Variant; var annotations = nsaReader.GetAnnotation(variant.Start); if (annotations == null) { continue; } if (nsaReader.IsPositional) { AddPositionalAnnotation(annotations, annotatedVariant, nsaReader); continue; } if (nsaReader.MatchByAllele) { AddAlleleSpecificAnnotation(nsaReader, annotations, annotatedVariant, variant); } else { AddNonAlleleSpecificAnnotations(annotations, variant, annotatedVariant, nsaReader); } } }
private static string ExtractDbId(IAnnotatedVariant annotatedVariant, string idField) { var dbSnp = new VcfField(); var nonDbsnpIds = GetNonDbsnpIds(idField); if (nonDbsnpIds != null) { foreach (var nonDbsnpId in nonDbsnpIds) { dbSnp.Add(nonDbsnpId); } } foreach (var altAllele in annotatedVariant.AnnotatedAlternateAlleles) { if (altAllele.DbSnpIds == null) { continue; } foreach (var id in altAllele.DbSnpIds) { dbSnp.Add(id); } } return(dbSnp.GetString("")); }
internal static string GetAllele(IAnnotatedVariant annotatedVariant, int alleleIndex = 0) { var altAllele = annotatedVariant.AnnotatedAlternateAlleles.ElementAt(alleleIndex); Assert.NotNull(altAllele); return(altAllele.ToString()); }
internal static string GetSampleJson(IAnnotatedVariant annotatedVariant, int sampleIndex) { var sample = annotatedVariant.AnnotatedSamples.ElementAt(sampleIndex); Assert.NotNull(sample); return(sample.ToString()); }
private void WriteJson(IAnnotatedVariant annotatedVariant, IAnnotatedAlternateAllele firstAllele, UnifiedJsonWriter writer) { if (firstAllele.IsReference && !firstAllele.IsReferenceMinor && !firstAllele.IsReferenceNoCall) { return; } writer.Write(annotatedVariant.ToString()); }
private void AddRegulatoryRegion(IAnnotatedVariant annotatedVariant) { var regulatoryRegion = new RegulatoryRegion(_chromosome, 103, 104, CompactId.Convert("7157"), RegulatoryRegionType.TF_binding_site); var consequences = new List <ConsequenceTag> { ConsequenceTag.regulatory_region_amplification }; annotatedVariant.RegulatoryRegions.Add(new AnnotatedRegulatoryRegion(regulatoryRegion, consequences)); }
private static void AddTranscript(IAnnotatedVariant annotatedVariant) { var annotatedTranscript = new Mock <IAnnotatedTranscript>(); annotatedTranscript.SetupGet(x => x.Transcript.Id).Returns(CompactId.Convert("ENST00000540021")); annotatedTranscript.SetupGet(x => x.Transcript.Start).Returns(966300); annotatedTranscript.SetupGet(x => x.Transcript.End).Returns(966405); annotatedTranscript.SetupGet(x => x.AlternateCodons).Returns("cAt/cGt"); annotatedVariant.EnsemblTranscripts.Add(annotatedTranscript.Object); }
/// <summary> /// returns the desired JSON transcript given an annotated variant, a transcript ID, and an alt allele /// </summary> private static IRegulatoryRegion GetRegulatoryRegion(IAnnotatedVariant annotatedVariant, string regulatoryRegionId) { // ReSharper disable once LoopCanBeConvertedToQuery foreach (var variant in annotatedVariant.AnnotatedAlternateAlleles) { foreach (var regulatoryRegion in variant.RegulatoryRegions.Where(r => r.ID == regulatoryRegionId)) { return(regulatoryRegion); } } return(null); }
private static void AddSupplementaryAnnotation(IAnnotatedVariant annotatedVariant) { var dataSource = new SaDataSource("clinVar", "clinVar", "C", true, false, null, new[] { "\"good\":\"result\"" }); var annotatedSaDataSource = new AnnotatedSaDataSource(dataSource, "C"); var dataSource2 = new SaDataSource("exac", "exac", "G", true, true, null, new[] { "\"bad\":\"temper\"", "\"brutal\":\"kangaroo\"" }); var annotatedSaDataSource2 = new AnnotatedSaDataSource(dataSource2, "G"); annotatedVariant.SupplementaryAnnotations.Add(annotatedSaDataSource); annotatedVariant.SupplementaryAnnotations.Add(annotatedSaDataSource2); }
private static void AddSaPositon(ISaPosition saPosition, IAnnotatedVariant annotatedVariant) { foreach (var dataSource in saPosition.DataSources) { var saAltAllele = SaReaderUtils.GetReducedAllele(annotatedVariant.Variant.RefAllele, annotatedVariant.Variant.AltAllele); if (dataSource.MatchByAllele && dataSource.AltAllele != saAltAllele) { continue; } annotatedVariant.SupplementaryAnnotations.Add(new AnnotatedSaDataSource(dataSource, saAltAllele)); } }
internal static IAnnotatedVariant[] GetAnnotatedVariants(IVariant[] variants) { if (variants?[0].Behavior == null) { return(null); } var numVariants = variants.Length; var annotatedVariants = new IAnnotatedVariant[numVariants]; for (var i = 0; i < numVariants; i++) { annotatedVariants[i] = new AnnotatedVariant(variants[i]); } return(annotatedVariants); }
private void AddInfoField(string infoField, IAnnotatedVariant annotatedVariant, StringBuilder sb) { var infoEntries = new VcfField(); if (!string.IsNullOrEmpty(infoField)) { infoEntries.Add(infoField); } ExtractInfo(annotatedVariant as UnifiedJson, infoEntries); infoField = infoEntries.GetString(""); // remove . if (infoField == ".") { infoField = ""; } sb.Append(infoField); var csqs = new List <CsqEntry>(); ExtractCsqs(annotatedVariant as UnifiedJson, csqs); if (csqs.Count != 0) { if (infoField.Length > 0) { sb.Append(";"); } } // append CSQ tags using delegate from annotator sb.Append(GetCsqtAndCsqrVcfInfo(csqs)); if (csqs.Count == 0 && infoField.Length == 0) { sb.Append("."); } }
public string Convert(IVariant vcfVariant, IAnnotatedVariant annotatedVariant) { _sb.Clear(); var fields = vcfVariant.Fields; // add all of the fields before the info field for (var vcfIndex = 0; vcfIndex < VcfCommon.IdIndex; vcfIndex++) { _sb.Append(fields[vcfIndex]); _sb.Append('\t'); } // add dbSNP id var dbSnpId = ExtractDbId(annotatedVariant, fields[VcfCommon.IdIndex]); _sb.Append(dbSnpId); _sb.Append('\t'); for (var vcfIndex = VcfCommon.IdIndex + 1; vcfIndex < VcfCommon.InfoIndex; vcfIndex++) { _sb.Append(fields[vcfIndex]); _sb.Append('\t'); } var infoField = (annotatedVariant as UnifiedJson)?.InfoFromVcf; AddInfoField(infoField, annotatedVariant, _sb); // add all of the fields after the info field var numColumns = fields.Length; for (var vcfIndex = VcfCommon.InfoIndex + 1; vcfIndex < numColumns; vcfIndex++) { _sb.Append('\t'); _sb.Append(fields[vcfIndex]); } return(_sb.ToString()); }
public void AnnotateVariant(IVariantFeature variant, List <Transcript> transcripts, IAnnotatedVariant annotatedVariant, ICompressedSequence sequence) { if (variant.IsStructuralVariant) { return; } CreateTranscriptDictionary(transcripts); foreach (var altAllele in annotatedVariant.AnnotatedAlternateAlleles) { foreach (var transcript in altAllele.EnsemblTranscripts) { var lofteeOut = LofteeAnalysis(transcript, altAllele, sequence); if (lofteeOut != null) { if (transcript.AdditionalInfo == null) { transcript.AdditionalInfo = new Dictionary <string, string>(); } transcript.AdditionalInfo["loftee"] = lofteeOut; } } foreach (var transcript in altAllele.RefSeqTranscripts) { var lofteeOut = LofteeAnalysis(transcript, altAllele, sequence); if (lofteeOut != null) { if (transcript.AdditionalInfo == null) { transcript.AdditionalInfo = new Dictionary <string, string>(); } transcript.AdditionalInfo["loftee"] = lofteeOut; } } } }
private void WriteOutput(string vcfOutput, IAnnotatedVariant annotatedVariant, LiteVcfWriter vcfWriter, LiteVcfWriter gvcfWriter, UnifiedJsonWriter jsonWriter) { if (ConfigurationSettings.Gvcf) { WriteGvcf(vcfOutput, gvcfWriter); } if (annotatedVariant?.AnnotatedAlternateAlleles == null || annotatedVariant.AnnotatedAlternateAlleles.Count == 0) { return; } var firstAllele = annotatedVariant.AnnotatedAlternateAlleles[0]; WriteJson(annotatedVariant, firstAllele, jsonWriter); if (ConfigurationSettings.Vcf) { WriteVcf(vcfOutput, firstAllele, vcfWriter); } }
// ReSharper disable once UnusedParameter.Global internal static void AlleleContains(IAnnotatedVariant annotatedVariant, string expected, int alleleIndex = 0) { var observed = GetAllele(annotatedVariant, alleleIndex); Assert.Contains(expected, observed); }
/// <summary> /// returns the first alternate allele in JSON representation /// </summary> internal static string GetFirstAlleleJson(IAnnotatedVariant annotatedVariant) => annotatedVariant.AnnotatedAlternateAlleles.FirstOrDefault()?.ToString();
public void Write(IVariant vcfVariant, IAnnotatedVariant annotatedVariant) { _writer.WriteLine(_conversion.Convert(vcfVariant, annotatedVariant)); }
private string GetVcfString(IVariant variant, IAnnotatedVariant annotatedVariant) { return(ConfigurationSettings.Vcf || ConfigurationSettings.Gvcf ? _conversion.Convert(variant, annotatedVariant) : null); }
// ReSharper disable once UnusedParameter.Global public static void CheckSampleCount(int expectedCount, IAnnotatedVariant annotatedVariant) { var observedCount = annotatedVariant.AnnotatedSamples.Count(); Assert.Equal(expectedCount, observedCount); }
// ReSharper disable once UnusedParameter.Global public static void CheckJsonDoesNotContain(string expectedString, IAnnotatedVariant annotatedVariant) { var json = annotatedVariant.ToString(); Assert.DoesNotContain(expectedString, json); }
// ReSharper disable once UnusedParameter.Global public static void CheckIntervalCount(int expectedCount, IAnnotatedVariant annotatedVariant) { var observedCount = annotatedVariant.SupplementaryIntervals.Count(); Assert.Equal(expectedCount, observedCount); }
// ReSharper disable once UnusedParameter.Global public static void CheckAlleleCount(int expectedCount, IAnnotatedVariant annotatedVariant) { var observedCount = annotatedVariant.AnnotatedAlternateAlleles.Count; Assert.Equal(expectedCount, observedCount); }
private static bool IsStructVariant(IAnnotatedVariant annotatedVariant) => annotatedVariant.Variant.Behavior.StructuralVariantConsequence;