Debian Codegraph @

examples/list_matrices.pl

raw symbols SCIP
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 strictscip-perl cpan TFBS v0.5.0 strict/;
10 use Getopt::Longscip-perl cpan TFBS v0.5.0 Getopt/Long/; # for parsing command line arguments
11 use Pod::Usagescip-perl cpan TFBS v0.5.0 Pod/Usage/;
12 use TFBS::DB::FlatFileDirscip-perl cpan TFBS v0.5.0 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 GetOptionsscip-perl cpan TFBS v0.5.0 main/GetOptions().('help' => \$help,
20 'database=s' => \$database_dir,
21 'id-only' => \$id_only,
22 'verbose' => \$verbose
23 );
24
25 if($help) {
26 pod2usagescip-perl cpan TFBS v0.5.0 main/pod2usage().(-exitstatus=>0, -verbose=>2);
27 }
28 elsif (!$database_dir) {
29 pod2usagescip-perl cpan TFBS v0.5.0 main/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->connectscip-perl cpan TFBS v0.5.0 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_MatrixSetscip-perl cpan TFBS v0.5.0 TFBS/DB/FlatFileDir/get_MatrixSet().(-matrixtype=>"PFM");
45
46
47 # print heading if normal output
48
49 unless ($id_only or $verbose) {
50 printfscip-perl cpan TFBS v0.5.0 main/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) { printscip-perl cpan TFBS v0.5.0 main/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->Iteratorscip-perl cpan TFBS v0.5.0 main/Iterator().(-sort_by=>'ID');
64
65
66 while (my $pfm = $mx_iterator->nextscip-perl cpan TFBS v0.5.0 main/next().()) { #for each matrix in the set
67 if ($verbose) {
68 printscip-perl cpan TFBS v0.5.0 main/print(). ("\n","-"x65);
69 printscip-perl cpan TFBS v0.5.0 main/print(). ("\nMatrix ID : ", $pfm->IDscip-perl cpan TFBS v0.5.0 main/ID().);
70 printscip-perl cpan TFBS v0.5.0 main/print(). ("\nTransctiption factor name : ", $pfm->namescip-perl cpan TFBS v0.5.0 main/name().);
71 printscip-perl cpan TFBS v0.5.0 main/print(). ("\nStructural class : ", $pfm->classscip-perl cpan TFBS v0.5.0 main/class().);
72 printscip-perl cpan TFBS v0.5.0 main/print(). ("\nTotal information content : ",
73 sprintfscip-perl cpan TFBS v0.5.0 main/sprintf().("%2.2f",$pfm->to_ICMscip-perl cpan TFBS v0.5.0 main/to_ICM().->total_icscip-perl cpan TFBS v0.5.0 main/total_ic().));
74 printscip-perl cpan TFBS v0.5.0 main/print(). ("\nMatrix:\n", $pfm->prettyprintscip-perl cpan TFBS v0.5.0 main/prettyprint().);
75
76 printscip-perl cpan TFBS v0.5.0 main/print(). ("","-"x65,"\n\n");
77 }
78 elsif ($id_only) {
79 printscip-perl cpan TFBS v0.5.0 main/print(). ($pfm->IDscip-perl cpan TFBS v0.5.0 main/ID()., "\t", $pfm->namescip-perl cpan TFBS v0.5.0 main/name()., "\n");
80 }
81 else {
82 printfscip-perl cpan TFBS v0.5.0 main/printf().(" %-10s%-15s%-20s%10s%10.2f\n",
83 $pfm->IDscip-perl cpan TFBS v0.5.0 main/ID()., $pfm->namescip-perl cpan TFBS v0.5.0 main/name()., $pfm->classscip-perl cpan TFBS v0.5.0 main/class().,
84 $pfm->lengthscip-perl cpan TFBS v0.5.0 main/length()., $pfm->to_ICMscip-perl cpan TFBS v0.5.0 main/to_ICM().->total_icscip-perl cpan TFBS v0.5.0 main/total_ic().);
85 }
86 }
87
88 # print the line for normal and verbouse output
89
90 unless($id_only) {
91 printscip-perl cpan TFBS v0.5.0 main/print(). ("-"x70, "\nTotal ", $matrixset->sizescip-perl cpan TFBS v0.5.0 main/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