Skip to content

Commit

Permalink
Merge pull request #92 from fscheel/RemoveLabelListUsageFromJavaClient
Browse files Browse the repository at this point in the history
Remove label list usage from java client
  • Loading branch information
fscheel authored Nov 19, 2018
2 parents b387eb0 + 85ce68f commit 3fe038d
Show file tree
Hide file tree
Showing 5 changed files with 190 additions and 168 deletions.
2 changes: 2 additions & 0 deletions client/java/freq-client/.swagger-codegen-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md

.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
import io.swagger.client.model.HaplotypeFrequencyData;
import io.swagger.client.model.Label;
import io.swagger.client.model.LabelData;
import io.swagger.client.model.LabelList;
import io.swagger.client.model.License;
import io.swagger.client.model.License.TypeOfLicenseEnum;
import io.swagger.client.model.PopulationData;
Expand All @@ -67,172 +66,169 @@
*/
public class PostPopulationFrequencies implements Callable<Integer> {

private final File inputFile;
private final String gtRegistry;
private final String estEntity;
private final URL url;

private static final String USAGE = "post-population-frequencies [args]";

/**
* Post population frequencies to the frequency curation service
*
* @param inputFile
* input file
* @param accessId
* @param cohortId
* @throws MalformedURLException
*/
public PostPopulationFrequencies(File inputFile, String gtRegistry, String estEntity, URL url)
throws MalformedURLException {
this.inputFile = inputFile;
this.gtRegistry = gtRegistry;
this.estEntity = estEntity;
if (url == null) {
this.url = new URL("http://localhost:8080");
} else {
this.url = url;
}
}

@Override
public Integer call() throws Exception {
postPopulationFrequencies(reader(inputFile));

return 0;
}

public void postPopulationFrequencies(BufferedReader reader) throws IOException, ApiException {
String row;
String[] columns;

HashMap<String, HaplotypeFrequencyData> populationMap = new HashMap<String, HaplotypeFrequencyData>();
HaplotypeFrequencyData haplotypeFrequencyData;

License license = new License();
license.setTypeOfLicense(TypeOfLicenseEnum.CC0);

while ((row = reader.readLine()) != null) {
columns = row.split(",");

String race = columns[0];
String haplotype = columns[1];
Double frequency = new Double(columns[2]);

if (populationMap.containsKey(race)) {
haplotypeFrequencyData = populationMap.get(race);
} else {
haplotypeFrequencyData = new HaplotypeFrequencyData();
haplotypeFrequencyData.setLicense(license);
}

HaplotypeFrequency hapFrequency = new HaplotypeFrequency();
hapFrequency.setFrequency(new Double(frequency));
hapFrequency.setHaplotypeString(haplotype);
haplotypeFrequencyData.addHaplotypeFrequencyListItem(hapFrequency);

populationMap.put(race, haplotypeFrequencyData);
}

reader.close();

ApiClient apiClient = new ApiClient();
apiClient.setConnectTimeout(60000);
apiClient.setReadTimeout(60000);
apiClient.setWriteTimeout(60000);
apiClient.setBasePath(url.toString());
DefaultApi api = new DefaultApi(apiClient);
PopulationApi popApi = new PopulationApi(apiClient);
CohortApi cohortApi = new CohortApi(apiClient);

CohortRequest cohortRequest = new CohortRequest();

CohortData cohortData = new CohortData();
cohortData.setName(inputFile.getName());
cohortData.setGenotypeList(new GenotypeList());

cohortRequest.setCohortData(cohortData);

System.out.println("Creating cohort: " + cohortData.getName());

cohortData = cohortApi.createCohort(cohortRequest);

LabelData labelData = new LabelData();
LabelList labelList = new LabelList();
Label registryLabel = new Label();
registryLabel.setTypeOfLabel("GT_REGISTRY");
registryLabel.setValue(gtRegistry);
labelList.addLabelItem(registryLabel);

Label estimatorLabel = new Label();
estimatorLabel.setTypeOfLabel("HT_ESTIMATION_ENT");
estimatorLabel.setValue(estEntity);
labelList.addLabelItem(estimatorLabel);

labelData.setLabelList(labelList);

for (String populationName : populationMap.keySet()) {
HFCurationRequest hfCurationRequest = new HFCurationRequest();
PopulationRequest populationRequest = new PopulationRequest();

populationRequest.setName(populationName);

System.out.println("Creating population: " + populationRequest.getName());

PopulationData populationData = popApi.createPopulation(populationRequest);

hfCurationRequest.setPopulationID(populationData.getId());
hfCurationRequest.setCohortID(cohortData.getId());
hfCurationRequest.setHaplotypeFrequencyData(populationMap.get(populationName));

hfCurationRequest.setLabelData(labelData);

System.out.println("Submitting frequencies for population: " + populationData.getName());
HFCurationResponse response = api.hfcPost(hfCurationRequest);
}
}

/**
* Main.
*
* @param args
* command line args
* @throws MalformedURLException
*/
public static void main(final String[] args) throws MalformedURLException {
Switch about = new Switch("a", "about", "display about message");
Switch help = new Switch("h", "help", "display help message");
FileArgument inputFile = new FileArgument("i", "input-file", "input file, default stdin", true);
StringArgument gtRegistry = new StringArgument("r", "registry", "genotype registry", false);
StringArgument estEntity = new StringArgument("e", "estimator", "haplotype frequency estimating entity", false);
URLArgument url = new URLArgument("u", "url", "frequency service url", false);

ArgumentList arguments = new ArgumentList(about, help, inputFile, gtRegistry, estEntity, url);
CommandLine commandLine = new CommandLine(args);

PostPopulationFrequencies postPopulationFrequencies = null;
try {
CommandLineParser.parse(commandLine, arguments);
if (about.wasFound()) {
About.about(System.out);
System.exit(0);
}
if (help.wasFound()) {
Usage.usage(USAGE, null, commandLine, arguments, System.out);
System.exit(0);
}
postPopulationFrequencies = new PostPopulationFrequencies(inputFile.getValue(), gtRegistry.getValue(),
estEntity.getValue(), url.getValue());
} catch (CommandLineParseException | IllegalArgumentException e) {
Usage.usage(USAGE, e, commandLine, arguments, System.err);
System.exit(-1);
}
try {
System.exit(postPopulationFrequencies.call());
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
private final File inputFile;
private final String gtRegistry;
private final String estEntity;
private final URL url;

private static final String USAGE = "post-population-frequencies [args]";

/**
* Post population frequencies to the frequency curation service
*
* @param inputFile
* input file
* @param accessId
* @param cohortId
* @throws MalformedURLException
*/
public PostPopulationFrequencies(File inputFile, String gtRegistry, String estEntity, URL url)
throws MalformedURLException {
this.inputFile = inputFile;
this.gtRegistry = gtRegistry;
this.estEntity = estEntity;
if (url == null) {
this.url = new URL("http://localhost:8080");
} else {
this.url = url;
}
}

@Override
public Integer call() throws Exception {
postPopulationFrequencies(reader(inputFile));

return 0;
}

public void postPopulationFrequencies(BufferedReader reader) throws IOException, ApiException {
String row;
String[] columns;

HashMap<String, HaplotypeFrequencyData> populationMap = new HashMap<String, HaplotypeFrequencyData>();
HaplotypeFrequencyData haplotypeFrequencyData;

License license = new License();
license.setTypeOfLicense(TypeOfLicenseEnum.CC0);

while ((row = reader.readLine()) != null) {
columns = row.split(",");

String race = columns[0];
String haplotype = columns[1];
Double frequency = new Double(columns[2]);

if (populationMap.containsKey(race)) {
haplotypeFrequencyData = populationMap.get(race);
} else {
haplotypeFrequencyData = new HaplotypeFrequencyData();
haplotypeFrequencyData.setLicense(license);
}

HaplotypeFrequency hapFrequency = new HaplotypeFrequency();
hapFrequency.setFrequency(new Double(frequency));
hapFrequency.setHaplotypeString(haplotype);
haplotypeFrequencyData.addHaplotypeFrequencyListItem(hapFrequency);

populationMap.put(race, haplotypeFrequencyData);
}

reader.close();

ApiClient apiClient = new ApiClient();
apiClient.setConnectTimeout(60000);
apiClient.setReadTimeout(60000);
apiClient.setWriteTimeout(60000);
apiClient.setBasePath(url.toString());
DefaultApi api = new DefaultApi(apiClient);
PopulationApi popApi = new PopulationApi(apiClient);
CohortApi cohortApi = new CohortApi(apiClient);

CohortRequest cohortRequest = new CohortRequest();

CohortData cohortData = new CohortData();
cohortData.setName(inputFile.getName());
cohortData.setGenotypeList(new GenotypeList());

cohortRequest.setCohortData(cohortData);

System.out.println("Creating cohort: " + cohortData.getName());

cohortData = cohortApi.createCohort(cohortRequest);

LabelData labelData = new LabelData();
Label registryLabel = new Label();
registryLabel.setTypeOfLabel("GT_REGISTRY");
registryLabel.setValue(gtRegistry);
labelData.addLabelListItem(registryLabel);

Label estimatorLabel = new Label();
estimatorLabel.setTypeOfLabel("HT_ESTIMATION_ENT");
estimatorLabel.setValue(estEntity);
labelData.addLabelListItem(estimatorLabel);

for (String populationName : populationMap.keySet()) {
HFCurationRequest hfCurationRequest = new HFCurationRequest();
PopulationRequest populationRequest = new PopulationRequest();

populationRequest.setName(populationName);

System.out.println("Creating population: " + populationRequest.getName());

PopulationData populationData = popApi.createPopulation(populationRequest);

hfCurationRequest.setPopulationID(populationData.getId());
hfCurationRequest.setCohortID(cohortData.getId());
hfCurationRequest.setHaplotypeFrequencyData(populationMap.get(populationName));

hfCurationRequest.setLabelData(labelData);

System.out.println("Submitting frequencies for population: " + populationData.getName());
HFCurationResponse response = api.hfcPost(hfCurationRequest);
}
}

/**
* Main.
*
* @param args
* command line args
* @throws MalformedURLException
*/
public static void main(final String[] args) throws MalformedURLException {
Switch about = new Switch("a", "about", "display about message");
Switch help = new Switch("h", "help", "display help message");
FileArgument inputFile = new FileArgument("i", "input-file", "input file, default stdin", true);
StringArgument gtRegistry = new StringArgument("r", "registry", "genotype registry", false);
StringArgument estEntity = new StringArgument("e", "estimator", "haplotype frequency estimating entity", false);
URLArgument url = new URLArgument("u", "url", "frequency service url", false);

ArgumentList arguments = new ArgumentList(about, help, inputFile, gtRegistry, estEntity, url);
CommandLine commandLine = new CommandLine(args);

PostPopulationFrequencies postPopulationFrequencies = null;
try {
CommandLineParser.parse(commandLine, arguments);
if (about.wasFound()) {
About.about(System.out);
System.exit(0);
}
if (help.wasFound()) {
Usage.usage(USAGE, null, commandLine, arguments, System.out);
System.exit(0);
}
postPopulationFrequencies = new PostPopulationFrequencies(inputFile.getValue(), gtRegistry.getValue(),
estEntity.getValue(), url.getValue());
} catch (CommandLineParseException | IllegalArgumentException e) {
Usage.usage(USAGE, e, commandLine, arguments, System.err);
System.exit(-1);
}
try {
System.exit(postPopulationFrequencies.call());
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}

}
10 changes: 10 additions & 0 deletions client/testDataFiles/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Data requirements

This is a work in progress determining how to format data for upload.

* Do not include a header
* There can be no empty lines in the middle of the data. (A blank line at the end seems to be fine.)
* It currently doesn't care if the frequencies add up to one. (Working on that.)
* Haplotypes should be separated by tildas (~).

See demo_PHYCUS_HFs.csv for an example.
10 changes: 10 additions & 0 deletions client/testDataFiles/demo_PHYCUS_HFs.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
OTH,DRB1*07:01:01:01~DQB1*02:02:01,0.082586969
OTH,DRB1*15:01:01:01~DQB1*03:03:02:03,0.175318163
OTH,DRB1*01:01:01~DQB1*05:03:01:01,0.053289506
OTH,DRB1*03:01:02~DQB1*06:02:01,0.120375512
OTH,DRB1*03:01:01:01~DQB1*05:01:01:01,0.099318824
OTH,DRB1*04:01:01~DQB1*04:01:01,0.056614833
OTH,DRB1*15:01:01:01~DQB1*03:02:12,0.106412321
OTH,DRB1*08:01:03~DQB1*03:02:01,0.188099248
OTH,DRB1*13:01:01~DQB1*03:01:01:01,0.000557303
OTH,DRB1*15:01:01:01~DQB1*06:05:01,0.117427322
4 changes: 4 additions & 0 deletions client/testDataFiles/proto_hap_data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Beer License
AFA, ABCDE, 0.25
AFA, FGHIJ, 0.25
AFA, KLMNO, 0.50

0 comments on commit 3fe038d

Please sign in to comment.