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

View of /FigKernelScripts/extract_fasta_idmap.pl

Parent Directory Parent Directory | Revision Log Revision Log

Revision 1.1 - (download) (as text) (annotate)
Thu May 4 05:32:50 2006 UTC (13 years, 9 months ago) by overbeek
Branch: MAIN
CVS Tags: mgrast_dev_08112011, rast_rel_2009_05_18, mgrast_dev_08022011, rast_rel_2014_0912, rast_rel_2008_06_18, myrast_rel40, rast_rel_2008_06_16, mgrast_dev_05262011, rast_rel_2008_12_18, mgrast_dev_04082011, rast_rel_2008_07_21, rast_rel_2010_0928, rast_2008_0924, mgrast_version_3_2, mgrast_dev_12152011, rast_rel_2008_04_23, mgrast_dev_06072011, rast_rel_2008_09_30, rast_rel_2009_0925, rast_rel_2010_0526, rast_rel_2014_0729, mgrast_dev_02212011, rast_rel_2010_1206, mgrast_release_3_0, mgrast_dev_03252011, rast_rel_2010_0118, mgrast_rel_2008_0924, mgrast_rel_2008_1110_v2, rast_rel_2009_02_05, rast_rel_2011_0119, mgrast_rel_2008_0625, mgrast_release_3_0_4, mgrast_release_3_0_2, mgrast_release_3_0_3, mgrast_release_3_0_1, mgrast_dev_03312011, mgrast_release_3_1_2, mgrast_release_3_1_1, mgrast_release_3_1_0, mgrast_dev_04132011, rast_rel_2008_10_09, mgrast_dev_04012011, rast_release_2008_09_29, mgrast_rel_2008_0806, mgrast_rel_2008_0923, mgrast_rel_2008_0919, rast_rel_2009_07_09, rast_rel_2010_0827, mgrast_rel_2008_1110, myrast_33, rast_rel_2011_0928, rast_rel_2008_09_29, mgrast_rel_2008_0917, rast_rel_2008_10_29, mgrast_dev_04052011, mgrast_dev_02222011, rast_rel_2009_03_26, mgrast_dev_10262011, rast_rel_2008_11_24, rast_rel_2008_08_07, HEAD
RAE: Adding FigKernelScripts/extract_fasta_idmap.pl


=head1 extract_fasta_idmap

Extract three files from the BRC directories that are downloaded from BRC central. This just extracts the files assigned_functions, org.table, and fasta from each of the NMPDR organisms. You can then use something like build_nr to make the id mapping that we can use to build the create aliases and essentially identical protein links in the SEED


use strict;
use URI::Escape;

my $usage=<<EOF;

-d directory of GFF3's or directory of directory of GFF3's


my $dir;
while (@ARGV)
    my $t=shift;
    if ($t eq "-d") {$dir=shift}

die $usage unless ($dir);

if (-e "$dir/assigned_functions") {print STDERR "$dir/assigned_functions already exists. Overwritting. Oops.\n"}
if (-e "$dir/fasta")  {print STDERR "$dir/fasta already exists. Overwritting. Oops.\n"}

$dir =~ s/\/$//;
my @links=&links($dir);

open(ORG, ">$dir/org.table") || die "Can't open $dir/orgs";
open(IDMAP, ">$dir/assigned_functions") || die "Can't open $dir/assigned_functions";
open(FASTA, ">$dir/fasta") || die "CAn't open $dir/fasta";

my @files;
opendir(DIR, $dir) || die "Can't open $dir";
foreach my $f (grep {$_ !~ /^\./} readdir(DIR))
    if (-d "$dir/$f")
        opendir(SUB, "$dir/$f") || die "Can't open subdir $dir/$f";
        foreach my $s (grep {$_ !~ /^\./} readdir(SUB))
            if ($s =~ /gff$/i || $s =~ /gff3$/i || ($s =~ /gz$/ && $s =~ /gff3/)) {push @files, "$dir/$f/$s"}
            else {print STDERR "Not sure what $dir/$f/$s is\n"}
    elsif ($f =~ /gff/i || $f =~ /gff3$/i || ($f =~ /gz$/ && $f =~ /gff3/)) {push @files, "$dir/$f"}
foreach my $file (@files)
    if ($file =~ /gz$/) {open(IN, "gunzip -c $file|") || die "Can't open a pipe to gzip"}
    else {open(IN, $file) || die "Can't open $file"}
    my $fasta; my $id; my %cds; my $taxon;
    my $print=0; my %gene; my $organism;
    while (<IN>)
        if (/\t/ && $_ !~ /\;$/) {$_.=";"; s/\t\;$/\;/} #this is beautiful so that the regexps below match even at the end of the line :)
        if (/^\#\#FASTA/) {$fasta=1; next}
        if (/^\#\#gff-version/) {undef $fasta; next}
        if (/Dbxref=taxon:(\w+?)[\;\,]/) {$taxon=$1}
        if (/organism_name\=(.*?)\;/) {$organism=$1;}
        if (/strain\=(.*?)\;/) {$organism.=" ".$1; print STDERR "ORG: $organism\n";}
        next if (/^\#/);
        if ($print == -1) 
            print STDERR substr($_, 0, 10), "\n";
            undef $print;

        unless ($fasta) 
            my @line=split /\t/;
            if ($#line == 8)
                my %data=map
                        my @a=split /\=/, $_;
                    } split /\;/, $line[$#line];
                if ($dir eq "ApiDB" && $line[2] eq "mRNA") {$id->{$data{"ID"}}=\%data}
                if (uc($line[2]) eq "GENE" || $line[2] =~ /rna/i) {$gene{$data{"ID"}}=1}

                # We need to save all possible IDs and see that we have an ID for and a protein sequence
                # for each ID
                #if ($data{"translation_id"}) 
                #    $gene{$data{"ID"}}=1;
                #    $data{"ID"}=$data{"translation_id"}
                # map the things that could be used as identifiers for the protein sequences

                if (uc($line[2]) eq "CDS")
                    if (!$data{"ID"}) {print STDERR "No ID in $_\n"}
                    foreach my $potential (qw[translation_id Name ID]) {$cds{$data{$potential}}=1}

                if ($dir eq "ApiDB" && uc($line[2]) eq "CDS") 
                foreach my $potential (qw[translation_id Name ID]) {$id->{$data{$potential}}=\%data}
                #if ($data{"description"} && $data{"ID"}) {$id->{$data{"ID"}}=$data{"description"}}
                #elsif ($data{"Name"} && $data{"ID"}) {$id->{$data{"ID"}}=$data{"Name"}}
            elsif ($#line > 1) {print STDERR "Not enough (too many?) tabs in $_\n"}
            if (/^>(\S+)/)
                my $name=$1;
                if ($name eq "ntbp01.cds.A02644") {print STDERR "HELP ************** Found $name at 1\n"}
                if ($cds{$name}) 
                if ($name eq "ntbp01.cds.A02644") {print STDERR "HELP ************** Found $name at 2\n"}
                    my $ext_id=lc($dir)."|".join(".", map {$id->{$name}->{$_}} @links);
                    if ($ext_id =~ /\|$/) {$ext_id .= $name}
                    print ORG "$ext_id\t$organism\n";
                        if ($id->{$name}->{"description"}) {print IDMAP "$ext_id\t", uri_unescape($id->{$name}->{"description"}), "\n"}
                        elsif ($id->{$name}->{"Name"}) {print IDMAP "$ext_id\t", uri_unescape($id->{$name}->{"Name"}), "\n"}
                            print STDERR "No function for $name ($ext_id). Assigned Hypothetical\n";
                            print IDMAP "$ext_id\tHypothetical Protein\n";
                if ($name eq "ntbp01.cds.A02644") {print STDERR "HELP ************** Found $name at 3 and used $ext_id\n"}

                        print FASTA ">$ext_id\n";
                elsif ($gene{$name})  {undef $print}
                    print STDERR "$name does not appear to be a CDS. These are the first 10 characters: ";

            print FASTA "$_\n" if ($print > 0);

sub links {
my $need=shift;
my %data=(
    ApiDB   => ["taxon", "locus"],
    #ApiDB   => ["locus"],
    ERIC    => ["ID"],
    PATRIC  => ["ID"],
    TIGR    => ["locus"],
    VBRC    => ["ID"],
    VectorBase => ["ID"],
    NMPDR   => ["Dbxref"],
    BHB     => ["ID"],
unless (defined $data{$need}) {die "Sorry, don't have links for $need"}
return @{$data{$need}};

sub fulllinks {
my %data=(
    return \%data;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3