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

Annotation of /Sprout/SimLoad.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3