Skip to content

Commit

Permalink
Validate BED files
Browse files Browse the repository at this point in the history
  • Loading branch information
kcha committed Aug 8, 2018
1 parent 34885e8 commit 4b0fea8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
22 changes: 21 additions & 1 deletion qapa/annotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# complete poly(A) site coordinates from PolyAsite database and GENCODE poly(A)
# site track

#from __future__ import print_function
from __future__ import print_function
import sys
import os
import pybedtools
Expand Down Expand Up @@ -104,6 +104,23 @@ def sort_bed(bedobj):
return pybedtools.BedTool(tmpbed)


def validate(bedobj, filename):
"""
Validate the input BED file using solution from
https://github.com/daler/pybedtools/issues/252
"""
try:
ft = bedobj.file_type
if ft == 'empty':
print("[annotate] BED file %s is empty!" % filename,
file=sys.stderr)
sys.exit(1)
except IndexError:
print("[annotate] Error reading the BED file %s." % filename +
" Is the file properly formatted?", file=sys.stderr)
sys.exit(1)


def main(args, input_filename, fout=sys.stdout):

# Load intervals
Expand All @@ -115,16 +132,19 @@ def main(args, input_filename, fout=sys.stdout):
if args.other:
custom_mode = True
custom = pybedtools.BedTool(args.other)
validate(custom, args.other)
sites = sort_bed(custom)
elif not args.no_annotation:
pas_filter = re.compile("(DS|TE)$")
gencode = pybedtools.BedTool(args.gencode_polya)\
.filter(lambda x: x.name == 'polyA_site')\
.saveas()
validate(gencode, args.gencode_polya)
polyasite = pybedtools.BedTool(args.polyasite)\
.cut(range(0, 6))\
.filter(lambda x: int(x.score) >= args.min_polyasite)\
.saveas()
validate(polyasite, args.polyasite)
polyasite = sort_bed(polyasite)

polyasite_te = polyasite\
Expand Down
3 changes: 2 additions & 1 deletion qapa/collapse.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ def _guess_species(self, species=None):
return 'mm10'
elif species is not None:
return species
warnings.warn('Could not guess species from gene name!', Warning)
warnings.warn('Could not guess species from gene name!' +
' To disable this warning, use --species option', Warning)
return 'unk'


Expand Down
3 changes: 3 additions & 0 deletions qapa/qapa.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ def build(args):
delete=False)
tf3 = tempfile.NamedTemporaryFile(mode='w', prefix='qapa_extend_',
delete=False)

try:
# 1) get last exon from table
eprint("Extracting 3' UTRs from table")
Expand Down Expand Up @@ -281,7 +282,9 @@ def quant(args):

def main():
args = getoptions()
eprint("Version %s" % __version__)
args.func(args)
eprint("Finished!")


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion qapa/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.2.0'
__version__ = '1.2.1'

0 comments on commit 4b0fea8

Please sign in to comment.