@Test public void testParseAncestry() { InputStream inputStream = getClass().getResourceAsStream("ancestry.json"); Ancestry ancestry = converter.parseAncestry(inputStream); assertNotNull(ancestry); assertEquals("7ad467ea509080fb", ancestry.getProfileId()); assertEquals("Total", ancestry.getLabel()); assertEquals(1.0d, ancestry.getProportion(), 0.1d); assertEquals(0.0d, ancestry.getUnassigned(), 0.1d); assertNotNull(ancestry.getSubPopulations()); assertEquals(2, ancestry.getSubPopulations().size()); for (Ancestry subPopulation : ancestry.getSubPopulations()) { if ("Sub-Saharan African".equals(subPopulation.getLabel())) { assertEquals(0.8827d, subPopulation.getProportion(), 0.1d); assertEquals(0.0d, subPopulation.getUnassigned(), 0.1d); assertNotNull(subPopulation.getSubPopulations()); assertTrue(subPopulation.getSubPopulations().isEmpty()); } else if ("European".equals(subPopulation.getLabel())) { assertEquals(0.1773d, subPopulation.getProportion(), 0.1d); assertEquals(0.0193d, subPopulation.getUnassigned(), 0.1d); assertNotNull(subPopulation.getSubPopulations()); assertEquals(1, subPopulation.getSubPopulations().size()); Ancestry subSubPopulation = subPopulation.getSubPopulations().get(0); assertEquals("Northern European", subSubPopulation.getLabel()); assertEquals(0.1579d, subSubPopulation.getProportion(), 0.1d); assertEquals(0.0725d, subSubPopulation.getUnassigned(), 0.1d); assertNotNull(subSubPopulation.getSubPopulations()); assertEquals(1, subSubPopulation.getSubPopulations().size()); Ancestry subSubSubPopulation = subSubPopulation.getSubPopulations().get(0); assertEquals("French and German", subSubSubPopulation.getLabel()); assertEquals(0.1579d, subSubSubPopulation.getProportion(), 0.1d); assertEquals(0.0725d, subSubSubPopulation.getUnassigned(), 0.1d); assertNotNull(subSubSubPopulation.getSubPopulations()); assertTrue(subSubSubPopulation.getSubPopulations().isEmpty()); } else { fail("unexpected subpopulation label"); } } }
@Override public Ancestry parseAncestry(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String id = null; String label = null; double proportion = 0.0d; double unassigned = 0.0d; List<Ancestry> subPopulations = new ArrayList<Ancestry>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("ancestry".equals(field)) { while (parser.nextToken() != JsonToken.END_OBJECT) { String ancestryField = parser.getCurrentName(); parser.nextToken(); if ("label".equals(ancestryField)) { label = parser.getText(); } else if ("proportion".equals(ancestryField)) { proportion = Double.parseDouble(parser.getText()); } else if ("unassigned".equals(ancestryField)) { unassigned = Double.parseDouble(parser.getText()); } else if ("sub_populations".equals(ancestryField)) { subPopulations = parseSubPopulation(id, subPopulations, parser); } } } } return new Ancestry(id, label, proportion, unassigned, subPopulations); } catch (IOException e) { logger.warn("could not parse ancestry", e); } finally { try { inputStream.close(); } catch (Exception e) { } try { parser.close(); } catch (Exception e) { } } return null; }
JacksonPersonalGenomeConverter implements PersonalGenomeConverter { @Override public Ancestry parseAncestry(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String id = null; String label = null; double proportion = 0.0d; double unassigned = 0.0d; List<Ancestry> subPopulations = new ArrayList<Ancestry>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("ancestry".equals(field)) { while (parser.nextToken() != JsonToken.END_OBJECT) { String ancestryField = parser.getCurrentName(); parser.nextToken(); if ("label".equals(ancestryField)) { label = parser.getText(); } else if ("proportion".equals(ancestryField)) { proportion = Double.parseDouble(parser.getText()); } else if ("unassigned".equals(ancestryField)) { unassigned = Double.parseDouble(parser.getText()); } else if ("sub_populations".equals(ancestryField)) { subPopulations = parseSubPopulation(id, subPopulations, parser); } } } } return new Ancestry(id, label, proportion, unassigned, subPopulations); } catch (IOException e) { logger.warn("could not parse ancestry", e); } finally { try { inputStream.close(); } catch (Exception e) { } try { parser.close(); } catch (Exception e) { } } return null; } }
JacksonPersonalGenomeConverter implements PersonalGenomeConverter { @Override public Ancestry parseAncestry(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String id = null; String label = null; double proportion = 0.0d; double unassigned = 0.0d; List<Ancestry> subPopulations = new ArrayList<Ancestry>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("ancestry".equals(field)) { while (parser.nextToken() != JsonToken.END_OBJECT) { String ancestryField = parser.getCurrentName(); parser.nextToken(); if ("label".equals(ancestryField)) { label = parser.getText(); } else if ("proportion".equals(ancestryField)) { proportion = Double.parseDouble(parser.getText()); } else if ("unassigned".equals(ancestryField)) { unassigned = Double.parseDouble(parser.getText()); } else if ("sub_populations".equals(ancestryField)) { subPopulations = parseSubPopulation(id, subPopulations, parser); } } } } return new Ancestry(id, label, proportion, unassigned, subPopulations); } catch (IOException e) { logger.warn("could not parse ancestry", e); } finally { try { inputStream.close(); } catch (Exception e) { } try { parser.close(); } catch (Exception e) { } } return null; } JacksonPersonalGenomeConverter(final JsonFactory jsonFactory); }
JacksonPersonalGenomeConverter implements PersonalGenomeConverter { @Override public Ancestry parseAncestry(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String id = null; String label = null; double proportion = 0.0d; double unassigned = 0.0d; List<Ancestry> subPopulations = new ArrayList<Ancestry>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("ancestry".equals(field)) { while (parser.nextToken() != JsonToken.END_OBJECT) { String ancestryField = parser.getCurrentName(); parser.nextToken(); if ("label".equals(ancestryField)) { label = parser.getText(); } else if ("proportion".equals(ancestryField)) { proportion = Double.parseDouble(parser.getText()); } else if ("unassigned".equals(ancestryField)) { unassigned = Double.parseDouble(parser.getText()); } else if ("sub_populations".equals(ancestryField)) { subPopulations = parseSubPopulation(id, subPopulations, parser); } } } } return new Ancestry(id, label, proportion, unassigned, subPopulations); } catch (IOException e) { logger.warn("could not parse ancestry", e); } finally { try { inputStream.close(); } catch (Exception e) { } try { parser.close(); } catch (Exception e) { } } return null; } JacksonPersonalGenomeConverter(final JsonFactory jsonFactory); @Override PersonalGenomeClientException parseException(final InputStream inputStream); @Override User parseUser(final InputStream inputStream); @Override UserName parseNames(final InputStream inputStream); @Override Haplogroup parseHaplogroups(final InputStream inputStream); @Override Genotype parseGenotypes(final InputStream inputStream); @Override Genome parseGenomes(final InputStream inputStream); @Override Ancestry parseAncestry(final InputStream inputStream); @Override double parseNeanderthalProportion(final InputStream inputStream); @Override List<Relative> parseRelatives(final InputStream inputStream); @Override List<Risk> parseRisks(final InputStream inputStream); @Override List<Carrier> parseCarriers(final InputStream inputStream); @Override List<DrugResponse> parseDrugResponses(final InputStream inputStream); @Override List<Trait> parseTraits(final InputStream inputStream); }
JacksonPersonalGenomeConverter implements PersonalGenomeConverter { @Override public Ancestry parseAncestry(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String id = null; String label = null; double proportion = 0.0d; double unassigned = 0.0d; List<Ancestry> subPopulations = new ArrayList<Ancestry>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("ancestry".equals(field)) { while (parser.nextToken() != JsonToken.END_OBJECT) { String ancestryField = parser.getCurrentName(); parser.nextToken(); if ("label".equals(ancestryField)) { label = parser.getText(); } else if ("proportion".equals(ancestryField)) { proportion = Double.parseDouble(parser.getText()); } else if ("unassigned".equals(ancestryField)) { unassigned = Double.parseDouble(parser.getText()); } else if ("sub_populations".equals(ancestryField)) { subPopulations = parseSubPopulation(id, subPopulations, parser); } } } } return new Ancestry(id, label, proportion, unassigned, subPopulations); } catch (IOException e) { logger.warn("could not parse ancestry", e); } finally { try { inputStream.close(); } catch (Exception e) { } try { parser.close(); } catch (Exception e) { } } return null; } JacksonPersonalGenomeConverter(final JsonFactory jsonFactory); @Override PersonalGenomeClientException parseException(final InputStream inputStream); @Override User parseUser(final InputStream inputStream); @Override UserName parseNames(final InputStream inputStream); @Override Haplogroup parseHaplogroups(final InputStream inputStream); @Override Genotype parseGenotypes(final InputStream inputStream); @Override Genome parseGenomes(final InputStream inputStream); @Override Ancestry parseAncestry(final InputStream inputStream); @Override double parseNeanderthalProportion(final InputStream inputStream); @Override List<Relative> parseRelatives(final InputStream inputStream); @Override List<Risk> parseRisks(final InputStream inputStream); @Override List<Carrier> parseCarriers(final InputStream inputStream); @Override List<DrugResponse> parseDrugResponses(final InputStream inputStream); @Override List<Trait> parseTraits(final InputStream inputStream);  }