/// <summary> /// returns an array of exons given a list of ObjectValues (AbstractData) /// </summary> public static MutableExon[] ParseList(IImportNode importNode, IChromosome chromosome) { var listMembers = importNode.GetListMembers(); if (listMembers == null) { throw new InvalidDataException("Encountered an exon node that could not be converted to a member list."); } var exons = new MutableExon[listMembers.Count]; for (var exonIndex = 0; exonIndex < listMembers.Count; exonIndex++) { if (listMembers[exonIndex] is ObjectValueNode objectValue) { exons[exonIndex] = Parse(objectValue, chromosome); } else { throw new InvalidDataException($"Could not transform the AbstractData object into an ObjectValue: [{listMembers[exonIndex].GetType()}]"); } } return(exons); }
public static List <IListMember> GetListMembers(this IImportNode node) { if (node is ListObjectKeyValueNode listObjectKeyValueNode) { return(listObjectKeyValueNode.Values); } return(null); }
public static bool IsUndefined(this IImportNode node) { if (!(node is StringKeyValueNode stringKeyValue)) { return(false); } return(stringKeyValue.Value == null); }
public static ObjectValueNode GetObjectValueNode(this IImportNode node) { if (node is ObjectKeyValueNode objectKeyValueNode) { return(objectKeyValueNode.Value); } return(null); }
public static MapperUnitType GetMapperUnitType(IImportNode node) { string mapperUnitTypeString = node.GetString(); if (!MapperUnitTypes.TryGetValue(mapperUnitTypeString, out var ret)) { throw new InvalidDataException($"Unable to find the specified mapper unit type ({mapperUnitTypeString}) in the MapperUnitType dictionary."); } return(ret); }
/// <summary> /// returns an array of miRNAs given a list of ObjectValues (AbstractData) /// </summary> public static (IInterval[] MicroRnas, IRnaEdit[] RnaEdits, bool CdsStartNotFound, bool CdsEndNotFound) ParseList( IImportNode importNode) { var listMembers = importNode.GetListMembers(); if (listMembers == null) { throw new InvalidDataException("Encountered an attribute node that could not be converted to a member list."); } var microRnaList = new List <IInterval>(); var rnaEditList = new List <IRnaEdit>(); var cdsStartNotFound = false; var cdsEndNotFound = false; foreach (var node in listMembers) { if (!(node is ObjectValueNode objectValue)) { throw new InvalidDataException($"Could not transform the AbstractData object into an ObjectValue: [{node.GetType()}]"); } (var key, var value) = ParseKeyValue(objectValue); if (key == null) { continue; } // ReSharper disable once SwitchStatementMissingSomeCases switch (key) { case "miRNA": microRnaList.Add(GetInterval(value)); break; case "_rna_edit": rnaEditList.Add(GetRnaEdit(value)); break; case "cds_start_NF": cdsStartNotFound = true; break; case "cds_end_NF": cdsEndNotFound = true; break; } } var microRnas = microRnaList.Count == 0 ? null : microRnaList.ToArray(); var rnaEdits = rnaEditList.Count == 0 ? null : rnaEditList.ToArray(); return(microRnas, rnaEdits, cdsStartNotFound, cdsEndNotFound); }
public static bool GetStrand(IImportNode node) { int strandNum = node.GetInt32(); // sanity check: make sure the value is either 1 or -1 if (strandNum != -1 && strandNum != 1) { throw new InvalidDataException($"Expected the strand number to be either -1 or 1. Found: {strandNum}."); } return(strandNum == -1); }
public static T[] ParseObjectKeyValueNode <T>(this IImportNode node, Func <ObjectValueNode, T[]> parseFunc) { T[] results; if (node is ObjectKeyValueNode keyValueNode) { results = parseFunc(keyValueNode.Value); } else { throw new InvalidDataException($"Could not transform the AbstractData object into an ObjectKeyValue: [{node.GetType()}]"); } return(results); }
public static string GetString(this IImportNode node) { if (!(node is StringKeyValueNode stringKeyValue)) { throw new InvalidDataException($"Unable to convert the AbstractData type to a StringKeyValue type: [{node.Key}]"); } string s = stringKeyValue.Value; if (s == "" || s == "-") { s = null; } return(s); }
public static T[] ParseListObjectKeyValueNode <T>(this IImportNode node, Func <List <IListMember>, T[]> parseFunc) { T[] results = null; if (node is ListObjectKeyValueNode listObjectKeyValueNode) { results = parseFunc(listObjectKeyValueNode.Values); } else if (!node.IsUndefined()) { throw new InvalidDataException($"Could not transform the AbstractData object into a ListObjectKeyValue: [{node.GetType()}]"); } return(results); }
public static string GetPredictionData(this IImportNode node) { string predictionData = null; if (node is ObjectKeyValueNode predictionNode) { predictionData = ImportPrediction.Parse(predictionNode.Value); } else if (!node.IsUndefined()) { throw new InvalidDataException($"Could not transform the AbstractData object into an ObjectKeyValue: [{node.GetType()}]"); } return(predictionData); }
public static (int Start, int End, string Id, bool OnReverseStrand) Parse(IImportNode importNode) { var objectValue = importNode.GetObjectValueNode(); if (objectValue == null) { throw new InvalidDataException("Encountered a gene import node that could not be converted to an object value node."); } int start = -1; int end = -1; string stableId = null; var onReverseStrand = false; foreach (var node in objectValue.Values) { // sanity check: make sure we know about the keys are used for if (!KnownKeys.Contains(node.Key)) { throw new InvalidDataException($"Encountered an unknown key in the dumper gene object: {node.Key}"); } // handle each key switch (node.Key) { case ImportKeys.End: end = node.GetInt32(); break; case ImportKeys.StableId: stableId = node.GetString(); break; case ImportKeys.Start: start = node.GetInt32(); break; case ImportKeys.Strand: onReverseStrand = TranscriptUtilities.GetStrand(node); break; default: throw new InvalidDataException($"Unknown key found: {node.Key}"); } } return(start, end, stableId, onReverseStrand); }
public static int GetInt32(this IImportNode node) { string s = GetString(node); if (s == null) { return(-1); } if (!int.TryParse(s, out int ret)) { throw new InvalidDataException($"Unable to convert the string ({s}) to an integer."); } return(ret); }
public static int GetHgncId(this IImportNode node) { string hgnc = node.GetString(); if (hgnc != null && hgnc.StartsWith("HGNC:")) { hgnc = hgnc.Substring(5); } int hgncId = -1; if (hgnc != null) { hgncId = int.Parse(hgnc); } return(hgncId); }
private static void ParseRegulatoryRegions(IChromosome chromosome, IImportNode featureGroupNode, ICollection <IRegulatoryRegion> regulatoryRegions) { if (!(featureGroupNode is ListObjectKeyValueNode regulatoryFeatureNodes)) { return; } foreach (var node in regulatoryFeatureNodes.Values) { if (!(node is ObjectValueNode regulatoryFeatureNode)) { throw new InvalidOperationException("Expected a regulatory region object value node, but the current node is not an object value."); } if (regulatoryFeatureNode.Type != "Bio::EnsEMBL::Funcgen::RegulatoryFeature") { throw new InvalidOperationException($"Expected a regulatory region node, but the current data type is: [{regulatoryFeatureNode.Type}]"); } var regulatoryRegion = ImportRegulatoryFeature.Parse(regulatoryFeatureNode, chromosome); regulatoryRegions.Add(regulatoryRegion); } }
public static bool GetBool(this IImportNode node) { int num = GetInt32(node); return(num == 1); }
endExon) Parse(IImportNode importNode, IChromosome currentChromosome) { var objectValue = importNode.GetObjectValueNode(); if (objectValue == null) { throw new InvalidDataException("Encountered a translation import node that could not be converted to an object value node."); } int start = -1; int end = -1; string proteinId = null; byte proteinVersion = 0; MutableExon startExon = null; MutableExon endExon = null; foreach (var node in objectValue.Values) { // sanity check: make sure we know about the keys are used for if (!KnownKeys.Contains(node.Key)) { throw new InvalidDataException($"Encountered an unknown key in the dumper mapper object: {node.Key}"); } ObjectKeyValueNode exonNode; switch (node.Key) { case ImportKeys.Adaptor: case ImportKeys.Sequence: case ImportKeys.DbId: case ImportKeys.Transcript: // skip this key break; case ImportKeys.StartExon: exonNode = node as ObjectKeyValueNode; if (exonNode != null) { startExon = ImportExon.Parse(exonNode.Value, currentChromosome); } break; case ImportKeys.EndExon: exonNode = node as ObjectKeyValueNode; if (exonNode != null) { endExon = ImportExon.Parse(exonNode.Value, currentChromosome); } break; case ImportKeys.StableId: proteinId = node.GetString(); break; case ImportKeys.End: end = node.GetInt32(); break; case ImportKeys.Start: start = node.GetInt32(); break; case ImportKeys.Version: proteinVersion = (byte)node.GetInt32(); break; default: throw new InvalidDataException($"Unknown key found: {node.Key}"); } } return(start, end, proteinId, proteinVersion, startExon, endExon); }
TranslateableSequence, string SiftData, string PolyPhenData, int[] SelenocysteinePositions) Parse(IImportNode importNode) { var objectValue = importNode.GetObjectValueNode(); if (objectValue == null) { throw new InvalidDataException("Encountered a variant effect feature cache node that could not be converted to an object value node."); } MutableTranscriptRegion[] cdnaMaps = null; IInterval[] introns = null; string peptideSequence = null; string translateableSequence = null; string siftData = null; string polyphenData = null; int[] selenocysteinePositions = null; foreach (var node in objectValue.Values) { // sanity check: make sure we know about the keys are used for if (!KnownKeys.Contains(node.Key)) { throw new InvalidDataException($"Encountered an unknown key in the dumper variant effect feature cache object: {node.Key}"); } switch (node.Key) { case ImportKeys.CodonTable: case ImportKeys.FivePrimeUtr: case ImportKeys.ProteinFeatures: case ImportKeys.Selenocysteines: case ImportKeys.SortedExons: case ImportKeys.SplicedSequence: case ImportKeys.ThreePrimeUtr: // not used break; case ImportKeys.Introns: introns = node.ParseListObjectKeyValueNode(ImportIntron.ParseList); break; case ImportKeys.Mapper: cdnaMaps = node.ParseObjectKeyValueNode(ImportTranscriptMapper.Parse); break; case ImportKeys.Peptide: peptideSequence = node.GetString(); break; case ImportKeys.ProteinFunctionPredictions: if (node is ObjectKeyValueNode predictionsNode) { (siftData, polyphenData) = ImportProteinFunctionPredictions.Parse(predictionsNode.Value); } else { throw new InvalidDataException($"Could not transform the AbstractData object into an ObjectKeyValue: [{node.GetType()}]"); } break; case ImportKeys.SeqEdits: selenocysteinePositions = node.ParseListObjectKeyValueNode(ImportSeqEdits.Parse); break; case ImportKeys.TranslateableSeq: translateableSequence = node.GetString(); break; default: throw new InvalidDataException($"Unknown key found: {node.Key}"); } } return(cdnaMaps, introns, peptideSequence, translateableSequence, siftData, polyphenData, selenocysteinePositions); }
public static BioType GetBiotype(IImportNode node) => BioTypeHelper.GetBioType(node.GetString());