static async Task MainAsync(string[] args) { //Mutant - { "ATGCGA", "CAGTGC", "TTATGT", "AGAAGG", "CCCCTA", "TCACTG" }; string[] dnaSequence = { "ATGCGA", "CAGTGC", "TTATGT", "AGAAGG", "CCCCTA", "TCACTG" }; Console.WriteLine("Welcome to Magneto Solution! \n\n"); Console.WriteLine("Analyzing this DNA sequence to look for mutant genes:"); Console.WriteLine(string.Join(", ", dnaSequence)); MutantModel mutant = (MutantModel)await new MutantBusiness().IsMutant(dnaSequence); Console.WriteLine("\nIs mutant? " + mutant.IsMutant.ToString()); Console.WriteLine("\nConclusion of Analysis? \n" + mutant.ConclusionOfAnalysis); if (mutant.IsMutant && mutant.MutantSequences != null && mutant.MutantSequences.Any()) { Console.WriteLine("\nMutant sequences:"); foreach (string s in mutant.MutantSequences) { Console.WriteLine(s.ToString()); } } Console.ReadLine(); }
//this method look for mutation public async Task <MutantModel> IsMutant(string[] prmDna) { DnaBusiness DnaValidator = new DnaBusiness(); MutantModel mutantModel = new MutantModel(); var isDnaSampleValid = DnaValidator.IsDnaSampleValid(prmDna); if (isDnaSampleValid.Key) { string rowWord; string colWord; int n = prmDna.Length; int numberOfGenForMutation = Convert.ToInt32(Resource.MessageResource.NumberOfGensForMutation); string[,] dnaBoard = DnaValidator.GetDnaBoard(prmDna); Array2nUtility <string> arrayUtility = new Array2nUtility <string>(); List <string> diagonals = arrayUtility.GetDiagonals(dnaBoard, n); if (IsMutantGen(diagonals[0])) { mutantModel.MutantSequences.Add(diagonals[0]); } if (IsMutantGen(diagonals[1])) { mutantModel.MutantSequences.Add(diagonals[1]); } for (int r = 0; r < n; r++) { rowWord = string.Join("", arrayUtility.GetRow(dnaBoard, r)); colWord = string.Join("", arrayUtility.GetColumn(dnaBoard, r)); if (IsMutantGen(rowWord)) { mutantModel.MutantSequences.Add(rowWord); } if (IsMutantGen(colWord)) { mutantModel.MutantSequences.Add(colWord); } if (mutantModel.MutantSequences.Count >= numberOfGenForMutation) { mutantModel.IsMutant = true; break; } } AnalysisLogDAL dal = new AnalysisLogDAL(); await dal.AnalysisLogAdd(prmDna, mutantModel.IsMutant); mutantModel.ConclusionOfAnalysis = mutantModel.IsMutant ? Resource.MessageResource.MutantFounded : Resource.MessageResource.MutantNotFounded; } else { mutantModel.ConclusionOfAnalysis = isDnaSampleValid.Value; } return(mutantModel); }
// POST api/<controller> /// <summary> /// Validating mutant genes in dna sequences /// </summary> /// <param name="requestModel">dna sequences</param> /// <returns>mutants: http-200. no-mutants: http-403.</returns> public async Task <HttpResponseMessage> Post([FromBody] MutantRequestDTO requestModel) { try { string[] dnaSequence = requestModel.dna; MutantModel mutant = (MutantModel)await new MutantBusiness().IsMutant(dnaSequence); if (mutant != null && mutant.IsMutant) { return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.Forbidden)); } } catch (Exception e) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e.ToString())); } }
public async Task <HttpResponseMessage> Post([FromBody] MutantRequestDTO requestModel) { try { string[] dnaSequence = requestModel.dna; MutantResponseDTO responseDTO = new MutantResponseDTO(); MutantModel mutant = (MutantModel)await new MutantBusiness().IsMutant(dnaSequence); if (mutant != null) { responseDTO.IsMutant = mutant.IsMutant; responseDTO.MutantSequences = mutant?.MutantSequences; responseDTO.ConclusionOfAnalysis = mutant?.ConclusionOfAnalysis; } return(Request.CreateResponse(HttpStatusCode.OK, responseDTO)); } catch (Exception e) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e.ToString())); } }