# Path: pergola/mapping.py
# class MappingInfo():
#     def __init__(self, path, **kwargs):
#     def _correspondence_from_config(self, path):
#     def _tab_config(self, file_tab):
#     def _mapping_config(self, file_map):
#     def write(self, indent=0):
# def check_path(path):
# def write_chr(self, mode="w", path_w=None, min_c=None, max_c=None):
# def write_chr_sizes(self, mode="w", path_w=None, file_n=None, min_c=None, max_c=None):
# def write_cytoband(end, start=0, delta=43200, start_phase="light", mode="w", path_w=None, lab_bed=True, track_line=True):
# def write_period_seq (end, start=0, delta=43200, tag="day", mode="w", path_w=None, name_file="period_seq", lab_bed=True, track_line=True):
# 
# Path: pergola/intervals.py
# class IntData(object):
#     def __init__(self, path, map_dict, header=True, **kwargs):
#     def _check_delimiter (self, path, delimiter):
#     def _reader_data(self):
#     def _pandas_df_reader(self, df):
#     def _set_fields_b(self, fields=None):
#     def _set_fields_g (self, map_dict):
#     def _simple_read(self):
#     def get_field_items(self, data, field="data_types", default=None):
#     def read(self, fields=None, relative_coord=False, intervals=False, int_step=None, fields2rel=None, multiply_t=None,
#              **kwargs):
#     def _min_max(self, list_data, f_start="start", f_end="end"):
#     def _time2rel_time(self, i_fields):
#     def _multiply_values(self, i_fields, factor=1):
#     def _create_int(self, start_int, int_step=None):
#     def _create_int_add_integ(self, start_int, integer=1):
#     def __del__(self):
# def is_number(var):
# def num(s):
# 
# Path: pergola/tracks.py
# class GenomicContainer(object):
# class Track(GenomicContainer):
# class BedToolConvertible(GenomicContainer):
# class Bed(BedToolConvertible):
# class BedGraph(BedToolConvertible):
# class Gff(BedToolConvertible):
#     def __init__(self, data, fields=None, data_types=None, **kwargs):
#     def __iter__(self):
#     def next(self):
#     def save_track(self, mode="w", path=None, name_file=None, track_line=True, bed_label=False, gff_label=False):
#     def __init__(self, data, fields=None, data_types=None, list_tracks=None, min=0, max=0, **kwargs):
#     def convert(self, mode='bed', range_color=None, **kwargs):
#     def _convert2single_track(self, data_tuples,  mode=None, **kwargs):
#     def _get_range(self, data_tr):
#     def remove(self, dict_t, tracks2remove):
#     def join_by_track(self, dict_t, tracks2join):  
#     def join_by_dataType (self, dict_d, mode):
#     def track_convert2bed(self, track, in_call=False, **kwargs):
#     def track_convert2gff(self, track, in_call=False, **kwargs):
#     def track_convert2bedGraph(self, track, in_call=False, window=300, mean_win=False, mean_value=False,  **kwargs):
#     def __init__(self, data, **kwargs):
#     def create_pybedtools(self):
#     def _tmp_track(self):
#     def __init__(self, data, **kwargs):
#     def __init__(self, data, **kwargs):
#     def win_mean (self):
#     def _win_mean (self, data, n_tracks):     
#     def __init__(self, data, **kwargs):
# def assign_color(set_data_types, color_restrictions=None):
# def merge_tracks (tr_1, tr_2):


from argparse import ArgumentParser
from os import path, getcwd, makedirs, chdir
from sys import stderr
from pergola import mapping
from pergola import intervals
from pergola import tracks
import subprocess
import pybedtools
int_data_b1 = intervals.IntData ("../../sample_data/feeding_beh_CB1_mice/intake_CB1_B1.csv", map_dict=mapping_data.correspondence)
int_data_b2 = intervals.IntData ("../../sample_data/feeding_beh_CB1_mice/intake_CB1_B2.csv", map_dict=mapping_data.correspondence)
int_data_b3 = intervals.IntData ("../../sample_data/feeding_beh_CB1_mice/intake_CB1_B3.csv", map_dict=mapping_data.correspondence)
int_data_b4 = intervals.IntData ("../../sample_data/feeding_beh_CB1_mice/intake_CB1_B4.csv", map_dict=mapping_data.correspondence)

mapping_bed = mapping.MappingInfo("../../test/pybed2perg.txt")

# base_dir = path.dirname(getcwd())
base_dir = getcwd()
 
# out_dir = base_dir + "/results/" + statistic + "/"
out_dir = base_dir + "/results/" + args.behavioral_type + "/" +  statistic + "/"
 
if path.exists(out_dir):    
    rmtree(out_dir)
 
makedirs(out_dir)
chdir(out_dir)

data_read_b1 = int_data_b1.read(relative_coord=True)
data_read_b2 = int_data_b2.read(relative_coord=True)
data_read_b3 = int_data_b3.read(relative_coord=True)
data_read_b4 = int_data_b4.read(relative_coord=True)
 
# Check the longest period of time of any batches    
end_time = max (int_data_b1.max - int_data_b1.min, 
                int_data_b2.max - int_data_b2.min, 
                int_data_b3.max - int_data_b3.min, 
                int_data_b4.max - int_data_b4.min) 
 

# Path: pergola/mapping.py
# class MappingInfo():
#     def __init__(self, path, **kwargs):
#     def _correspondence_from_config(self, path):
#     def _tab_config(self, file_tab):
#     def _mapping_config(self, file_map):
#     def write(self, indent=0):
# def check_path(path):
# def write_chr(self, mode="w", path_w=None, min_c=None, max_c=None):
# def write_chr_sizes(self, mode="w", path_w=None, file_n=None, min_c=None, max_c=None):
# def write_cytoband(end, start=0, delta=43200, start_phase="light", mode="w", path_w=None, lab_bed=True, track_line=True):
# def write_period_seq (end, start=0, delta=43200, tag="day", mode="w", path_w=None, name_file="period_seq", lab_bed=True, track_line=True):
# 
# Path: pergola/intervals.py
# class IntData(object):
#     def __init__(self, path, map_dict, header=True, **kwargs):
#     def _check_delimiter (self, path, delimiter):
#     def _reader_data(self):
#     def _pandas_df_reader(self, df):
#     def _set_fields_b(self, fields=None):
#     def _set_fields_g (self, map_dict):
#     def _simple_read(self):
#     def get_field_items(self, data, field="data_types", default=None):
#     def read(self, fields=None, relative_coord=False, intervals=False, int_step=None, fields2rel=None, multiply_t=None,
#              **kwargs):
#     def _min_max(self, list_data, f_start="start", f_end="end"):
#     def _time2rel_time(self, i_fields):
#     def _multiply_values(self, i_fields, factor=1):
#     def _create_int(self, start_int, int_step=None):
#     def _create_int_add_integ(self, start_int, integer=1):
#     def __del__(self):
# def is_number(var):
# def num(s):
# 
# Path: pergola/tracks.py
# class GenomicContainer(object):
# class Track(GenomicContainer):
# class BedToolConvertible(GenomicContainer):
# class Bed(BedToolConvertible):
# class BedGraph(BedToolConvertible):
# class Gff(BedToolConvertible):
#     def __init__(self, data, fields=None, data_types=None, **kwargs):
#     def __iter__(self):
#     def next(self):
#     def save_track(self, mode="w", path=None, name_file=None, track_line=True, bed_label=False, gff_label=False):
#     def __init__(self, data, fields=None, data_types=None, list_tracks=None, min=0, max=0, **kwargs):
#     def convert(self, mode='bed', range_color=None, **kwargs):
#     def _convert2single_track(self, data_tuples,  mode=None, **kwargs):
#     def _get_range(self, data_tr):
#     def remove(self, dict_t, tracks2remove):
#     def join_by_track(self, dict_t, tracks2join):  
#     def join_by_dataType (self, dict_d, mode):
#     def track_convert2bed(self, track, in_call=False, **kwargs):
#     def track_convert2gff(self, track, in_call=False, **kwargs):
#     def track_convert2bedGraph(self, track, in_call=False, window=300, mean_win=False, mean_value=False,  **kwargs):
#     def __init__(self, data, **kwargs):
#     def create_pybedtools(self):
#     def _tmp_track(self):
#     def __init__(self, data, **kwargs):
#     def __init__(self, data, **kwargs):
#     def win_mean (self):
#     def _win_mean (self, data, n_tracks):     
#     def __init__(self, data, **kwargs):
# def assign_color(set_data_types, color_restrictions=None):
# def merge_tracks (tr_1, tr_2):


# Path: examples/CB1_mice/pybedtools_nicotine.py
from argparse import ArgumentParser
from os import path, getcwd, makedirs, chdir
from sys import stderr
from pergola import mapping
from pergola import intervals
from pergola import tracks
import subprocess
import pybedtools

int_data_b1 = intervals.IntData ("../../sample_data/feeding_beh_CB1_mice/intake_CB1_B1.csv", map_dict=mapping_data.correspondence)
int_data_b2 = intervals.IntData ("../../sample_data/feeding_beh_CB1_mice/intake_CB1_B2.csv", map_dict=mapping_data.correspondence)
int_data_b3 = intervals.IntData ("../../sample_data/feeding_beh_CB1_mice/intake_CB1_B3.csv", map_dict=mapping_data.correspondence)
int_data_b4 = intervals.IntData ("../../sample_data/feeding_beh_CB1_mice/intake_CB1_B4.csv", map_dict=mapping_data.correspondence)

mapping_bed = mapping.MappingInfo("../../test/pybed2perg.txt")

# base_dir = path.dirname(getcwd())
base_dir = getcwd()
 
# out_dir = base_dir + "/results/" + statistic + "/"
out_dir = base_dir + "/results/" + args.behavioral_type + "/" +  statistic + "/"
 
if path.exists(out_dir):    
    rmtree(out_dir)
 
makedirs(out_dir)
chdir(out_dir)

data_read_b1 = int_data_b1.read(relative_coord=True)
data_read_b2 = int_data_b2.read(relative_coord=True)
data_read_b3 = int_data_b3.read(relative_coord=True)
data_read_b4 = int_data_b4.read(relative_coord=True)
 
# Check the longest period of time of any batches    
end_time = max (int_data_b1.max - int_data_b1.min, 
                int_data_b2.max - int_data_b2.min, 
                int_data_b3.max - int_data_b3.min, 
                int_data_b4.max - int_data_b4.min) 
 

data_read_all_batches = tracks.merge_tracks (tracks.merge_tracks (tracks.merge_tracks (data_read_b1, data_read_b2), data_read_b3), data_read_b4)