Exemple #1
0
    def test_add_track(self):
        new_track_name, new_track_file = self.new_track

        # Open new track
        genome = Genome(self.gdfilepath, mode="r+")
        with genome:
            self.assertEqual(genome.num_tracks_continuous, 0)
            genome.add_track_continuous(new_track_name)

        # Load data for new track
        load_data(self.gdfilepath, new_track_name,
                  test_filename(new_track_file), verbose=self.verbose)

        # Close data with new track
        close_data(self.gdfilepath, verbose=self.verbose)

        # Make sure addition was successful
        genome = Genome(self.gdfilepath)
        with genome:
            # Track ordering should now end with dnase
            self.assertEqual(genome.tracknames_continuous, [new_track_name])

            # Given track ordering, check single track data retrieval
            self.assertArraysEqual(genome["chr1"][305:310, new_track_name],
                                   [-2.65300012, 0.37200001, 0.37200001,
                                     0.37200001, 0.37099999])
Exemple #2
0
    def test_replace_track(self):
        # Test ability to delete and replace a track

        old_trackname = "primate"
        old_entry = (290, -2.327)
        new_trackname = "placental"
        new_entry = (290, -2.297)

        # Test value before deleting track
        with Genome(self.gdfilepath) as genome:
            chromosome = genome["chr1"]
            self.assertArraysEqual(chromosome[old_entry[0], old_trackname],
                                   old_entry[1])

        # Remove track
        erase_data(self.gdfilepath, old_trackname,
                      verbose=self.verbose)

        # Now replace it with the data from a different track
        track_index = self.tracknames.index(new_trackname)
        datafile = self.trackfiles[track_index]
        load_data(self.gdfilepath, new_trackname, datafile,
                  verbose=self.verbose)

        # Re-close data
        close_data(self.gdfilepath, verbose=self.verbose)

        # Now test that the data matches the new track data
        with Genome(self.gdfilepath) as genome:
            chromosome = genome["chr1"]
            self.assertArraysEqual(chromosome[new_entry[0], new_trackname],
                                   new_entry[1])
Exemple #3
0
    def test_replace_track(self):
        # Test ability to delete and replace a track

        old_trackname = "primate"
        old_entry = (290, -2.327)
        new_trackname = "placental"
        new_entry = (290, -2.297)

        # Test value before deleting track
        with warnings.catch_warnings():
            warnings.simplefilter("ignore", GenomedataDirtyWarning)
            with Genome(self.gdfilepath) as genome:
                chromosome = genome["chr1"]
                self.assertArraysEqual(chromosome[old_entry[0], old_trackname],
                                       old_entry[1])

            # Remove track
            erase_data(self.gdfilepath, old_trackname, verbose=self.verbose)

        # Now replace it with the data from a different track
        track_index = self.tracknames.index(new_trackname)
        datafile = self.trackfiles[track_index]
        load_data(self.gdfilepath,
                  new_trackname,
                  datafile,
                  verbose=self.verbose)

        # Re-close data
        close_data(self.gdfilepath, verbose=self.verbose)

        # Now test that the data matches the new track data
        with Genome(self.gdfilepath) as genome:
            chromosome = genome["chr1"]
            self.assertArraysEqual(chromosome[new_entry[0], new_trackname],
                                   new_entry[1])
Exemple #4
0
    def test_add_track(self):
        new_track_name, new_track_file = self.new_track

        # Open new track
        genome = Genome(self.gdfilepath, mode="r+")
        with warnings.catch_warnings():
            warnings.simplefilter("ignore", GenomedataDirtyWarning)
            with genome:
                self.assertEqual(genome.num_tracks_continuous, 0)
                genome.add_track_continuous(new_track_name)

        # Load data for new track
        load_data(self.gdfilepath,
                  new_track_name,
                  test_filename(new_track_file),
                  verbose=self.verbose)

        # Close data with new track
        close_data(self.gdfilepath, verbose=self.verbose)

        # Make sure addition was successful
        genome = Genome(self.gdfilepath)
        with genome:
            # Track ordering should now end with dnase
            self.assertEqual(genome.tracknames_continuous, [new_track_name])

            # Given track ordering, check single track data retrieval
            self.assertArraysEqual(
                genome["chr1"][305:310, new_track_name],
                [-2.65300012, 0.37200001, 0.37200001, 0.37200001, 0.37099999])
Exemple #5
0
    def test_filter_track(self):
        # Add filter track
        open_data(self.gdfilepath, [UNFILTERED_TRACKNAME],
                  verbose=self.verbose)
        load_data(self.gdfilepath,
                  UNFILTERED_TRACKNAME,
                  test_filename(UNFILTERED_TRACK_FILENAME),
                  verbose=self.verbose)
        close_data(self.gdfilepath, verbose=self.verbose)

        # Perform filtering on data
        hardmask_data(self.gdfilepath,
                      test_filename(self.filter), [UNFILTERED_TRACKNAME],
                      lambda x: x < self.filter_threshold,
                      verbose=self.verbose)

        # Make sure filtering was successful
        genome = Genome(self.gdfilepath)
        with genome:
            self.assertArraysEqual(genome["chr1"][0:4, UNFILTERED_TRACKNAME],
                                   [nan, nan, nan, nan])
            self.assertArraysEqual(
                genome["chr1"][128:132, UNFILTERED_TRACKNAME],
                [nan, nan, 0.5, 0.5])
            self.assertArraysEqual(
                genome["chr1"][168:172, UNFILTERED_TRACKNAME],
                [0.9, 0.9, nan, nan])
            self.assertArraysEqual(
                genome["chr1"][206:210, UNFILTERED_TRACKNAME],
                [nan, nan, nan, nan])