Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use user input filename for analysis #85

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 29 additions & 13 deletions src/DNAnalyzer/CoreExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@
*/
public class CoreExecutor {

/**
* Gets the path to the file to be analyzed
*
* @param sc The input scanner
* @returns The path to file
* @category Input
*/
private String getFilePathInput(final Scanner sc) {
System.out.print("Enter the path to the file to be analyzed: ");
return sc.nextLine();
}

/**
* Reads the inputted file to a string
*
Expand Down Expand Up @@ -54,18 +66,13 @@ private boolean isValidDNA(final String dna) {
/**
* Gets the amino acid from the user
*
* @param sc The input scanner
* @returns The amino acid
* @category Input
*/
private String getAminoAcidInput() {
Scanner sc = null;
try {
sc = new Scanner(System.in);
System.out.print("Enter an amino acid: ");
return sc.nextLine().toLowerCase();
} finally {
sc.close();
}
private String getAminoAcidInput(final Scanner sc) {
System.out.print("Enter an amino acid: ");
return sc.nextLine().toLowerCase();
}

/**
Expand Down Expand Up @@ -108,19 +115,28 @@ private ArrayList<String> createProteinList(final String dna, final String userA
* Calls the other methods to output the results
*
* @category Output
* @param sc The input scanner
* @throws IOException
* @throws InterruptedException
*/
public void defaultCaller() throws IOException, InterruptedException {
// Change the file to be analyzed here
String dna = readFile("assets/dna/random/dnalong.fa");
public void defaultCaller(final Scanner sc) throws IOException, InterruptedException {
String dna = null;

while (true) {
try {
dna = readFile(getFilePathInput(sc));
break;
} catch (final IOException e) {
System.out.println("File not found. Please try again.");
}
}

// Notifies user if DNA is invalid
if (!isValidDNA(dna)) {
throw new IllegalArgumentException("Invalid characters present in DNA sequence.");
}

final String userAminoAcid = getAminoAcidInput();
final String userAminoAcid = getAminoAcidInput(sc);

// Prevents an error from occurring when the user enters an RNA sequence.
// Recently, using DNA sequences instead of RNA sequences has been a more common
Expand Down
6 changes: 5 additions & 1 deletion src/DNAnalyzer/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
package DNAnalyzer;

import java.io.IOException;
import java.util.Scanner;

/**
* Main Class for the DNAnalyzer program.
Expand Down Expand Up @@ -50,6 +51,9 @@ public static void main(final String[] args) throws IOException, InterruptedExce
clearTerminal();

final CoreExecutor gs = new CoreExecutor();
gs.defaultCaller();

try (Scanner sc = new Scanner(System.in)) {
gs.defaultCaller(sc);
}
}
}