Skip to content

Commit

Permalink
Conform to guides
Browse files Browse the repository at this point in the history
  • Loading branch information
VerisimilitudeX committed Mar 30, 2024
1 parent 0fabec3 commit 3d29d72
Show file tree
Hide file tree
Showing 20 changed files with 199 additions and 180 deletions.
5 changes: 4 additions & 1 deletion src/main/java/DNAnalyzer/core/ApiKeyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/** The purpose of this service is to handle all operations concerning the OpenAI API key. */
/**
* The purpose of this service is to handle all operations concerning the OpenAI
* API key.
*/
@Service
public class ApiKeyService implements GetApiKeyUseCase, SetApiKeyUseCase {

Expand Down
28 changes: 17 additions & 11 deletions src/main/java/DNAnalyzer/core/DNAAnalysis.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
/**
* Provides functionality to analyze the DNA
*
* @param dna the DNA to be analyzed
* @param protein the DNA sequence
* @param dna the DNA to be analyzed
* @param protein the DNA sequence
* @param aminoAcid name of amino acid
*/
public record DNAAnalysis(DNATools dna, String protein, String aminoAcid) {
Expand Down Expand Up @@ -80,8 +80,7 @@ public DNAAnalysis printHighCoverageRegions(PrintStream out) {
public void configureReadingFrames(final int minCount, final int maxCount, PrintStream out) {
final short READING_FRAME = 1;
final String dna = this.dna.getDna();
final ReadingFrames aap =
new ReadingFrames(new CodonFrame(dna, READING_FRAME, minCount, maxCount));
final ReadingFrames aap = new ReadingFrames(new CodonFrame(dna, READING_FRAME, minCount, maxCount));
out.print("\n");
aap.printCodonCounts(out);
}
Expand Down Expand Up @@ -119,13 +118,19 @@ private List<String> getProteins(final String aminoAcid) {
}

/**
* countBasePairsStream returns total counts of each DNA base pair found in the provided String.
* countBasePairsStream returns total counts of each DNA base pair found in the
* provided String.
*
* @param dnaString String of DNA bases. Accepts lowercase and uppercase Strings.
* @return returns an array of long(primitive type). long[0] = count of ADENINE bases long[1] =
* count of THYMINE bases long[2] = count of GUANINE bases long[3] = count of CYTOSINE bases
* <p>Constants for the indices can be found in public static class {@link BasePairIndex} for
* convenience/consistency.
* @param dnaString String of DNA bases. Accepts lowercase and uppercase
* Strings.
* @return returns an array of long(primitive type). long[0] = count of ADENINE
* bases long[1] =
* count of THYMINE bases long[2] = count of GUANINE bases long[3] =
* count of CYTOSINE bases
* <p>
* Constants for the indices can be found in public static class
* {@link BasePairIndex} for
* convenience/consistency.
*/
public static long[] countBasePairs(String dnaString) {
return new BasePairCounter(dnaString)
Expand All @@ -151,7 +156,8 @@ public static class BasePairIndex {
}

/**
* Constants to obtain the corresponding ASCII int values for letters used to represent DNA bases.
* Constants to obtain the corresponding ASCII int values for letters used to
* represent DNA bases.
*/
public static class AsciiInt {

Expand Down
33 changes: 17 additions & 16 deletions src/main/java/DNAnalyzer/core/Properties.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static String getVersion() {
* Prints the list of proteins found in the DNA.
*
* @param proteinList The list of proteins to be printed
* @param aminoAcid The amino acid to be searched for {@code @category} Output
* @param aminoAcid The amino acid to be searched for {@code @category} Output
*/
public static void printProteinList(
final List<String> proteinList, final String aminoAcid, PrintStream out) {
Expand All @@ -68,11 +68,12 @@ public static void printProteinList(
* @return The GC content of the DNA sequence
* @category Properties
* @see
* "https://www.sciencedirect.com/topics/biochemistry-genetics-and-molecular-biology/gc-content"
* "https://www.sciencedirect.com/topics/biochemistry-genetics-and-molecular-biology/gc-content"
*/
public static float getGCContent(String dna) {
float gcContent = 0;
if (dna.length() == 0) return gcContent;
if (dna.length() == 0)
return gcContent;

dna = dna.toLowerCase();
float gcLen = (float) calculateLengthOfCG(dna);
Expand All @@ -82,7 +83,8 @@ public static float getGCContent(String dna) {
}

/**
* Calculate the total number of characters that are 'g' or 'c' of a given DNA String
* Calculate the total number of characters that are 'g' or 'c' of a given DNA
* String
*
* @param dna The DNA sequence that was analyzed
* @category Property
Expand Down Expand Up @@ -160,26 +162,25 @@ public static void printNucleotideCount(final String dna, PrintStream out) {
* Checks if the DNA sequence is random or not.
*
* @param dna The DNA sequence that was analyzed
* @return Whether the DNA sequence is random or not {@code @category} Properties
* @return Whether the DNA sequence is random or not {@code @category}
* Properties
*/
public static boolean isRandomDNA(final String dna) {
long[] nucleotideCount = countBasePairs(dna);
int[] percentages =
Arrays.stream(nucleotideCount).mapToInt(c -> nucleotidePercentage(c, dna)).toArray();
int[] percentages = Arrays.stream(nucleotideCount).mapToInt(c -> nucleotidePercentage(c, dna)).toArray();

int a = percentages[BasePairIndex.ADENINE];
int t = percentages[BasePairIndex.THYMINE];
int g = percentages[BasePairIndex.GUANINE];
int c = percentages[BasePairIndex.CYTOSINE];

IntStream diffs =
IntStream.of(
Math.abs(a - t),
Math.abs(a - g),
Math.abs(a - c),
Math.abs(t - g),
Math.abs(t - c),
Math.abs(g - c));
IntStream diffs = IntStream.of(
Math.abs(a - t),
Math.abs(a - g),
Math.abs(a - c),
Math.abs(t - g),
Math.abs(t - c),
Math.abs(g - c));

return diffs.allMatch(diff -> diff <= 2);
}
Expand All @@ -188,7 +189,7 @@ public static boolean isRandomDNA(final String dna) {
* Calculates the percentage of given amount of nucleotide in the dna sequence/
*
* @param nucleotideCount Number of nucleotides (int)
* @param dna DNA sequence
* @param dna DNA sequence
* @return the percentage of nucleotides in that DNA sequence
*/
private static int nucleotidePercentage(final long nucleotideCount, final String dna) {
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/DNAnalyzer/data/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ private static String parseFasta(File file) throws IOException {
StringBuilder dna = new StringBuilder();
while (true) {
String line = rd.readLine();
if (line == null) break;
if (line == null)
break;

// Extra info
if (line.startsWith(">")) { // File descriptor
Expand All @@ -40,7 +41,8 @@ private static String parseFasta(File file) throws IOException {
}
line = line.toLowerCase();
dna.append(line);
if (stop) break;
if (stop)
break;
}

rd.close();
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/DNAnalyzer/data/aminoAcid/AminoAcid.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
import java.util.List;

/**
* AminoAcid enum that represent the amino acid values. Each value can be searched by several
* AminoAcid enum that represent the amino acid values. Each value can be
* searched by several
* abbreviations.
*/
public enum AminoAcid {
Expand Down Expand Up @@ -54,9 +55,10 @@ public enum AminoAcid {
private final List<String> codonData;

/**
* Constructs an instance of an AminoAcid enum, setting its name and list of abbreviations.
* Constructs an instance of an AminoAcid enum, setting its name and list of
* abbreviations.
*
* @param fullName full name of the amino acid.
* @param fullName full name of the amino acid.
* @param abbreviations a list of abbreviations that an acid can be searched by.
*/
AminoAcid(final String fullName, final List<String> abbreviations, final List<String> codonData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
public class AminoAcidFactory {

/**
* Searches for an amino acid by its name or abbreviation passed as the argument.
* Searches for an amino acid by its name or abbreviation passed as the
* argument.
*
* @param aminoAcid amino acid name to search by.
* @return a {@link AminoAcid} value.
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/DNAnalyzer/data/codon/CodonDataConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
*/
public class CodonDataConstants {
/** Private CodonDataConstants class constructor to avoid initialization */
private CodonDataConstants() {}
private CodonDataConstants() {
}

// Declares the stop codon data for the 20 amino acids. Note that the stop
// codons are the same for all amino acids.
Expand All @@ -32,8 +33,7 @@ private CodonDataConstants() {}
// Block to put all AminoAcidNames and their respective codon data into an enum
// map for faster
// retrieval
protected static EnumMap<AminoAcid, List<String>> codonDataAcidMap =
new EnumMap<>(AminoAcid.class);
protected static EnumMap<AminoAcid, List<String>> codonDataAcidMap = new EnumMap<>(AminoAcid.class);

static {
for (AminoAcid aminoAcid : AminoAcid.values()) {
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/DNAnalyzer/data/codon/CodonDataUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ public static List<String> getAminoAcid(final String name) {
}

/**
* Given a dna string and the index that corresponds to first character of a codon of interest
* within that string, this returns the corresponding string. For example, given dnaString
* Given a dna string and the index that corresponds to first character of a
* codon of interest
* within that string, this returns the corresponding string. For example, given
* dnaString
* "gggggaggtggcgaggaagatgac" and index 3, the string "gga" is returned.
*
* @param dnaString DNA data
* @param index Index of the first character of the codon
* @param index Index of the first character of the codon
* @return Codon data with first character at index in the dnaString
*/
public static String returnSubstring(String dnaString, int index) {
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/DNAnalyzer/data/codon/CodonFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,10 @@ public boolean equals(final Object o) {
if (this == o) {
result = true;
} else if (o instanceof final CodonFrame inputFrame) {
result =
getReadingFrame() == inputFrame.getReadingFrame()
&& getMin() == inputFrame.getMin()
&& getMax() == inputFrame.getMax()
&& getDna().equals(inputFrame.getDna());
result = getReadingFrame() == inputFrame.getReadingFrame()
&& getMin() == inputFrame.getMin()
&& getMax() == inputFrame.getMax()
&& getDna().equals(inputFrame.getDna());
}
return result;
}
Expand Down
53 changes: 17 additions & 36 deletions src/main/java/DNAnalyzer/ui/cli/CmdArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,65 +30,45 @@
* @author Nishant Vikramaditya (@Nv7-GitHub)
* @version 1.2.1
*/
@Command(
name = "DNAnalyzer",
mixinStandardHelpOptions = true,
description = "A program to analyze DNA sequences.")
@Command(name = "DNAnalyzer", mixinStandardHelpOptions = true, description = "A program to analyze DNA sequences.")
public class CmdArgs implements Runnable {
@Option(
names = {"--gui"},
description = "Start in GUI mode")
@Option(names = { "--gui" }, description = "Start in GUI mode")
Boolean startGUI = false;

@Option(
names = {"--amino"},
description = "The amino acid representing the start of a gene.")
@Option(names = { "--amino" }, description = "The amino acid representing the start of a gene.")
String aminoAcid;

@Option(
names = {"--min"},
description = "The minimum count of the reading frame.")
@Option(names = { "--min" }, description = "The minimum count of the reading frame.")
int minCount = 0;

@Option(
names = {"--max"},
description = "The maximum count of the reading frame.")
@Option(names = { "--max" }, description = "The maximum count of the reading frame.")
int maxCount = 0;

@Parameters(paramLabel = "DNA", description = "The FASTA file to be analyzed.")
File dnaFile;

@Option(
names = {"--find"},
description = "The DNA sequence to be found within the FASTA file.")
@Option(names = { "--find" }, description = "The DNA sequence to be found within the FASTA file.")
File proteinFile;

@Option(
names = {"--reverse", "-r"},
description = "Reverse the DNA sequence before processing.")
@Option(names = { "--reverse", "-r" }, description = "Reverse the DNA sequence before processing.")
boolean reverse;

@Option(
names = {"--help", "-h"},
description = "Prints this help message and exits.",
help = true)
@Option(names = { "--help", "-h" }, description = "Prints this help message and exits.", help = true)
boolean help;

@Option(
names = {"--version", "-v"},
description = "Prints version information and exits.")
@Option(names = { "--version", "-v" }, description = "Prints version information and exits.")
boolean version;

@Option(
names = {"--rcomplement"},
description = "Prints the complement of the DNA sequence.")
@Option(names = { "--rcomplement" }, description = "Prints the complement of the DNA sequence.")
boolean rcomplement;

/**
* Output a list of proteins, GC content, Nucleotide content, and other information found in a DNA
* Output a list of proteins, GC content, Nucleotide content, and other
* information found in a DNA
* sequence.
*
* @throws IllegalArgumentException when the DNA FASTA file contains an invalid DNA sequence
* @throws IllegalArgumentException when the DNA FASTA file contains an invalid
* DNA sequence
*/
@Override
public void run() {
Expand Down Expand Up @@ -125,8 +105,9 @@ public void run() {

/**
* @param aminoAcid representing the start of the gene
* @return DnaAnalyzer which provides functions to analyze the dnaFile, protein file and supplied
* aminoAcid
* @return DnaAnalyzer which provides functions to analyze the dnaFile, protein
* file and supplied
* aminoAcid
*/
private DNAAnalysis dnaAnalyzer(final String aminoAcid) {
try {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/DNAnalyzer/ui/gui/DNAnalyzerGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public class DNAnalyzerGUI extends Application {
*/
public void start(Stage stage) throws Exception {
// Parent root = FXMLLoader.load(getClass().getResource("DNAnalyzerGUI.fxml"));
Parent root =
FXMLLoader.load(DNAnalyzerGUI.class.getResource("/DNAnalyzer/gui/fxml/DNAnalyzerGUI.fxml"));
Parent root = FXMLLoader.load(DNAnalyzerGUI.class.getResource("/DNAnalyzer/gui/fxml/DNAnalyzerGUI.fxml"));
Scene scene = new Scene(root);
// scene.getStylesheets().add(getClass().getResource("styles.css").toExternalForm());

Expand Down
Loading

0 comments on commit 3d29d72

Please sign in to comment.