예제 #1
0
bed_dict ['KO_cb1_saline'][data_type_1] = data_read_all_batches.convert(mode="bed", data_types=[data_type_1],
                                                               color_restrictions=data_type_col, tracks=list_KO_cb1_sal)
bed_dict ['KO_cb1_saline'][data_type_2] = data_read_all_batches.convert(mode="bed", data_types=[data_type_2],
                                                               color_restrictions=data_type_col, tracks=list_KO_cb1_sal)
bed_dict ['KO_cb1_nicotine'][data_type_1] =  data_read_all_batches.convert(mode="bed", data_types=[data_type_1],
                                                                 color_restrictions=data_type_col, tracks=list_KO_cb1_nic)                                
bed_dict ['KO_cb1_nicotine'][data_type_2] =  data_read_all_batches.convert(mode="bed", data_types=[data_type_2],
                                                                 color_restrictions=data_type_col, tracks=list_KO_cb1_nic) 
 
####################
## Generate to BedTool objects containing light and dark phases
 
## Write phases file
# mapping.write_cytoband(int_data, end = int_data.max - int_data.min, delta=43200, start_phase="light")
mapping.write_cytoband(end = end_time, delta=43200, start_phase="light", path_w=out_dir)
 
light_ph_f = out_dir +  "phases_light.bed"
dark_ph_f = out_dir + "phases_dark.bed"
   
light_bed = pybedtools.BedTool(light_ph_f)
dark_bed = pybedtools.BedTool(dark_ph_f)

## Reading experimental phases from csv file
mapping_data_phases = mapping.MappingInfo("../../../data/f2g.txt")

int_exp_phases = intervals.IntData ("../../../data/exp_phases.csv", map_dict=mapping_data_phases.correspondence)
data_read_exp_phases = int_exp_phases.read(relative_coord=True)

d_exp_phases_bed2file = data_read_exp_phases.convert(mode="bed", data_types_actions="all")
d_exp_phases_bed2file[d_exp_phases_bed2file.keys()[0]].save_track(bed_label="True", path=base_dir + results_dir, name_file="exp_phases")
예제 #2
0
bed_dict['hf']['food'] = data_read_all_batches.convert(
    mode="bed",
    data_types=data_type_joined,
    data_types_actions="all",
    color_restrictions=data_type_col,
    tracks=list_hf)

# Generating sequence of days without light and dark phases #del
mapping.write_period_seq(end=end_time,
                         delta=86400,
                         tag="day",
                         name_file="days_seq")
# mapping.write_cytoband(start=0, end=end_time, start_phase="dark", track_line=False, lab_bed=False)
mapping.write_cytoband(start=26953,
                       end=end_time,
                       start_phase="light",
                       track_line=False,
                       lab_bed=False)
days_bed_f = "days_seq.bed"
days_bed = pybedtools.BedTool(days_bed_f)

## weeks
mapping.write_period_seq(end=end_time,
                         delta=604800,
                         tag="week",
                         name_file="weeks_seq",
                         lab_bed=True,
                         track_line=True)
weeks_bed_f = "weeks_seq.bed"

## Reading experimental phases from csv file
예제 #3
0
def pergola_rules(path, map_file_path, sel_tracks=None, list=None, range=None, track_actions=None, 
                  data_types_actions=None, data_types_list=None, write_format=None, relative_coord=False,
                  intervals_gen=False, multiply_f=None, no_header=False, fields2read=None, window_size=None,
                  no_track_line=False, separator=None, bed_lab_sw=False, color_dict=None, window_mean=False,
                  value_mean=False, min_t=None, max_t=None, interval_step=None):
    
    print >> stderr, "@@@Pergola_rules.py: Input file: %s" % path 
    print >> stderr, "@@@Pergola_rules.py: Configuration file: %s" % map_file_path
    
    # Tracks selected by user
    print >> stderr, "@@@Pergola_rules.py: Selected tracks are: ", sel_tracks
    
    # Configuration file
    map_file_dict = mapping.MappingInfo(map_file_path)
    
    # Reading color dictionary to set data_types
    if color_dict:
        print >> stderr, "@@@Pergola_rules.py: Color for data_types in file............ %s" % color_dict
        d_colors_data_types = parsers.read_colors (color_dict)
    else:
        d_colors_data_types = None    
        
    # Handling list or range of tracks to join if set
    if list and range:
        raise ValueError("@@@Pergola_rules.py: Argument -l/--list and -r/--range are not compatible. " \
                         "As both arguments set tracks to be joined.")    
    elif (list):
        tracks2merge = list
    elif (range):
        tracks2merge = range
    else:
        tracks2merge = ""
    
    if tracks2merge: print >> stderr, "@@@Pergola_rules.py: Tracks to join are............ ", tracks2merge
    
    # Handling argument track actions
    if tracks2merge and track_actions:
        raise ValueError ("Options --list -l or --range -r are incompatible with " \
                          "--track_actions -a, please change your options")
    
    track_act = track_actions
    print >> stderr, "@@@Pergola_rules.py: Track actions are.............................. ", track_act
    
    data_types_list = data_types_list
    print >> stderr, "@@@Pergola_rules.py: data_types list is: ", data_types_list
      
    # Handling argument data_types actions
    data_types_act = data_types_actions
    print >> stderr, "@@@Pergola_rules.py: data_types actions are......................... ", data_types_act
    
    # Handling argument format    
    if write_format:
        print >> stderr, "@@@Pergola_rules.py format to write files....................... ", write_format
    else:
        write_format = 'bed'
        print >>stderr, "@@@Pergola_rules.py format to write files has been set" \
                        " to default value:", write_format

    # Handling relative coordinates
    print >> stderr, "@@@Pergola_rules.py: Relative coordinates set to................. %s" % relative_coord
    
    # Handling intervals_gen
    print >> stderr, "@@@Pergola_rules.py: Intervals parameter set to.................. %s" % intervals_gen

    # Handling interval_step
    if interval_step:
        if intervals_gen:
            print >> stderr, "@@@Pergola_rules.py: Interval step set to........................ %s" % interval_step
        else:
            raise ValueError("Interval step needs intervals paramater to be set -n/--intervals_gen")

    # Handling multiply_intervals
    if multiply_f:
        print >>stderr, "@@@Pergola_rules.py: Multiply intervals parameter set to...... %s" % multiply_f                        
    else:
        multiply_f = 1
    
    print >> stderr, "@@@Pergola_rules.py: Selected tracks are......................... ", sel_tracks
    
    # Setting whether input file has header or not
    header_sw = True
    
    if no_header:
        header_sw = False
        print >> stderr, "@@@Pergola_rules.py: Data file has header set to............. ", header_sw

    # Handling fields to read
    if fields2read:
        print >>stderr, "@@@Pergola_rules.py: Fields to read from the file are......... %s" % fields2read                        
    else:
        fields2read = None    
    
    # When binning data setting the window of time used in seconds
    # if not size provided set to False
    if window_size:
        print >>stderr, "@@@Pergola_rules.py: Window size set to....................... %d" % window_size
    else:
#         window_size = 300
        window_size = False
        print >>stderr, "@@@Pergola_rules.py: Window size set by default to............ %d" % window_size
    
    if window_mean:
        print >>stderr, "@@@Pergola_rules.py: Window mean set to....................... %d" % window_mean
    else:      
        window_mean = False

    if value_mean:
        print >> stderr, "@@@Pergola_rules.py: Value mean set to....................... %d" % value_mean
    else:
        value_mean = False

    if no_track_line:
        track_line=False
    else:
        track_line=True
        
    print >>stderr, "@@@Pergola_rules.py: track_line set to............................ %s" % track_line
    
    # Handling input file field delimiter    
    if not separator:
        separator = "\t"
        print >> stderr, "@@@Pergola_rules.py input file field separator set by default to...... \"\\t\"."
    else:        
        print >>stderr, "@@@Pergola_rules.py input file field separator set to..... \"%s\"" % separator
    
    if bed_lab_sw:
        bed_lab = True
        print >>stderr, "@@@Pergola_rules.py: bed_label set to......................... %s" % bed_lab
    else:
        bed_lab = False

    intData = intervals.IntData(path, map_dict=map_file_dict.correspondence,
                                fields_names=fields2read,
                                header=header_sw, delimiter=separator)

    start = intData.min
    end = intData.max

    if relative_coord:
        start = 0
        end = intData.max - intData.min

    print >> stderr, "@@@Pergola_rules.py: min time in file......................... %d" % start
    print >> stderr, "@@@Pergola_rules.py: max time in file......................... %d" % end

    if min_t or min_t == 0:
        min_time = min_t
        print >> stderr, "@@@Pergola_rules.py: min_time set by user to.............. %d" % min_t
    else:
        min_time = start

    if max_t:
        max_time = max_t
        print >> stderr, "@@@Pergola_rules.py: max_time set by user to............... %d" % max_t
    else:
        if interval_step:
            max_time = end + interval_step
        else:
            max_time = end + 1

    if multiply_f:
        min_time = min_time * multiply_f
        max_time = max_time * multiply_f

    if track_act: tracks2merge = parsers.read_track_actions(tracks=intData.tracks, track_action=track_act)

    data_read = intData.read(relative_coord=relative_coord,
                             intervals=intervals_gen,
                             multiply_t=multiply_f,
                             min_time=min_time, max_time=max_time,
                             int_step=interval_step)

    mapping.write_chr(data_read)#mantain
    mapping.write_chr_sizes(data_read)

    # writes cytoband and light, dark and light_dark bed files
    mapping.write_cytoband(end=end, track_line=track_line, lab_bed=False)
#     mapping.write_period_seq(start=0, end=intData.max, delta=43200, name_file="phases_dark", track_line=False) 
    
    data_read.save_track(name_file="all_intervals")

    bed_str = data_read.convert(mode=write_format, tracks=sel_tracks,
                                tracks_merge=tracks2merge, data_types=data_types_list,
                                data_types_actions=data_types_act, window=window_size,
                                mean_win=window_mean, mean_value=value_mean, color_restrictions=d_colors_data_types)
                                #min_t_trim=min_t, max_t_trim=max_t)
    
    for key in bed_str:
        bedSingle = bed_str[key]
        bedSingle.save_track(track_line=track_line, bed_label=bed_lab)
예제 #4
0
    data_types=[data_type_1],  #dataTypes_actions="all", 
    color_restrictions=data_type_col,
    tracks=list_KO_cb1)
bed_dict['KO_cb1'][data_type_2] = data_read_all_batches.convert(
    mode="bed",
    data_types=[data_type_2],  #dataTypes_actions="all", 
    color_restrictions=data_type_col,
    tracks=list_KO_cb1)

####################
## Generate to BedTool objects containing light and dark phases

## Write phases file
# mapping.write_cytoband(int_data, end = int_data.max - int_data.min, delta=43200, start_phase="light")
mapping.write_cytoband(end=end_time,
                       delta=43200,
                       start_phase="light",
                       path_w=out_dir)

light_ph_f = out_dir + "phases_light.bed"
dark_ph_f = out_dir + "phases_dark.bed"

light_bed = pybedtools.BedTool(light_ph_f)
dark_bed = pybedtools.BedTool(dark_ph_f)

for exp_group, dict_exp_gr in bed_dict.iteritems():

    for data_type, dict_bed in dict_exp_gr.iteritems():
        for tr, bed in dict_bed.iteritems():
            bed_BedTools = bed.create_pybedtools()

            ## Generates a bed file of a single interval of the size of the whole recording
예제 #5
0
mapping_data = mapping.MappingInfo(base_dir +
                                   "/sample_data/feeding_behavior/b2g.txt")

int_data = intervals.IntData(
    base_dir + "/sample_data/feeding_behavior/feedingBehavior_HF_mice.csv",
    map_dict=mapping_data.correspondence)

data_read = int_data.read(relative_coord=True)

###################
# Generate to BedTool objects containing light and dark phases

# Write phases file
mapping.write_cytoband(end=int_data.max - int_data.min,
                       delta=43200,
                       start_phase="dark")

light_ph_f = out_dir + "phases_light.bed"
dark_ph_f = out_dir + "phases_dark.bed"
light_bed = pybedtools.BedTool(light_ph_f)
dark_bed = pybedtools.BedTool(dark_ph_f)

# Generate a chr.size file in order to calculate complement of merged meals
chr_file_n = "chrom"
mapping.write_chr_sizes(data_read, path_w=out_dir, file_n=chr_file_n)
chr_file = out_dir + chr_file_n + ".sizes"

# Dictionary to set colors of each type of food
data_type_col = {'food_sc': 'orange', 'food_fat': 'blue'}
data_type_col_m = {'food_sc': 'orange', 'food_fat_food_sc': 'blue'}
예제 #6
0
from pergola import intervals

base_dir = path.dirname(getcwd())
out_dir = base_dir + "/test/"

mapping_data = mapping.MappingInfo(base_dir + "/sample_data/feeding_behavior/b2g.txt")

int_data = intervals.IntData(base_dir + "/sample_data/feeding_behavior/feedingBehavior_HF_mice.csv", map_dict=mapping_data.correspondence)

data_read = int_data.read(relative_coord=True)

###################
# Generate to BedTool objects containing light and dark phases

# Write phases file
mapping.write_cytoband(end = int_data.max - int_data.min, delta=43200, start_phase="dark")

light_ph_f = out_dir +  "phases_light.bed"
dark_ph_f = out_dir + "phases_dark.bed"
light_bed = pybedtools.BedTool(light_ph_f)
dark_bed = pybedtools.BedTool(dark_ph_f)

# Generate a chr.size file in order to calculate complement of merged meals
chr_file_n = "chrom"
mapping.write_chr_sizes (data_read, path_w=out_dir, file_n=chr_file_n)
chr_file = out_dir + chr_file_n + ".sizes"

# Dictionary to set colors of each type of food
data_type_col = {'food_sc': 'orange', 'food_fat':'blue'}
data_type_col_m = {'food_sc': 'orange', 'food_fat_food_sc':'blue'}
예제 #7
0
from pergola import intervals

base_dir = path.dirname(getcwd())
out_dir = base_dir + "/test/"

mapping_data = mapping.MappingInfo(base_dir + "/sample_data/feeding_behavior/b2g.txt")

int_data = intervals.IntData(base_dir + "/sample_data/feeding_behavior/feedingBehavior_HF_mice.csv", map_dict=mapping_data.correspondence)

data_read = int_data.read(relative_coord=True)

###################
# Generate to BedTool objects containing light and dark phases
# Write phases file
total_time = int_data.max - int_data.min
mapping.write_cytoband(end = total_time, delta=43200, start_phase="dark")
light_ph_f = out_dir +  "phases_light.bed"
dark_ph_f = out_dir + "phases_dark.bed"
all_phases = out_dir + "phases.bed"

light_bed = pybedtools.BedTool(light_ph_f)
dark_bed = pybedtools.BedTool(dark_ph_f)
all_phases_bed = pybedtools.BedTool(all_phases)

# Generate a chr.size file in order to calculate complement of merged meals
chr_file_n = "chrom"
mapping.write_chr_sizes (data_read, path_w=out_dir, file_n=chr_file_n)
chr_file = out_dir + chr_file_n + ".sizes"

# Dictionary to set colors of each type of food
data_type_col = {'food_sc': 'orange', 'food_fat':'blue'}
예제 #8
0
    mode="bed",
    data_types=[data_type_1],
    color_restrictions=data_type_col,
    tracks=list_KO_cb1_nic)
bed_dict['KO_cb1_nicotine'][data_type_2] = data_read_all_batches.convert(
    mode="bed",
    data_types=[data_type_2],
    color_restrictions=data_type_col,
    tracks=list_KO_cb1_nic)

# Generating sequence of days without light and dark phases
mapping.write_period_seq(end=end_time,
                         delta=86400,
                         tag="day",
                         name_file="days_seq")
mapping.write_cytoband(start=0, end=end_time, track_line=False, lab_bed=False)

days_bed_f = "days_seq.bed"

days_bed = pybedtools.BedTool(days_bed_f)

## Reading experimental phases from csv file
mapping_data_phases = mapping.MappingInfo(args.mapping_phases)

int_exp_phases = intervals.IntData(args.phases_exp_file,
                                   map_dict=mapping_data_phases.correspondence)

data_read_exp_phases = int_exp_phases.read(relative_coord=True)

d_exp_phases_bed2file = data_read_exp_phases.convert(mode="bed",
                                                     data_types_actions="all")