@Test public void testParseHaplogroups() { InputStream inputStream = getClass().getResourceAsStream("haplogroups.json"); Haplogroup haplogroup = converter.parseHaplogroups(inputStream); assertNotNull(haplogroup); assertEquals("c4480ba411939067", haplogroup.getProfileId()); assertEquals("D2a1", haplogroup.getPaternal()); assertEquals("D4e2", haplogroup.getMaternal()); assertEquals(1, haplogroup.getPaternalTerminalSnps().size()); assertEquals("i3000015", haplogroup.getPaternalTerminalSnps().get(0).getRsid()); assertEquals("M125", haplogroup.getPaternalTerminalSnps().get(0).getSnp()); assertEquals(2, haplogroup.getMaternalTerminalSnps().size()); assertEquals("i3001424", haplogroup.getMaternalTerminalSnps().get(0).getRsid()); assertEquals("15874", haplogroup.getMaternalTerminalSnps().get(0).getRcrsPosition()); assertEquals("i5050411", haplogroup.getMaternalTerminalSnps().get(1).getRsid()); assertEquals("15874", haplogroup.getMaternalTerminalSnps().get(1).getRcrsPosition()); }
@Override public Haplogroup parseHaplogroups(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String id = null; String maternal = null; String paternal = null; String rsid = null; String rcrsPosition = null; String snp = null; List<PaternalTerminalSnp> paternalTerminalSnps = new ArrayList<PaternalTerminalSnp>(); List<MaternalTerminalSnp> maternalTerminalSnps = new ArrayList<MaternalTerminalSnp>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("maternal".equals(field)) { maternal = parser.getText(); } else if ("paternal".equals(field)) { paternal = "null" == parser.getText() ? null : parser.getText(); } else if ("maternal_terminal_snps".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String maternalTerminalSnpsField = parser.getCurrentName(); parser.nextToken(); if ("rsid".equals(maternalTerminalSnpsField)) { rsid = parser.getText(); } else if ("rcrs_position".equals(maternalTerminalSnpsField)) { rcrsPosition = parser.getText(); } } maternalTerminalSnps.add(new MaternalTerminalSnp(rsid, rcrsPosition)); } } else if ("paternal_terminal_snps".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String paternalTerminalSnpsField = parser.getCurrentName(); parser.nextToken(); if ("rsid".equals(paternalTerminalSnpsField)) { rsid = parser.getText(); } else if ("snp".equals(paternalTerminalSnpsField)) { snp = parser.getText(); } } paternalTerminalSnps.add(new PaternalTerminalSnp(rsid, snp)); } } } return new Haplogroup(id, paternal, maternal, paternalTerminalSnps, maternalTerminalSnps); } catch (IOException e) { logger.warn("could not parse haplogroups", e); } finally { try { inputStream.close(); } catch (Exception e) { } try { parser.close(); } catch (Exception e) { } } return null; }
JacksonPersonalGenomeConverter implements PersonalGenomeConverter { @Override public Haplogroup parseHaplogroups(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String id = null; String maternal = null; String paternal = null; String rsid = null; String rcrsPosition = null; String snp = null; List<PaternalTerminalSnp> paternalTerminalSnps = new ArrayList<PaternalTerminalSnp>(); List<MaternalTerminalSnp> maternalTerminalSnps = new ArrayList<MaternalTerminalSnp>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("maternal".equals(field)) { maternal = parser.getText(); } else if ("paternal".equals(field)) { paternal = "null" == parser.getText() ? null : parser.getText(); } else if ("maternal_terminal_snps".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String maternalTerminalSnpsField = parser.getCurrentName(); parser.nextToken(); if ("rsid".equals(maternalTerminalSnpsField)) { rsid = parser.getText(); } else if ("rcrs_position".equals(maternalTerminalSnpsField)) { rcrsPosition = parser.getText(); } } maternalTerminalSnps.add(new MaternalTerminalSnp(rsid, rcrsPosition)); } } else if ("paternal_terminal_snps".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String paternalTerminalSnpsField = parser.getCurrentName(); parser.nextToken(); if ("rsid".equals(paternalTerminalSnpsField)) { rsid = parser.getText(); } else if ("snp".equals(paternalTerminalSnpsField)) { snp = parser.getText(); } } paternalTerminalSnps.add(new PaternalTerminalSnp(rsid, snp)); } } } return new Haplogroup(id, paternal, maternal, paternalTerminalSnps, maternalTerminalSnps); } catch (IOException e) { logger.warn("could not parse haplogroups", e); } finally { try { inputStream.close(); } catch (Exception e) { } try { parser.close(); } catch (Exception e) { } } return null; } }
JacksonPersonalGenomeConverter implements PersonalGenomeConverter { @Override public Haplogroup parseHaplogroups(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String id = null; String maternal = null; String paternal = null; String rsid = null; String rcrsPosition = null; String snp = null; List<PaternalTerminalSnp> paternalTerminalSnps = new ArrayList<PaternalTerminalSnp>(); List<MaternalTerminalSnp> maternalTerminalSnps = new ArrayList<MaternalTerminalSnp>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("maternal".equals(field)) { maternal = parser.getText(); } else if ("paternal".equals(field)) { paternal = "null" == parser.getText() ? null : parser.getText(); } else if ("maternal_terminal_snps".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String maternalTerminalSnpsField = parser.getCurrentName(); parser.nextToken(); if ("rsid".equals(maternalTerminalSnpsField)) { rsid = parser.getText(); } else if ("rcrs_position".equals(maternalTerminalSnpsField)) { rcrsPosition = parser.getText(); } } maternalTerminalSnps.add(new MaternalTerminalSnp(rsid, rcrsPosition)); } } else if ("paternal_terminal_snps".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String paternalTerminalSnpsField = parser.getCurrentName(); parser.nextToken(); if ("rsid".equals(paternalTerminalSnpsField)) { rsid = parser.getText(); } else if ("snp".equals(paternalTerminalSnpsField)) { snp = parser.getText(); } } paternalTerminalSnps.add(new PaternalTerminalSnp(rsid, snp)); } } } return new Haplogroup(id, paternal, maternal, paternalTerminalSnps, maternalTerminalSnps); } catch (IOException e) { logger.warn("could not parse haplogroups", 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 Haplogroup parseHaplogroups(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String id = null; String maternal = null; String paternal = null; String rsid = null; String rcrsPosition = null; String snp = null; List<PaternalTerminalSnp> paternalTerminalSnps = new ArrayList<PaternalTerminalSnp>(); List<MaternalTerminalSnp> maternalTerminalSnps = new ArrayList<MaternalTerminalSnp>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("maternal".equals(field)) { maternal = parser.getText(); } else if ("paternal".equals(field)) { paternal = "null" == parser.getText() ? null : parser.getText(); } else if ("maternal_terminal_snps".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String maternalTerminalSnpsField = parser.getCurrentName(); parser.nextToken(); if ("rsid".equals(maternalTerminalSnpsField)) { rsid = parser.getText(); } else if ("rcrs_position".equals(maternalTerminalSnpsField)) { rcrsPosition = parser.getText(); } } maternalTerminalSnps.add(new MaternalTerminalSnp(rsid, rcrsPosition)); } } else if ("paternal_terminal_snps".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String paternalTerminalSnpsField = parser.getCurrentName(); parser.nextToken(); if ("rsid".equals(paternalTerminalSnpsField)) { rsid = parser.getText(); } else if ("snp".equals(paternalTerminalSnpsField)) { snp = parser.getText(); } } paternalTerminalSnps.add(new PaternalTerminalSnp(rsid, snp)); } } } return new Haplogroup(id, paternal, maternal, paternalTerminalSnps, maternalTerminalSnps); } catch (IOException e) { logger.warn("could not parse haplogroups", 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 Haplogroup parseHaplogroups(final InputStream inputStream) { checkNotNull(inputStream); JsonParser parser = null; try { parser = jsonFactory.createParser(inputStream); parser.nextToken(); String id = null; String maternal = null; String paternal = null; String rsid = null; String rcrsPosition = null; String snp = null; List<PaternalTerminalSnp> paternalTerminalSnps = new ArrayList<PaternalTerminalSnp>(); List<MaternalTerminalSnp> maternalTerminalSnps = new ArrayList<MaternalTerminalSnp>(); while (parser.nextToken() != JsonToken.END_OBJECT) { String field = parser.getCurrentName(); parser.nextToken(); if ("id".equals(field)) { id = parser.getText(); } else if ("maternal".equals(field)) { maternal = parser.getText(); } else if ("paternal".equals(field)) { paternal = "null" == parser.getText() ? null : parser.getText(); } else if ("maternal_terminal_snps".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String maternalTerminalSnpsField = parser.getCurrentName(); parser.nextToken(); if ("rsid".equals(maternalTerminalSnpsField)) { rsid = parser.getText(); } else if ("rcrs_position".equals(maternalTerminalSnpsField)) { rcrsPosition = parser.getText(); } } maternalTerminalSnps.add(new MaternalTerminalSnp(rsid, rcrsPosition)); } } else if ("paternal_terminal_snps".equals(field)) { while (parser.nextToken() != JsonToken.END_ARRAY) { while (parser.nextToken() != JsonToken.END_OBJECT) { String paternalTerminalSnpsField = parser.getCurrentName(); parser.nextToken(); if ("rsid".equals(paternalTerminalSnpsField)) { rsid = parser.getText(); } else if ("snp".equals(paternalTerminalSnpsField)) { snp = parser.getText(); } } paternalTerminalSnps.add(new PaternalTerminalSnp(rsid, snp)); } } } return new Haplogroup(id, paternal, maternal, paternalTerminalSnps, maternalTerminalSnps); } catch (IOException e) { logger.warn("could not parse haplogroups", 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);  }