package PGF::GapResolution::ParseContigOrientation; =head1 NAME PGF::GapResolution::ParseContigOrientation =head1 SYNOPSIS use PGF::GapResolution::ParseContigOrientation; my $obj = PGF::GapResolution::ParseContigOrientation->new($contigOrientationFile); my @contigs = $obj->getAllContigs(); foreach my $contig (@contigs) { my $orientation = $obj->getOrientation($contig); ... } =head1 DESCRIPTION This module parses the contigOrientation.txt file generated by the module PGF::Newbler::Scaffolds454.pm as part of the Gap Resolution sub system and contains access methods to the data. The format of the contigOrientation.txt file are as follows, whereby each entry is separated by a tab, one per line: 1. contigName 2. orientation (+/-) =head1 AUTHOR(s) Stephan Trong =head1 HISTORY =over =item * Stephan Trong 12/17/2008 Creation =back =cut #============================================================================# use strict; use Carp; use Carp qw(cluck); use FindBin qw($RealBin); use lib "$FindBin::RealBin/../lib"; #============================================================================# sub new { my $class = shift; my $file = shift; my $self = {}; bless $self, $class; $self->_parseFile( $file); return $self; } #============================================================================# sub _parseFile { my $self = shift; my $file = shift; my %attribs = (); my @contigs = (); unless (open FH, $file ) { confess "ERROR: failed to open file $file: $!"; } while ( my $entry = ) { chomp $entry; next if !length $entry; if ( $entry =~ /^(\S+)\t(\S+)$/ ) { $attribs{$1} = $2; push @contigs, $1; } } close FH; $self->{_attribs} = \%attribs; $self->{_contigs} = \@contigs; } #============================================================================# sub getAllContigs { my $self = shift; my @contigs = (); if ( defined @{$self->{_contigs}} ) { @contigs = @{$self->{_contigs}}; } return @contigs; } #============================================================================# sub getOrientation { my $self = shift; my $contig = shift; my $orientation = ''; if ( exists $self->{_attribs}{$contig} ) { $orientation = $self->{_attribs}{$contig}; } return $orientation; } #============================================================================# 1;