#!/usr/local/bin/perl -w

use strict;
use CompBio::Simple;
use Getopt::Long;

if(! defined $ARGV[0]){
    print "tbl_to_fa <-help|-out> (seqfile.fa|-)\n";
    exit;
}#if

my $stdin = '';
my %opt = ();
# '' allows - in command args to indicate input from stdin (console or pipe)
my $result = GetOptions(\%opt,'help|h','' => \$stdin,'out|o=s','v+');
my $VERSION = '0.13';

if ($opt{"help"}) { exec "perldoc $0" }

=head1 NAME

tbl_to_fa - Convert sequence records in table format to fasta format

=head1 SYNOPSIS



=head1 DESCRIPTION

Convert sequence records in table format to fasta format. Input sequences can be
in a file or piped in on the command line (see L<examples>). Output is to standard
out or to a file if specified with the -out flag.

=cut

my $cbs = CompBio::Simple->new;

my %params = ();
$params{OUTFILE} = $opt{out} if ($opt{'out'});
$params{DEBUG} = $opt{v} if $opt{v};

$| = 1; # because I am inherently impatient
# Just bomb the code from here to TODO if not using input file. Might as well 
# remove the $stdin stuff from above too then.
my $input_file = shift;
print "stdin = $stdin.\n" if $opt{v};
if ($stdin) {
    print "stdin = $stdin.\n" if $opt{v};
    while (<>) {
        my $result = $cbs->tbl_to_fa($_,%params);
        print $result if $result;
    } # while
} # loop over std in
elsif ($input_file) {
    print "input_file = $input_file.\n" if $opt{v};
    print join("\n",@{$cbs->tbl_to_fa($input_file,%params)}),"\n";
} # either a single sequence on the comand line or a file - let Simple handle it
else {
    die "No input to convert!\n";
} # no dna?

=head1 TODO



=head1 COPYRIGHT

Developed at the BioMolecular Engineering Research Center at Boston
University under the NHLBI's Programs for Genomic Applications grant.

Copyright Sean Quinlan, Trustees of Boston University 2000-2002.

All rights reserved. This program is free software; you can redistribute it
and/or modify it under the same terms as Perl itself.

=head1 AUTHOR

Sean Quinlan, seanq@darwin.bu.edu

Please email me with any changes you make or suggestions for changes/additions.
Latest version is available through SourceForge
L<http://sourceforge.net/projects/compbio/>, or on the CPAN
L<http://www.cpan.org/authors/id/S/SE/SEANQ/>.
Thank you!

=head1 SEE ALSO

perl(1).

=cut
