Module Expr Str Import alias Import alias Import alias Import alias Import alias Import alias identifier 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 Str keyword Str keyword Str keyword Str Expr Call AttributeLoad NameLoad attr Str Str keyword Str keyword Str keyword Str Assign TupleStore NameStore NameStore Call AttributeLoad NameLoad attr NameLoad keyword NameLoad Expr Call AttributeLoad NameLoad attr Str Assign NameStore Num Assign NameStore Dict For NameStore Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr body AugAssignAdd NameStore Num Assign SubscriptStore NameLoad Index SubscriptLoad Call AttributeLoad AttributeLoad NameLoad attr attr Str Index Num Call NameLoad AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr BinOpMod Str NameLoad Assign NameStore Dict For NameStore Call AttributeLoad Call NameLoad AttributeLoad NameLoad attr attr body Assign NameStore Call AttributeLoad SubscriptLoad NameLoad Slice Num attr Str Assign TupleStore NameStore NameStore TupleLoad SubscriptLoad NameLoad Index Num SubscriptLoad NameLoad Index Num Assign SubscriptStore NameLoad Index NameLoad NameLoad Expr Call AttributeLoad NameLoad attr BinOpMod Str AttributeLoad NameLoad attr Assign NameStore Dict Assign NameStore Num For NameStore Call AttributeLoad NameLoad attr Call AttributeLoad AttributeLoad NameLoad attr attr AttributeLoad NameLoad attr Str body AugAssignAdd NameStore Num For NameStore Call AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr NameLoad body Assign SubscriptStore NameLoad Index AttributeLoad NameLoad attr AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr BinOpMod Str TupleLoad NameLoad AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr Str Assign NameStore Num For TupleStore NameStore NameStore Call AttributeLoad NameLoad attr body If CompareNotIn NameLoad NameLoad body Expr Call AttributeLoad NameLoad attr BinOpMod Str NameLoad orelse AugAssignAdd NameStore Num Assign NameStore SubscriptLoad NameLoad Index NameLoad Assign NameStore Call NameLoad SubscriptLoad NameLoad Index NameLoad Assign NameStore Call AttributeLoad NameLoad attr Num NameLoad TryExcept body Assign NameStore BinOpSub BinOpAdd NameLoad NameLoad Num handlers ExceptHandler type NameLoad body Print Str Assign NameStore SubscriptLoad SubscriptLoad NameLoad Index NameLoad Slice NameLoad NameLoad Expr Call AttributeLoad AttributeLoad NameLoad attr attr BinOpMod Str TupleLoad BinOpAdd NameLoad BinOpMod Str SubscriptLoad NameLoad Index 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 
contigs2random_sample.py
=============================================

:Author: Nick Ilott
:Release: $Id$
:Date: |today|
:Tags: Python

Purpose
-------

When conducting a simulation study it is often useful to simulate contigs from the 
original genome/genomes from which your contigs have been derived. This can then 
provide an expectation dataset for downstream analyses.

Usage
-----

Example::

   python contigs2random_sample.py --help

Type::

   python contigs2random_sample_.py --help

for command line help.

Documentation
-------------

The script takes as input a multifasta set of contigs with arbitrary names as may have
been generated by any assembly algorithm. It also takes as input a map which maps the 
contig id to a genome id. The genomes that are referred to in the species-map file
are specified as a directory and these are where the samples are derived.

The contigs file is read from stdin and writes the result to stdout.

The species map MUST be in the format "contig" "species" and the species MUST be the 
contig identifier of the respective genome.

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

 N/A os N/A sys N/A optparse N/A glob N/A random N/A CGAT.Experiment E N/A CGAT.FastaIterator FastaIterator N/A CGAT.IOTools IOTools 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 optparse OptionParser version %prog version: $Id: contigs2random_sample.py 2871 2010-03-03 10:20:44Z nicki $ usage N/A N/A globals N/A __doc__ N/A N/A N/A parser add_option -m --species-map dest species_map type string help text file specifying the mapping between contig and genome N/A N/A N/A parser add_option -g --genome-dir dest genome_dir type string help specify directory where genome / genomes are stored N/A N/A options args N/A N/A E Start parser argv argv N/A N/A N/A E info reading contigs file N/A c_contigs 0 N/A contigs_lengths N/A N/A fasta N/A N/A FastaIterator iterate N/A options stdin N/A N/A c_contigs 1 N/A N/A contigs_lengths N/A N/A N/A N/A N/A fasta title split N/A 0 N/A len N/A fasta sequence N/A N/A N/A E info N/A read %i contigs c_contigs N/A species_map N/A N/A line N/A N/A N/A open N/A options species_map readlines N/A N/A data N/A N/A N/A line N/A -1 split N/A N/A contig species N/A N/A data N/A 0 N/A data N/A 1 N/A N/A species_map N/A contig species N/A N/A N/A E info N/A reading genomes from %s N/A options genome_dir N/A genomes_sequences N/A N/A c_genomes 0 N/A genome_file N/A N/A glob glob N/A N/A N/A os path join N/A options genome_dir * N/A N/A c_genomes 1 N/A fasta N/A N/A FastaIterator iterate N/A N/A IOTools openFile genome_file N/A N/A N/A genomes_sequences N/A N/A fasta title N/A fasta sequence N/A N/A N/A E info N/A read %i genomes from %s N/A c_genomes N/A options genome_dir N/A N/A N/A E info iterating over contigs N/A c_contigs_output 0 N/A N/A contig length N/A N/A contigs_lengths iteritems N/A N/A N/A contig species_map N/A N/A N/A N/A E warn N/A contig %s not in species map file contig N/A N/A c_contigs_output 1 N/A genome N/A species_map N/A contig N/A genome_length N/A len N/A genomes_sequences N/A genome N/A start N/A N/A random randint 1 genome_length N/A N/A N/A end N/A N/A start length 1 N/A N/A N/A ValueError N/A N/A end of sampled contig extends beyond length of genome N/A sampled_seq N/A N/A genomes_sequences N/A genome N/A start end N/A N/A N/A N/A options stdout write N/A >%s_random
%s
 N/A N/A contig N/A _%s N/A species_map N/A contig sampled_seq N/A N/A N/A E info N/A written %i contigs c_contigs_output 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