]> git.donarmstrong.com Git - biopieces.git/blob - code_perl/Maasha/GFF.pm
8d8a20b70a563fe9428e049596f9fd3fe1e07b33
[biopieces.git] / code_perl / Maasha / GFF.pm
1 package Maasha::GFF;
2
3
4 # Copyright (C) 2007-2008 Martin A. Hansen.
5
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
20 # http://www.gnu.org/copyleft/gpl.html
21
22
23 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
24
25
26 # Routines for manipulation 'Generic Feature Format' - GFF.
27
28
29 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
30
31
32 use strict;
33 use Data::Dumper;
34 use Maasha::Common;
35
36 use vars qw( @ISA @EXPORT_OK );
37
38 require Exporter;
39
40 @ISA = qw( Exporter );
41
42
43 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
44
45
46 sub get_entry
47 {
48     # Martin A. Hansen, February 2008.
49
50     # Reads a single entry from a filehandle to a GFF file.
51
52     my ( $fh,   # file handle
53        ) = @_;
54
55     # Returns hashref.
56
57     my ( $line, @fields, %entry, $q_beg, $q_end, @atts, $att, $key, $val );
58
59     while ( $line = <$fh> )
60     {
61         chomp $line;
62
63         @fields = split "\t", $line;
64     
65         if ( @fields == 9 )
66         {
67             $q_beg = $fields[ 3 ] - 1;
68             $q_end = $fields[ 4 ] - 1;
69
70             ( $q_beg, $q_end ) = ( $q_end, $q_beg ) if $q_beg > $q_end;
71
72             %entry = (
73                 Q_ID       => $fields[ 0 ],
74                 SOURCE     => $fields[ 1 ],
75                 TYPE       => $fields[ 2 ],
76                 Q_BEG      => $q_beg,
77                 Q_END      => $q_end,
78                 SCORE      => $fields[ 5 ],
79                 STRAND     => $fields[ 6 ],
80                 PHASE      => $fields[ 7 ],
81                 ATT        => $fields[ 8 ],
82             );
83
84             @atts = split ";", $fields[ 8 ];
85
86             foreach $att ( @atts )
87             {
88                 ( $key, $val ) = split "=", $att;
89             
90                 $entry{ "ATT_" . uc $key } = $val;
91             }
92
93             return wantarray ? %entry : \%entry;
94         }
95     }
96 }
97
98
99 sub get_entries
100 {
101     # Martin A. Hansen, February 2008.
102
103     # Reads GFF file and returns a list of entries.
104
105     my ( $path,   # full path to GFF file.
106        ) = @_;
107
108     # Returns a list.
109
110     my ( $fh, $entry, @entries );
111
112     $fh = &Maasha::Common::read_open( $path );
113
114     while ( $entry = &get_entry( $fh ) ) {
115         push @entries, $entry;
116     }
117
118     close $fh;
119
120     return wantarray ? @entries : \@entries;
121 }
122
123
124 sub put_entry
125 {
126
127
128 }
129
130
131 sub put_entries
132 {
133
134
135 }
136
137
138 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
139
140 1;