Module Expr Str Import alias Import alias identifier Import alias identifier Import alias identifier Import alias identifier FunctionDef arguments args NameParam defaults NameLoad body If CompareIs NameLoad 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 Str keyword Str keyword Str keyword Str Expr Call AttributeLoad NameLoad attr Str Str keyword Str keyword Str keyword TupleLoad Str Str Str Str keyword Str Expr Call AttributeLoad NameLoad attr Str keyword Str keyword Str keyword TupleLoad Str Str Str keyword Str Expr Call AttributeLoad NameLoad attr Str keyword Str keyword Str keyword Str Expr Call AttributeLoad NameLoad attr Str keyword Str keyword Str keyword Str Expr Call AttributeLoad NameLoad attr Str keyword Str keyword Str keyword TupleLoad Str Str Str Str Str Str keyword Str Expr Call AttributeLoad NameLoad attr Str keyword Str keyword Str keyword Str Expr Call AttributeLoad NameLoad attr Str keyword Str keyword Str keyword Str Expr Call AttributeLoad NameLoad attr keyword NameLoad keyword NameLoad keyword Str keyword Num keyword Num keyword NameLoad keyword Num keyword NameLoad Assign TupleStore NameStore NameStore Call AttributeLoad NameLoad attr NameLoad If AttributeLoad NameLoad attr body Assign NameStore Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr Assign NameStore Call AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr Str Assign NameStore Call AttributeLoad NameLoad attr Assign TupleStore NameStore NameStore TupleLoad ListLoad ListLoad Expr Call AttributeLoad NameLoad attr Str For NameStore Call AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr body AugAssignAdd AttributeStore NameLoad attr Num Assign NameStore Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr If AttributeLoad NameLoad attr body Assign NameStore Str orelse Assign NameStore AttributeLoad NameLoad attr If BoolOpAnd CompareEq AttributeLoad NameLoad attr Str CompareEq AttributeLoad NameLoad attr Num body Expr Call AttributeLoad NameLoad attr BinOpMod Str TupleLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr NameLoad SubscriptLoad NameLoad Index Str SubscriptLoad NameLoad Index Str Assign NameStore ListComp Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr NameLoad NameLoad NameLoad comprehension TupleStore NameStore NameStore Call AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr Call AttributeLoad Str attr NameLoad orelse If BoolOpOr CompareEq AttributeLoad NameLoad attr Str CompareEq AttributeLoad NameLoad attr Str body Expr Call AttributeLoad NameLoad attr BinOpMod Str TupleLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr NameLoad Expr Call AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr NameLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr orelse If CompareEq AttributeLoad NameLoad attr Str body Assign NameStore BinOpSub AttributeLoad NameLoad attr AttributeLoad NameLoad attr Assign TupleStore NameStore NameStore TupleLoad Call NameLoad Num BinOpSub AttributeLoad NameLoad attr NameLoad BinOpSub AttributeLoad NameLoad attr NameLoad Expr Call AttributeLoad NameLoad attr BinOpMod Str TupleLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr NameLoad NameLoad NameLoad Expr Call AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr NameLoad NameLoad NameLoad Assign TupleStore NameStore NameStore TupleLoad BinOpAdd AttributeLoad NameLoad attr NameLoad Call NameLoad NameLoad BinOpAdd AttributeLoad NameLoad attr NameLoad Expr Call AttributeLoad NameLoad attr BinOpMod Str TupleLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr NameLoad NameLoad NameLoad Expr Call AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr NameLoad NameLoad NameLoad Expr Call AttributeLoad NameLoad attr BinOpMod Str Call NameLoad NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad AttributeLoad NameLoad attr Expr Call AttributeLoad AttributeLoad NameLoad attr attr BinOpAdd Call AttributeLoad Str attr ListComp BinOpMod Str TupleLoad NameLoad NameLoad comprehension TupleStore NameStore NameStore Call NameLoad NameLoad NameLoad Str Expr Call AttributeLoad NameLoad attr BinOpMod Str Call NameLoad NameLoad Assign AttributeStore NameLoad attr Call NameLoad NameLoad Expr Call AttributeLoad NameLoad attr BinOpMod Str NameLoad 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 
bed2fasta.py - get sequences from bed file
==========================================

:Author: Andreas Heger
:Release: $Id$
:Date: |today|
:Tags: Genomics Intervals Sequences Conversion BED FASTA 



Purpose
-------

This script outputs nucleotide sequences for intervals within
a :term:`bed` formatted file using a corresponding genome file.

Usage
-----

A required input to bed2fasta.py is a CGAT indexed genome. To obtain an
idexed human reference genome we would type

Example::
   cat hg19.fasta | index_fasta.py hg19 > hg19.log

This file would then serve as the --genome-file when we wish to extract
sequences from a :term:`bed` formatted file.


For example we could now type::

   cat in.bed | python bed2fasta.py --genome-file hg19 > out.fasta

Where we take a set of genomic intervals (e.g. from a human ChIP-seq experiment)
and output their respective nucleotide sequences.


Type::

   python bed2fasta.py --help

for command line help.

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

 N/A sys N/A CGAT.Experiment E N/A CGAT.Bed Bed N/A CGAT.IndexedFasta IndexedFasta N/A CGAT.Masker Masker main N/A N/A argv N/A None N/A N/A N/A argv None 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 -g --genome-file dest genome_file type string help filename with genomic sequence to retrieve sequences from. N/A N/A N/A parser add_option -m --masker dest masker type choice choices N/A dust dustmasker softmask none help apply masker to mask output sequences [%default]. N/A N/A N/A parser add_option --output-mode dest output_mode type choice choices N/A intervals leftright segments help what to output. 'intervals' generates a single sequence for each bed interval. 'leftright' generates two sequences, one in each direction, for each bed interval. 'segments' can be used to output sequence from bed12 files so that sequence only covers the segements [%default] N/A N/A N/A parser add_option --min-sequence-length dest min_length type int help require a minimum sequence length [%default] N/A N/A N/A parser add_option --max-sequence-length dest max_length type int help require a maximum sequence length [%default] N/A N/A N/A parser add_option --extend-at dest extend_at type choice choices N/A none 3 5 both 3only 5only help extend at 3', 5' or both or no ends. If 3only or 5only are set, only the added sequence is returned [default=%default] N/A N/A N/A parser add_option --extend-by dest extend_by type int help extend by # bases [default=%default] N/A N/A N/A parser add_option --use-strand dest ignore_strand action store_false help use strand information and return reverse complement on intervals located on the negative strand. [default=%default] N/A N/A N/A parser set_defaults genome_file None masker None output_mode intervals min_length 0 max_length 0 extend_at None extend_by 100 ignore_strand True N/A N/A options args N/A N/A E Start parser N/A N/A options genome_file N/A N/A fasta N/A N/A IndexedFasta IndexedFasta N/A options genome_file N/A contigs N/A N/A fasta getContigSizes N/A N/A N/A fasta setConverter N/A N/A IndexedFasta getConverter zero-both-open N/A counter N/A N/A E Counter N/A N/A ids seqs N/A N/A N/A N/A N/A N/A E info collecting sequences N/A bed N/A N/A Bed setName N/A N/A Bed iterator N/A options stdin N/A N/A N/A counter input 1 N/A lcontig N/A N/A fasta getLength N/A bed contig N/A N/A options ignore_strand N/A N/A strand + N/A N/A strand N/A bed strand N/A N/A N/A N/A options output_mode segments N/A N/A bed columns 12 N/A N/A N/A N/A ids append N/A %s %s:%i..%i (%s) %s %s N/A N/A bed name N/A bed contig N/A bed start N/A bed end strand N/A bed N/A blockSizes N/A bed N/A blockStarts N/A seg_seqs N/A N/A N/A fasta getSequence N/A bed contig strand start end N/A N/A start end N/A N/A bed toIntervals N/A N/A N/A seqs append N/A N/A join seg_seqs N/A N/A N/A N/A N/A options output_mode intervals N/A N/A options output_mode segments N/A N/A N/A N/A ids append N/A %s %s:%i..%i (%s) N/A N/A bed name N/A bed contig N/A bed start N/A bed end strand N/A N/A N/A seqs append N/A N/A fasta getSequence N/A bed contig strand N/A bed start N/A bed end N/A N/A N/A N/A options output_mode leftright N/A N/A l N/A N/A bed end N/A bed start N/A N/A start end N/A N/A max 0 N/A N/A bed start l N/A N/A bed end l N/A N/A N/A ids append N/A %s_l %s:%i..%i (%s) N/A N/A bed name N/A bed contig start end strand N/A N/A N/A seqs append N/A N/A fasta getSequence N/A bed contig strand start end N/A N/A start end N/A N/A N/A bed start l N/A min lcontig N/A N/A bed end l N/A N/A N/A ids append N/A %s_r %s:%i..%i (%s) N/A N/A bed name N/A bed contig start end strand N/A N/A N/A seqs append N/A N/A fasta getSequence N/A bed contig strand start end N/A N/A N/A E info N/A collected %i sequences N/A len seqs N/A masked N/A N/A Masker maskSequences seqs N/A options masker N/A N/A N/A N/A options stdout write N/A N/A N/A join N/A N/A >%s
%s N/A x y N/A N/A x y N/A zip ids masked N/A N/A N/A E info N/A masked %i sequences N/A len seqs N/A N/A counter output N/A len seqs N/A N/A N/A E info N/A %s counter 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