Exemplo n.º 1
0
  @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());
  }
Exemplo n.º 2
0
  @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++;
      }
    }
  }
Exemplo n.º 3
0
  @Test
  public void testLoadSIF() throws Exception {
    String filepath = TestUtils.DATA_DIR + "sample/BRCA_sif.txt";
    List<String> expectedAttributeNames =
        Arrays.asList(
            "TCGA_EXPERIMENT",
            "TCGA_BATCH",
            "TUMOR_NORMAL",
            "BIRDSEED_GENDER",
            "LEVEL2_NOISE",
            "LEVEL3_SEGMENT_COUNT",
            "PURITY	PLOIDY",
            "DELTA",
            "CANCER_DNA_FRACTION",
            "SUBCLONAL_GENOME_FRACTION");

    tstLoadFi(filepath, 0, false); // Sample information file, shouldn't have tracks.

    Set<String> attrNames = new HashSet<String>(AttributeManager.getInstance().getAttributeNames());

    assertTrue(
        attrNames.size()
            >= expectedAttributeNames.size()); // Can be larger because of default attributes
    for (String name : expectedAttributeNames) {
      assertTrue(expectedAttributeNames.contains(name));
    }
  }
Exemplo n.º 4
0
  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;
  }
Exemplo n.º 5
0
  @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());
  }
Exemplo n.º 6
0
  @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());
  }
Exemplo n.º 7
0
  @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
  public void insertMixOfWronglyFormedAndCorrectlyFormedEvents() {
    try {
      cassandraConnector.saveStreamDefinitionToStore(getCluster(), streamDefinition1);
    } catch (StreamDefinitionStoreException e) {
      e.printStackTrace();
      fail();
    }

    List<Event> eventList =
        EventConverterUtils.convertFromJson(
            CassandraTestConstants.properandImproperEvent, streamDefinition1.getStreamId());
    List<String> insertedEvents = new ArrayList<String>();
    int eventCounter = 0;
    for (Event event : eventList) {
      try {
        String rowKey = insertEvent(cluster, event, eventCounter++);
        // inserts row key only if event is valid, i.e. only proper events will add a row key
        insertedEvents.add(rowKey);
      } catch (Exception e) {
        // ignore
      }
    }
    assertEquals(2, insertedEvents.size());
  }
Exemplo n.º 9
0
  /**
   * 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);
  }
Exemplo n.º 10
0
  @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());
  }
Exemplo n.º 11
0
  @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"});
  }
Exemplo n.º 12
0
  @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"});
  }
Exemplo n.º 13
0
  @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());
  }
Exemplo n.º 14
0
  @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());
  }
Exemplo n.º 15
0
  @Test
  public void shouldCreateNewFlw() {
    Flw newFlw =
        flw(
            "5ba9a0928dde95d187544babf6c0ad24",
            "FirstName1",
            flwGroupWithNameAndId("64a9a0928dde95d187544babf6c0ad38", "oldGroupName"));

    careService.saveOrUpdateAllByExternalPrimaryKey(Flw.class, Arrays.asList(newFlw));

    List<Flw> flwsFromDb = template.loadAll(Flw.class);
    assertEquals(1, flwsFromDb.size());
    assertReflectionContains(newFlw, flwsFromDb, new String[] {"id"});
  }
Exemplo n.º 16
0
  /**
   * Test loading sample information file from a sql database, using a profile
   *
   * @throws Exception
   */
  @Test
  public void testLoadSampleInfoProfile() throws Exception {

    AttributeManager.getInstance().clearAllAttributes();
    String path = TestUtils.DATA_DIR + "sql/sampleinfo_brca_sif_profile.dbxml";

    int expectedTracks = 0;
    List<Track> tracks = trackLoader.load(new ResourceLocator(path), genome);
    assertEquals(expectedTracks, tracks.size());

    String[] attrNames =
        "TCGA_EXPERIMENT	TCGA_BATCH	TUMOR_NORMAL	BIRDSEED_GENDER	LEVEL2_NOISE	LEVEL3_SEGMENT_COUNT	PURITY	PLOIDY	DELTA	CANCER_DNA_FRACTION	SUBCLONAL_GENOME_FRACTION"
            .split("\\s+");
    Set<String> expAttrNames = new HashSet<String>(Arrays.asList(attrNames));
    List<String> actAttrNames = AttributeManager.getInstance().getAttributeNames();
    actAttrNames.remove("NAME");
    actAttrNames.remove("DATA TYPE");
    actAttrNames.remove("DATA FILE");
    assertEquals(actAttrNames.size(), expAttrNames.size());
    for (String attrName : actAttrNames) {
      assertTrue(expAttrNames.contains(attrName));
    }
  }
Exemplo n.º 17
0
  /**
   * Test loading segmented data file from a sql database, using a profile
   *
   * @throws Exception
   */
  @Test
  public void testLoadSegProfile() throws Exception {
    String path = TestUtils.DATA_DIR + "sql/seg_canFam2_profile.dbxml";

    int expectedTracks = 6;
    List<Track> tracks = trackLoader.load(new ResourceLocator(path), genome);
    assertEquals(expectedTracks, tracks.size());
    Set<String> expSampleIds =
        new HashSet<String>(
            Arrays.asList("0123-A", "0123-B-1", "0123-C-1", "0123-C-2", "0123-C-3"));
    Set<String> actSampleIds = new HashSet<String>(5);
    for (Track track : tracks) {
      if (track instanceof DataSourceTrack) {
        actSampleIds.add(track.getName());
      }
    }
    assertEquals(expSampleIds, actSampleIds);
  }
Exemplo n.º 18
0
  @Test
  public void shouldSaveNewGroup() throws Exception {
    FlwGroup newGroup =
        new FlwGroupBuilder()
            .groupId("5ba9a0928dde95d187544babf6c0ad24")
            .name("amir team 1")
            .domain("care-mp")
            .awcCode("007")
            .caseSharing(true)
            .reporting(true)
            .build();

    careService.saveOrUpdateAllByExternalPrimaryKey(FlwGroup.class, Arrays.asList(newGroup));

    List<FlwGroup> flwGroupsFromDb = template.loadAll(FlwGroup.class);
    assertEquals(1, flwGroupsFromDb.size());
    assertReflectionContains(newGroup, flwGroupsFromDb, new String[] {"id"});
  }
Exemplo n.º 19
0
  @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());
  }
Exemplo n.º 20
0
  @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 testDataConsumption() throws Exception {
   List<SampleData> ginzburg = create("ginzburg", 10, 10);
   assertEquals(ginzburg.size(), 10);
 }