[Bio] / FigKernelScripts / rewrite_peg_syns.pl Repository:
ViewVC logotype

View of /FigKernelScripts/rewrite_peg_syns.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (download) (as text) (annotate)
Fri May 3 17:29:19 2013 UTC (6 years, 6 months ago) by redwards
Branch: MAIN
CVS Tags: rast_rel_2014_0729, rast_rel_2014_0912, HEAD
 a set of scripts for adding phage genomes to the seed

#__perl--

# rewrite and merge peg.synonyms file with a partial file. For example, after adding a genome, you might run sims_after_adding_genome which then creates a partial sims file
# this will take that file, and the existing peg.synonyms file and merge them.
#
# Rob Edwards
# Nov 11, 2009

use strict;
use Getopt::Std;
my %opts;
getopts('n:o:d:', \%opts);
unless ($opts{n} && $opts{o} && $opts{d}) {
	die <<EOF;
$0
-n new peg synonyms that will be appended to old ones
-o directory where old peg synonyms file is
-d directory where new peg synonyms should end up
EOF
}

unless (-e "$opts{o}/peg.synonyms") {die "OLD FILE: $opts{o}/peg.synonyms does not exist!"}
unless (-e "$opts{n}") {die "NEW FILE: $opts{n} does not exist!"}
if (-e "$opts{d}/peg.synonyms") {die "Cowardly won't overwrite $opts{d}/peg.synonyms"}

open(IN, $opts{n}) || die "can't open $opts{n}";
my $line;
while (<IN>) {
	chomp;
	my ($md5, $matches)=split /\t/;
	foreach my $tple (split /\;/, $matches) {
		my ($peg, $len)=split /\,/, $tple;
		$line->{$md5}->{$peg}=$len;
	}
}
close IN;

open(IN, "$opts{o}/peg.synonyms") || die "can't open $opts{o}/peg.synonyms";
open(OUT, ">$opts{d}/peg.synonyms") || die "can't write to $opts{d}/peg.synonyms";
while (<IN>) {
	my ($md5, $matches)=split /\t/;
	if ($line->{$md5}) {
		chomp($matches);
		foreach my $tple (split /\;/, $matches) {
			my ($peg, $len)=split /\,/, $tple;
			$line->{$md5}->{$peg}=$len;
		}
	}
	else {
		print OUT;
	}
}
foreach my $md5 (keys %$line) {
	print OUT "$md5\t", join(";", map {$_="$_,".$line->{$md5}->{$_}} keys %{$line->{$md5}}), "\n";
}
close IN;
close OUT;


MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3