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

View of /FigKernelScripts/make_fam_tabs.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (download) (as text) (annotate)
Mon Dec 5 18:56:37 2005 UTC (14 years, 5 months ago) by olson
Branch: MAIN
Changes since 1.3: +17 -0 lines
Add license words.

#
# Copyright (c) 2003-2006 University of Chicago and Fellowship
# for Interpretations of Genomes. All Rights Reserved.
#
# This file is part of the SEED Toolkit.
# 
# The SEED Toolkit is free software. You can redistribute
# it and/or modify it under the terms of the SEED Toolkit
# Public License. 
#
# You should have received a copy of the SEED Toolkit Public License
# along with this program; if not write to the University of Chicago
# at info@ci.uchicago.edu or the Fellowship for Interpretation of
# Genomes at veronika@thefig.info or download a copy from
# http://www.theseed.org/LICENSE.TXT.
#


$usage = "usage: make_fam_tabs Sources Synonyms Dir";

(
 ($sources = shift @ARGV) &&
 ($syn     = shift @ARGV) &&
 ($dir     = shift @ARGV)
)
    || die $usage;

open(TAB1,">$dir/localid_cid")       || die "could not open $dir/localid_cid";
open(TAB2,">$dir/localfam_cid")      || die "could not open $dir/localfam_cid";
open(TAB3,">$dir/localfam_function") || die "could not open $dir/localfam_function";

opendir(SOURCES,$sources) || die "could not open $sources";
@specific = grep { $_ !~ /^\./ } readdir(SOURCES);
closedir(SOURCES);

open(SYN,"<$syn") || die "could not open $syn";
$cid = 1;
while (defined($_ = <SYN>))
{
    chomp;
    @prots = split(/\t/,$_);
    foreach $prot (@prots)
    {
	print TAB1 "$prot\t$cid\n";
	$to_cid{$prot} = $cid;
    }
    $cid++;
}


foreach $source (@specific)
{
    next unless (-d "$sources/$source"); # don't try and process it if it is not a directory!
    open(IDMAP,"<$sources/$source/id.map") || die "could not open $sources/$source/id.map";
    while (defined($_ = <IDMAP>))
    {
	chomp;
	($fam,$lid) = split(/\t/,$_);
	if (!$to_cid{$lid}) 
	{
	 # we don't have a synonym for this protein
	 # we can either ignore it or just give it a unique id. Lets do that.
	 $to_cid{$lid}=$cid; 
	 $cid++;
	 # and write it to the file
	 print TAB1 "$prot\t$cid\n";
	}
	print TAB2 "$fam\t$to_cid{$lid}\n";
    }
    close(IDMAP);

    if (open(FAMFUNC,"<$sources/$source/family.funcs"))
    {
	while (defined($_ = <FAMFUNC>))
	{
	    # ignore things that begin with a # or things that are just white space
	    # some files also have the last line with just a | on it. This should just be skipped
	    next if (/^\s+$/ || /^\s*\#/ || /^\|/);
	    chomp;
	    # this was originally written with this regexp
	    # but there were problems when the function was not defined and also with some functions
	    # that had leading or trailing spaces. These are removed now.
	    #if (($_ =~ /^(\S+)\t(\S[^\t]*\S)$/) && (length($2) < 256))
	    
	    if ($_ !~ /\t/) {print STDERR "Not enough columns in $sources/$source/family.funcs at $_\n"; next}
	    my @line=split /\t/;
	    if ($#line > 1) {print STDERR "Too many columns in $sources/$source/family.funcs at $_\n"; next}
	    
	    # trim leading and trailing spaces
	    $line[1] =~ s/^\s+//; $line[1] =~ s/\s*$//; 
	    $line[0] =~ s/^\s+//; $line[0] =~ s/\s*$//; 

	    # define the function if it is unknown
            unless (defined $line[1]) {$line[1] = "unknown"}
	    print TAB3 join("\t", @line), "\n";
	
	}
	close(FAMFUNC);
    }
}

close(TAB1);
close(TAB2);
close(TAB3);

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3