#!/usr/bin/env perl =head1 NAME tagCTAce Script to add Consensus Tags to an ace file. =head1 SYNOPSIS tagCTAce [options] Options: -s Silent mode; don't print status on screen. -trans Allow the transfer of ace file tags (takes precedence over entry in input file) -notrans Do not allow the transfer of ace file tags (takes precedence over entry in input file) -h Detailed help message. =head1 DESCRIPTION Items are tagged according to the following tab delimited format: =over =item - contigName =item - tagType =item - tag source =item - unpadded startOfRegion =item - unpadded endOfRegion =item - isNoTrans (1 or 0) =item - comment =back =head1 VERSION $Revision: 1.10 $ $Date: 2010-05-12 22:27:23 $ =head1 HISTORY =over =item * Stephan Trong 08/05/2009 - print number of tags added to ace file. =item * Brian Foster 02/06/2008 Simplified version (no duplicate checking) to boost performance. =item * Brian Foster 09/13/2007 Modified from tagAceForPolishing =item * Stephan Trong 09/25/2006 Creation =back =cut use strict; use FindBin qw($RealBin); use lib "$RealBin/../lib"; use PGF::Parsers::ParseAce; use PGF::Polishing::TagAceFile; use Pod::Usage; use Getopt::Long; use vars qw($optHelp $optSilentMode $optTrans $optNoTrans); #============================================================================# # INPUT VALIDATION #============================================================================# if( !GetOptions( "h"=>\$optHelp, "trans"=>\$optTrans, "notrans"=>\$optNoTrans, "s"=>\$optSilentMode, ) ) { pod2usage(); exit 1; } pod2usage(-verbose=>2) and exit 1 if defined $optHelp; pod2usage and exit 1 if @ARGV != 2; my ($tagsFile, $aceFile) = @ARGV; if ( !-e $aceFile ) { print STDERR "Cannot find your ace file $aceFile\n"; exit 1; } my $ace = PGF::Parsers::ParseAce->parse($aceFile,{-verbose=>0}); my $TAG_OBJECT = PGF::Polishing::TagAceFile->new(aceObject=>$ace); my (%contigs, $contigName); %contigs = map {$_,'1'} $ace->allContigs(); my ($tmp,%tags); open IN, "$tagsFile" or die "Can't open $tagsFile\n"; while (){ chomp; if (($tmp = $_) =~ tr/\t// != 6){ warn "input requires 6 tab delimited fields $tmp\n"; next; } ($contigName = $_) =~ s/^(\S*)\t.*$/$1/; if (!exists($contigs{$contigName})){ warn "Contig $contigName not found in $aceFile\n"; next; } push @{$tags{$contigName}},&generateTagHash($_); } open(OUT,">>$aceFile") or die "can't open $aceFile\n"; my @consensusTags; foreach $contigName (sort keys %tags){ $TAG_OBJECT->doNotDuplicateConsensusTags($contigName); foreach my $tag (@{$tags{$contigName}}){ my $isNoTrans = $tag->{'isNoTrans'}; $isNoTrans = 1 if $optNoTrans; $isNoTrans = 0 if $optTrans; my $consTag = $TAG_OBJECT->makeConsensusTag( contig=>$tag->{'contig'}, nameOfProgram=>$tag->{'nameOfProgram'}, unpaddedStart=>$tag->{'unpaddedStart'}, unpaddedStop=>$tag->{'unpaddedStop'}, tagType=>$tag->{'tagType'}, isNoTrans=>$isNoTrans, additionalInfo=>$tag->{'additionalInfo'} ); push @consensusTags, $consTag if length $consTag; } } if ( @consensusTags ) { print OUT map "$_\n\n", @consensusTags; #add to acefile print scalar(@consensusTags), " tags added to $aceFile\n"; #add to acefile } close(OUT); #============================================================================# sub generateTagHash{ my $line = $_[0]; my %returnHash; chomp $line; my ($contig, $tagType, $nameOfProgram, $unpaddedStart, $unpaddedStop, $isNoTrans, $comment) = split (/\t/,$line); $returnHash{'contig'} = $contig; $returnHash{'tagType'} = $tagType; $returnHash{'nameOfProgram'} = $nameOfProgram; $returnHash{'unpaddedStart'} = $unpaddedStart; $returnHash{'unpaddedStop'} = $unpaddedStop; $returnHash{'isNoTrans'} = $isNoTrans; $returnHash{'additionalInfo'} = ($comment) ? "\nCOMMENT\{\n${comment}\nC\}" : ""; return \%returnHash; } 1;