| 1 | #!/usr/bin/env perl -w |
| 2 | |
| 3 | # list_matrices.pl |
| 4 | # by Boris Lenhard |
| 5 | # |
| 6 | # See POD documentation for this script at the end of the file |
| 7 | # |
| 8 | |
| 9 | use strict; |
| 10 | use Getopt::Long; # for parsing command line arguments |
| 11 | use Pod::Usage; |
| 12 | use TFBS::DB::FlatFileDir; |
| 13 | |
| 14 | # Get command line options - if you are curious how this |
| 15 | # works, check the Getopt::Long module documentation. |
| 16 | |
| 17 | my ($database_dir, $id_only, $verbose, $help); |
| 18 | |
| 19 | GetOptions('help' => \$help, |
| 20 | 'database=s' => \$database_dir, |
| 21 | 'id-only' => \$id_only, |
| 22 | 'verbose' => \$verbose |
| 23 | ); |
| 24 | |
| 25 | if($help) { |
| 26 | pod2usage(-exitstatus=>0, -verbose=>2); |
| 27 | } |
| 28 | elsif (!$database_dir) { |
| 29 | pod2usage(1); |
| 30 | } |
| 31 | |
| 32 | # connect to FlatFileDir matrix database |
| 33 | # (there is a sample FlatFileDir matrix database directory |
| 34 | # examples/SAMPLE_FlatFileDir in the TFBS distribution package) |
| 35 | # Change this line if you want to use a different type of database |
| 36 | # (e.g. TFBS::DB::JASPAR2) |
| 37 | |
| 38 | |
| 39 | my $db = TFBS::DB::FlatFileDir->connect($database_dir); |
| 40 | |
| 41 | |
| 42 | # get all matrices (TFBS::Matrix::PWM objects) into a TFBS::MatrixSet object |
| 43 | |
| 44 | my $matrixset = $db->get_MatrixSet(-matrixtype=>"PFM"); |
| 45 | |
| 46 | |
| 47 | # print heading if normal output |
| 48 | |
| 49 | unless ($id_only or $verbose) { |
| 50 | printf("\n %-10s%-15s%-20s%10s%10s\n", |
| 51 | 'MatrixID', 'Name', 'Class','Length', 'Total IC'); |
| 52 | } |
| 53 | # print line if normal or verbose output |
| 54 | |
| 55 | unless($id_only) { print ("-"x70,"\n"); } |
| 56 | |
| 57 | |
| 58 | # Iterate through the set and display ID and name |
| 59 | # (aggregate classes in TFBS - TFBS::MatrixSet, TFBS::SiteSet, |
| 60 | # TFBS::SitePairSet) are equipped with iterators that all follow |
| 61 | # the same syntax:) |
| 62 | |
| 63 | my $mx_iterator = $matrixset->Iterator(-sort_by=>'ID'); |
| 64 | |
| 65 | |
| 66 | while (my $pfm = $mx_iterator->next()) { #for each matrix in the set |
| 67 | if ($verbose) { |
| 68 | print ("\n","-"x65); |
| 69 | print ("\nMatrix ID : ", $pfm->ID); |
| 70 | print ("\nTransctiption factor name : ", $pfm->name); |
| 71 | print ("\nStructural class : ", $pfm->class); |
| 72 | print ("\nTotal information content : ", |
| 73 | sprintf("%2.2f",$pfm->to_ICM->total_ic)); |
| 74 | print ("\nMatrix:\n", $pfm->prettyprint); |
| 75 | |
| 76 | print ("","-"x65,"\n\n"); |
| 77 | } |
| 78 | elsif ($id_only) { |
| 79 | print ($pfm->ID, "\t", $pfm->name, "\n"); |
| 80 | } |
| 81 | else { |
| 82 | printf(" %-10s%-15s%-20s%10s%10.2f\n", |
| 83 | $pfm->ID, $pfm->name, $pfm->class, |
| 84 | $pfm->length, $pfm->to_ICM->total_ic); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | # print the line for normal and verbouse output |
| 89 | |
| 90 | unless($id_only) { |
| 91 | print ("-"x70, "\nTotal ", $matrixset->size, " matrices.\n\n"); |
| 92 | } |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | # The rest is usage message if the user requests help |
| 103 | # or fails to provide required parameters |
| 104 | |
| 105 | __END__ |
| 106 | |
| 107 | |
| 108 | =head1 NAME |
| 109 | |
| 110 | list_matrices.pl - List info on matrix patterns stored in a flat file directory |
| 111 | |
| 112 | =head1 SYNOPSIS |
| 113 | |
| 114 | ./list_matrices.pl -d <TFBS_matrix_dbase_dir> [other_options] |
| 115 | |
| 116 | =head1 OPTIONS |
| 117 | |
| 118 | =over 8 |
| 119 | |
| 120 | =item B<-d or --database> <directory name> |
| 121 | |
| 122 | REQUIRED: Name of the FlatFileDir database directory to |
| 123 | use for retrieving matrices. |
| 124 | A sample database directory examples/SAMPLE_FlatFileDir |
| 125 | is available in TFBS distribution. |
| 126 | |
| 127 | =item B<-i or --id-only> |
| 128 | |
| 129 | OPTIONAL: Prints only a list of matrix IDs |
| 130 | |
| 131 | |
| 132 | =item B<-v or --verbose> |
| 133 | |
| 134 | OPTIONAL: Prints full record (matrix and info). Overrides -i if set simultaneously. |
| 135 | |
| 136 | =back |
| 137 | |
| 138 | =head1 DESCRIPTION |
| 139 | |
| 140 | This is an example script that displays information about matrix patterns stored |
| 141 | in a flat file directory-type database. Its source code is |
| 142 | meant to be studied by bioinformaticians who wish to learn how to |
| 143 | use TFBS modules. |
| 144 | |
| 145 | |
| 146 | =cut |