# 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):


import pybedtools
from pergola import mapping
from pergola import intervals

################################
# Meal modelling 120 s
# mergeBed -i ${track} -d 120 -S + -c 4,5,6,9 -o distinct,sum,distinct,collapse -delim ";" > ${filename}_joined.bed
# mergeBed -i tr_1_dt_food_sc.bed -d 120 -c 5 -o sum  > tr_merge.bed

# bed short for testing
b_short = pybedtools.BedTool(bedTools_tr2 [1:5])

# si lo voy a leer tambien con pergola quiza no me haria falta que tuviera todos los campos
# lo podria leer solo con los intervalos y los valores 
# Algo asi
# b_values_test = b_short.merge(d=100, stream=True, c=(5), o=("sum"))

# collapse (i.e., print a delimited list (duplicates allowed))
# distinct the same no duplicates allowed
# c_values_test = c_short.merge(d=100, stream=True, c=(4,5), o=("distinct", "sum"))
b_values_test = b_short.merge(d=100, stream=True, c=(4,5,6,9), o=("distinct","sum","distinct","collapse"))

type (b_values_test)
for i in b_values_test: print(i)

## Merge implemented for example in paper
# Tips in https://pythonhosted.org/pybedtools/3-brief-examples.html
# result = g.filter(featuretype_filter, featuretype).saveas()
b_short = pybedtools.BedTool(bedTools_tr2 [1:5])
merged_bed_fn = b_short.merge(d=120, stream=True, c=(4,5,6,9), o=("distinct","sum","distinct","collapse")).saveas().fn

print (merged_bed_fn)


# 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: test/pybedtools_pergola.py
import pybedtools
from pergola import mapping
from pergola import intervals


################################
# Meal modelling 120 s
# mergeBed -i ${track} -d 120 -S + -c 4,5,6,9 -o distinct,sum,distinct,collapse -delim ";" > ${filename}_joined.bed
# mergeBed -i tr_1_dt_food_sc.bed -d 120 -c 5 -o sum  > tr_merge.bed

# bed short for testing
b_short = pybedtools.BedTool(bedTools_tr2 [1:5])

# si lo voy a leer tambien con pergola quiza no me haria falta que tuviera todos los campos
# lo podria leer solo con los intervalos y los valores 
# Algo asi
# b_values_test = b_short.merge(d=100, stream=True, c=(5), o=("sum"))

# collapse (i.e., print a delimited list (duplicates allowed))
# distinct the same no duplicates allowed
# c_values_test = c_short.merge(d=100, stream=True, c=(4,5), o=("distinct", "sum"))
b_values_test = b_short.merge(d=100, stream=True, c=(4,5,6,9), o=("distinct","sum","distinct","collapse"))

type (b_values_test)
for i in b_values_test: print(i)

## Merge implemented for example in paper
# Tips in https://pythonhosted.org/pybedtools/3-brief-examples.html
# result = g.filter(featuretype_filter, featuretype).saveas()
b_short = pybedtools.BedTool(bedTools_tr2 [1:5])
merged_bed_fn = b_short.merge(d=120, stream=True, c=(4,5,6,9), o=("distinct","sum","distinct","collapse")).saveas().fn

print (merged_bed_fn)


mapping_bed = mapping.MappingInfo("/Users/jespinosa/git/pergola/test/pybed2perg.txt")