Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
#!/usr/bin/perl -w use strict; use Getopt::Long; use Bio::SeqIO; use File::Basename; use Pod::Usage; # seq-convert # Copyright 2003 Tex Thompson <tex@mail.rit.edu> # This is free software released under the Perl artistic license, see +the # RIT Package website at http://bioinformatics.rit.edu/~tex/ritpackage +/ for # more information. $0 = basename $0; our @valid_formats = qw( fasta genbank embl gcg swiss ); # Bioperl supports more valid file formats, but they are currently unt +ested my $formats = "Valid sequence file formats:\n"; map { $formats .= "\t$_\n" } @valid_formats; # parse the command line options my ( $input, $output, $subseq, $help, $print_formats ); GetOptions( 'input=s', \$input, 'output=s', \$output, 'help', \$help, 'subseq=s', \$subseq, 'formats', \$print_formats ); if ( !$output ) { $output = 'fasta' }; # die and print some information if appropriate if ( $print_formats ) { die $formats }; if ( $help ) { pod2usage( -verbose => 2 ) }; die pod2usage( -verbose => 0 ) unless @ARGV; # if a range is provided, make sure that it is valid if ( $subseq ) { validate_range( $subseq ); } # create input/output objects using Bio::SeqIO my $infile = $ARGV[0]; my ($in, $out); eval { if ( $input ) { $in = Bio::SeqIO->new( -file => $infile, -format => $input ); } else { $in = Bio::SeqIO->new( -file => $infile ); } }; # catch exceptions from creating Bio::SeqIO input object if ( $@ ) { print "Couldn't open file $infile\: $!\n";exit(1) }; eval { $out = Bio::SeqIO->new( -fh=>\*STDOUT, -format => $output ); }; # catch exceptions from creating Bio::SeqIO input object if ( $@ ) { print "Error using format $output: $!\n"; exit(1) }; if ( $subseq ) { my ($start,$end) = split /\-/, $subseq; my $seqobj = $in->next_seq(); print $seqobj->subseq( $start, $end ); } else { while ( my $seq = $in->next_seq() ) { $out->write_seq($seq); } } print "\n"; ############### # Subroutines # ############### sub validate_range { my $range = shift; my $invalid_range = 1; if ( $range =~ /\d+-\d+/ ) { $invalid_range = 0; } else { # clean up error handling around here $invalid_range = 1; print "Bad range: $_\n"; } } ##################### + # Usage Information # + ##################### + + =head1 NAME + + seq-convert - Conversion of biological sequence files. =head1 SYNOPSIS seq-convert [options] input-file + options: + --input <inputformat> --output <outputformat> --formats --subseq <range> --help =head1 OPTIONS =over 8 + + =item B< --input> + Specifies the format of the input file. Defaults to fasta. =item B< --output> Specifies the output format. Defaults to fasta. =item B< --print-formats> Prints the sequence file formats available to this program. + =item B< --subsequence range> Selects a subsequence of the sequence contained in the input file. Ran +ges should have the form x-y, where x and y are positive integers. =item B< --help> Prints a detailed help message. =item B< --version> Prints version information. =back =head1 EXAMPLES + # print a help message $ seq-convert --help # convert mySeq.fasta to a GCG formatted file $ seq-convert --input fasta --output gcg mySeq.fasta # convert the first 100 nucleotides from mySequence.genbank # into a fasta formatted file $ seq-convert --input genbank --output fasta mySequence.genbank $ seq-convert --input genbank mySequence.genbank =head1 DESCRIPTION + Part of the RIT Bioinformatics Package: http://bioinformatics.sourceforge.net This program reads a sequence from a file, converts it to another form +at and prints the converted file to standard output. =head1 AUTHOR + + Tex Thompson <tex@bioinformatics.rit.edu> =head1 LICENSE + + B<seq-convert> is licensed under the GNU GPL license, available from http://www.gnu.org/. =cut

In reply to seq-convert by biosysadmin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2023-02-07 04:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (38 votes). Check out past polls.

    Notices?