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


from argparse import ArgumentParser
from os import path, getcwd
from csv import writer
from os.path import expanduser
from pergola import mapping
from pergola import intervals
from sys import stderr, exit
import pybedtools

# # mapping_bed = mapping.MappingInfo(base_dir + "/test/" + "bed2pergola.txt")
mapping_bed = mapping.MappingInfo(args.bed_mapping)
## mapping_bed = mapping.MappingInfo("/Users/jespinosa/git/pergola/test/c_elegans_data_test/bed2pergola.txt")

# speed bed file
## read file from input args
# bed_speed_file = dir_development + "midbody.575_JU440_on_food_L_2011_02_17__16_43___3___11_features_speed.csv.bed"
# bed_speed_file ='/Users/jespinosa/git/pergola/test/c_elegans_data_test/results_GB/midbody.575_JU440_on_food_L_2011_02_17__11_00___3___1_features.mat.GB.bed'
## bed_speed_file = '/Users/jespinosa/git/pergola/test/c_elegans_data_test/work/be/c8a7942756ee7053d0f9856e1caa88/bed_speed_no_tr'

## error to debug nextflow Paolo
# bed_speed_file = dir_development + args.speed

bed_speed_file = args.speed

int_data_speed = intervals.IntData(bed_speed_file, map_dict=mapping_bed.correspondence, header=False, 
                                   fields_names=['chrm', 'start', 'end', 'nature', 'value', 'strain', 'color'])

speed_data_read = int_data_speed.read(relative_coord=False)
# speed_data_read.data

###################
# Generate to BedTool objects containing motion type (forward, backward, paused)

# motion_bed_file = dir_development +  "575_JU440_on_food_L_2011_02_17__11_00___3___1_features_forward.csv.bed"
# motion_bed_file = '/Users/jespinosa/git/pergola/test/c_elegans_data_test/work/be/c8a7942756ee7053d0f9856e1caa88/bed_speed_no_tr/motion_file'
## motion_bed_file = '/Users/jespinosa/git/pergola/test/c_elegans_data_test/work/8a/b26a0fbfb292bb573e582ef842b646/tr_1_dt_a.bed'
# motion_bed_file = dir_development + args.motion
motion_bed_file = args.motion

# 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: examples/celegans_db_speed_motion/bin/celegans_speed_i_motion.py
from argparse import ArgumentParser
from os import path, getcwd
from csv import writer
from os.path import expanduser
from pergola import mapping
from pergola import intervals
from sys import stderr, exit
import pybedtools


# # mapping_bed = mapping.MappingInfo(base_dir + "/test/" + "bed2pergola.txt")
mapping_bed = mapping.MappingInfo(args.bed_mapping)
## mapping_bed = mapping.MappingInfo("/Users/jespinosa/git/pergola/test/c_elegans_data_test/bed2pergola.txt")

# speed bed file
## read file from input args
# bed_speed_file = dir_development + "midbody.575_JU440_on_food_L_2011_02_17__16_43___3___11_features_speed.csv.bed"
# bed_speed_file ='/Users/jespinosa/git/pergola/test/c_elegans_data_test/results_GB/midbody.575_JU440_on_food_L_2011_02_17__11_00___3___1_features.mat.GB.bed'
## bed_speed_file = '/Users/jespinosa/git/pergola/test/c_elegans_data_test/work/be/c8a7942756ee7053d0f9856e1caa88/bed_speed_no_tr'

## error to debug nextflow Paolo
# bed_speed_file = dir_development + args.speed

bed_speed_file = args.speed

int_data_speed = intervals.IntData(bed_speed_file, map_dict=mapping_bed.correspondence, header=False, 
                                   fields_names=['chrm', 'start', 'end', 'nature', 'value', 'strain', 'color'])

speed_data_read = int_data_speed.read(relative_coord=False)
# speed_data_read.data

###################
# Generate to BedTool objects containing motion type (forward, backward, paused)

# motion_bed_file = dir_development +  "575_JU440_on_food_L_2011_02_17__11_00___3___1_features_forward.csv.bed"
# motion_bed_file = '/Users/jespinosa/git/pergola/test/c_elegans_data_test/work/be/c8a7942756ee7053d0f9856e1caa88/bed_speed_no_tr/motion_file'
## motion_bed_file = '/Users/jespinosa/git/pergola/test/c_elegans_data_test/work/8a/b26a0fbfb292bb573e582ef842b646/tr_1_dt_a.bed'
# motion_bed_file = dir_development + args.motion
motion_bed_file = args.motion

int_data_motion = intervals.IntData(motion_bed_file, map_dict=mapping_bed.correspondence, header=False, 