Skip to content

Commit

Permalink
Merge pull request #97 from B4CKF1SH/refactor1
Browse files Browse the repository at this point in the history
Refactor Properties.isRandomDNA(String) - Issue #73
  • Loading branch information
VerisimilitudeX authored Oct 20, 2022
2 parents 513fcfe + 256f9aa commit 06a0900
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/main/java/DNAnalyzer/Properties.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Arrays;

import DNAnalyzer.aminoAcid.*;

Expand Down Expand Up @@ -129,21 +130,19 @@ public static void printNucleotideCount(final String dna) {
* @category Properties
*/
public static boolean isRandomDNA(final String dna) {
final Map<Character, Integer> nucleotideCount = countNucleotides(dna);

final int a = nucleotidePercentage(nucleotideCount.get('a'), dna);
final int t = nucleotidePercentage(nucleotideCount.get('t'), dna);
final int g = nucleotidePercentage(nucleotideCount.get('g'), dna);
final int c = nucleotidePercentage(nucleotideCount.get('c'), dna);
final Map<Character, Integer> nucleotideCountMapping = countNucleotides(dna);
// Convert Map values to Integer[]
final Integer[] nucleotideCount = nucleotideCountMapping.values().toArray(new Integer[0]);

// This sorts the array to get min and max value
Arrays.sort(nucleotideCount);

// Only calculate 2 Percentages, as only the highest difference (max - min) is relevant
final int maxPercent = nucleotidePercentage(nucleotideCount[3], dna);
final int minPercent = nucleotidePercentage(nucleotideCount[0], dna);
// If the percentage of each nucleotide is between 2% of one another, then it is
// random
return (Math.abs(a - t) <= 2)
&& (Math.abs(a - g) <= 2)
&& (Math.abs(a - c) <= 2)
&& (Math.abs(t - g) <= 2)
&& (Math.abs(t - c) <= 2)
&& (Math.abs(g - c) <= 2);
return (maxPercent - minPercent) <= 2;
}

/**
Expand Down

0 comments on commit 06a0900

Please sign in to comment.