Skip to content

Commit

Permalink
style: format code with Autopep8 and Google Java Format
Browse files Browse the repository at this point in the history
This commit fixes the style issues introduced in 54c8306 according to the output
from Autopep8 and Google Java Format.

Details: None
  • Loading branch information
deepsource-autofix[bot] authored Feb 16, 2025
1 parent 54c8306 commit 6cafb1a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
47 changes: 22 additions & 25 deletions src/main/java/DNAnalyzer/core/DNAMutation.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
package DNAnalyzer.core;

import java.util.Random;

import DNAnalyzer.utils.core.DNATools;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.io.FileWriter;
import java.util.Date;
import java.util.List;
import java.util.Random;

/**
* This class provides provides functionality for generating mutated DNA
* sequences.
*/
/** This class provides provides functionality for generating mutated DNA sequences. */
public class DNAMutation {

private static final char[] BASES = { 'A', 'T', 'C', 'G', 'N' };
private static final char[] BASES = {'A', 'T', 'C', 'G', 'N'};
private static Random random = new Random();

/**
* Generates a list of 10 mutated DNA sequences based on the specified number of
* base mutations and prints them to the console.
*
* @param dnaString Original DNA sequence to mutate
* @param numMutations The number of base mutations to apply to each mutated
* sequence
* Generates a list of 10 mutated DNA sequences based on the specified number of base mutations
* and prints them to the console.
*
* @param dnaString Original DNA sequence to mutate
* @param numMutations The number of base mutations to apply to each mutated sequence
*/
public static void generateAndWriteMutatedSequences(String dnaString, int numMutations, PrintStream out) {
public static void generateAndWriteMutatedSequences(
String dnaString, int numMutations, PrintStream out) {
List<String> mutatedSequences = new ArrayList<>();

out.println("\nMutating DNA sequence...");
Expand All @@ -47,12 +42,13 @@ public static void generateAndWriteMutatedSequences(String dnaString, int numMut
// Write the mutated sequences to a file
try (FileWriter writer = new FileWriter(fileName)) {
for (int i = 0; i < mutatedSequences.size(); i++) {
writer.write(">mutation_" + (i + 1) + "\n"); // Write a header for each mutated sequence
writer.write(">mutation_" + (i + 1) + "\n"); // Write a header for each mutated sequence
String mutatedSequence = mutatedSequences.get(i);

// Write the sequence over multiple lines (e.g., 80 characters per line)
for (int j = 0; j < mutatedSequence.length(); j += 80) {
writer.write(mutatedSequence.substring(j, Math.min(j + 80, mutatedSequence.length())) + "\n");
writer.write(
mutatedSequence.substring(j, Math.min(j + 80, mutatedSequence.length())) + "\n");
}
}
out.println("Mutated DNA sequences have been written to: " + fileName + "\n");
Expand All @@ -64,16 +60,17 @@ public static void generateAndWriteMutatedSequences(String dnaString, int numMut
/**
* Mutates a DNA sequence with a specified number of random base mutations.
*
* @param dnaString Original DNA sequence to mutate
* @param numMutations The number of mutations (substitutions) to apply to the
* sequence
* @param dnaString Original DNA sequence to mutate
* @param numMutations The number of mutations (substitutions) to apply to the sequence
* @return A new mutated DNA sequence
*/
private static String mutate(String dnaString, int numMutations) {
StringBuilder mutatedDna = new StringBuilder(dnaString);

if (numMutations > mutatedDna.length()) {
System.out.println("Warning: Number of requested mutations exceeds DNA length. Limiting to " + mutatedDna.length());
System.out.println(
"Warning: Number of requested mutations exceeds DNA length. Limiting to "
+ mutatedDna.length());
numMutations = mutatedDna.length();
}

Expand Down Expand Up @@ -108,7 +105,7 @@ private static char getDifferentBase(char originalBase) {
int index = new String(BASES).indexOf(originalBase);

// Pick a random index that isn’t the same as the original
int newIndex = (index + 1 + random.nextInt(BASES.length - 1)) % BASES.length;
int newIndex = (index + 1 + random.nextInt(BASES.length - 1)) % BASES.length;

return BASES[newIndex];
}
Expand Down
17 changes: 10 additions & 7 deletions src/main/java/DNAnalyzer/ui/cli/CmdArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@

package DNAnalyzer.ui.cli;

import java.io.File;
import java.io.IOException;
import java.util.Objects;
import static DNAnalyzer.data.Parser.parseFile;

import DNAnalyzer.core.DNAAnalysis;
import DNAnalyzer.core.Properties;
import DNAnalyzer.core.DNAMutation;
import static DNAnalyzer.data.Parser.parseFile;
import DNAnalyzer.core.Properties;
import DNAnalyzer.ui.gui.DNAnalyzerGUI;
import DNAnalyzer.utils.core.DNATools;
import DNAnalyzer.utils.core.Utils;
import java.io.File;
import java.io.IOException;
import java.util.Objects;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
import picocli.CommandLine.Parameters;
Expand Down Expand Up @@ -92,7 +92,9 @@ public class CmdArgs implements Runnable {

@Option(
names = {"--mutate"},
description = "Generates 10 mutations of the DNA sequence, each with the specified number of mutations, and saves them to a file.")
description =
"Generates 10 mutations of the DNA sequence, each with the specified number of mutations,"
+ " and saves them to a file.")
int mutationCount = 0;

@Option(
Expand Down Expand Up @@ -134,7 +136,8 @@ public void run() {
DNAAnalysis dnaAnalyzer = dnaAnalyzer(aminoAcid).isValidDna().replaceDNA("u", "t");

if (mutationCount > 0) {
DNAMutation.generateAndWriteMutatedSequences(dnaAnalyzer.dna().getDna(), mutationCount, System.out);
DNAMutation.generateAndWriteMutatedSequences(
dnaAnalyzer.dna().getDna(), mutationCount, System.out);
}

if (reverse) {
Expand Down

0 comments on commit 6cafb1a

Please sign in to comment.