[Bio] / Sprout / SimLoad.pl Repository:
ViewVC logotype

Annotation of /Sprout/SimLoad.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : parrello 1.1 #!/usr/bin/perl -w
2 :    
3 :     use strict;
4 :     use CGI;
5 :     use Tracer;
6 :     use Genome;
7 :     use SimBlocks;
8 :     use File::Path;
9 : parrello 1.2 use BasicLocation;
10 : parrello 1.3 use Cwd;
11 : parrello 1.1
12 :     =head1 Similarity Block Loader
13 :    
14 :     This script loads the similarity block database from
15 : parrello 1.3 the input files. The load process involves two steps:
16 :     converting the input files into C<dtx> load files
17 :     (B<generate>), and loading the C<dtx> files into the
18 :     database (B<load>).
19 : parrello 1.1
20 : parrello 1.3 The script takes a single parameter-- a directory name.
21 : parrello 1.1 The default directory name is taken from the config file
22 :     parameter C<$fig_config::SimBlastData>. The output files
23 :     will be produced in the similarity block data directory
24 :     C<$fig_config::SimBlockData>, which will be created if
25 : parrello 1.3 it does not exist. The input directory and all its
26 :     subdirectories will be processed for input files.
27 : parrello 1.1
28 :     In addition to the directory name, the following
29 :     option parameters are supported.
30 :    
31 :     =over 4
32 :    
33 :     =item trace
34 :    
35 :     Trace level for output messages. A higher number means more
36 : parrello 1.4 messages. The default is C<3>. Trace messages are sent to
37 : parrello 1.3 the file C<trace.log> in the B<$FIG_Config::tmp>
38 :     directory.
39 : parrello 1.1
40 : parrello 1.4 =item sql
41 :    
42 :     If specified, SQL activity will be traced at the specified
43 :     trace level.
44 :    
45 : parrello 1.1 =item load
46 :    
47 :     C<yes> to load the data into the database, else C<no>.
48 :     The default is C<yes>.
49 :    
50 :     =item generate
51 :    
52 :     C<yes> to generate output files from input files, else
53 :     C<no>. The default is C<yes>.
54 :    
55 :     =back
56 :    
57 :     For example, the following command line will process the
58 : parrello 1.3 input files in the C</Users/fig/BlastData> directory and
59 : parrello 1.1 run at a trace level of 3.
60 :    
61 : parrello 1.3 C<< SimLoad -trace=3 /Users/fig/BlastData >>
62 :    
63 :     The following command line converts the input files in
64 :     the default directory into load files but does not load
65 :     the database and runs at a trace level of 2.
66 : parrello 1.1
67 : parrello 1.3 C<< SimLoad -load=no >>
68 : parrello 1.1
69 :     =head2 Input Directory
70 :    
71 : parrello 1.3 The following files must exist in each input directory.
72 : parrello 1.1
73 :     =over 4
74 :    
75 :     =item Genome.tbl
76 :    
77 :     This is a tab-delimited file that contains the ID of each
78 :     genome followed by a description string.
79 :    
80 :     =item Block.tbl, InterGenic_Block.tbl
81 :    
82 :     These are tab-delimited files that associate a gene name
83 :     with each block. The InterGenic file is optional.
84 :    
85 :     =item Region.tbl, InterGenic_Region.tbl
86 :    
87 :     These are tab-delimited files that describe each region
88 :     of a block. The InterGenic file is optional.
89 :    
90 :     =back
91 :    
92 :     The format of each file is given below.
93 :    
94 :     =head3 Genome.tbl
95 :    
96 :     The Genome file is copied almost unmodified to the
97 :     load file for the B<Genome> entity. Each record
98 :     represents a single genome. It has the following
99 :     fields.
100 :    
101 :     =over 4
102 :    
103 :     =item genomeID
104 :    
105 :     The ID of the genome.
106 :    
107 :     =item description
108 :    
109 :     A text description of the genome (usually the species name with
110 :     a strain ID).
111 :    
112 :     =back
113 :    
114 :     =head3 Block.tbl, InterGenic_Block.tbl
115 :    
116 :     These files produce most of the data found in the B<GroupBlock>
117 :     entity. Each record represents a single block. Blocks either
118 :     correspond to genes or to inter-genic regions. Both types
119 :     of blocks may appear in multiple locations in multiple
120 :     contigs. The files should be sorted by block ID.
121 :    
122 :     =over 4
123 :    
124 :     =item blockID
125 :    
126 :     The unique ID of the block. This ID is also used in the
127 :     C<Region.tbl> file.
128 :    
129 :     =item blockName
130 :    
131 :     The name of the block. For a gene block, this is the gene
132 :     name. For an inter-genic block, it is a name computed
133 :     from the names of the genes that are commonly nearby.
134 :    
135 :     =back
136 :    
137 :     =head3 Region.tbl, InterGenic_Region.tbl
138 :    
139 :     These files describe the regions in each block. They are
140 :     used to derive the relationships between genomes and
141 :     contigs (B<ConsistsOf>), the contigs themselves
142 :     (B<Contig>), the relationships between blocks and
143 :     contigs (B<ContainsRegionIn>), and the derived
144 :     relationship between genomes and blocks
145 :     (B<HasInstanceOf>). The files must be sorted by block
146 :     ID, and each record in a file represents a single
147 :     region in a contig. Each region belongs to a
148 :     single block. Note that the C<Region.tbl> file contains
149 :     the regions for the C<Block.tbl> file, and the
150 :     C<InterGenic_Region.tbl> file contains the regions for
151 :     the C<InterGenic_Block.tbl> file. No mixing is allowed.
152 :    
153 :     =over 4
154 :    
155 :     =item regionPEG
156 :    
157 :     PEG ID for this region. If the region is in an
158 :     inter-genic block, this field will be composed of
159 :     the IDs for the neighboring genes.
160 :    
161 :     =item genomeID
162 :    
163 :     ID of the relevant genome.
164 :    
165 :     =item contigID
166 :    
167 :     ID of the contig containing this region. This is a standard contig
168 :     ID that does not include the genome ID. It will be converted to
169 :     a Sprout-style contig ID (which includes the genome data) before
170 :     it is written to the output files.
171 :    
172 :     =item begin
173 :    
174 :     The start point of the region. For a forward region this is the
175 :     left endpoint; for a reverse region it is the right endpoint. It
176 :     is a 1-based offset (which is consistent with Sprout usage), and
177 :     the identified location is inside the region.
178 :    
179 :     =item end
180 :    
181 :     The end point of the region. For a forward region this is the
182 :     right endpoint; for a reverse region it is the left endpoint. It
183 :     is a 1-based offset (which is consistent with Sprout usage), and
184 :     the identified location is inside the region.
185 :    
186 :     =item blockID
187 :    
188 :     The ID of the block containing this region.
189 :    
190 :     =item snippet
191 :    
192 :     A DNA snippet representing the contents of the region. The region
193 :     may be shorter than the block length. If that is the case, the
194 :     snippet will contain insertion characters (C<->). So, while it
195 :     is not the case that every region in a block must be the same
196 :     length, all of the snippets for a block must be the same length.
197 :     The snippets will be in alignment form. In other words, if the
198 :     region is reversed, the nucleotide letters will be the complement
199 :     in transcription order. (For example, if positions 20 through 25
200 :     of contig B<XXX> are C<AGCCTT>, then the snippet for C<XXX_25_20>
201 :     will be C<AAGGCT>.)
202 :    
203 :     =back
204 :    
205 :     =head2 Output File Notes
206 :    
207 :     =over 4
208 :    
209 :     =item Genome.dtx
210 :    
211 :     This file is a direct copy of the C<Genome.tbl> file; however, we
212 :     also use it to create a hash of genome IDs (C<%genomes>). The hash
213 :     is useful when validating the C<Region.tbl> file.
214 :    
215 :     =item Contig.dtx
216 :    
217 :     This file contains nothing but contig IDs. As contigs are
218 :     discovered from the C<Region.tbl> file their IDs are put
219 :     into the C<%contigs> hash. This hash maps contig IDs to
220 :     their parent genome IDs. When processing is complete,
221 :     this file is generated from the hash.
222 :    
223 :     =item GroupBlock.dtx
224 :    
225 :     This file describes the blocks. As records come in from
226 :     C<Region.tbl>, we build a hash called C<%blockData> that
227 :     contains our latest estimate of all the C<GroupBlock.dtx>
228 :     columns for the current block (with the exception of
229 :     B<variance>, which is computed by dividing the B<snip-count>
230 :     by the length (B<len>).
231 :    
232 :     =item ConsistsOf.dtx
233 :    
234 :     This file maps genomes to contigs, and is generated from
235 :     the C<%contigs> hash built while reading the C<Region.tbl>
236 :     file.
237 :    
238 :     =item HasInstanceOf.dtx
239 :    
240 :     This file lists the genomes containing each block. The
241 :     C<Region.tbl> file is sorted by block. While inside a
242 :     block's section of the file, we use a hash called
243 :     C<%genomesFound> that contains the ID of every genome
244 :     found for the block. When we finish with a block,
245 :     we run through the C<%genomesFound> hash to produce
246 :     the block's B<HasInstanceOf> data.
247 :    
248 :     =item Region.dtx
249 :    
250 :     This file describes the contig regions in the blocks.
251 :     As the C<Region.tbl> file is read in, we build a
252 :     hash called C<%regionMap> that maps a region's
253 :     SEED-style location string to the DNA content.
254 :     When we finish with a block, the DNA content is
255 :     converted into an alignment by comparing it to
256 :     the block's pattern in C<%blockData>. (Essentially,
257 :     we only include the region's content for the
258 :     positions that vary between regions in the block.)
259 :     From this and the region string itself, we have
260 :     enough data to create the B<Region>
261 :     data.
262 :    
263 :     =item IncludesRegion.dtx
264 :    
265 :     This file maps group blocks to regions. The first column
266 :     is the block ID and the second column is the SEED-style
267 :     region string for the target region. This file is built
268 :     in parallel with C<Region.dtx>. It will have one record
269 :     for each region.
270 :    
271 :     =item ContainsRegion.dtx
272 :    
273 :     This file maps contigs to regions. The first column is
274 :     the contig ID and the second column is the SEED-style
275 :     location string for the region. It contains two redundant
276 :     columns used for sorting-- the region length (column 3)
277 :     and the left-most region position (column 4). This
278 :     file is built in parallel with C<Region.dtx>. It will
279 :     have one record for each region.
280 :    
281 :     =cut
282 :    
283 :     # Create a huge number we can use for an end-of-file
284 :     # indicator in the block ID.
285 :     my $TRAILER = 999999999;
286 :    
287 :     # Parse the command line.
288 : parrello 1.5 my ($options, @arguments) = StandardSetup(['SimBlocks'],
289 :     { load => ['yes', "'no' to suppress loading the database"],
290 :     generate => ['yes', "'no' to suppress generating the load files"]
291 :     },
292 :     "directoryName",
293 : parrello 1.1 @ARGV);
294 :     # Extract the directory name from the argument array.
295 : parrello 1.3 my $inDirectoryTree = $FIG_Config::simBlastData;
296 : parrello 1.1 if ($arguments[0]) {
297 : parrello 1.3 $inDirectoryTree = Cwd::abs_path($arguments[0]);
298 : parrello 1.1 }
299 :     # Get the output directory.
300 :     my $outDirectory = $FIG_Config::simBlocksData;
301 :     # Insure that it exists.
302 :     if (! -d $outDirectory) {
303 : parrello 1.3 Trace("Creating output directory $outDirectory.") if T(2);
304 : parrello 1.1 mkpath($outDirectory);
305 : parrello 1.4 } elsif ($options->{generate} eq 'yes') {
306 :     # Here we have an output directory already and are going to generate new
307 :     # load files. Clear any leftover data from previous runs.
308 : parrello 1.3 my @files = grep { $_ =~ /.dtx$/ } Tracer::OpenDir($outDirectory);
309 :     my $numFiles = @files;
310 :     if ($numFiles > 0) {
311 :     Trace("Deleting $numFiles old dtx files from $outDirectory.") if T(2);
312 :     unlink map { "$outDirectory/$_" } @files;
313 :     }
314 : parrello 1.1 }
315 : parrello 1.3 # Create an error counter and a directory counter.
316 : parrello 1.1 my $errorCount = 0;
317 : parrello 1.3 my $dirCount = 0;
318 : parrello 1.1 # Check to see if we should generate the output files.
319 :     if ($options->{generate} eq 'no') {
320 :     # Here we are to use existing output files.
321 : parrello 1.3 Trace("Existing database load files will be used.") if T(2);
322 : parrello 1.1 } else {
323 :     # Here we need to produce new output files.
324 :     # Verify that the input directory exists.
325 : parrello 1.3 if (! -d $inDirectoryTree) {
326 :     Confess("Input directory \"$inDirectoryTree\" not found.");
327 : parrello 1.1 }
328 : parrello 1.3 # Loop through the subdirectories.
329 :     for my $inputDirectory (Tracer::OpenDir($inDirectoryTree, 0)) {
330 :     # Verify that this is a directory. If it's ".", we use
331 :     # the top-level directory.
332 :     my $inDirectory = ($inputDirectory eq "." ? $inDirectoryTree :
333 :     "$inDirectoryTree/$inputDirectory");
334 :     if (($inputDirectory !~ /\../) && -d $inDirectory) {
335 :     # Here we have a directory to process. Check for a genome
336 :     # file.
337 :     my $genomeFileName = "$inDirectory/Genome.tbl";
338 :     if (! -e $genomeFileName) {
339 :     Trace("$genomeFileName not found. Directory skipped.") if T(1);
340 :     } else {
341 :     # Now we can process the directory and accumulate the error
342 :     # count.
343 :     $errorCount += ProcessDirectory($inDirectory, $outDirectory);
344 :     $dirCount++;
345 :     }
346 :     }
347 :     }
348 :     Trace("Load files generated from $dirCount directories.") if T(2);
349 :     }
350 :     # Check for errors.
351 :     if ($errorCount > 0) {
352 :     Trace("$errorCount errors found in input files.") if T(0);
353 :     } else {
354 :     # No errors, so it's okay to load the database.
355 :     if ($options->{load} eq 'yes') {
356 :     # Here we have no outstanding errors and the user wants us to load
357 :     # the database. First, we create a similarity block object.
358 :     my $simBlocks = SimBlocks->new();
359 :     # Use it to load the database. Note we specify that the tables are to be
360 :     # dropped and rebuilt.
361 :     $simBlocks->LoadTables($outDirectory, 1);
362 :     Trace("Database loaded.") if T(2);
363 :     }
364 :     }
365 :    
366 :     # Process a single input directory.
367 :     sub ProcessDirectory {
368 :     my ($inDirectory, $outDirectory) = @_;
369 :     Trace("Processing directory $inDirectory.") if T(2);
370 : parrello 1.1 # Our first task is to copy the genome data to the output directory
371 : parrello 1.3 # and add them to the genome list.
372 : parrello 1.1 my %genomes = ();
373 : parrello 1.3 Open(\*GENOMESIN, "<$inDirectory/Genome.tbl");
374 :     Open(\*GENOMESOUT, ">>$outDirectory/Genome.dtx");
375 :     # Count the genomes read and errors found.
376 : parrello 1.1 my $genomeCount = 0;
377 : parrello 1.3 my $errorCount = 0;
378 : parrello 1.1 # Loop through the input.
379 :     while (my $genomeData = <GENOMESIN>) {
380 :     # Echo the genome record to the output.
381 :     print GENOMESOUT $genomeData;
382 :     # Extract the genome ID.
383 :     my ($genomeID) = Tracer::ParseRecord($genomeData);
384 :     # Store it in the genomes hash. We start with a value of 0. If
385 :     # contig information for the genome is found, we change the value
386 :     # to 1. When we're all done with the regions, we can check the
387 :     # hash to insure all the genomes were represented in the input.
388 :     $genomes{$genomeID} = 0;
389 :     # Count this genome.
390 :     $genomeCount++;
391 :     }
392 : parrello 1.3 Trace("$genomeCount genomes found.") if T(2);
393 : parrello 1.1 # Close the files.
394 :     close GENOMESIN;
395 :     close GENOMESOUT;
396 :     # Create the contig hash used to associate contigs to their parent
397 :     # genomes.
398 :     my %contigs = ();
399 :     # Now we begin to read the Block and Region files in parallel. Both
400 :     # are sorted by block ID, so all processing for this section of the
401 :     # script is done a block at a time. The first task is to
402 :     # open the output files.
403 : parrello 1.3 Open(\*BLOCKSOUT, ">>$outDirectory/GroupBlock.dtx");
404 :     Open(\*REGIONSOUT, ">>$outDirectory/Region.dtx");
405 :     Open(\*INSTANCESOUT, ">>$outDirectory/HasInstanceOf.dtx");
406 :     Open(\*CONTAINSOUT, ">>$outDirectory/ContainsRegion.dtx");
407 :     Open(\*INCLUDESOUT, ">>$outDirectory/IncludesRegion.dtx");
408 : parrello 1.1 # Determine which file sets we'll be processing.
409 :     my @fileSets = ();
410 :     my @prefixes = ("", "InterGenic_");
411 :     for my $prefix (@prefixes) {
412 :     if (-e "$inDirectory/${prefix}Block.tbl") {
413 :     push @fileSets, $prefix;
414 :     }
415 :     }
416 : parrello 1.3 # Set up the duplicate-region check.
417 :     my %allRegions = ();
418 : parrello 1.1 # Set up some counters.
419 :     my ($blocksCount, $regionsCount) = (0, 0);
420 :     # Loop through the useful file sets.
421 :     for my $fileSet (@fileSets) {
422 : parrello 1.3 Open(\*BLOCKSIN, "<$inDirectory/${fileSet}Block.tbl");
423 :     Open(\*REGIONSIN, "<$inDirectory/${fileSet}Region.tbl");
424 :     Trace("Processing ${fileSet}Blocks.") if T(2);
425 : parrello 1.1 # The outer loop processes blocks. This is accomplished by reading
426 :     # through the block file. We prime the loop by reading the first
427 :     # region record. This is because we finish processing a block when
428 :     # the first record of the next block is found in the region file.
429 :     my %regionRecord = GetRegionRecord();
430 :     $regionsCount++;
431 :     while (my $blockRecord = <BLOCKSIN>) {
432 :     $blocksCount++;
433 :     # Parse the block record.
434 :     my ($blockID, $blockName, $pegID) = Tracer::ParseRecord($blockRecord);
435 :     # Create the block data for this block.
436 :     my %blockData = ( id => $blockID, description => $blockName );
437 :     # Initialize the tracking hashes. "genomesFound" tracks the
438 : parrello 1.2 # genomes whose contigs are represented by the block,
439 : parrello 1.1 # "regionMap" maps each region to its contents, and
440 :     # "regionPeg" maps each region to its PEG (if any).
441 :     my %genomesFound = ();
442 :     my %regionMap = ();
443 :     my %regionPeg = ();
444 :     # Count the number of regions found in this block.
445 :     my $regionCounter = 0;
446 :     # Loop through the regions in the block. Because of the way
447 :     # "GetRegionRecord" works, the "blockID" field will have an
448 :     # impossibly high value if we've hit end-of-file in the
449 :     # region input file.
450 :     while ($regionRecord{blockID} <= $blockID) {
451 :     # If this region's block ID is invalid, complain
452 :     # and skip it.
453 :     if ($regionRecord{blockID} != $blockID) {
454 : parrello 1.3 Trace("Block $regionRecord{blockID} in region record $regionsCount not found in block input file at record $blocksCount.") if T(0);
455 : parrello 1.1 $errorCount++;
456 :     } else {
457 :     # Here both files are in sync, which is good. The next step is
458 :     # to connect with the Genome and the Contig.
459 :     my $genomeID = $regionRecord{genomeID};
460 :     my $contigID = "$genomeID:$regionRecord{contigID}";
461 :     if (! exists $genomes{$genomeID}) {
462 : parrello 1.3 Trace("Genome $genomeID in region record $regionsCount not found in genome input file.") if T(0);
463 : parrello 1.1 $errorCount++;
464 :     } else {
465 :     # Denote this genome has an instance of this block.
466 :     $genomesFound{$genomeID} = 1;
467 :     # Denote this genome has occurred in the region file.
468 :     $genomes{$genomeID} = 1;
469 :     # Connect the contig to the genome.
470 :     $contigs{$contigID} = $genomeID;
471 :     # Now we need to process the snippet. First, we create a
472 :     # region string.
473 :     my $regionString = "${contigID}_$regionRecord{begin}_$regionRecord{end}";
474 :     # Next, we stuff the snippet and PEG in the region's hash entries.
475 :     my $snippet = $regionRecord{snippet};
476 :     $regionMap{$regionString} = $snippet;
477 :     $regionPeg{$regionString} = $regionRecord{peg};
478 :     # Check to see if this is the block's first snippet.
479 :     if (! exists $blockData{pattern}) {
480 :     # Here it is, so store the snippet as the pattern.
481 :     $blockData{pattern} = $snippet;
482 :     $blockData{"snip-count"} = 0;
483 :     $blockData{len} = length $snippet;
484 :     } elsif ($blockData{len} != length $snippet) {
485 :     # Here it is not the first, but the lengths do not match.
486 : parrello 1.3 Trace("Snippet for region record $regionsCount does not match block length $blockData{len}.") if T(0);
487 : parrello 1.1 $errorCount++;
488 :     } else {
489 :     # Here everything is legitimate, so we merge the new
490 :     # snippet into the pattern.
491 :     ($blockData{pattern}, $blockData{"snip-count"}) =
492 :     SimBlocks::MergeDNA($blockData{pattern}, $snippet);
493 :     }
494 :     }
495 :     # Count this region.
496 :     $regionCounter++;
497 :     }
498 :     # Get the next region record.
499 :     %regionRecord = GetRegionRecord();
500 :     }
501 :     # We have now processed all the regions in the block. Insure we found at least
502 :     # one.
503 :     if (! $regionCounter) {
504 : parrello 1.3 Trace("No regions found for block $blockID at $blocksCount in block input file.") if T(0);
505 : parrello 1.1 $errorCount++;
506 :     } else {
507 : parrello 1.4 Trace("$regionCounter regions found in block $blockID.") if T(4);
508 : parrello 1.1 # Write the block record.
509 :     my $variance = $blockData{"snip-count"} / $blockData{len};
510 :     print BLOCKSOUT join("\t", $blockID, $blockData{description}, $blockData{len},
511 :     $blockData{"snip-count"}, $variance, $blockData{pattern}) . "\n";
512 :     # Find all the variance points in the block pattern. We'll use them to create
513 :     # the content strings for each region.
514 :     my @positions = SimBlocks::ParsePattern($blockData{pattern});
515 :     # Loop through the regions, writing them out to the region output file.
516 :     for my $region (keys %regionMap) {
517 : parrello 1.3 if (length($region) > 80) {
518 :     Trace("Invalid region key \"$region\".") if T(1);
519 :     }
520 : parrello 1.1 # Get the region's snips.
521 :     my $source = $regionMap{$region};
522 :     my $content = "";
523 :     for my $pos (@positions) {
524 :     $content .= substr $source, $pos, 1;
525 :     }
526 :     # Get the region's location data.
527 : parrello 1.2 my $location = BasicLocation->new($region);
528 : parrello 1.1 # Write this region to the output files.
529 :     print REGIONSOUT join("\t", $region, $location->Contig, $location->Dir,
530 : parrello 1.3 $location->Right, $location->Length,
531 :     $regionPeg{$region}, $location->Left, $content) . "\n";
532 : parrello 1.1 print CONTAINSOUT join("\t", $location->Contig, $region,
533 :     $location->Length, $location->Left) . "\n";
534 : parrello 1.4 print INCLUDESOUT join("\t", $blockID, $region) . "\n";
535 : parrello 1.1 }
536 :     # Finally, we need to connect this block to the genomes in which it occurs.
537 :     for my $genomeID (keys %genomesFound) {
538 :     print INSTANCESOUT join("\t", $genomeID, $blockID) . "\n";
539 :     }
540 :     # Count this block's regions.
541 :     $regionsCount += $regionCounter;
542 :     }
543 :     }
544 :     # Close the input files.
545 :     close BLOCKSIN;
546 :     close REGIONSIN;
547 :     }
548 :     # Close the output files.
549 :     close REGIONSOUT;
550 :     close BLOCKSOUT;
551 :     close INSTANCESOUT;
552 :     # All the block data has been written. Tell the user what we found.
553 : parrello 1.3 Trace("$blocksCount blocks processed, $regionsCount regions processed.") if T(2);
554 : parrello 1.1 # The next task is to write the genome/contig data. This is provided by the
555 :     # "%contigs" hash. First, we need to open the files.
556 :     my $contigsCount = 0;
557 : parrello 1.3 Open(\*CONTIGSOUT, ">>$outDirectory/Contig.dtx");
558 :     Open(\*CONSISTSOUT, ">>$outDirectory/ConsistsOf.dtx");
559 : parrello 1.1 for my $contigID (keys %contigs) {
560 :     print CONTIGSOUT "$contigID\n";
561 :     print CONSISTSOUT join("\t", $contigs{$contigID}, $contigID) . "\n";
562 :     $contigsCount++;
563 :     }
564 : parrello 1.3 Trace("$contigsCount contigs found.") if T(2);
565 : parrello 1.4 # Close the output files.
566 :     close CONTIGSOUT;
567 :     close CONSISTSOUT;
568 : parrello 1.1 # Now warn the user about all the genomes that didn't have blocks.
569 :     for my $genomeID (keys %genomes) {
570 :     if (! $genomes{$genomeID}) {
571 : parrello 1.3 Trace("Genome $genomeID did not have any regions.") if T(1);
572 : parrello 1.1 $errorCount++;
573 :     }
574 :     }
575 : parrello 1.3 return $errorCount;
576 : parrello 1.1 }
577 :     # Tell the user we're done.
578 : parrello 1.3 Trace("Processing complete.") if T(0);
579 : parrello 1.1
580 :     # Read a region record from the file and parse it into a hash
581 :     # for return to the caller. If we reach end-of-file, the
582 :     # hash returned will have $TRAILER in the blockID field.
583 :     sub GetRegionRecord {
584 :     # Create the return hash.
585 :     my %retVal = ();
586 :     # Read the record.
587 :     my $regionData = <REGIONSIN>;
588 :     # Check for end-of-file.
589 :     if (!defined $regionData) {
590 :     # Here we have end-of-file, so stuff in a trailer
591 :     # value for the block ID.
592 :     $retVal{blockID} = $TRAILER;
593 :     } else {
594 :     # Here we have a real record.
595 :     ($retVal{peg}, $retVal{genomeID}, $retVal{contigID},
596 :     $retVal{begin}, $retVal{end}, $retVal{blockID},
597 :     $retVal{snippet}) = Tracer::ParseRecord($regionData);
598 :     }
599 :     # Return the hash created.
600 :     return %retVal;
601 :     }
602 :    
603 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3