extending the marker location to markers with ranges, such as qtl markers.
[cxgn-corelibs.git] / bin / agp_to_fasta.pl
blob09378dfa19a8811af29508d63e4875e6fc225b80
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
5 =head1 NAME
7 agp_to_fasta.pl - assemble an AGP file into fasta
9 =head1 SYNOPSIS
11 agp_to_fasta.pl foo.agp source.fasta > result.fasta
13 =head1 OPTIONS
15 =head2 -w <num>
17 Column width of fasta output, with 0 being unlimited (no additional
18 newlines). Default 80.
20 =cut
22 use File::Temp;
23 use Getopt::Std;
24 use Pod::Usage;
26 use Bio::Index::Fasta;
28 use CXGN::BioTools::AGP qw/ agp_to_seqs /;
30 my %opts;
31 getopts( 'w', \%opts );
32 $opts{w} = 80 unless defined $opts{w};
33 pod2usage() unless @ARGV;
35 @ARGV == 2 or die "must pass exactly 2 file names as arguments\n";
37 for( @ARGV ) {
38 -r or die "cannot read file '$_'"
40 my ( $agp_file, $source_seqs ) = @ARGV;
42 my $index = make_seqs_index( $source_seqs );
44 my @seqs = agp_to_seqs(
45 $agp_file,
46 fetch_default => sub {
47 my $s = $index->fetch( $_[0] )
48 or return;
49 return $s->seq;
53 my $o = Bio::SeqIO->new(
54 -format => 'fasta',
55 -fh => \*STDOUT,
56 ( $opts{w} ? (-width => 80) : () ),
59 # the while/shift cuts down a bit on disk space usage
60 while( @seqs ) {
61 $o->write_seq( shift @seqs );
64 exit;
66 ################# SUBS ###########3
68 my $temp;
69 sub make_seqs_index {
70 my ( $seqs ) = @_;
71 $temp = File::Temp->new;
72 $temp->close;
74 # index of source sequences, for random access
75 my $inx = Bio::Index::Fasta->new(
76 -filename => "$temp",
77 -write_flag => 1 );
78 $inx->make_index( $source_seqs );
80 return $inx;