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

Annotation of /Sprout/SimLoad.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (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.4 my ($options, @arguments) = Tracer::StandardSetup(['SimBlocks'],
289 :     { load => 'yes',
290 :     generate => 'yes'},
291 : parrello 1.1 @ARGV);
292 :     # Extract the directory name from the argument array.
293 : parrello 1.3 my $inDirectoryTree = $FIG_Config::simBlastData;
294 : parrello 1.1 if ($arguments[0]) {
295 : parrello 1.3 $inDirectoryTree = Cwd::abs_path($arguments[0]);
296 : parrello 1.1 }
297 :     # Get the output directory.
298 :     my $outDirectory = $FIG_Config::simBlocksData;
299 :     # Insure that it exists.
300 :     if (! -d $outDirectory) {
301 : parrello 1.3 Trace("Creating output directory $outDirectory.") if T(2);
302 : parrello 1.1 mkpath($outDirectory);
303 : parrello 1.4 } elsif ($options->{generate} eq 'yes') {
304 :     # Here we have an output directory already and are going to generate new
305 :     # load files. Clear any leftover data from previous runs.
306 : parrello 1.3 my @files = grep { $_ =~ /.dtx$/ } Tracer::OpenDir($outDirectory);
307 :     my $numFiles = @files;
308 :     if ($numFiles > 0) {
309 :     Trace("Deleting $numFiles old dtx files from $outDirectory.") if T(2);
310 :     unlink map { "$outDirectory/$_" } @files;
311 :     }
312 : parrello 1.1 }
313 : parrello 1.3 # Create an error counter and a directory counter.
314 : parrello 1.1 my $errorCount = 0;
315 : parrello 1.3 my $dirCount = 0;
316 : parrello 1.1 # Check to see if we should generate the output files.
317 :     if ($options->{generate} eq 'no') {
318 :     # Here we are to use existing output files.
319 : parrello 1.3 Trace("Existing database load files will be used.") if T(2);
320 : parrello 1.1 } else {
321 :     # Here we need to produce new output files.
322 :     # Verify that the input directory exists.
323 : parrello 1.3 if (! -d $inDirectoryTree) {
324 :     Confess("Input directory \"$inDirectoryTree\" not found.");
325 : parrello 1.1 }
326 : parrello 1.3 # Loop through the subdirectories.
327 :     for my $inputDirectory (Tracer::OpenDir($inDirectoryTree, 0)) {
328 :     # Verify that this is a directory. If it's ".", we use
329 :     # the top-level directory.
330 :     my $inDirectory = ($inputDirectory eq "." ? $inDirectoryTree :
331 :     "$inDirectoryTree/$inputDirectory");
332 :     if (($inputDirectory !~ /\../) && -d $inDirectory) {
333 :     # Here we have a directory to process. Check for a genome
334 :     # file.
335 :     my $genomeFileName = "$inDirectory/Genome.tbl";
336 :     if (! -e $genomeFileName) {
337 :     Trace("$genomeFileName not found. Directory skipped.") if T(1);
338 :     } else {
339 :     # Now we can process the directory and accumulate the error
340 :     # count.
341 :     $errorCount += ProcessDirectory($inDirectory, $outDirectory);
342 :     $dirCount++;
343 :     }
344 :     }
345 :     }
346 :     Trace("Load files generated from $dirCount directories.") if T(2);
347 :     }
348 :     # Check for errors.
349 :     if ($errorCount > 0) {
350 :     Trace("$errorCount errors found in input files.") if T(0);
351 :     } else {
352 :     # No errors, so it's okay to load the database.
353 :     if ($options->{load} eq 'yes') {
354 :     # Here we have no outstanding errors and the user wants us to load
355 :     # the database. First, we create a similarity block object.
356 :     my $simBlocks = SimBlocks->new();
357 :     # Use it to load the database. Note we specify that the tables are to be
358 :     # dropped and rebuilt.
359 :     $simBlocks->LoadTables($outDirectory, 1);
360 :     Trace("Database loaded.") if T(2);
361 :     }
362 :     }
363 :    
364 :     # Process a single input directory.
365 :     sub ProcessDirectory {
366 :     my ($inDirectory, $outDirectory) = @_;
367 :     Trace("Processing directory $inDirectory.") if T(2);
368 : parrello 1.1 # Our first task is to copy the genome data to the output directory
369 : parrello 1.3 # and add them to the genome list.
370 : parrello 1.1 my %genomes = ();
371 : parrello 1.3 Open(\*GENOMESIN, "<$inDirectory/Genome.tbl");
372 :     Open(\*GENOMESOUT, ">>$outDirectory/Genome.dtx");
373 :     # Count the genomes read and errors found.
374 : parrello 1.1 my $genomeCount = 0;
375 : parrello 1.3 my $errorCount = 0;
376 : parrello 1.1 # Loop through the input.
377 :     while (my $genomeData = <GENOMESIN>) {
378 :     # Echo the genome record to the output.
379 :     print GENOMESOUT $genomeData;
380 :     # Extract the genome ID.
381 :     my ($genomeID) = Tracer::ParseRecord($genomeData);
382 :     # Store it in the genomes hash. We start with a value of 0. If
383 :     # contig information for the genome is found, we change the value
384 :     # to 1. When we're all done with the regions, we can check the
385 :     # hash to insure all the genomes were represented in the input.
386 :     $genomes{$genomeID} = 0;
387 :     # Count this genome.
388 :     $genomeCount++;
389 :     }
390 : parrello 1.3 Trace("$genomeCount genomes found.") if T(2);
391 : parrello 1.1 # Close the files.
392 :     close GENOMESIN;
393 :     close GENOMESOUT;
394 :     # Create the contig hash used to associate contigs to their parent
395 :     # genomes.
396 :     my %contigs = ();
397 :     # Now we begin to read the Block and Region files in parallel. Both
398 :     # are sorted by block ID, so all processing for this section of the
399 :     # script is done a block at a time. The first task is to
400 :     # open the output files.
401 : parrello 1.3 Open(\*BLOCKSOUT, ">>$outDirectory/GroupBlock.dtx");
402 :     Open(\*REGIONSOUT, ">>$outDirectory/Region.dtx");
403 :     Open(\*INSTANCESOUT, ">>$outDirectory/HasInstanceOf.dtx");
404 :     Open(\*CONTAINSOUT, ">>$outDirectory/ContainsRegion.dtx");
405 :     Open(\*INCLUDESOUT, ">>$outDirectory/IncludesRegion.dtx");
406 : parrello 1.1 # Determine which file sets we'll be processing.
407 :     my @fileSets = ();
408 :     my @prefixes = ("", "InterGenic_");
409 :     for my $prefix (@prefixes) {
410 :     if (-e "$inDirectory/${prefix}Block.tbl") {
411 :     push @fileSets, $prefix;
412 :     }
413 :     }
414 : parrello 1.3 # Set up the duplicate-region check.
415 :     my %allRegions = ();
416 : parrello 1.1 # Set up some counters.
417 :     my ($blocksCount, $regionsCount) = (0, 0);
418 :     # Loop through the useful file sets.
419 :     for my $fileSet (@fileSets) {
420 : parrello 1.3 Open(\*BLOCKSIN, "<$inDirectory/${fileSet}Block.tbl");
421 :     Open(\*REGIONSIN, "<$inDirectory/${fileSet}Region.tbl");
422 :     Trace("Processing ${fileSet}Blocks.") if T(2);
423 : parrello 1.1 # The outer loop processes blocks. This is accomplished by reading
424 :     # through the block file. We prime the loop by reading the first
425 :     # region record. This is because we finish processing a block when
426 :     # the first record of the next block is found in the region file.
427 :     my %regionRecord = GetRegionRecord();
428 :     $regionsCount++;
429 :     while (my $blockRecord = <BLOCKSIN>) {
430 :     $blocksCount++;
431 :     # Parse the block record.
432 :     my ($blockID, $blockName, $pegID) = Tracer::ParseRecord($blockRecord);
433 :     # Create the block data for this block.
434 :     my %blockData = ( id => $blockID, description => $blockName );
435 :     # Initialize the tracking hashes. "genomesFound" tracks the
436 : parrello 1.2 # genomes whose contigs are represented by the block,
437 : parrello 1.1 # "regionMap" maps each region to its contents, and
438 :     # "regionPeg" maps each region to its PEG (if any).
439 :     my %genomesFound = ();
440 :     my %regionMap = ();
441 :     my %regionPeg = ();
442 :     # Count the number of regions found in this block.
443 :     my $regionCounter = 0;
444 :     # Loop through the regions in the block. Because of the way
445 :     # "GetRegionRecord" works, the "blockID" field will have an
446 :     # impossibly high value if we've hit end-of-file in the
447 :     # region input file.
448 :     while ($regionRecord{blockID} <= $blockID) {
449 :     # If this region's block ID is invalid, complain
450 :     # and skip it.
451 :     if ($regionRecord{blockID} != $blockID) {
452 : parrello 1.3 Trace("Block $regionRecord{blockID} in region record $regionsCount not found in block input file at record $blocksCount.") if T(0);
453 : parrello 1.1 $errorCount++;
454 :     } else {
455 :     # Here both files are in sync, which is good. The next step is
456 :     # to connect with the Genome and the Contig.
457 :     my $genomeID = $regionRecord{genomeID};
458 :     my $contigID = "$genomeID:$regionRecord{contigID}";
459 :     if (! exists $genomes{$genomeID}) {
460 : parrello 1.3 Trace("Genome $genomeID in region record $regionsCount not found in genome input file.") if T(0);
461 : parrello 1.1 $errorCount++;
462 :     } else {
463 :     # Denote this genome has an instance of this block.
464 :     $genomesFound{$genomeID} = 1;
465 :     # Denote this genome has occurred in the region file.
466 :     $genomes{$genomeID} = 1;
467 :     # Connect the contig to the genome.
468 :     $contigs{$contigID} = $genomeID;
469 :     # Now we need to process the snippet. First, we create a
470 :     # region string.
471 :     my $regionString = "${contigID}_$regionRecord{begin}_$regionRecord{end}";
472 :     # Next, we stuff the snippet and PEG in the region's hash entries.
473 :     my $snippet = $regionRecord{snippet};
474 :     $regionMap{$regionString} = $snippet;
475 :     $regionPeg{$regionString} = $regionRecord{peg};
476 :     # Check to see if this is the block's first snippet.
477 :     if (! exists $blockData{pattern}) {
478 :     # Here it is, so store the snippet as the pattern.
479 :     $blockData{pattern} = $snippet;
480 :     $blockData{"snip-count"} = 0;
481 :     $blockData{len} = length $snippet;
482 :     } elsif ($blockData{len} != length $snippet) {
483 :     # Here it is not the first, but the lengths do not match.
484 : parrello 1.3 Trace("Snippet for region record $regionsCount does not match block length $blockData{len}.") if T(0);
485 : parrello 1.1 $errorCount++;
486 :     } else {
487 :     # Here everything is legitimate, so we merge the new
488 :     # snippet into the pattern.
489 :     ($blockData{pattern}, $blockData{"snip-count"}) =
490 :     SimBlocks::MergeDNA($blockData{pattern}, $snippet);
491 :     }
492 :     }
493 :     # Count this region.
494 :     $regionCounter++;
495 :     }
496 :     # Get the next region record.
497 :     %regionRecord = GetRegionRecord();
498 :     }
499 :     # We have now processed all the regions in the block. Insure we found at least
500 :     # one.
501 :     if (! $regionCounter) {
502 : parrello 1.3 Trace("No regions found for block $blockID at $blocksCount in block input file.") if T(0);
503 : parrello 1.1 $errorCount++;
504 :     } else {
505 : parrello 1.4 Trace("$regionCounter regions found in block $blockID.") if T(4);
506 : parrello 1.1 # Write the block record.
507 :     my $variance = $blockData{"snip-count"} / $blockData{len};
508 :     print BLOCKSOUT join("\t", $blockID, $blockData{description}, $blockData{len},
509 :     $blockData{"snip-count"}, $variance, $blockData{pattern}) . "\n";
510 :     # Find all the variance points in the block pattern. We'll use them to create
511 :     # the content strings for each region.
512 :     my @positions = SimBlocks::ParsePattern($blockData{pattern});
513 :     # Loop through the regions, writing them out to the region output file.
514 :     for my $region (keys %regionMap) {
515 : parrello 1.3 if (length($region) > 80) {
516 :     Trace("Invalid region key \"$region\".") if T(1);
517 :     }
518 : parrello 1.1 # Get the region's snips.
519 :     my $source = $regionMap{$region};
520 :     my $content = "";
521 :     for my $pos (@positions) {
522 :     $content .= substr $source, $pos, 1;
523 :     }
524 :     # Get the region's location data.
525 : parrello 1.2 my $location = BasicLocation->new($region);
526 : parrello 1.1 # Write this region to the output files.
527 :     print REGIONSOUT join("\t", $region, $location->Contig, $location->Dir,
528 : parrello 1.3 $location->Right, $location->Length,
529 :     $regionPeg{$region}, $location->Left, $content) . "\n";
530 : parrello 1.1 print CONTAINSOUT join("\t", $location->Contig, $region,
531 :     $location->Length, $location->Left) . "\n";
532 : parrello 1.4 print INCLUDESOUT join("\t", $blockID, $region) . "\n";
533 : parrello 1.1 }
534 :     # Finally, we need to connect this block to the genomes in which it occurs.
535 :     for my $genomeID (keys %genomesFound) {
536 :     print INSTANCESOUT join("\t", $genomeID, $blockID) . "\n";
537 :     }
538 :     # Count this block's regions.
539 :     $regionsCount += $regionCounter;
540 :     }
541 :     }
542 :     # Close the input files.
543 :     close BLOCKSIN;
544 :     close REGIONSIN;
545 :     }
546 :     # Close the output files.
547 :     close REGIONSOUT;
548 :     close BLOCKSOUT;
549 :     close INSTANCESOUT;
550 :     # All the block data has been written. Tell the user what we found.
551 : parrello 1.3 Trace("$blocksCount blocks processed, $regionsCount regions processed.") if T(2);
552 : parrello 1.1 # The next task is to write the genome/contig data. This is provided by the
553 :     # "%contigs" hash. First, we need to open the files.
554 :     my $contigsCount = 0;
555 : parrello 1.3 Open(\*CONTIGSOUT, ">>$outDirectory/Contig.dtx");
556 :     Open(\*CONSISTSOUT, ">>$outDirectory/ConsistsOf.dtx");
557 : parrello 1.1 for my $contigID (keys %contigs) {
558 :     print CONTIGSOUT "$contigID\n";
559 :     print CONSISTSOUT join("\t", $contigs{$contigID}, $contigID) . "\n";
560 :     $contigsCount++;
561 :     }
562 : parrello 1.3 Trace("$contigsCount contigs found.") if T(2);
563 : parrello 1.4 # Close the output files.
564 :     close CONTIGSOUT;
565 :     close CONSISTSOUT;
566 : parrello 1.1 # Now warn the user about all the genomes that didn't have blocks.
567 :     for my $genomeID (keys %genomes) {
568 :     if (! $genomes{$genomeID}) {
569 : parrello 1.3 Trace("Genome $genomeID did not have any regions.") if T(1);
570 : parrello 1.1 $errorCount++;
571 :     }
572 :     }
573 : parrello 1.3 return $errorCount;
574 : parrello 1.1 }
575 :     # Tell the user we're done.
576 : parrello 1.3 Trace("Processing complete.") if T(0);
577 : parrello 1.1
578 :     # Read a region record from the file and parse it into a hash
579 :     # for return to the caller. If we reach end-of-file, the
580 :     # hash returned will have $TRAILER in the blockID field.
581 :     sub GetRegionRecord {
582 :     # Create the return hash.
583 :     my %retVal = ();
584 :     # Read the record.
585 :     my $regionData = <REGIONSIN>;
586 :     # Check for end-of-file.
587 :     if (!defined $regionData) {
588 :     # Here we have end-of-file, so stuff in a trailer
589 :     # value for the block ID.
590 :     $retVal{blockID} = $TRAILER;
591 :     } else {
592 :     # Here we have a real record.
593 :     ($retVal{peg}, $retVal{genomeID}, $retVal{contigID},
594 :     $retVal{begin}, $retVal{end}, $retVal{blockID},
595 :     $retVal{snippet}) = Tracer::ParseRecord($regionData);
596 :     }
597 :     # Return the hash created.
598 :     return %retVal;
599 :     }
600 :    
601 :     1;

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3