private static List <string> ReadSingleFile() { var patterns = new List <string>(); JsonSerializer serializer = new JsonSerializer(); for (int index = Constants.MIN_SIZE_ANTIBODY; index <= Constants.MAX_SIZE_ANTIBODY; index++) { try { var fileName = $"memoryCells{index}.json"; var filePath = Path.Combine(Helpers.GetPath(), fileName); using (StreamReader streamReader = new StreamReader(filePath)) { JsonTextReader reader = new JsonTextReader(streamReader); var fragments = serializer.Deserialize <List <string> >(reader); fragments.ForEach(fragment => patterns.Add(fragment)); } } catch (Exception) { continue; } } return(patterns); }
private static void ReadResults(int antigensCount) { var results = new List <Result>(); if (IsSigle) { for (int index = Constants.MIN_SIZE_ANTIBODY; index <= Constants.MAX_SIZE_ANTIBODY; index++) { try { var fileName = $"results{index}.json"; var filePath = Path.Combine(Helpers.GetPath(), fileName); JsonSerializer serializer = new JsonSerializer(); using (StreamReader streamReader = new StreamReader(filePath)) { JsonTextReader reader = new JsonTextReader(streamReader); var result = serializer.Deserialize <Result>(reader); results.Add(result); } } catch (Exception) { continue; } } } else { for (int index = 0; index < antigensCount; index++) { try { var fileName = $"results{index}.json"; var filePath = Path.Combine(Helpers.GetPath(), fileName); JsonSerializer serializer = new JsonSerializer(); using (StreamReader streamReader = new StreamReader(filePath)) { JsonTextReader reader = new JsonTextReader(streamReader); var result = serializer.Deserialize <Result>(reader); results.Add(result); } } catch (Exception) { continue; } } } }
private void SaveMemoryCells(int index = 0) { if (_memoryCellsStr.Count() == 0) { return; } var filePath = Path.Combine(Helpers.GetPath(), $"memoryCells{(index == 0 ? _antibodySize : index)}.json"); using (StreamWriter file = File.CreateText(filePath)) { JsonSerializer serializer = new JsonSerializer(); serializer.Serialize(file, _memoryCellsStr); } }
private void SaveResult(int index = 0) { if (_results.Average == 0) { return; } var filePath = Path.Combine(Helpers.GetPath(), $"results{index}.json"); using (StreamWriter file = File.CreateText(filePath)) { JsonSerializer serializer = new JsonSerializer(); serializer.Serialize(file, _results); } }
private static List <string> ReadMultipleFiles(int antigensCount) { var patterns = new List <string>(); JsonSerializer serializer = new JsonSerializer(); for (int index = 0; index < antigensCount; index++) { try { var fileName = $"memoryCells{index}.json"; var filePath = Path.Combine(Helpers.GetPath(), fileName); using (StreamReader streamReader = new StreamReader(filePath)) { JsonTextReader reader = new JsonTextReader(streamReader); var fragments = serializer.Deserialize <List <string> >(reader); for (int j = 0; j < fragments.Count(); j++) { if (patterns.Count() <= j) { patterns.Add(fragments[j]); } else { patterns[j] += fragments[j]; } } } } catch (Exception) { continue; } } return(patterns); }