[Bio] / FigKernelScripts / match_to_axes.pl Repository:
ViewVC logotype

View of /FigKernelScripts/match_to_axes.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (download) (as text) (annotate)
Mon Aug 31 20:26:17 2015 UTC (4 years, 2 months ago) by golsen
Branch: MAIN
CVS Tags: HEAD
Changes since 1.6: +2 -2 lines
Fixed spelling errors in the documentation.

#!/usr/bin/env perl -w
#
#  Usage: match_to_axes [Options] gid
#         match_to_axes [Options] -f fasta_file
#
#  Options:
#
#     -d            # Compute native codon usage de novo
#     -f fasta      # Get data from a fasta file of coding sequences (e.g.,
#                   #     an NCBI .ffn file); implies -d
#     -g gname      # Genome id and name; only used with -f
#     -h            # Help: Display command usage information
#     -l maxlen     # Maximum amino acids in significance calculation (D = 500)
#                   #     A value of 0 gives no limit.
#     -o format     # format is html | tab
#     -s source     # Source is KBase | Sapling (D) | SEED
#     -t title      # Title to be put on html output
#     -u usage_gid  # Genome id for codon usages, if different than the genes
#     -U usage_ffn  # Fasta file for codon usages, if different than the genes
#
use strict;
use gjocodonlib;
use CodonUsageTable;
use Data::Dumper;

use warnings;

my $usage = <<'End_of_Usage';

Usage: match_to_axes [Options] gid
       match_to_axes [Options] -f fasta_file

Options:

   -c            # Display only the named contig
   -d            # Compute native codon usage de novo
   -f fasta      # Get data from a fasta file of coding sequences (e.g., an
                 #     NCBI .ffn file); implies -d
   -g gname      # Genome id and name; only used with -f
   -h            # Help: Display command usage information
   -l maxlen     # Maximum amino acids in significance calculation (D = 500);
                 #     a value of 0 gives no limit.
   -o format     # html | html_page (D) | html_table | page | tab | table
   -r location   # Display only the region specified by SEED or Sapling location
   -s source     # KBase | Sapling (D) | SEED
   -t title      # Title to be put on html output
   -u usage_gid  # Genome id for codon usages, if different than the genes
   -U usage_ffn  # Fasta file for codon usages, if different than the genes

Output formats:

   -o html        # A complete html page
   -o html_page   # A complete html page
   -o html_table  # An html table
   -o page        # A complete html page (D)
   -o tab         # Tab separated text
   -o table       # An html table

End_of_Usage

my $contig   = '';
my $de_novo  =  0;
my $ffn_file = '';
my $format   = 'page';
my $gname    = '';
my $region   = '';
my $max_len  = 500;
my $source   = '';
my $title    = '';
my $u_ffn    = '';
my $u_gid    = '';

while ( @ARGV && $ARGV[0] =~ s/^-// )
{
    local $_ = shift;
    if ( /^h$/ ) { print STDERR $usage; exit }

    if ( s/^c// ) { $contig   = /./ ? $_ : shift; next; }
    if ( s/^f// ) { $ffn_file = /./ ? $_ : shift; next; }
    if ( s/^g// ) { $gname    = /./ ? $_ : shift; next; }
    if ( s/^l// ) { $max_len  = /./ ? $_ : shift; next; }
    if ( s/^o// ) { $format   = /./ ? $_ : shift; next; }
    if ( s/^r// ) { $region   = /./ ? $_ : shift; next; }
    if ( s/^s// ) { $source   = /./ ? $_ : shift; next; }
    if ( s/^t// ) { $title    = /./ ? $_ : shift; next; }
    if ( s/^u// ) { $u_gid    = /./ ? $_ : shift; next; }
    if ( s/^U// ) { $u_ffn    = /./ ? $_ : shift; next; }

    if ( s/d//g ) { $de_novo  =  1 }
    if ( /./ )
    {
        print STDERR "Bad flag ($_).\n", $usage;
        exit;
    }
}

$format = $format =~ /^html$/i ? 'page'
        : $format =~ /page/i   ? 'page'
        : $format =~ /table/i  ? 'html'
        : $format =~ /^tab$/i  ? 'tab'
        :                        'page';

my $opts = {};
$opts->{ de_novo } = $de_novo;
if ( $u_ffn )
{
    $opts->{ g_ffn } = $ffn_file;
    $opts->{ u_ffn } = $u_ffn;
}
else
{
    $opts->{ ffn } = $ffn_file;
}
$opts->{ contig }       = $contig  if $contig;
$opts->{ format }       = $format;
$opts->{ genome_title } = $gname;
$opts->{ max_len }      = $max_len;
$opts->{ region }       = $region  if $region;
$opts->{ title }        = $title;

my $gid = shift || '';

#  Supply default source if id form is recognized
$source ||= $gid =~ /^(?:fig\|)?\d+\.\d+$/ ? 'Sapling'
          : $gid =~ /^(?:kb\|)?g\.\d+$/    ? 'KBase'
          : '';

#  Canonicalize source
{
    local $_ = $source;
    $source = m/^kbase/i   ? 'KBase'
            : m/^sapling/i ? 'Sapling'
            : m/^seed/i    ? 'SEED'
            :                '';
}

#  A default gid = E. coli K12 for debugging
# $gid ||= $source eq 'KBase'   ? 'kb|g.0'
#        : $source eq 'Sapling' ? '83333.1'
#        : $source eq 'SEED'    ? '83333.1'
#       : '';

$opts->{ gid } = $gid;
if ( $u_gid )
{
    $opts->{ g_gid } = $gid;
    $opts->{ u_gid } = $u_gid;
}

$opts->{ source } = $source;

print CodonUsageTable::match_to_axes( $opts );

exit;


MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3