Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
Merge branch 'master' into network
Browse files Browse the repository at this point in the history
  • Loading branch information
msbentsen committed Aug 7, 2019
2 parents e7199f4 + cb62a73 commit e63f9da
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.6.4 (2019-08-07)
- Bug fix for error with regions very close to chromosome borders for ATACorrect and ScoreBigwig.

## 0.6.3 (2019-07-16)
- Increased size of texts in BINDetect volcano plot and moved label into plot

Expand Down
2 changes: 1 addition & 1 deletion tobias/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.6.3"
__version__ = "0.6.4"
7 changes: 5 additions & 2 deletions tobias/footprinting/atacorrect.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,13 @@ def run_atacorrect(args):
output_regions = RegionList().from_bed(args.regions_out)
else:
output_regions = deepcopy(peak_regions)

output_regions.apply_method(OneRegion.extend_reg, args.extend)

#Extend regions to make sure extend + flanking for window/flank are within boundaries
flank_extend = args.k_flank + int(args.window/2.0)
output_regions.apply_method(OneRegion.extend_reg, args.extend + flank_extend)
output_regions.merge()
output_regions.apply_method(OneRegion.check_boundary, bam_chrom_info, "cut")
output_regions.apply_method(OneRegion.extend_reg, -flank_extend) #Cut to needed size knowing that the region will be extended in function

#Remove blacklisted regions and chromosomes not in common
blacklist_regions = RegionList().from_bed(args.blacklist) if args.blacklist != None else RegionList([]) #fill in with regions from args.blacklist
Expand Down
2 changes: 1 addition & 1 deletion tobias/footprinting/atacorrect_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def bias_correction(regions_list, params, bias_obj):
for region_obj in regions_list:

region_obj.extend_reg(f_extend)
region_obj.check_boundary(chrom_lengths, "cut")
#region_obj.check_boundary(chrom_lengths, "cut") #moved to outside of function
reg_len = region_obj.get_length() #length including flanking
reg_key = (region_obj.chrom, region_obj.start+f_extend, region_obj.end-f_extend) #output region
out_signals[reg_key] = {"uncorrected":{}, "bias":{}, "expected":{}, "corrected":{}}
Expand Down
13 changes: 9 additions & 4 deletions tobias/footprinting/scorebigwig.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ def add_scorebigwig_arguments(parser):
#------------------------------------------------------------------#
def calculate_scores(regions, args):

logger = TobiasLogger("", args.verbosity, args.log_q)

pybw_signal = pyBigWig.open(args.signal) #cutsites signal
pybw_header = pybw_signal.chroms()
chrom_lengths = {chrom:int(pybw_header[chrom]) for chrom in pybw_header}
Expand All @@ -84,6 +86,8 @@ def calculate_scores(regions, args):
#Go through each region
for i, region in enumerate(regions):

logger.debug("Calculating scores for region: {0}".format(region))

#Extend region with necessary flank
region.extend_reg(flank)
reg_key = (region.chrom, region.start+flank, region.end-flank) #output region
Expand Down Expand Up @@ -168,14 +172,16 @@ def run_scorebigwig(args):
pybw_signal = pyBigWig.open(args.signal)
pybw_header = pybw_signal.chroms()
chrom_info = {chrom:int(pybw_header[chrom]) for chrom in pybw_header}
logger.debug("Chromosome lengths from input bigwig: {0}".format(chrom_info))

#Decide regions
logger.info("- Getting output regions ready")
if args.regions:
regions = RegionList().from_bed(args.regions)
regions.apply_method(OneRegion.extend_reg, args.extend)
regions.merge()
regions.apply_method(OneRegion.check_boundary, chrom_info)
regions.apply_method(OneRegion.check_boundary, chrom_info, "cut")

else:
regions = RegionList().from_list([OneRegion([chrom, 0, chrom_info[chrom]]) for chrom in chrom_info])

Expand All @@ -190,9 +196,8 @@ def run_scorebigwig(args):
#Go through each region
for i, region in enumerate(regions):
region.extend_reg(args.region_flank)
region.check_boundary(chrom_info, "cut")
region.start = region.start + args.region_flank
region.end = region.end - args.region_flank
region = region.check_boundary(chrom_info, "cut")
region.extend_reg(-args.region_flank)

#Information for output bigwig
reference_chroms = sorted(list(chrom_info.keys()))
Expand Down
3 changes: 3 additions & 0 deletions tobias/utils/regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ def check_boundary(self, boundaries_dict, action="cut"):
else:
exit("Error in regions.check_boundary: unknown action")

self[1] = self.start
self[2] = self.end

return(self)

def get_signal(self, pybw, numpy_bool = True):
Expand Down
1 change: 1 addition & 0 deletions tobias/utils/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def bigwig_writer(q, key_file_dict, header, regions, args):
if i_to_write[akey] != no_regions - 1:
logger.error("Wrote {0} regions but there are {1} in total".format(i_to_write[akey], len(region_tups)))
logger.error("Ready_to_write[{0}]: {1}".format(akey, len(ready_to_write[akey])))
sys.exit()
break

#Save key:region:signal to ready_to_write
Expand Down

0 comments on commit e63f9da

Please sign in to comment.