-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: #964: Report discrepant results from exercise 1 of wmda cons…
…ensus dataset.
- Loading branch information
Showing
17 changed files
with
559 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using CsvHelper; | ||
|
||
namespace Atlas.ManualTesting.Common | ||
{ | ||
public interface IFileReader<T> | ||
{ | ||
Task<IReadOnlyCollection<T>> ReadAllLines(string delimiter, string filePath); | ||
IAsyncEnumerable<T> ReadAsync(string delimiter, string filePath); | ||
} | ||
|
||
public class FileReader<T> : IFileReader<T> | ||
{ | ||
public async Task<IReadOnlyCollection<T>> ReadAllLines(string delimiter, string filePath) | ||
{ | ||
FileChecks(filePath); | ||
|
||
await using var stream = File.OpenRead(filePath); | ||
using var reader = new StreamReader(stream); | ||
using var csv = new CsvReader(reader); | ||
|
||
csv.Configuration.Delimiter = delimiter; | ||
csv.Configuration.HeaderValidated = null; | ||
csv.Configuration.MissingFieldFound = null; | ||
csv.Configuration.TypeConverterOptionsCache.GetOptions<string>().NullValues.Add(""); | ||
|
||
return csv.GetRecords<T>().ToList(); | ||
} | ||
|
||
public async IAsyncEnumerable<T> ReadAsync(string delimiter, string filePath) | ||
{ | ||
FileChecks(filePath); | ||
|
||
await using var stream = File.OpenRead(filePath); | ||
using var reader = new StreamReader(stream); | ||
using var csv = new CsvReader(reader); | ||
|
||
csv.Configuration.Delimiter = delimiter; | ||
csv.Configuration.HeaderValidated = null; | ||
csv.Configuration.MissingFieldFound = null; | ||
csv.Configuration.TypeConverterOptionsCache.GetOptions<string>().NullValues.Add(""); | ||
|
||
await csv.ReadAsync(); | ||
csv.ReadHeader(); | ||
|
||
while (await csv.ReadAsync()) | ||
{ | ||
yield return csv.GetRecord<T>(); | ||
} | ||
} | ||
|
||
private static void FileChecks(string filePath) | ||
{ | ||
if (string.IsNullOrEmpty(filePath)) | ||
{ | ||
throw new ArgumentNullException(nameof(filePath)); | ||
} | ||
|
||
if (!File.Exists(filePath)) | ||
{ | ||
throw new ArgumentException($"File not found at {filePath}."); | ||
} | ||
} | ||
} | ||
} |
36 changes: 0 additions & 36 deletions
36
Atlas.ManualTesting.Common/SubjectImport/SubjectInfoReader.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
namespace Atlas.ManualTesting.Models | ||
{ | ||
public class ReportDiscrepanciesRequest | ||
{ | ||
/// <summary> | ||
/// Path to file with consensus results | ||
/// </summary> | ||
public string ConsensusFilePath { get; set; } | ||
|
||
/// <summary> | ||
/// Path to file with Atlas results that should be compared to the <see cref="ConsensusFilePath"/> | ||
/// </summary> | ||
public string ResultsFilePath { get; set; } | ||
|
||
/// <summary> | ||
/// Path to file containing patient HLA | ||
/// </summary> | ||
public string PatientFilePath { get; set; } | ||
|
||
/// <summary> | ||
/// Path to file containing donor HLA | ||
/// </summary> | ||
public string DonorFilePath { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Atlas.Common.Public.Models.GeneticData; | ||
using Atlas.HlaMetadataDictionary.ExternalInterface.Models; | ||
using Atlas.ManualTesting.Settings; | ||
using Microsoft.Extensions.Options; | ||
using Newtonsoft.Json; | ||
using Polly; | ||
|
||
namespace Atlas.ManualTesting.Services | ||
{ | ||
/// <summary> | ||
/// Copied <see cref="Atlas.MatchingAlgorithm.Functions.Models.Debug.HlaConversionRequest"/>, | ||
/// instead of moving the model to the MatchingAlgorithm.Client.Models project, | ||
/// to avoid breaking client/interface changes that would come from moving <see cref="Atlas.HlaMetadataDictionary.ExternalInterface.Models.TargetHlaCategory"/>. | ||
/// </summary> | ||
public class ConvertHlaRequest | ||
{ | ||
public Locus Locus { get; set; } | ||
public string HlaName { get; set; } | ||
public TargetHlaCategory TargetHlaCategory { get; set; } | ||
|
||
public override string ToString() | ||
{ | ||
return $"convert {Locus},{HlaName} to {TargetHlaCategory}"; | ||
} | ||
} | ||
|
||
public interface IConvertHlaRequester | ||
{ | ||
Task<IEnumerable<string>> ConvertHla(ConvertHlaRequest request); | ||
} | ||
|
||
internal class ConvertHlaRequester : IConvertHlaRequester | ||
{ | ||
private const string FailedRequestPrefix = "Failed to"; | ||
private static readonly HttpClient HttpRequestClient = new(); | ||
private readonly HlaMetadataDictionarySettings hlaMetadataDictionarySettings; | ||
|
||
public ConvertHlaRequester(IOptions<HlaMetadataDictionarySettings> settings) | ||
{ | ||
hlaMetadataDictionarySettings = settings.Value; | ||
} | ||
|
||
public async Task<IEnumerable<string>> ConvertHla(ConvertHlaRequest request) | ||
{ | ||
if (request?.HlaName is null) | ||
{ | ||
throw new ArgumentException("ConvertHla request is missing required data."); | ||
} | ||
|
||
return await ExecuteHlaConversionRequest(request); | ||
} | ||
|
||
private async Task<IEnumerable<string>> ExecuteHlaConversionRequest(ConvertHlaRequest request) | ||
{ | ||
var retryPolicy = Policy.Handle<Exception>().RetryAsync(10); | ||
|
||
var requestResponse = await retryPolicy.ExecuteAndCaptureAsync(async () => await SendHlaConversionRequest(request)); | ||
|
||
return requestResponse.Outcome == OutcomeType.Successful | ||
? requestResponse.Result | ||
: new[] { $"{FailedRequestPrefix} {request}" }; | ||
} | ||
|
||
private async Task<IReadOnlyCollection<string>> SendHlaConversionRequest(ConvertHlaRequest request) | ||
{ | ||
try | ||
{ | ||
var response = await HttpRequestClient.PostAsync( | ||
hlaMetadataDictionarySettings.ConvertHlaRequestUrl, new StringContent(JsonConvert.SerializeObject(request))); | ||
response.EnsureSuccessStatusCode(); | ||
var hlaConversionResult = JsonConvert.DeserializeObject<List<string>>(await response.Content.ReadAsStringAsync()); | ||
|
||
Debug.WriteLine($"Result received: {request}"); | ||
|
||
return hlaConversionResult; | ||
} | ||
catch (Exception ex) | ||
{ | ||
Debug.WriteLine($"{FailedRequestPrefix} {request}. Details: {ex.Message}. Re-attempting until success or re-attempt count reached."); | ||
throw; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.