Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
5
Task/FASTA-format/Java/fasta-format-1.java
Normal file
5
Task/FASTA-format/Java/fasta-format-1.java
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
44
Task/FASTA-format/Java/fasta-format-2.java
Normal file
44
Task/FASTA-format/Java/fasta-format-2.java
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
public static void main(String[] args) throws IOException {
|
||||
List<FASTA> fastas = readFile("fastas.txt");
|
||||
for (FASTA fasta : fastas)
|
||||
System.out.println(fasta);
|
||||
}
|
||||
|
||||
static List<FASTA> readFile(String path) throws IOException {
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(path))) {
|
||||
List<FASTA> list = new ArrayList<>();
|
||||
StringBuilder lines = null;
|
||||
String newline = System.lineSeparator();
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (line.startsWith(">")) {
|
||||
if (lines != null)
|
||||
list.add(parseFASTA(lines.toString()));
|
||||
lines = new StringBuilder();
|
||||
lines.append(line).append(newline);
|
||||
} else {
|
||||
lines.append(line);
|
||||
}
|
||||
}
|
||||
list.add(parseFASTA(lines.toString()));
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
static FASTA parseFASTA(String string) {
|
||||
String description;
|
||||
char[] sequence;
|
||||
int indexOf = string.indexOf(System.lineSeparator());
|
||||
description = string.substring(1, indexOf);
|
||||
/* using 'stripLeading' will remove any additional line-separators */
|
||||
sequence = string.substring(indexOf + 1).stripLeading().toCharArray();
|
||||
return new FASTA(description, sequence);
|
||||
}
|
||||
|
||||
/* using a 'char' array seems more logical */
|
||||
record FASTA(String description, char[] sequence) {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "%s: %s".formatted(description, new String(sequence));
|
||||
}
|
||||
}
|
||||
26
Task/FASTA-format/Java/fasta-format-3.java
Normal file
26
Task/FASTA-format/Java/fasta-format-3.java
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import java.io.*;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ReadFastaFile {
|
||||
|
||||
public static void main(String[] args) throws FileNotFoundException {
|
||||
|
||||
boolean first = true;
|
||||
|
||||
try (Scanner sc = new Scanner(new File("test.fasta"))) {
|
||||
while (sc.hasNextLine()) {
|
||||
String line = sc.nextLine().trim();
|
||||
if (line.charAt(0) == '>') {
|
||||
if (first)
|
||||
first = false;
|
||||
else
|
||||
System.out.println();
|
||||
System.out.printf("%s: ", line.substring(1));
|
||||
} else {
|
||||
System.out.print(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue