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

Annotation of /FigKernelScripts/process_sim_deletions_and_replacements.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (view) (download) (as text)

1 : olson 1.3 #
2 :     # Copyright (c) 2003-2006 University of Chicago and Fellowship
3 :     # for Interpretations of Genomes. All Rights Reserved.
4 :     #
5 :     # This file is part of the SEED Toolkit.
6 :     #
7 :     # The SEED Toolkit is free software. You can redistribute
8 :     # it and/or modify it under the terms of the SEED Toolkit
9 :     # Public License.
10 :     #
11 :     # You should have received a copy of the SEED Toolkit Public License
12 :     # along with this program; if not write to the University of Chicago
13 :     # at info@ci.uchicago.edu or the Fellowship for Interpretation of
14 :     # Genomes at veronika@thefig.info or download a copy from
15 :     # http://www.theseed.org/LICENSE.TXT.
16 :     #
17 :    
18 : overbeek 1.1
19 :     use strict;
20 :     use FIG;
21 :    
22 :     my $usage = "usage: process_sim_deletions_and_replacements InDir OutDir Replaced Deleted";
23 :    
24 : overbeek 1.2 my($in_dir,$out_dir,$rep,$del);
25 : overbeek 1.1
26 :     (
27 :     ($in_dir = shift @ARGV) &&
28 :     ($out_dir = shift @ARGV) &&
29 :     ($rep = shift @ARGV) && open(REP,"<$rep") &&
30 :     ($del = shift @ARGV) && open(DEL,"<$del")
31 :     )
32 :     || die $usage;
33 :    
34 : overbeek 1.2 my %replace_with;
35 : overbeek 1.1 while (defined($_ = <REP>))
36 :     {
37 :     if ($_ =~ /^(\S+)\t(\S+)/)
38 :     {
39 :     $replace_with{$1} = $2;
40 :     }
41 :     }
42 :     close(REP);
43 :    
44 : overbeek 1.2 my %to_delete;
45 : overbeek 1.1 while (defined($_ = <DEL>))
46 :     {
47 :     if ($_ =~ /^(\S+)/)
48 :     {
49 :     $to_delete{$1} = 1;
50 :     }
51 :     }
52 :     close(DEL);
53 :    
54 :     opendir(SIMS,$in_dir)
55 :     || die "could not open $in_dir";
56 : overbeek 1.2 my @files = grep { $_ !~ /^\./ } readdir(SIMS);
57 : overbeek 1.1 closedir(SIMS);
58 :    
59 :    
60 :     mkdir($out_dir,0777) || die "could not make $out_dir";
61 :    
62 : overbeek 1.2 my($file,$rep1,$rep2,$id1,$id2,$x);
63 : overbeek 1.1 foreach $file (@files)
64 :     {
65 :     print STDERR "processing $file\n";
66 :     open(OLD,"<$in_dir/$file")
67 :     || die "could not open $in_dir/$file";
68 :    
69 :     open(NEW,">$out_dir/$file")
70 :     || die "could not open $out_dir/$file";
71 :    
72 : overbeek 1.2 while (defined($_ = <OLD>))
73 : overbeek 1.1 {
74 :     if ($_ =~ /^(\S+)\t(\S+)/)
75 :     {
76 :     if (! ($to_delete{$1} || $to_delete{$2}))
77 :     {
78 :     $rep1 = $replace_with{$1};
79 :     $rep2 = $replace_with{$2};
80 :     if ((! $rep1) && (! $rep2))
81 :     {
82 : overbeek 1.2 print NEW $_;
83 : overbeek 1.1 }
84 :     elsif ($_ -~ /^(\S+)\t(\S+)(.*)$/)
85 :     {
86 :     $id1 = ($x = $replace_with{$1}) ? $x : $1;
87 :     $id2 = ($x = $replace_with{$2}) ? $x : $2;
88 : overbeek 1.2 print NEW "$id1\t$id2\t$3\n";
89 : overbeek 1.1 }
90 :     }
91 :     }
92 :     }
93 : overbeek 1.2 close(OLD);
94 :     close(NEW);
95 : overbeek 1.1 }

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3