Skip to content

Commit

Permalink
Merge pull request #403 from VerisimilitudeX/deepsource-transform-56a…
Browse files Browse the repository at this point in the history
…054c8

format code with autopep8 and google-java-format
  • Loading branch information
VerisimilitudeX authored Jun 8, 2023
2 parents 93b25b6 + 8f44c11 commit b863d7f
Showing 1 changed file with 65 additions and 62 deletions.
127 changes: 65 additions & 62 deletions src/main/java/DNAnalyzer/data/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,86 +9,89 @@
* @version 3.0.0-beta.0
*/
public class Parser {
/**
* Parses a FASTA file and returns the DNA sequence.
*
* @param file File to parse
* @return DNA sequence
* @throws IOException
*/
private static String parseFasta(File file) throws IOException {
BufferedReader rd = new BufferedReader(new FileReader(file));
StringBuilder dna = new StringBuilder();
while (true) {
String line = rd.readLine();
if (line == null) break;

// Extra info
if (line.startsWith(">")) { // File descriptor
System.out.println("Reading DNA: " + line.substring(1).trim());
continue;
}
if (line.startsWith(";")) { // Comment
continue;
}

// Read file
boolean stop = false;
if (line.endsWith("*")) {
line = line.replace("*", "");
stop = true;
}
line = line.toLowerCase();
dna.append(line);
if (stop) break;
}
/**
* Parses a FASTA file and returns the DNA sequence.
*
* @param file File to parse
* @return DNA sequence
* @throws IOException
*/
private static String parseFasta(File file) throws IOException {
BufferedReader rd = new BufferedReader(new FileReader(file));
StringBuilder dna = new StringBuilder();
while (true) {
String line = rd.readLine();
if (line == null) break;

rd.close();
// Extra info
if (line.startsWith(">")) { // File descriptor
System.out.println("Reading DNA: " + line.substring(1).trim());
continue;
}
if (line.startsWith(";")) { // Comment
continue;
}

return dna.toString();
// Read file
boolean stop = false;
if (line.endsWith("*")) {
line = line.replace("*", "");
stop = true;
}
line = line.toLowerCase();
dna.append(line);
if (stop) break;
}

/**
* Parses a FASTQ file and returns the DNA sequence.
*
* @param file File to parse
* @return DNA sequence
* @throws IOException
*/
private static String parseFastq(File file) throws IOException {
BufferedReader br = new BufferedReader(new FileReader(file));
rd.close();

return dna.toString();
}

// Read SEQ id
System.out.println("Reading DNA: " + br.readLine().substring(1).trim());
/**
* Parses a FASTQ file and returns the DNA sequence.
*
* @param file File to parse
* @return DNA sequence
* @throws IOException
*/
private static String parseFastq(File file) throws IOException {
BufferedReader br = new BufferedReader(new FileReader(file));

// Read DNA
String dna = br.readLine();
br.close();
// Read SEQ id
System.out.println("Reading DNA: " + br.readLine().substring(1).trim());

if (dna == null) {
return "No DNA found";
}
// Read DNA
String dna = br.readLine();
br.close();

// TODO: Read field 3 (just a "+"), and then parse the quality data in Field 4
return dna.toLowerCase();
if (dna == null) {
return "No DNA found";
}

// TODO: Read field 3 (just a "+"), and then parse the quality data in Field 4
return dna.toLowerCase();
}

/**
/**
* Parses a file and returns the DNA sequence.
*
* @param file File to parse
* @return DNA sequence
* @throws IOException
*/
public static String parseFile(File file) throws IOException {
if (file.getName().endsWith(".fa")) { // Regular FASTA file, this implementation only reads the first DNA sequence
return parseFasta(file);
}
if (file.getName().endsWith(".fastq")) { // Regular FASTA file, this implementation only reads the first DNA sequence
return parseFastq(file);
}
if (file.getName()
.endsWith(
".fa")) { // Regular FASTA file, this implementation only reads the first DNA sequence
return parseFasta(file);
}
if (file.getName()
.endsWith(".fastq")) { // Regular FASTA file, this implementation only reads the first DNA
// sequence
return parseFastq(file);
}

return null; // TODO: Error handling, handle more types of files
return null; // TODO: Error handling, handle more types of files
}
}

0 comments on commit b863d7f

Please sign in to comment.