/// <summary> /// writes the transcript to the binary writer /// </summary> public void Write(IExtendedBinaryWriter writer, Dictionary <IGene, int> geneIndices, Dictionary <ITranscriptRegion, int> transcriptRegionIndices, Dictionary <IInterval, int> microRnaIndices, Dictionary <string, int> peptideIndices) { // transcript writer.WriteOpt(Chromosome.Index); writer.WriteOpt(Start); writer.WriteOpt(End); // ReSharper disable once ImpureMethodCallOnReadonlyValueField Id.Write(writer); // gene writer.WriteOpt(GetIndex(Gene, geneIndices)); // encoded data var encoded = EncodedTranscriptData.GetEncodedTranscriptData(BioType, CdsStartNotFound, CdsEndNotFound, Source, IsCanonical, SiftIndex != -1, PolyPhenIndex != -1, MicroRnas != null, RnaEdits != null, Selenocysteines != null, TranscriptRegions != null, Translation != null, StartExonPhase); encoded.Write(writer); // transcript regions if (encoded.HasTranscriptRegions) { WriteIndices(writer, TranscriptRegions, transcriptRegionIndices); } writer.WriteOpt(NumExons); // protein function predictions if (encoded.HasSift) { writer.WriteOpt(SiftIndex); } if (encoded.HasPolyPhen) { writer.WriteOpt(PolyPhenIndex); } // translation if (encoded.HasTranslation) { // ReSharper disable once PossibleNullReferenceException var peptideIndex = GetIndex(Translation.PeptideSeq, peptideIndices); Translation.Write(writer, peptideIndex); } // attributes if (encoded.HasMirnas) { WriteIndices(writer, MicroRnas, microRnaIndices); } if (encoded.HasRnaEdits) { WriteItems(writer, RnaEdits, (x, y) => x.Write(y)); } if (encoded.HasSelenocysteines) { WriteItems(writer, Selenocysteines, (x, y) => y.WriteOpt(x)); } }
public static ITranscript Read(BufferedBinaryReader reader, IDictionary <ushort, IChromosome> chromosomeIndexDictionary, IGene[] cacheGenes, ITranscriptRegion[] cacheTranscriptRegions, IInterval[] cacheMirnas, string[] cachePeptideSeqs) { // transcript var referenceIndex = reader.ReadOptUInt16(); var start = reader.ReadOptInt32(); var end = reader.ReadOptInt32(); var id = CompactId.Read(reader); // gene var geneIndex = reader.ReadOptInt32(); var gene = cacheGenes[geneIndex]; // encoded data var encoded = EncodedTranscriptData.Read(reader); // transcript regions var transcriptRegions = encoded.HasTranscriptRegions ? ReadIndices(reader, cacheTranscriptRegions) : null; ushort numExons = reader.ReadOptUInt16(); // protein function predictions int siftIndex = encoded.HasSift ? reader.ReadOptInt32() : -1; int polyphenIndex = encoded.HasPolyPhen ? reader.ReadOptInt32() : -1; // translation var translation = encoded.HasTranslation ? DataStructures.Translation.Read(reader, cachePeptideSeqs) : null; // attributes var mirnas = encoded.HasMirnas ? ReadIndices(reader, cacheMirnas) : null; var rnaEdits = encoded.HasRnaEdits ? ReadItems(reader, RnaEdit.Read) : null; var selenocysteines = encoded.HasSelenocysteines ? ReadItems(reader, x => x.ReadOptInt32()) : null; return(new Transcript(chromosomeIndexDictionary[referenceIndex], start, end, id, translation, encoded.BioType, gene, ExonUtilities.GetTotalExonLength(transcriptRegions), encoded.StartExonPhase, encoded.IsCanonical, transcriptRegions, numExons, mirnas, siftIndex, polyphenIndex, encoded.TranscriptSource, encoded.CdsStartNotFound, encoded.CdsEndNotFound, selenocysteines, rnaEdits)); }