| 1 | #!/usr/local/bin/perl | ||
| 2 | |||
| 3 | use warnings; | ||
| 4 | use strict; | ||
| 5 | use Getopt::Long; | ||
| 6 | use Pod::Usage; | ||
| 7 | use Bio::DB::USeq; | ||
| 8 | |||
| 9 | my $VERSION = '0.23'; | ||
| 10 | |||
| 11 | ### Quick help | ||
| 12 | unless (@ARGV) { | ||
| 13 | # when no command line options are present | ||
| 14 | # print SYNOPSIS | ||
| 15 | pod2usage( { | ||
| 16 | '-verbose' => 0, | ||
| 17 | '-exitval' => 1, | ||
| 18 | } ); | ||
| 19 | } | ||
| 20 | |||
| 21 | |||
| 22 | |||
| 23 | ### Get command line options and initialize values | ||
| 24 | my ( | ||
| 25 | $do_chrom, | ||
| 26 | $do_stats, | ||
| 27 | $help, | ||
| 28 | $print_version, | ||
| 29 | ); | ||
| 30 | |||
| 31 | # Command line options | ||
| 32 | GetOptions( | ||
| 33 | 'chrom!' => \$do_chrom, # print chromosome information | ||
| 34 | 'stat!' => \$do_stats, # print statistics | ||
| 35 | 'help' => \$help, # request help | ||
| 36 | 'version' => \$print_version, # print the version | ||
| 37 | ) or die " unrecognized option(s)!! please refer to the help documentation\n\n"; | ||
| 38 | |||
| 39 | # Print help | ||
| 40 | if ($help) { | ||
| 41 | # print entire POD | ||
| 42 | pod2usage( { | ||
| 43 | '-verbose' => 2, | ||
| 44 | '-exitval' => 1, | ||
| 45 | } ); | ||
| 46 | } | ||
| 47 | |||
| 48 | # Print version | ||
| 49 | if ($print_version) { | ||
| 50 | print " USeqInfo.pl, version $VERSION\n\n"; | ||
| 51 | exit; | ||
| 52 | } | ||
| 53 | |||
| 54 | |||
| 55 | |||
| 56 | |||
| 57 | ### Process files | ||
| 58 | foreach my $file (@ARGV) { | ||
| 59 | |||
| 60 | # check extension | ||
| 61 | unless ($file =~ /\.useq$/i) { | ||
| 62 | warn "$file does not have a .useq extension. skipping\n"; | ||
| 63 | next; | ||
| 64 | } | ||
| 65 | process_file($file); | ||
| 66 | } | ||
| 67 | exit; | ||
| 68 | |||
| 69 | |||
| 70 | |||
| 71 | |||
| 72 | |||
| 73 | |||
| 74 | ############ Subroutines ################### | ||
| 75 | |||
| 76 | sub process_file { | ||
| 77 | my $file = shift; | ||
| 78 | |||
| 79 | my $useq = Bio::DB::USeq->new($file) or return; | ||
| 80 | |||
| 81 | # Basic metadata | ||
| 82 | print "$file\n"; | ||
| 83 | printf " versioned genome: %s\n", $useq->genome; | ||
| 84 | printf " data type: %s\n", $useq->type; | ||
| 85 | printf " graph style: %s\n", $useq->attribute('initialGraphStyle') || q( ); | ||
| 86 | printf " creation date: %s\n", $useq->attribute('archiveCreationDate') || q( ); | ||
| 87 | printf " original data: %s\n", $useq->attribute('originatingDataSource') || q( ); | ||
| 88 | printf " description: %s\n", $useq->attribute('description') || q(none); | ||
| 89 | printf " stranded: %s\n", $useq->stranded ? 'yes' : 'no'; | ||
| 90 | my @seqs = $useq->seq_ids; | ||
| 91 | printf " number chromosomes: %s\n", scalar(@seqs); | ||
| 92 | |||
| 93 | # slice information | ||
| 94 | my @slices = $useq->slices; | ||
| 95 | printf " number slices: %s\n", scalar(@slices); | ||
| 96 | my $obs_number = 0; | ||
| 97 | foreach (@slices) { | ||
| 98 | $obs_number += $useq->slice_obs_number($_); | ||
| 99 | } | ||
| 100 | print " number observations: $obs_number\n"; | ||
| 101 | |||
| 102 | # observation type | ||
| 103 | my $obs_type = "chromosome, "; | ||
| 104 | if ($useq->slice_type( $slices[0] ) =~ /^[is][is]/) { | ||
| 105 | $obs_type .= "start, stop"; | ||
| 106 | } | ||
| 107 | else { | ||
| 108 | $obs_type .= "position"; | ||
| 109 | } | ||
| 110 | if ($useq->slice_type( $slices[0] ) =~ /f/) { | ||
| 111 | $obs_type .= ", score"; | ||
| 112 | } | ||
| 113 | if ($useq->slice_type( $slices[0] ) =~ /t/) { | ||
| 114 | $obs_type .= ", text"; | ||
| 115 | } | ||
| 116 | print " observations include: $obs_type\n"; | ||
| 117 | |||
| 118 | # chromosome and statistics information | ||
| 119 | if ($do_chrom and $do_stats) { | ||
| 120 | print " chromosome length min mean stdev max\n"; | ||
| 121 | my $global_stats = $useq->global_stats; | ||
| 122 | my $genome_length = 0; | ||
| 123 | foreach (@seqs) { | ||
| 124 | my $stats = $useq->chr_stats($_); | ||
| 125 | printf " $_ %s %0.3f %0.3f %0.3f %0.3f\n", $useq->length($_), | ||
| 126 | $stats->{minVal}, $useq->chr_mean($_), $useq->chr_stdev($_), | ||
| 127 | $stats->{maxVal}; | ||
| 128 | $genome_length += $useq->length($_); | ||
| 129 | } | ||
| 130 | printf " genome $genome_length %0.3f %0.3f %0.3f %0.3f\n", | ||
| 131 | $global_stats->{minVal}, $useq->global_mean, $useq->global_stdev, | ||
| 132 | $global_stats->{maxVal}; | ||
| 133 | } | ||
| 134 | elsif ($do_chrom) { | ||
| 135 | print " chromosome length:\n"; | ||
| 136 | foreach (@seqs) { | ||
| 137 | printf " $_ %s\n", $useq->length($_); | ||
| 138 | } | ||
| 139 | } | ||
| 140 | elsif ($do_stats) { | ||
| 141 | my $global_stats = $useq->global_stats; | ||
| 142 | print " genome scores: min mean stdev max\n"; | ||
| 143 | printf " %0.3f %0.3f %0.3f %0.3f\n", | ||
| 144 | $global_stats->{minVal}, $useq->global_mean, $useq->global_stdev, | ||
| 145 | $global_stats->{maxVal}; | ||
| 146 | } | ||
| 147 | |||
| 148 | return; | ||
| 149 | } | ||
| 150 | |||
| 151 | |||
| 152 | |||
| 153 | |||
| 154 | |||
| 155 | |||
| 156 | |||
| 157 | __END__ |