package PGF::Polishing::TagAceFile; =head1 NAME PGF::Polishing::TagAceFile Module for adding consensus tags to ace file. =head1 VERSION $Revision: 1.5 $ $Date: 2009-08-26 17:18:36 $ =head1 SYNOPSIS =head1 DESCRIPTION Adds consensus tags to an existing ace file. =head1 AUTHOR(S) Stephan Trong =head1 HISTORY =over =item * Stephan Trong 10/03/2006 Creation =back =cut #============================================================================# use strict; use warnings; use Carp; use vars qw($RealBin); use FindBin qw($RealBin); use lib "$RealBin/../lib"; use PGF::Parsers::ParseAce::Unpad; my $_unpadObject = PGF::Parsers::ParseAce::Unpad->new(); #============================================================================# sub new { my $class = shift; my %params = @_; if ( !defined $params{aceObject} ) { die "aceObject must be defined."; } my $self = { _aceObject=>$params{aceObject}, _consensusTags=>{} }; bless $self, $class; return $self; } #============================================================================# sub doNotDuplicateConsensusTags { my $self = shift; my $contigName = shift; my $aceObject = $self->{_aceObject}; my %consensusTagsForThisContig = (); my @ctags = $aceObject->tag('CT'); foreach my $rawAceCtTag (@ctags) { # look for tag like: # 'Contig1 polishLowQualConsensus findPolishingRegions 12760 1304' # if ( $rawAceCtTag =~ /^($contigName \S+ \S+ \-*\d+ \-*\d+)/ ) { $consensusTagsForThisContig{$1} = 1; } } $self->{_consensusTags} = \%consensusTagsForThisContig; } #============================================================================# sub makeConsensusTag { my $self = shift; my %params = @_; my $contigName = $params{contig}; my $unpaddedStart = $params{unpaddedStart}; my $unpaddedStop = $params{unpaddedStop}; my $tagType = $params{tagType}; my $nameOfProgram = $params{nameOfProgram} || 'unknown'; my $isNoTrans = $params{isNoTrans} || 0; my $additionalInfo = $params{additionalInfo} || ''; # need to get contig sequence in order to prepare unpad object for # converting upad to pad positions. The code snippit is placed in # a block to free up memory after the unpad object has been initialized. # { if ( defined $self->{_previousContig} && $self->{_previousContig} eq $contigName ) { $_unpadObject = $self->{_previousContigUnpadObject}; } else{ my $aceObject = $self->{_aceObject}; my $contigDataRef = $aceObject->contig($contigName); my $paddedContigSequence = $contigDataRef->{sequence}; $_unpadObject->use($paddedContigSequence); $self->{_previousContigUnpadObject} = $_unpadObject; $self->{_previousContig} = $contigName; } } # get date and time # my $datetime = $self->getCurrentDateTime(); my $unpadObj = PGF::Parsers::ParseAce::Unpad->new(); # convert unpadded start and stop pos to padded pos. # my $paddedStart = $_unpadObject->unpadToPad($unpaddedStart); my $paddedStop = $_unpadObject->unpadToPad($unpaddedStop); # Create ace tag. # my $aceCtTag = "$contigName". " $tagType". " $nameOfProgram". " $paddedStart". " $paddedStop"; # If noDuplicateConsensusTags was previously called, then check this # consensus tag with ones already present in ace file for this contig. # If found, then return empty string. Otherwise, return string of the # consesus tag. # if ( %{$self->{_consensusTags}} && defined $self->{_consensusTags}{$aceCtTag} ) { return ''; } else { $aceCtTag .= " $datetime"; $aceCtTag .= " NoTrans" if $isNoTrans; $aceCtTag .= " $additionalInfo" if length $additionalInfo; $aceCtTag = "CT{\n".$aceCtTag."\n}"; return $aceCtTag; } } #============================================================================# sub getCurrentConsensusTags { my $self = shift; return keys %{$self->{_consensusTags}}; } #============================================================================# sub getCurrentDateTime { my $self = shift; my ($sec,$min,$hr,$day,$mon,$year) = localtime(time()); $year+=1900; $year =~ s/^\d{2}//; # get last 2 digits of year only. $year = sprintf("%02d",$year); $mon = sprintf("%02d",++$mon); $day = sprintf("%02d",$day); $hr = sprintf("%02d",$hr); $min = sprintf("%02d",$min); $sec = sprintf("%02d",$sec); my $datetime = "$year$mon$day:$hr$min$sec"; return $datetime; } #============================================================================# 1;