ExperimentDesignParser { public ExperimentDesign parse(String experimentAccession) { AtlasResource<TsvStreamer> r = dataFileHub.getExperimentFiles(experimentAccession).experimentDesign; if (!r.exists()) { throw new UncheckedIOException(new FileNotFoundException(String.format("%s does not exist", r))); } try (TsvStreamer tsvStreamer = r.get()) { Iterator<String[]> lineIterator = tsvStreamer.get().iterator(); ExperimentDesign experimentDesign = new ExperimentDesign(); if (dataFileHub.getExperimentFiles(experimentAccession).sdrf.exists()) { Map<String, Set<String>> headers = sdrfParser.parseHeader(experimentAccession); experimentDesign.setOrderedSampleHeaders(headers.get("characteristics")); experimentDesign.setOrderedFactorHeaders(headers.get("factorvalue")); } if (lineIterator.hasNext()) { String[] headerLine = lineIterator.next(); Map<String, Integer> sampleHeaderIndexes = extractHeaderIndexes(headerLine, SAMPLE_COLUMN_HEADER_PATTERN); Map<String, Integer> sampleValueOntologyTermHeaderIndexes = extractHeaderIndexes(headerLine, SAMPLE_ONTOLOGY_TERM_COLUMN_HEADER_PATTERN); Map<String, Integer> factorHeaderIndexes = extractHeaderIndexes(headerLine, FACTOR_COLUMN_HEADER_PATTERN); Map<String, Integer> factorValueOntologyTermHeaderIndexes = extractHeaderIndexes(headerLine, FACTOR_VALUE_ONTOLOGY_TERM_COLUMN_HEADER_PATTERN); int headersStartIndex = headerLine.length - (sampleHeaderIndexes.size() + sampleValueOntologyTermHeaderIndexes.size() + factorHeaderIndexes.size() + factorValueOntologyTermHeaderIndexes.size()); for (String assayHeaderField : Arrays.copyOf(headerLine, headersStartIndex)) { experimentDesign.addAssayHeader(assayHeaderField); } while (lineIterator.hasNext()) { String[] line = lineIterator.next(); String runOrAssay = line[0]; if (headersStartIndex > 1) { experimentDesign.putArrayDesign(runOrAssay, line[1]); } for (String sampleHeader : sampleHeaderIndexes.keySet()) { String sampleValue = line[sampleHeaderIndexes.get(sampleHeader)]; Integer sampleValueOntologyTermIndex = sampleValueOntologyTermHeaderIndexes.get(sampleHeader); OntologyTerm[] sampleValueOntologyTerms = createOntologyTerms(line, sampleValueOntologyTermIndex); SampleCharacteristic sampleCharacteristic = SampleCharacteristic.create(sampleHeader, sampleValue, sampleValueOntologyTerms); experimentDesign.putSampleCharacteristic(runOrAssay, sampleHeader, sampleCharacteristic); } for (String factorHeader : factorHeaderIndexes.keySet()) { String factorValue = line[factorHeaderIndexes.get(factorHeader)]; Integer factorValueOntologyTermIndex = factorValueOntologyTermHeaderIndexes.get(factorHeader); OntologyTerm[] factorValueOntologyTerms = createOntologyTerms(line, factorValueOntologyTermIndex); experimentDesign.putFactor(runOrAssay, factorHeader, factorValue, factorValueOntologyTerms); } } } return experimentDesign; } } @Inject  ExperimentDesignParser(DataFileHub dataFileHub, SdrfParser sdrfParser); ExperimentDesign parse(String experimentAccession);  }
@Test public void testParseHeaders() { ExperimentDesign experimentDesign = subject.parse(EXPERIMENT_ACCESSION); assertThat(experimentDesign.getFactorHeaders(), IsIterableContainingInOrder.contains(GENOTYPE)); assertThat( experimentDesign.getSampleHeaders(), IsIterableContainingInOrder.contains(SAMPLE_NAME_1, "Genotype", "Organism", SAMPLE_NAME_2)); }
@Test public void testParseFactors() { ExperimentDesign experimentDesign = subject.parse(EXPERIMENT_ACCESSION); assertThat(experimentDesign.getFactorValue(ASSAY_ACCESSION_1, GENOTYPE), is(CYC_C_MUTANT)); assertThat(experimentDesign.getFactorValue(ASSAY_ACCESSION_1, DUMMY), is(nullValue())); assertThat(experimentDesign.getFactorValue(DUMMY, GENOTYPE), is(nullValue())); }
@Test public void testParseSamples() { ExperimentDesign experimentDesign = subject.parse(EXPERIMENT_ACCESSION); assertThat( experimentDesign.getSampleCharacteristicValue(ASSAY_ACCESSION_1, SAMPLE_NAME_1), is(RD_INSTAR_LARVA)); assertThat( experimentDesign.getSampleCharacteristicValue(ASSAY_ACCESSION_2, SAMPLE_NAME_1), is(RD_INSTAR_LARVA)); assertThat(experimentDesign.getSampleCharacteristicValue(ASSAY_ACCESSION_1, SAMPLE_NAME_2), is("")); assertThat(experimentDesign.getSampleCharacteristicValue(ASSAY_ACCESSION_2, SAMPLE_NAME_2), is(OREGON_R)); assertThat(experimentDesign.getSampleCharacteristicValue(ASSAY_ACCESSION_1, DUMMY), is(nullValue())); assertThat(experimentDesign.getSampleCharacteristicValue(DUMMY, SAMPLE_NAME_1), is(nullValue())); }
@Test public void testAssays() { ExperimentDesign experimentDesign = subject.parse(EXPERIMENT_ACCESSION); assertThat(experimentDesign.getArrayDesign(ASSAY_ACCESSION_1), is(A_AFFY_35)); assertThat(experimentDesign.getArrayDesign(ASSAY_ACCESSION_2), is(A_AFFY_35)); }
@Test public void testAssayHeaders() { ExperimentDesign experimentDesign = subject.parse(EXPERIMENT_ACCESSION); assertThat(experimentDesign.getAssayHeaders(), IsIterableContainingInOrder.contains(ASSAY, ARRAY)); }
@Test public void testGetAllRunOrAssay() { ExperimentDesign experimentDesign = subject.parse(EXPERIMENT_ACCESSION); assertThat( experimentDesign.getAllRunOrAssay(), IsIterableContainingInOrder.contains(ASSAY_ACCESSION_1, ASSAY_ACCESSION_2)); }
@Test public void testGetSpeciesForAssays() { ExperimentDesign experimentDesign = subject.parse(EXPERIMENT_ACCESSION); String species = experimentDesign.getSpeciesForAssays(Sets.newHashSet(ASSAY_ACCESSION_1, ASSAY_ACCESSION_2)); assertThat(species, is(SPECIES_1)); }