Skip to content

Commit

Permalink
copy phenopackets to output
Browse files Browse the repository at this point in the history
  • Loading branch information
pnrobinson committed Jun 7, 2024
1 parent c158b44 commit bd8fc30
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.monarchinitiative.phenopacket2prompt.model.PhenopacketDisease;
import org.monarchinitiative.phenopacket2prompt.model.PpktIndividual;
import org.monarchinitiative.phenopacket2prompt.output.CorrectResult;
import org.monarchinitiative.phenopacket2prompt.output.PpktCopy;
import org.monarchinitiative.phenopacket2prompt.output.PromptGenerator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -41,6 +42,10 @@ public class GbtTranslateBatchCommand implements Callable<Integer> {
description = "path to translations file")
private String translationsPath = "data/hp-international.obo";

@CommandLine.Option(names = {"-o", "--outdir"},
description = "path to outdir")
private String outdirname = "prompts";

@CommandLine.Option(names = {"-d", "--dir"}, description = "Path to directory with JSON phenopacket files", required = true)
private String ppktDir;

Expand All @@ -61,10 +66,11 @@ public Integer call() throws Exception {
return 1;
}
HpInternationalOboParser oboParser = new HpInternationalOboParser(translationsFile);

Map<String, HpInternational> internationalMap = oboParser.getLanguageToInternationalMap();
LOGGER.info("Got {} translations", internationalMap.size());
List<File> ppktFiles = getAllPhenopacketJsonFiles();
createDir("prompts");
createDir(outdirname);
List<CorrectResult> correctResultList = outputPromptsEnglish(ppktFiles, hpo);
// output all non-English languages here

Expand All @@ -86,7 +92,11 @@ public Integer call() throws Exception {
PromptGenerator italian = PromptGenerator.italian(internationalMap.get("it"));
outputPromptsInternational(ppktFiles, hpo, "it", italian);
resetOutput("finished");

// output original phenopackets
PpktCopy pcopy = new PpktCopy(new File(outdirname));
for (var file : ppktFiles) {
pcopy.copyFile(file);
}

// output file with correct diagnosis list
outputCorrectResults(correctResultList);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.monarchinitiative.phenopacket2prompt.output;


import org.monarchinitiative.phenol.base.PhenolRuntimeException;

import java.io.*;

/**
* Class to copy phenopackets from the input directory to an output directory so that we have all of the files
* used for an experiment in one place.
*/
public class PpktCopy {

private final File ppkt_out_dir;


public PpktCopy(File outdirectory) {
ppkt_out_dir = new File(outdirectory + File.separator + "original_phenopackets");
createDir(ppkt_out_dir);
}



private void createDir(File path) {
if (! path.exists() ) {
boolean result = path.mkdir();
if (! result) {
throw new PhenolRuntimeException("Could not create output directory at " + path);
}
}
}

public void copyFile(File sourceLocation) {
try {
String fname = sourceLocation.getName();
File outfile = new File(ppkt_out_dir + File.separator + fname);

InputStream in = new FileInputStream(sourceLocation);
OutputStream out = new FileOutputStream(outfile);

// Copy the bits from instream to outstream
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
} catch (IOException e) {
throw new PhenolRuntimeException(e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.monarchinitiative.phenopacket2prompt.output.impl.dutch;

import org.monarchinitiative.phenol.ontology.data.Ontology;
import org.monarchinitiative.phenopacket2prompt.model.OntologyTerm;
import org.monarchinitiative.phenopacket2prompt.model.PhenopacketAge;
import org.monarchinitiative.phenopacket2prompt.model.PhenopacketSex;
Expand All @@ -15,9 +14,6 @@

public class DutchPromptGenerator implements PromptGenerator {

private final Ontology hpo;


private final PPKtIndividualInfoGenerator ppktAgeSexGenerator;

private final PhenopacketTextGenerator ppktTextGenerator;
Expand All @@ -27,7 +23,6 @@ public class DutchPromptGenerator implements PromptGenerator {


public DutchPromptGenerator(PpktPhenotypicFeatureGenerator pfgen) {
this.hpo = hpo;
ppktAgeSexGenerator = new PpktIndividualDutch();
ppktTextGenerator = new PpktTextDutch();
this.ppktPhenotypicFeatureGenerator = pfgen;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.monarchinitiative.phenopacket2prompt.output.impl.german;

import com.sun.source.tree.BreakTree;
import org.monarchinitiative.phenol.base.PhenolRuntimeException;
import org.monarchinitiative.phenopacket2prompt.model.*;
import org.monarchinitiative.phenopacket2prompt.output.PPKtIndividualInfoGenerator;
Expand Down Expand Up @@ -449,7 +448,10 @@ public String atAge(PhenopacketAge ppktAge) {
case "Neonatal onset" -> "In der neugeborenen Zeit";
case "Congenital onset" -> "Zum Zeitpunkt der Geburt";
case "Adult onset" -> "Im Erwachsenenalter";
default-> String.format("TODO TODO el %s período", label.replace(" onset", ""));
case "Juvenile onset" -> "Im Jugendlichenalter";
default-> {
throw new PhenolRuntimeException("No German translation for " + label);
}
};
} else {
return ""; // should never get here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ public String formatFeatures(List<OntologyTerm> ontologyTerms) {
} else {
String exclusion;
if (excludedLabels.size() == 1) {
exclusion = String.format(" En cambio, se descartó %s.", getOxfordCommaList(excludedLabels));
exclusion = String.format(". En cambio, se descartó %s.", getOxfordCommaList(excludedLabels));
} else {
exclusion = String.format(" En cambio, se descartaron %s.", getOxfordCommaList(excludedLabels));
exclusion = String.format(". En cambio, se descartaron %s.", getOxfordCommaList(excludedLabels));
}
return getOxfordCommaList(observedLabels) + exclusion;
}
Expand Down

0 comments on commit bd8fc30

Please sign in to comment.