Skip to content

Commit

Permalink
Upload two files for unit test #56
Browse files Browse the repository at this point in the history
  • Loading branch information
zjzxiaohei committed Aug 6, 2024
1 parent 86a9573 commit ce88370
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -41,7 +43,7 @@ public void testAlignment() {
*
* Expected log likelihoood calculated using R script: calcLogP.R
*/
// @Test
@Test
public void testReadCountModel() throws IOException {
ReadCountModel readCountModel = new ReadCountModel();

Expand All @@ -53,8 +55,10 @@ public void testReadCountModel() throws IOException {
Double[] s = new Double[]{1.0399635911708527, 1.0419228814287969};
Double w = 10.0;

String alignmentFile = "/Users/yxia415/Desktop/data_new/gt16ReadCountModel_A.nexus";
String readCountFile = "/Users/yxia415/Desktop/data_new/readCountNumbers.txt";
Path dir = Path.of("src","test", "resources");
File alignmentFile = Paths.get(dir.toString(),"gt16ReadCountModel_A.nexus").toFile();
File readCountFile = Paths.get(dir.toString(),"readCountNumbers.txt").toFile();

Alignment alignment = getAlignment(alignmentFile);
ReadCount readCounts = getReadCounts(readCountFile);

Expand Down Expand Up @@ -94,29 +98,27 @@ public void testReadCountModel() throws IOException {

}

private Alignment getAlignment(String fileName) {
System.out.println("Processing " + fileName);
private Alignment getAlignment(File file) {
System.out.println("Processing " + file);
NexusParser parser = new NexusParser();
try {
parser.parseFile(new File(fileName));
parser.parseFile(file);
System.out.println("Done " + file);
return parser.m_alignment;
} catch (Exception e) {
e.printStackTrace();
System.out.println("ExampleNexusParsing::Failed for " + fileName
throw new RuntimeException("ExampleNexusParsing::Failed for " + file
+ ": " + e.getMessage());
}
System.out.println("Done " + fileName);
return null;
}

private ReadCount getReadCounts(String fileName) throws IOException {
private ReadCount getReadCounts(File file) throws IOException {
ReadCount readCount;
int ntaxa;
int nchar;
int lineCount = 0;
ArrayList<Integer> numbers = new ArrayList<>();
// File reader
BufferedReader reader = new BufferedReader(new FileReader(fileName));
BufferedReader reader = new BufferedReader(new FileReader(file));
String line;
while ((line = reader.readLine()) != null) {
Pattern pattern = Pattern.compile("\\d+");
Expand Down
16 changes: 16 additions & 0 deletions phylonco-beast/src/test/resources/gt16ReadCountModel_A.nexus
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#NEXUS

begin taxa;
dimensions ntax=2;
taxlabels 0 1;
end;

begin characters;
dimensions nchar=2;
format datatype=nucleotideDiploid16;
matrix
0 26
1 22;

end;

2 changes: 2 additions & 0 deletions phylonco-beast/src/test/resources/readCountNumbers.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
A: 1, C: 2, G: 12, T: 0; A: 0, C: 7, G: 17, T: 0;
A: 17, C: 0, G: 14, T: 0; A: 6, C: 0, G: 21, T: 1;

0 comments on commit ce88370

Please sign in to comment.