# Path: scgv/qtviews/base.py
# class BaseDialog(QDialog):
# 
#     def __init__(self, *args, **kwargs):
#         super(BaseDialog, self).__init__(*args, **kwargs)
#         # self.setWindowFlags(
#         #     self.windowFlags() |
#         #     Qt.CustomizeWindowHint |
#         #     Qt.WindowMaximizeButtonHint |
#         #     Qt.WindowType_Mask)
#         self.signals = CloseSignals()
#         print(self.sizeHint())
#         # self.resize(self.sizeHint())
# 
#     def closeEvent(self, event):
#         print("closing window...")
#         self.signals.closing.emit()
# 
# Path: scgv/views/sample.py
# class SamplesViewer(ViewerBase):
# 
#     def __init__(self, model):
#         super(SamplesViewer, self).__init__(model)
# 
#     def calc_chrom_lines(self):
#         return self.model.calc_chrom_lines()
# 
#     def calc_ploidy(self, sample_name):
#         return self.model.data\
#             .seg_df[sample_name]\
#             .iloc[:self.model.chrom_x_index]\
#             .mean()
# 
#     def upto_chrom_x(self, data):
#         assert len(data) == len(self.model.data.seg_df)
#         return data[0:self.model.chrom_x_index]
# 
#     def calc_error(self, sample_name):
#         if self.model.data.ratio_df is None:
#             return np.NaN
#         df_r = self.upto_chrom_x(self.model.data.ratio_df[sample_name].values)
#         df_s = self.upto_chrom_x(self.model.data.seg_df[sample_name].values)
#         return np.sqrt(np.sum(((df_r - df_s) / df_s)**2))
# 
#     def calc_shredded(self, sample_name):
#         upto_x_data = \
#             self.model.data \
#             .seg_df[sample_name].values[0:self.model.chrom_x_index]
#         shredded = np.sum(upto_x_data < 0.4) / float(self.model.chrom_x_index)
#         return shredded
# 
#     def draw_samples(self, fig, sample_list):
#         self.chrom_lines = self.calc_chrom_lines()
# 
#         ax_common = None
#         for num, sample_name in enumerate(sample_list):
#             if num == 0:
#                 ax = fig.add_subplot(len(sample_list), 1, num + 1)
#                 ax_common = ax
#             else:
#                 ax = fig.add_subplot(
#                     len(sample_list), 1, num + 1,
#                     sharex=ax_common,
#                     sharey=ax_common)
# 
#             for chrom_line in self.chrom_lines:
#                 ax.axvline(x=chrom_line, color="#000000", linewidth=1)
#             for hl in [1, 2, 3, 4, 5, 6]:
#                 ax.axhline(y=hl, color="#000000", linewidth=1, linestyle="--")
# 
#             if self.model.data.ratio_df is not None:
#                 ax.plot(
#                     self.model.data.ratio_df['abspos'],
#                     self.model.data.ratio_df[sample_name],
#                     color="#bbbbbb", alpha=0.8)
#             ax.plot(
#                 self.model.data.seg_df['abspos'],
#                 self.model.data.seg_df[sample_name],
#                 color='b', alpha=0.8)
#             ax.set_yscale('log')
# 
#             ax.set_xlim((0, self.model.data.seg_df['abspos'].values[-1]))
#             ax.set_ylim((0.05, 20))
# 
#             ploidy = self.calc_ploidy(sample_name)
#             error = self.calc_error(sample_name)
#             shredded = self.calc_shredded(sample_name)
# 
#             ax.set_title(
#                 "{} Ploidy={:.2f} Error={:.2f} Shredded={:.2f}".format(
#                     sample_name, ploidy, error, shredded))
# 
#             ax.set_xticks([])
#             ax.set_xticklabels([])
# 
#             chrom_labels_pos = self.calc_chrom_labels_pos(self.chrom_lines)
#             ax.set_xticks(chrom_labels_pos)
#             ax.set_xticklabels(self.CHROM_LABELS, rotation='vertical')
#         fig.tight_layout()


import webbrowser
import numpy as np
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QApplication
from PyQt5.QtWidgets import QAction, QMenu
from PyQt5.QtCore import Qt
from matplotlib.backends.backend_qt5agg import FigureCanvas, \
    NavigationToolbar2QT as NavigationToolbar
from matplotlib.figure import Figure
from scgv.qtviews.base import BaseDialog
from scgv.views.sample import SamplesViewer
            .format(genome, position)
        print('opening url: ', url)
        webbrowser.open(url, new=False, autoraise=True)

    def on_open_genome_browser_region_start(self):
        genome = self.model.data.genome
        assert genome is not None

        if self.browse_position is None:
            print("UCSC Genome Broser position not found....")
            return

        chrom, pos = self.browse_position
        self.browse_position_region = True
        self.browse_position_start = self.browse_position
        self.browse_position = None
        QApplication.setOverrideCursor(Qt.SplitHCursor)

    def ucsc_chrom(self, chrom):
        genome = self.model.data.genome
        assert genome is not None

        if 'hg' in genome:
            if chrom == 23:
                chrom = 'X'
            if chrom == 24:
                chrom = 'Y'
        if 'mm' in genome:
            if chrom == 20:
                chrom = 'X'

# Path: scgv/qtviews/base.py
# class BaseDialog(QDialog):
# 
#     def __init__(self, *args, **kwargs):
#         super(BaseDialog, self).__init__(*args, **kwargs)
#         # self.setWindowFlags(
#         #     self.windowFlags() |
#         #     Qt.CustomizeWindowHint |
#         #     Qt.WindowMaximizeButtonHint |
#         #     Qt.WindowType_Mask)
#         self.signals = CloseSignals()
#         print(self.sizeHint())
#         # self.resize(self.sizeHint())
# 
#     def closeEvent(self, event):
#         print("closing window...")
#         self.signals.closing.emit()
# 
# Path: scgv/views/sample.py
# class SamplesViewer(ViewerBase):
# 
#     def __init__(self, model):
#         super(SamplesViewer, self).__init__(model)
# 
#     def calc_chrom_lines(self):
#         return self.model.calc_chrom_lines()
# 
#     def calc_ploidy(self, sample_name):
#         return self.model.data\
#             .seg_df[sample_name]\
#             .iloc[:self.model.chrom_x_index]\
#             .mean()
# 
#     def upto_chrom_x(self, data):
#         assert len(data) == len(self.model.data.seg_df)
#         return data[0:self.model.chrom_x_index]
# 
#     def calc_error(self, sample_name):
#         if self.model.data.ratio_df is None:
#             return np.NaN
#         df_r = self.upto_chrom_x(self.model.data.ratio_df[sample_name].values)
#         df_s = self.upto_chrom_x(self.model.data.seg_df[sample_name].values)
#         return np.sqrt(np.sum(((df_r - df_s) / df_s)**2))
# 
#     def calc_shredded(self, sample_name):
#         upto_x_data = \
#             self.model.data \
#             .seg_df[sample_name].values[0:self.model.chrom_x_index]
#         shredded = np.sum(upto_x_data < 0.4) / float(self.model.chrom_x_index)
#         return shredded
# 
#     def draw_samples(self, fig, sample_list):
#         self.chrom_lines = self.calc_chrom_lines()
# 
#         ax_common = None
#         for num, sample_name in enumerate(sample_list):
#             if num == 0:
#                 ax = fig.add_subplot(len(sample_list), 1, num + 1)
#                 ax_common = ax
#             else:
#                 ax = fig.add_subplot(
#                     len(sample_list), 1, num + 1,
#                     sharex=ax_common,
#                     sharey=ax_common)
# 
#             for chrom_line in self.chrom_lines:
#                 ax.axvline(x=chrom_line, color="#000000", linewidth=1)
#             for hl in [1, 2, 3, 4, 5, 6]:
#                 ax.axhline(y=hl, color="#000000", linewidth=1, linestyle="--")
# 
#             if self.model.data.ratio_df is not None:
#                 ax.plot(
#                     self.model.data.ratio_df['abspos'],
#                     self.model.data.ratio_df[sample_name],
#                     color="#bbbbbb", alpha=0.8)
#             ax.plot(
#                 self.model.data.seg_df['abspos'],
#                 self.model.data.seg_df[sample_name],
#                 color='b', alpha=0.8)
#             ax.set_yscale('log')
# 
#             ax.set_xlim((0, self.model.data.seg_df['abspos'].values[-1]))
#             ax.set_ylim((0.05, 20))
# 
#             ploidy = self.calc_ploidy(sample_name)
#             error = self.calc_error(sample_name)
#             shredded = self.calc_shredded(sample_name)
# 
#             ax.set_title(
#                 "{} Ploidy={:.2f} Error={:.2f} Shredded={:.2f}".format(
#                     sample_name, ploidy, error, shredded))
# 
#             ax.set_xticks([])
#             ax.set_xticklabels([])
# 
#             chrom_labels_pos = self.calc_chrom_labels_pos(self.chrom_lines)
#             ax.set_xticks(chrom_labels_pos)
#             ax.set_xticklabels(self.CHROM_LABELS, rotation='vertical')
#         fig.tight_layout()


# Path: scgv/qtviews/profiles_window.py
import webbrowser
import numpy as np
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QApplication
from PyQt5.QtWidgets import QAction, QMenu
from PyQt5.QtCore import Qt
from matplotlib.backends.backend_qt5agg import FigureCanvas, \
    NavigationToolbar2QT as NavigationToolbar
from matplotlib.figure import Figure
from scgv.qtviews.base import BaseDialog
from scgv.views.sample import SamplesViewer

            .format(genome, position)
        print('opening url: ', url)
        webbrowser.open(url, new=False, autoraise=True)

    def on_open_genome_browser_region_start(self):
        genome = self.model.data.genome
        assert genome is not None

        if self.browse_position is None:
            print("UCSC Genome Broser position not found....")
            return

        chrom, pos = self.browse_position
        self.browse_position_region = True
        self.browse_position_start = self.browse_position
        self.browse_position = None
        QApplication.setOverrideCursor(Qt.SplitHCursor)

    def ucsc_chrom(self, chrom):
        genome = self.model.data.genome
        assert genome is not None

        if 'hg' in genome:
            if chrom == 23:
                chrom = 'X'
            if chrom == 24:
                chrom = 'Y'
        if 'mm' in genome:
            if chrom == 20:
                chrom = 'X'

            if chrom == 21: