File: feature_serializer.pm

package info (click to toggle)
libbio-db-gff-perl 1.7.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,216 kB
  • sloc: perl: 9,976; makefile: 2
file content (37 lines) | stat: -rw-r--r-- 1,030 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package Bio::DB::GFF::Adaptor::memory::feature_serializer;
$Bio::DB::GFF::Adaptor::memory::feature_serializer::VERSION = '1.7.4';

=head1 NAME

Bio::DB::GFF::Adaptor::memory::feature_serializer - utility methods for serializing and deserializing GFF features

=cut

use strict;

require Exporter;
use vars qw(@EXPORT @EXPORT_OK @hash2array_map);
use base qw(Exporter);
@EXPORT_OK = qw(feature2string string2feature @hash2array_map);
@EXPORT = @EXPORT_OK;

@hash2array_map = qw(ref start stop source method score strand phase gclass gname tstart tstop feature_id group_id bin);

sub feature2string {
  my $feature = shift;
  local $^W = 0;
  my @a = @{$feature}{@hash2array_map};
  push @a,map {join "\0",@$_} @{$feature->{attributes}} if $feature->{attributes};
  return join $;,@a;
}

sub string2feature {
  my $string  = shift;
  my (@attributes,%feature);
  (@feature{@hash2array_map},@attributes) = split $;,$string;
  $feature{attributes} = [map {[split "\0",$_]} @attributes];
  undef $feature{group_id};
  \%feature;
}

1;