use of org.edamontology.edammap.core.input.json.Biotools in project edammap by edamontology.
the class Util method biotoolsFull.
private static void biotoolsFull(String outputPath, FetcherArgs fetcherArgs, boolean dev) throws IOException {
logger.info("Make full {}bio.tools JSON to {}", dev ? "dev." : "", outputPath);
String api = "https://" + (dev ? "dev." : "") + "bio.tools/api/tool";
Path output = FetcherCommon.outputPath(outputPath);
ObjectMapper mapper = new ObjectMapper();
mapper.enable(SerializationFeature.INDENT_OUTPUT);
mapper.enable(SerializationFeature.CLOSE_CLOSEABLE);
Biotools biotoolsFull = new Biotools();
int count = 0;
String next = "?page=1";
while (next != null) {
try (InputStream is = Input.newInputStream(api + next + "&format=json", false, fetcherArgs.getTimeout(), fetcherArgs.getPrivateArgs().getUserAgent())) {
Biotools biotools = mapper.readValue(is, Biotools.class);
biotoolsFull.addTools(biotools.getList());
biotoolsFull.setCount(biotools.getCount());
count += biotools.getList().size();
next = biotools.getNext();
} catch (Exception e) {
logger.error("Exception!", e);
break;
}
}
mapper.writeValue(output.toFile(), biotoolsFull);
if (count != biotoolsFull.getCount()) {
logger.error("Got {} entries instead of advertised {}", count, biotoolsFull.getCount());
}
logger.info("Made bio.tools JSON with {} entries", count);
}
use of org.edamontology.edammap.core.input.json.Biotools in project edammap by edamontology.
the class Json method outputBiotools.
public static void outputBiotools(CoreArgs args, String queryPath, Path biotoolsPath, Map<EdamUri, Concept> concepts, Results results) throws IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.enable(SerializationFeature.INDENT_OUTPUT);
mapper.enable(SerializationFeature.CLOSE_CLOSEABLE);
mapper.setSerializationInclusion(Include.NON_EMPTY);
Biotools biotools = null;
try (InputStream is = Input.newInputStream(queryPath, true, args.getFetcherArgs().getTimeout(), args.getFetcherArgs().getPrivateArgs().getUserAgent())) {
biotools = mapper.readValue(is, Biotools.class);
}
if (biotools.getList().size() != results.getMappings().size()) {
throw new RuntimeException("Number of results (" + results.getMappings().size() + ") does not correspond to number of tools (" + biotools.getList().size() + ") from " + queryPath);
}
for (int i = 0; i < biotools.getList().size(); ++i) {
Tool tool = biotools.getList().get(i);
MappingTest mapping = results.getMappings().get(i);
if (tool.getBiotoolsID() != null && !tool.getBiotoolsID().equals(mapping.getId())) {
throw new RuntimeException("Tool ID from " + queryPath + " (" + tool.getBiotoolsID() + ") does not correspond to ID from results (" + mapping.getId() + ")");
}
if (!tool.getName().equals(mapping.getName())) {
throw new RuntimeException("Tool name from " + queryPath + " (" + tool.getName() + ") does not correspond to name from results (" + mapping.getName() + ")");
}
}
for (int i = 0; i < biotools.getList().size(); ++i) {
Tool tool = biotools.getList().get(i);
MappingTest mapping = results.getMappings().get(i);
addAnnotations(args, tool, mapping, concepts);
}
mapper.writeValue(biotoolsPath.toFile(), biotools);
}
use of org.edamontology.edammap.core.input.json.Biotools in project edammap by edamontology.
the class BiotoolsFull method get.
public static int get(String outputPath, FetcherArgs fetcherArgs, boolean dev, boolean stderr) throws IOException {
logger.info("Make full {}bio.tools JSON to {}", dev ? "dev." : "", outputPath);
String api = "https://" + (dev ? "dev." : "") + "bio.tools/api/tool";
Path output = PubFetcher.outputPath(outputPath);
ObjectMapper mapper = new ObjectMapper();
mapper.enable(SerializationFeature.INDENT_OUTPUT);
mapper.enable(SerializationFeature.CLOSE_CLOSEABLE);
Biotools biotoolsFull = new Biotools();
int count = 0;
boolean error = false;
String next = "?page=1";
int page = 0;
long start = System.currentTimeMillis();
while (next != null) {
++page;
try (InputStream is = Input.newInputStream(api + next + "&format=json", false, fetcherArgs.getTimeout(), fetcherArgs.getPrivateArgs().getUserAgent())) {
Biotools biotools = mapper.readValue(is, Biotools.class);
if (stderr) {
System.err.print(PubFetcher.progress(page, biotools.getCount() / 10 + 1, start) + " \r");
}
biotoolsFull.addTools(biotools.getList());
biotoolsFull.setCount(biotools.getCount());
count += biotools.getList().size();
next = biotools.getNext();
} catch (Exception e) {
logger.error("Exception at " + next + "!", e);
error = true;
break;
}
}
mapper.writeValue(output.toFile(), biotoolsFull);
if (count != biotoolsFull.getCount()) {
logger.error("Got {} {}bio.tools entries instead of advertised {}", count, dev ? "dev." : "", biotoolsFull.getCount());
}
logger.info("Made {}bio.tools JSON with {} entries", dev ? "dev." : "", count);
if (count != biotoolsFull.getCount()) {
throw new RuntimeException("Got " + count + " " + (dev ? "dev." : "") + "bio.tools entries instead of advertised " + biotoolsFull.getCount());
} else if (error) {
throw new RuntimeException("Error getting full " + (dev ? "dev." : "") + "bio.tools content");
}
return count;
}
Aggregations