Module Expr Str Import alias Import alias TryExcept body Import alias handlers ExceptHandler type NameLoad body Pass Import alias identifier Import alias identifier Import alias Import alias identifier Import alias identifier FunctionDef arguments args NameParam defaults NameLoad body Expr Str If UnaryOpNot NameLoad body Assign NameStore AttributeLoad NameLoad attr Assign NameStore Call AttributeLoad NameLoad attr keyword Str keyword SubscriptLoad Call NameLoad Index Str Expr Call AttributeLoad NameLoad attr Str keyword Str keyword Str keyword Str keyword Str keyword Str Expr Call AttributeLoad NameLoad attr keyword ListLoad Assign TupleStore NameStore NameStore Call AttributeLoad NameLoad attr NameLoad keyword NameLoad Expr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad If CompareEq Call NameLoad AttributeLoad NameLoad attr Num body Raise Call NameLoad Str Expr Call AttributeLoad NameLoad attr Str Assign NameStore Call AttributeLoad NameLoad attr keyword NameLoad Assign NameStore Call AttributeLoad NameLoad attr keyword NameLoad Assign NameStore AttributeLoad NameLoad attr For NameStore NameLoad body For NameStore Call AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr NameLoad body Expr Call AttributeLoad NameLoad attr BinOpMod Str NameLoad Expr Call AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr Str Assign NameStore AttributeLoad NameLoad attr Assign NameStore Call AttributeLoad NameLoad attr NameLoad Expr Call AttributeLoad Call AttributeLoad Call AttributeLoad NameLoad attr attr attr AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr Str Assign NameStore Call AttributeLoad NameLoad attr For NameStore Call AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr body Expr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign NameStore AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr Str For NameStore NameLoad body Assign NameStore Call NameLoad For NameStore Call AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr NameLoad body If Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr body Assign NameStore BinOpAdd ListLoad AttributeLoad NameLoad attr ListComp NameLoad comprehension NameStore Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr Assign NameStore TupleLoad SubscriptLoad NameLoad Index Num SubscriptLoad SubscriptLoad NameLoad Index Num Index Num SubscriptLoad SubscriptLoad NameLoad Index Num Index Num If CompareIn NameLoad NameLoad body Continue Expr Call AttributeLoad NameLoad attr NameLoad AugAssignAdd SubscriptStore NameLoad Index NameLoad Num Expr Call AttributeLoad AttributeLoad NameLoad attr attr Str Expr Call AttributeLoad NameLoad attr Str For TupleStore NameStore NameStore Call AttributeLoad NameLoad attr body Expr Call AttributeLoad AttributeLoad NameLoad attr attr BinOpAdd BinOpAdd BinOpAdd Call AttributeLoad Str attr Call NameLoad NameLoad NameLoad Str Call NameLoad NameLoad Str Expr Call AttributeLoad NameLoad attr decorator_list If CompareEq NameLoad Str body Expr Call AttributeLoad NameLoad attr Call NameLoad AttributeLoad NameLoad attr
N/A N/A beds2counts - compute overlap stats between multiple bed files
=================================================================

:Author: Nick Ilott
:Release: $Id$
:Date: |today|
:Tags: Genomics Intervals Comparison BED Counting

Purpose
-------

This script takes multiple bed files e.g. from multiple samples from
the same experiment. It assesses the overlap between samples and
outputs a count for each merged interval corresponding to the number
of samples that a particular interval was found in.


Example
-------

For example if the command::

    cgat bed2counts a.bed b.bed c.bed > output.tsv

is run, where a.bed-c.bed look like::

                     1         2         3         4
           012345678901234567890123456789012345678901234
    a.bed: -------          -----               -------
    b.bed:      -----        --
    c.bed:  ---

    Union: ----------       -----               -------

Then output.tsv will look like::

    contig	start	end	count
    chr1	0	7	3
    chr1	17	22	2
    chr1	37	44	1

Options
-------

The only option other than the standard cgat options is -i, --bed-file this
allows the input files to be provided as a comma seperated list to the option
rather than a space delimited set of positional arguements. It is present
purely for galaxy compatibility.

Usage
-----

    cgat beds2counts BED [BED ...] [OPTIONS]

Command line options
--------------------

 N/A tempfile N/A sys N/A N/A N/A pybedtools N/A N/A N/A ImportError N/A N/A N/A CGAT.Experiment E N/A CGAT.Bed Bed N/A collections N/A CGAT.IOTools IOTools N/A CGAT.IndexedGenome IndexedGenome main N/A N/A argv N/A None N/A N/A script main.

    parses command line options in sys.argv, unless *argv* is given.
     N/A N/A argv N/A N/A argv N/A sys argv N/A parser N/A N/A E OptionParser version %prog version: $Id usage N/A N/A globals N/A __doc__ N/A N/A N/A parser add_option --bed-file dest infiles type string metavar bed help supply list of bed files action append N/A N/A N/A parser set_defaults infiles N/A N/A N/A options args N/A N/A E Start parser argv argv N/A N/A N/A N/A options infiles extend args N/A N/A N/A len N/A options infiles 0 N/A N/A N/A ValueError please provide at least 1 bed file N/A N/A N/A E info concatenating bed files N/A tmp N/A N/A tempfile NamedTemporaryFile delete False N/A tmp_merge N/A N/A tempfile NamedTemporaryFile delete False N/A infs N/A options infiles N/A inf infs N/A N/A bed N/A N/A Bed iterator N/A N/A IOTools openFile inf N/A N/A N/A N/A tmp write N/A %s
 bed N/A N/A N/A tmp close N/A N/A N/A E info merging bed entries N/A name N/A tmp name N/A tmp_bed N/A N/A pybedtools BedTool name N/A N/A N/A N/A N/A N/A N/A tmp_bed sort merge saveas N/A tmp_merge name N/A N/A N/A tmp_merge close N/A N/A N/A E info indexing bed entries N/A merged N/A N/A IndexedGenome Simple N/A bed N/A N/A Bed iterator N/A N/A IOTools openFile N/A tmp_merge name N/A N/A N/A N/A merged add N/A bed contig N/A bed start N/A bed end N/A counts N/A N/A collections defaultdict int N/A samples N/A options infiles N/A N/A N/A E info counting no. samples overlapping each interval N/A sample samples N/A N/A found N/A set N/A bed N/A N/A Bed iterator N/A N/A IOTools openFile sample N/A N/A N/A N/A merged contains N/A bed contig N/A bed start N/A bed end N/A N/A key N/A N/A N/A bed contig N/A x N/A x N/A N/A merged get N/A bed contig N/A bed start N/A bed end N/A key N/A N/A key N/A 0 N/A N/A key N/A 1 N/A 0 N/A N/A key N/A 1 N/A 1 N/A N/A key found N/A N/A N/A N/A N/A found add key N/A N/A counts N/A key 1 N/A N/A N/A N/A options stdout write contig	start	end	count
 N/A N/A N/A E info outputting result N/A N/A interval count N/A N/A counts iteritems N/A N/A N/A N/A N/A options stdout write N/A N/A N/A N/A N/A join N/A map str interval N/A str count N/A N/A N/A E Stop N/A N/A N/A __name__ __main__ N/A N/A N/A N/A sys exit N/A main N/A sys argv