@Test public void testBedAndBigBed() throws Exception { String bedPath = TestUtils.DATA_DIR + "bed/Unigene.sample.nolong.bed"; String bigBedPath = TestUtils.DATA_DIR + "bed/Unigene.sample.nolong.bigbed"; File bigBedFile = new File(bigBedPath); // Need to index so query of bed file is accurate TestUtils.createIndex(bedPath); List<Track> bedtracks = tstLoadFi(bedPath, 1, false); List<Track> bigBedtracks = tstLoadFi(bigBedPath, 1, false); String chr = "chr2"; int start = 178711404 - 1; int end = 179189619 + 1; FeatureTrack bedTrack = (FeatureTrack) bedtracks.get(0); FeatureTrack bigBedTrack = (FeatureTrack) bigBedtracks.get(0); // Multiple trials because we're concerned about file open/close issues int trials = 10; for (int ii = 0; ii < trials; ii++) { int strt = start + ii; List<Feature> bedFeatures = bedTrack.getFeatures(chr, strt, end); List<Feature> bigBedFeatures = bigBedTrack.getFeatures(chr, strt, end); TestUtils.assertFeatureListsEqual(bedFeatures.iterator(), bigBedFeatures.iterator()); // NOT FOOLPROOF assertTrue(bigBedFile.canWrite()); } }
@Test public void shouldSaveChildForm() { ArrayList<Map<String, String>> childFormValues = new ArrayList<>(); HashMap<String, String> childFormValue = new HashMap<>(); childFormValue.put("caseId", "94d5374f-290e-409f-bc57-86c2e4bcc43f"); childFormValue.put("xmlns", "http://bihar.commcarehq.org/pregnancy/registration"); childFormValue.put("childName", "suraj"); childFormValue.put("birthStatus", "healthy"); childFormValue.put("instanceId", "ff2eb090-03a9-4f23-afed-cf6012784c55"); childFormValue.put("flw", "89fda0284e008d2e0c980fb13fa0e5bb"); childFormValue.put("timeStart", "2013-03-03T10:31:51.045+05:30"); childFormValue.put("timeEnd", "2013-03-03T10:38:52.804+05:30"); childFormValue.put("dateModified", "2013-03-03T10:38:52.804+05:30"); childFormValues.add(childFormValue); careService.processAndSaveForms(null, childFormValues); List<RegistrationChildForm> registrationChildForms = template.loadAll(RegistrationChildForm.class); assertEquals(1, registrationChildForms.size()); RegistrationChildForm expectedForm = getExpectedForm("94d5374f-290e-409f-bc57-86c2e4bcc43f"); assertReflectionEqualsWithIgnore( expectedForm, registrationChildForms.get(0), new String[] {"id", "flw", "childCase", "creationTime", "lastModifiedTime"}); List<Flw> flws = template.loadAll(Flw.class); assertEquals(1, flws.size()); assertEquals("89fda0284e008d2e0c980fb13fa0e5bb", flws.get(0).getFlwId()); }
@Test public void testWigAndBigWig() throws Exception { String wigPath = TestUtils.DATA_DIR + "wig/test_fixedStep.wig"; String bigWigPath = TestUtils.DATA_DIR + "wig/test_fixedStep.bigwig"; List<Track> wigtracks = tstLoadFi(wigPath, 1, false); List<Track> bigWigtracks = tstLoadFi(bigWigPath, 1, false); String chr = "chr19"; int start = 5930725; int end = 5930764; int zoom = 21; DataSourceTrack wigTrack = (DataSourceTrack) wigtracks.get(0); DataSourceTrack bigWigTrack = (DataSourceTrack) bigWigtracks.get(0); int trials = 10; for (int ii = 0; ii < trials; ii++) { int strt = start + ii; List<LocusScore> wigScores = wigTrack.getSummaryScores(chr, strt, end, zoom); List<LocusScore> bigWigScores = bigWigTrack.getSummaryScores(chr, strt, end, zoom); assertEquals(wigScores.size(), bigWigScores.size()); int ind = 0; for (LocusScore ws : wigScores) { LocusScore bws = bigWigScores.get(ind); assertEquals(ws.getScore(), bws.getScore()); ind++; } } }
@Test public void shouldDeleteEarlierFormIfBothNewerAndOlderMotherFormWithSameInstanceIdHasNullDate() { NewForm persistedForm = new NewForm(); persistedForm.setInstanceId("e34707f8-80c8-4198-bf99-c11c90ba5c98"); persistedForm.setCaste("OldCaste"); persistedForm.setServerDateModified(null); template.save(persistedForm); final String newCaste = "NewCaste"; Map<String, String> motherFormValues = new HashMap<String, String>() { { put("caseId", "94d5374f-290e-409f-bc57-86c2e4bcc43f"); put("serverDateModified", null); put("userId", "89fda0284e008d2e0c980fb13fa0e5bb"); put("xmlns", "http://bihar.commcarehq.org/pregnancy/new"); put("instanceId", "e34707f8-80c8-4198-bf99-c11c90ba5c98"); put("caste", newCaste); } }; careService.processAndSaveForms(motherFormValues, new ArrayList<Map<String, String>>()); List<NewForm> newFormsFromDb = template.loadAll(NewForm.class); assertEquals(1, newFormsFromDb.size()); assertNull(newFormsFromDb.get(0).getDateModified()); assertEquals(newCaste, newFormsFromDb.get(0).getCaste()); }
static List<Track> tstLoadFi( TrackLoader trackLoader, String filepath, Integer expected_tracks, Genome genome, boolean makeIndex) throws Exception { ResourceLocator locator = new ResourceLocator(filepath); // Try creating an index // UI would ask for confirmation if (makeIndex) { try { TestUtils.createIndex(filepath); } catch (Exception e) { } } List<Track> tracks = trackLoader.load(locator, genome); if (expected_tracks != null) { assertEquals(expected_tracks.intValue(), tracks.size()); if (expected_tracks == 0) { return tracks; } } Track track = tracks.get(0); assertEquals(locator, track.getResourceLocator()); return tracks; }
@Test public void shouldNotDeleteEarlierFormIfNewerMotherFormWithSameInstanceIdHasOldDate() { NewForm persistedForm = new NewForm(); persistedForm.setInstanceId("e34707f8-80c8-4198-bf99-c11c90ba5c98"); final Date oldFormModifiedDate = DateTime.parse("2012-07-20T12:02:59.923+05:30").toDate(); persistedForm.setServerDateModified(oldFormModifiedDate); persistedForm.setDateModified(oldFormModifiedDate); template.save(persistedForm); final String newFormModifiedOn = "2012-07-10T12:02:59.923+05:30"; Map<String, String> motherFormValues = new HashMap<String, String>() { { put("caseId", "94d5374f-290e-409f-bc57-86c2e4bcc43f"); put("dateModified", newFormModifiedOn); put("serverDateModified", newFormModifiedOn); put("userId", "89fda0284e008d2e0c980fb13fa0e5bb"); put("xmlns", "http://bihar.commcarehq.org/pregnancy/new"); put("instanceId", "e34707f8-80c8-4198-bf99-c11c90ba5c98"); } }; careService.processAndSaveForms(motherFormValues, new ArrayList<Map<String, String>>()); List<NewForm> newFormsFromDb = template.loadAll(NewForm.class); assertEquals(1, newFormsFromDb.size()); assertEquals(oldFormModifiedDate, newFormsFromDb.get(0).getDateModified()); }
@Test public void shouldUpdateEntityByExternalPrimaryKeyWhenExists() { String caseId = "94d5374f-290e-409f-bc57-86c2e4bcc43f"; ChildCase existingChild = new ChildCase(); existingChild.setCaseId(caseId); existingChild.setName("old Child name"); template.save(existingChild); HashMap<String, String> updatedValues = new HashMap<String, String>() { { put("caseId", "94d5374f-290e-409f-bc57-86c2e4bcc43f"); put("name", "new child name"); } }; careService.saveByExternalPrimaryKey(ChildCase.class, updatedValues); List<ChildCase> childCases = template.loadAll(ChildCase.class); Assert.assertEquals(1, childCases.size()); ChildCase expectedChildCase = new ChildCase(); expectedChildCase.setCaseId(caseId); expectedChildCase.setName("new child name"); assertReflectionEqualsWithIgnore( expectedChildCase, childCases.get(0), new String[] {"id", "creationTime", "lastModifiedTime"}); }
/** * Test that we properly load a vcf file, even though the extension is upper-case. IGV-2012 * * @throws Exception */ @Test public void testLoadVCFUpperCase() throws Exception { String filepath = TestUtils.DATA_DIR + "vcf/HC_MOD_CAPS.VCF"; ResourceLocator locator = new ResourceLocator(filepath); TestUtils.createIndex(filepath); List<Track> tracks = trackLoader.load(locator, genome); assertEquals(1, tracks.size()); assertTrue("VCF file loaded incorrect track type", tracks.get(0) instanceof VariantTrack); }
@Test public void testLoadGFF() throws Exception { String filepath = TestUtils.DATA_DIR + "gff/simfeatures.gff3"; List<Track> tracks = trackLoader.load(new ResourceLocator(filepath), genome); assertEquals(1, tracks.size()); FeatureTrack track = (FeatureTrack) tracks.get(0); assertEquals("notmeaningful", track.getName()); List<Feature> features = track.getFeatures("chr1", 0, Integer.MAX_VALUE); assertEquals(2, features.size()); IGVFeature feat0 = (IGVFeature) features.get(0); IGVFeature feat1 = (IGVFeature) features.get(1); assertEquals(707 - 1, feat0.getStart()); assertEquals(943, feat0.getEnd()); assertEquals(7563 - 1, feat1.getStart()); assertEquals(7938, feat1.getEnd()); }
@Test public void shouldSaveFlwOnceForMotherAndChild() { final String flwId = "89fda0284e008d2e0c980fb13fa0e5bb"; Flw flw = new FlwBuilder().flwId(flwId).build(); final String instanceId = "e34707f8-80c8-4198-bf99-c11c90ba5c98"; HashMap<String, String> motherCase = new HashMap<String, String>() { { put("caseId", "3e8998ce-b19f-4fa7-b1a1-721b6951e3cf"); put("userId", flwId); put("flw", flwId); put("instanceId", instanceId); put("xmlns", "http://bihar.commcarehq.org/pregnancy/registration"); } }; final HashMap<String, String> child1 = new HashMap<String, String>() { { put("caseId", "3e8998ce-b19f-4fa7-b1a1-721b6951e3c1"); put("userId", flwId); put("flw", flwId); put("instanceId", instanceId); put("xmlns", "http://bihar.commcarehq.org/pregnancy/registration"); } }; final HashMap<String, String> child2 = new HashMap<String, String>() { { put("caseId", "3e8998ce-b19f-4fa7-b1a1-721b6951e3c2"); put("userId", flwId); put("flw", flwId); put("instanceId", instanceId); put("xmlns", "http://bihar.commcarehq.org/pregnancy/registration"); } }; careService.processAndSaveForms( motherCase, new ArrayList<Map<String, String>>() { { add(child1); add(child2); } }); List<Flw> actualFlws = template.loadAll(Flw.class); assertEquals(1, actualFlws.size()); assertReflectionEqualsWithIgnore( flw, actualFlws.get(0), new String[] {"id", "creationTime", "lastModifiedTime"}); }
@Test public void shouldSaveMotherFormAndCreateNewCase() { Map<String, String> motherForm = motherFormValues( "94d5374f-290e-409f-bc57-86c2e4bcc43f", "89fda0284e008d2e0c980fb13fa0e5bb"); careService.processAndSaveForms(motherForm, new ArrayList<Map<String, String>>()); List<MotherCase> persistedMotherCases = template.loadAll(MotherCase.class); assertEquals(1, persistedMotherCases.size()); List<NewForm> newForms = template.loadAll(NewForm.class); assertEquals(1, newForms.size()); NewForm expectedForm = expectedForm( new MotherCaseBuilder().caseId("94d5374f-290e-409f-bc57-86c2e4bcc43f").build(), new FlwBuilder().flwId("89fda0284e008d2e0c980fb13fa0e5bb").build()); assertReflectionEqualsWithIgnore( expectedForm, newForms.get(0), new String[] {"id", "creationTime", "flw", "motherCase"}); assertEquals( "94d5374f-290e-409f-bc57-86c2e4bcc43f", newForms.get(0).getMotherCase().getCaseId()); assertEquals("89fda0284e008d2e0c980fb13fa0e5bb", newForms.get(0).getFlw().getFlwId()); }
@Test public void shouldSaveChildFormByDeletingOlderFormIfFormWithSameInstanceIdAndCaseIdExistsAlready() { final String instanceId = "e34707f8-80c8-4198-bf99-c11c90ba5c98"; final String caseId = "3e8998ce-b19f-4fa7-b1a1-721b6951e3cf"; final Date oldFormModifiedDate = DateTime.parse("2012-07-10T12:02:59.923+05:30").toDate(); ChildCase persistedChildCase = new ChildCase(); persistedChildCase.setCaseId(caseId); final DeathChildForm persistedForm = new DeathChildForm(); persistedForm.setInstanceId(instanceId); persistedForm.setChildCase(persistedChildCase); persistedForm.setDateModified(oldFormModifiedDate); persistedForm.setServerDateModified(oldFormModifiedDate); template.save(persistedForm); final String newFormModifiedOn = "2012-07-20T12:02:59.923+05:30"; final Date newFormModifiedDate = DateTime.parse(newFormModifiedOn).toDate(); final HashMap<String, String> deathChildFormValues = new HashMap<String, String>() { { put("caseId", caseId); put("dateModified", newFormModifiedOn); put("serverDateModified", newFormModifiedOn); put("userId", "89fda0284e008d2e0c980fb13fa0e5bb"); put("close", "true"); put("instanceId", instanceId); put("xmlns", "http://bihar.commcarehq.org/pregnancy/death"); } }; careService.processAndSaveForms( null, new ArrayList<Map<String, String>>() { { add(deathChildFormValues); } }); List<DeathChildForm> deathChildForms = template.loadAll(DeathChildForm.class); assertEquals(1, deathChildForms.size()); assertEquals(newFormModifiedDate, deathChildForms.get(0).getDateModified()); }
@Test public void shouldInsertAnEntityByExternalPrimaryKeyWhenDoesNotExists() throws Exception { HashMap<String, String> flwValues = new HashMap<String, String>() { { put("flwId", "5ba9a0928dde95d187544babf6c0ad24"); put("firstName", "FirstName1"); } }; careService.saveByExternalPrimaryKey(Flw.class, flwValues); List<Flw> flws = template.loadAll(Flw.class); Flw expectedFlw = flw("5ba9a0928dde95d187544babf6c0ad24", "FirstName1", null); assertEquals(1, flws.size()); assertReflectionEqualsWithIgnore( expectedFlw, flws.get(0), new String[] {"id", "flwGroups", "creationTime", "lastModifiedTime"}); }
@Test public void shouldSaveMotherFormForExistingCase() { MotherCase motherCase = new MotherCase(); motherCase.setCaseId("94d5374f-290e-409f-bc57-86c2e4bcc43f"); template.save(motherCase); Flw flw = new Flw(); flw.setFlwId("89fda0284e008d2e0c980fb13fa0e5bb"); template.save(flw); Map<String, String> motherForm = motherFormValues(motherCase.getCaseId(), flw.getFlwId()); careService.processAndSaveForms(motherForm, new ArrayList<Map<String, String>>()); List<MotherCase> persistedMotherCases = template.loadAll(MotherCase.class); assertEquals(1, persistedMotherCases.size()); List<NewForm> newForms = template.loadAll(NewForm.class); assertEquals(1, newForms.size()); NewForm expectedForm = expectedForm(motherCase, flw); assertReflectionEqualsWithIgnore( expectedForm, newForms.get(0), new String[] {"id", "creationTime", "lastModifiedTime"}); }
@Test public void testLoadGFFAliasedChrs() throws Exception { String filepath = TestUtils.DATA_DIR + "gff/aliased.unsorted.gff"; Genome genome = IgvTools.loadGenome(TestUtils.DATA_DIR + "genomes/hg18_truncated_aliased.genome"); List<Track> tracks = trackLoader.load(new ResourceLocator(filepath), genome); assertEquals(1, tracks.size()); FeatureTrack track = (FeatureTrack) tracks.get(0); assertEquals("aliased.unsorted.gff", track.getName()); List<Feature> features = track.getFeatures("chr1", 0, Integer.MAX_VALUE); assertEquals(56, features.size()); features = track.getFeatures("chr5", 0, Integer.MAX_VALUE); assertEquals(16, features.size()); // Non-aliased features = track.getFeatures("NC_007072.3", 0, Integer.MAX_VALUE); assertEquals(30, features.size()); }
public void call(Call call) throws AssertionFailedError { if (pendingCalls.isEmpty() || !pendingCalls.get(0).equals(call)) fail(stateMessage(new StringBuilder("Unexpected call: ").append(call))); receivedCalls.add(pendingCalls.remove(0)); }