# Path: scgv/models/sector_model.py
# class SectorsDataModel(BaseModel):
# 
#     def __init__(self, model):
#         super(SectorsDataModel, self).__init__(model.data)
#         self.model = model
#         assert self.model.sector is not None
#         self.tracks = self.model.tracks
#         self.selected_tracks = self.model.selected_tracks
# 
#     def make_ordering(self):
#         index = np.array(self.model.Z['leaves'])
#         order = np.arange(len(index))
# 
#         sector = self.model.sector
#         self.sector_mapping = self.model.sector_mapping
# 
#         res = np.lexsort(
#             (
#                 order,
#                 sector,
#             ))
# 
#         return index[res]
# 
# class SingleSectorDataModel(BaseModel):
# 
#     def __init__(self, model, sector_id):
#         super(SingleSectorDataModel, self).__init__(model.data)
#         if isinstance(model, DataModel):
#             self.model = model
#         else:
#             self.model = model.model
#         assert self.model.sector is not None
#         assert self.model.sector_mapping is not None
# 
#         self.sector_mapping = self.model.sector_mapping
#         self.sector_id = None
# 
#         if sector_id in self.sector_mapping:
#             self.sector_id = sector_id
#         else:
#             for key, value in self.sector_mapping.items():
#                 if sector_id == value:
#                     self.sector_id = key
# 
#         assert self.sector_id in self.sector_mapping
# 
#         self.bins, self.samples = self.model.seg_data.shape
#         self.lmat = None
#         self.selected_tracks = self.model.selected_tracks
#         self.tracks = self.model.tracks
# 
#     def make_ordering(self):
#         index = np.array(self.model.Z['leaves'])
#         order = np.arange(len(index))
# 
#         sector = self.model.sector
# 
#         res = np.lexsort(
#             (
#                 order,
#                 sector,
#             ))
# 
#         return index[res]
# 
#     def make_subtree(self):
# 
#         return get_subtree(
#             self.model.lmat[:],
#             self.model._original_column_labels(),
#             self.column_labels
#         )
# 
#     def make(self):
#         self.ordering = self.make_ordering()
#         self.sector, self.sector_mapping = \
#             self.make_sector(ordering=self.ordering)
# 
#         sector_val = self.sector_mapping[self.sector_id]
#         sector_index = self.sector == sector_val
# 
#         self.column_labels = self.make_column_labels(ordering=self.ordering)
#         self.column_labels = self.column_labels[sector_index]
# 
#         self.lmat = self.make_subtree()
#         self.Z = self.make_dendrogram(self.lmat)
# 
#         self.samples = len(self.column_labels)
#         self.interval_length = self.make_interval_length(self.Z)
#         self.label_midpoints = self.make_label_midpoints()
# 
#         self.bins = self.model.bins
# 
#         self.clone, self.subclone = self.make_clone(
#             ordering=self.ordering)
#         if self.clone is not None:
#             self.clone = self.clone[sector_index]
#             self.subclone = self.subclone[sector_index]
# 
#         self.heatmap = self.make_heatmap(
#             ordering=self.ordering)
#         self.heatmap = self.heatmap[:, sector_index]
# 
#         if self.sector is not None:
#             self.sector = self.sector[sector_index]
# 
#         self.multiplier = self.model.make_multiplier(
#             ordering=self.ordering)
#         if self.multiplier is not None:
#             self.multiplier = self.multiplier[sector_index]
# 
#         self.error = self.model.make_error(
#             ordering=self.ordering)
#         if self.error is not None:
#             self.error = self.error[sector_index]
# 
#         self.update_selected_tracks(sector_index)
# 
# Path: scgv/models/model.py
# class DataModel(BaseModel):
# 
#     def __init__(self, filename):
#         self.data = DataLoader(filename)
#         self.data.load()
#         self.data.filter_cells()
#         self.data.order_cells()
# 
#         super(DataModel, self).__init__(self.data)


import numpy as np
from scgv.models.sector_model import SectorsDataModel, SingleSectorDataModel
from scgv.models.model import DataModel
    assert np.all(elements[res] == np.array([1, 0, 3, 2]))


def test_single_sector_subtree_experiments(example_data):
    model = DataModel(example_data)
    assert model is not None
    model.make()
    print(model.sector_mapping)

    single_sector_model = SingleSectorDataModel(model, 1)
    single_sector_model.make()

    lmat = np.array(single_sector_model.lmat)
    print(lmat[:, 0])
    print(lmat[:, 1])


def test_single_sector_subtree_twice(example_data):
    model = DataModel(example_data)
    assert model is not None
    model.make()
    print(model.sector_mapping)

    single_sector_model = SingleSectorDataModel(model, 1)
    single_sector_model.make()

    lmat = np.array(single_sector_model.lmat)
    print(lmat[:, 0])
    print(lmat[:, 1])


# Path: scgv/models/sector_model.py
# class SectorsDataModel(BaseModel):
# 
#     def __init__(self, model):
#         super(SectorsDataModel, self).__init__(model.data)
#         self.model = model
#         assert self.model.sector is not None
#         self.tracks = self.model.tracks
#         self.selected_tracks = self.model.selected_tracks
# 
#     def make_ordering(self):
#         index = np.array(self.model.Z['leaves'])
#         order = np.arange(len(index))
# 
#         sector = self.model.sector
#         self.sector_mapping = self.model.sector_mapping
# 
#         res = np.lexsort(
#             (
#                 order,
#                 sector,
#             ))
# 
#         return index[res]
# 
# class SingleSectorDataModel(BaseModel):
# 
#     def __init__(self, model, sector_id):
#         super(SingleSectorDataModel, self).__init__(model.data)
#         if isinstance(model, DataModel):
#             self.model = model
#         else:
#             self.model = model.model
#         assert self.model.sector is not None
#         assert self.model.sector_mapping is not None
# 
#         self.sector_mapping = self.model.sector_mapping
#         self.sector_id = None
# 
#         if sector_id in self.sector_mapping:
#             self.sector_id = sector_id
#         else:
#             for key, value in self.sector_mapping.items():
#                 if sector_id == value:
#                     self.sector_id = key
# 
#         assert self.sector_id in self.sector_mapping
# 
#         self.bins, self.samples = self.model.seg_data.shape
#         self.lmat = None
#         self.selected_tracks = self.model.selected_tracks
#         self.tracks = self.model.tracks
# 
#     def make_ordering(self):
#         index = np.array(self.model.Z['leaves'])
#         order = np.arange(len(index))
# 
#         sector = self.model.sector
# 
#         res = np.lexsort(
#             (
#                 order,
#                 sector,
#             ))
# 
#         return index[res]
# 
#     def make_subtree(self):
# 
#         return get_subtree(
#             self.model.lmat[:],
#             self.model._original_column_labels(),
#             self.column_labels
#         )
# 
#     def make(self):
#         self.ordering = self.make_ordering()
#         self.sector, self.sector_mapping = \
#             self.make_sector(ordering=self.ordering)
# 
#         sector_val = self.sector_mapping[self.sector_id]
#         sector_index = self.sector == sector_val
# 
#         self.column_labels = self.make_column_labels(ordering=self.ordering)
#         self.column_labels = self.column_labels[sector_index]
# 
#         self.lmat = self.make_subtree()
#         self.Z = self.make_dendrogram(self.lmat)
# 
#         self.samples = len(self.column_labels)
#         self.interval_length = self.make_interval_length(self.Z)
#         self.label_midpoints = self.make_label_midpoints()
# 
#         self.bins = self.model.bins
# 
#         self.clone, self.subclone = self.make_clone(
#             ordering=self.ordering)
#         if self.clone is not None:
#             self.clone = self.clone[sector_index]
#             self.subclone = self.subclone[sector_index]
# 
#         self.heatmap = self.make_heatmap(
#             ordering=self.ordering)
#         self.heatmap = self.heatmap[:, sector_index]
# 
#         if self.sector is not None:
#             self.sector = self.sector[sector_index]
# 
#         self.multiplier = self.model.make_multiplier(
#             ordering=self.ordering)
#         if self.multiplier is not None:
#             self.multiplier = self.multiplier[sector_index]
# 
#         self.error = self.model.make_error(
#             ordering=self.ordering)
#         if self.error is not None:
#             self.error = self.error[sector_index]
# 
#         self.update_selected_tracks(sector_index)
# 
# Path: scgv/models/model.py
# class DataModel(BaseModel):
# 
#     def __init__(self, filename):
#         self.data = DataLoader(filename)
#         self.data.load()
#         self.data.filter_cells()
#         self.data.order_cells()
# 
#         super(DataModel, self).__init__(self.data)


# Path: scgv/tests/test_sector_model.py
import numpy as np
from scgv.models.sector_model import SectorsDataModel, SingleSectorDataModel
from scgv.models.model import DataModel

    assert np.all(elements[res] == np.array([1, 0, 3, 2]))


def test_single_sector_subtree_experiments(example_data):
    model = DataModel(example_data)
    assert model is not None
    model.make()
    print(model.sector_mapping)

    single_sector_model = SingleSectorDataModel(model, 1)
    single_sector_model.make()

    lmat = np.array(single_sector_model.lmat)
    print(lmat[:, 0])
    print(lmat[:, 1])


def test_single_sector_subtree_twice(example_data):
    model = DataModel(example_data)
    assert model is not None
    model.make()
    print(model.sector_mapping)

    single_sector_model = SingleSectorDataModel(model, 1)
    single_sector_model.make()

    lmat = np.array(single_sector_model.lmat)
    print(lmat[:, 0])
    print(lmat[:, 1])


    single_sector_model = SingleSectorDataModel(model, 1)