Skip to content

Commit

Permalink
fix: use IntegrationTestSpec.assertEqualTextFiles()
Browse files Browse the repository at this point in the history
  • Loading branch information
sanashah007 committed Aug 9, 2024
1 parent 33dd8ea commit e7ea45f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* <pre>
* java -jar GtfToBed.jar \
* -gtf-path input.gtf \
* -gtf-sequence-dictionary dictionary.dict \
* -gtf-dictionary dictionary.dict \
= * -output output.bed \
* </pre>
*
Expand All @@ -50,8 +50,8 @@
* <pre>
* java -jar GtfToBed.jar \
* -gtf-path input.gtf \
* -gtf-sequence-dictionary dictionary.dict \
* -sort-by-transcript \
* -gtf-dictionary dictionary.dict \
* -sort-transcript \
* -output output.bed \
* </pre>
*
Expand All @@ -61,9 +61,9 @@
* * <pre>
* java -jar GtfToBed.jar \
* -gtf-path input.gtf \
* -gtf-sequence-dictionary dictionary.dict \
* -sort-by-transcript \
* -sort-by-basic \
* -gtf-dictionary dictionary.dict \
* -sort-transcript \
* -sort-basic \
* -output output.bed \
* * </pre>
*/
Expand All @@ -75,9 +75,9 @@
)

public class GtfToBed extends FeatureWalker<GencodeGtfFeature> {
public static final String SORT_BY_TRANSCRIPT_LONG_NAME = "sort-by-transcript";
public static final String SEQUENCE_DICTIONARY_LONG_NAME = "gtf-sequence-dictionary";
public static final String SORT_BY_BASIC_LONG_NAME = "sort-by-basic";
public static final String SORT_BY_TRANSCRIPT_LONG_NAME = "sort-transcript";
public static final String SEQUENCE_DICTIONARY_LONG_NAME = "gtf-dictionary";
public static final String SORT_BY_BASIC_LONG_NAME = "sort-basic";
public static final String INPUT_LONG_NAME = "gtf-path";


Expand Down Expand Up @@ -126,7 +126,7 @@ private void processFeature(GencodeGtfFeature gtfFeature) {
}

// check if the gtf feature is a transcript. If user only wants basic transcripts check that it has the basic tag
if (gtfFeature.getFeatureType() == GencodeGtfFeature.FeatureType.TRANSCRIPT) {
else if (gtfFeature.getFeatureType() == GencodeGtfFeature.FeatureType.TRANSCRIPT) {
if (sortByBasic) {
for (GencodeGtfFeature.OptionalField<?> field : optionalFields) {
if ("basic".equals(field.getValue())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public static String getReferenceDict(){
return getTestDataDir()+"/reference.dict";
}

// public static String getReferenceDict(){
// return GATKBaseTest.publicTestDir + "large/Homo_sapiens_assembly38.dict";
// }

public static String getDecoySamplesGeneBed(){
return getTestDataDir() + "/decoySampleGene.bed";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.broadinstitute.hellbender.CommandLineProgramTest;
import org.broadinstitute.hellbender.cmdline.StandardArgumentDefinitions;
import org.broadinstitute.hellbender.testutils.ArgumentsBuilder;
import org.broadinstitute.hellbender.testutils.IntegrationTestSpec;
import org.testng.Assert;
import org.testng.annotations.Test;

Expand Down Expand Up @@ -109,10 +110,10 @@ private void runMapk1(boolean transcript) throws IOException {

if (transcript) {
Assert.assertEquals(countLines(outputFile), 3);
Assert.assertTrue(compareFiles(mapk1TranscriptBed, outputFile));
IntegrationTestSpec.assertEqualTextFiles(mapk1TranscriptBed, outputFile);
} else {
Assert.assertEquals(countLines(outputFile), 1);
Assert.assertTrue(compareFiles(mapk1GeneBed, outputFile));
IntegrationTestSpec.assertEqualTextFiles(mapk1GeneBed, outputFile);
}
}

Expand All @@ -128,11 +129,11 @@ private void runDecoySample(boolean transcript) throws IOException {

if (transcript) {
Assert.assertEquals(countLines(outputFile), 20);
Assert.assertTrue(compareFiles(decoysTranscriptBed, outputFile));
IntegrationTestSpec.assertEqualTextFiles(decoysTranscriptBed, outputFile);

} else {
Assert.assertEquals(countLines(outputFile), 19);
Assert.assertTrue(compareFiles(decoysGeneBed, outputFile));
IntegrationTestSpec.assertEqualTextFiles(decoysGeneBed, outputFile);
}
}

Expand All @@ -144,7 +145,7 @@ private void runManyTranscripts() throws IOException {
.add(GtfToBed.SORT_BY_BASIC_LONG_NAME, true)
.addOutput(outputFile);
runCommandLine(argsBuilder);
Assert.assertTrue(compareFiles( manyTranscriptsBed, outputFile));
IntegrationTestSpec.assertEqualTextFiles(manyTranscriptsBed, outputFile);

}

Expand All @@ -156,7 +157,7 @@ private void runNotBasic() throws IOException {
.add(GtfToBed.SORT_BY_BASIC_LONG_NAME, false)
.addOutput(outputFile);
runCommandLine(argsBuilder);
Assert.assertTrue(compareFiles(notBasicBed, outputFile));
IntegrationTestSpec.assertEqualTextFiles(notBasicBed, outputFile);
}

private void runMouse() throws IOException {
Expand All @@ -167,7 +168,7 @@ private void runMouse() throws IOException {
.add(GtfToBed.SORT_BY_BASIC_LONG_NAME, false)
.addOutput(outputFile);
runCommandLine(argsBuilder);
Assert.assertTrue(compareFiles(mouseBed, outputFile));
IntegrationTestSpec.assertEqualTextFiles(mouseBed, outputFile);
}

private int countLines(File file) throws IOException {
Expand All @@ -178,31 +179,4 @@ private int countLines(File file) throws IOException {
}
return lines;
}

private boolean compareFiles(File file1, File file2) throws IOException {
BufferedReader reader1 = new BufferedReader(new FileReader(file1));
BufferedReader reader2 = new BufferedReader(new FileReader(file2));

String line1 = reader1.readLine();
String line2 = reader2.readLine();
int lineNum = 1;

while (line1 != null || line2 != null) {
if (line1 == null || line2 == null) {
System.out.println("File are different lengths");
return false;
} else if (!line1.equals(line2)) {
System.out.println("Difference at line " + lineNum);
System.out.println("File1: " + line1);
System.out.println("File2: " + line2);
return false;
}
line1 = reader1.readLine();
line2 = reader2.readLine();
lineNum++;
}

System.out.println("Files are identical");
return true;
}
}

0 comments on commit e7ea45f

Please sign in to comment.