#!/usr/bin/perl ############################################################################# # PERL Program "fnaprocess.pl # # April 8th, 1998 # # AUTHORS # Anton Chuppin # Eric Larson # # PURPOSE # This program processes the fnaindex files into a usable form. # ################################################################### $numargs = @ARGV ; if ($numargs ne "2") { print "Usage: ", $0, "\"Input sub-dir\" \"Output sub-dir\" -- Use trailing backslash\n" ; die ; } $subdir = $ARGV[0] ; # Input sub-dir name $outdir = $ARGV[1] ; # Output sub-dir name unless (((-d $outdir)&&(-w $outdir)) || mkdir($outdir,0775)) { die ("$0 died -- output directory $outdir could not be created or written to\n"); } unless (opendir (DATADIR, $subdir)) { ; # Open up the data sub-directory die "$0 Died -- $subdir data input sub-dir cannot be opened" ; } while ($filelist = readdir(DATADIR)) { # Read the filelist in $readfile = $subdir . $filelist ; # Create the input file path $skipfile = 0 ; unless (open(INFILE, "$readfile")) { # Open the input file print STDERR "$0 Error: ". "$filelist input file cannot be opened -- skipping\n" ; $skipfile = 1 ; } if ($skipfile = 1 ) { $outfile = $outdir . $filelist ; # Create the output file path unless (open (OUTFILE, ">>$outfile")) { # Open the output file if (!(-w $outfile)) { warn ("$0 error -- No write permissions to $outfile \n") ; } else { warn ("$0 error -- Outfile $outfile cannot be opened \n") ; } } while ($line = ) { chomp($line) ; $line =~ tr/A-Z/a-z/; # Convert to lowercase $line =~ tr/-/_/ ; # Convert dashes to underlines $line =~ s/\ \;/_/ ; # Find   and convert to _ $line =~ s/\s+/ /g ; # Remove excess spaces $line =~ s/\\s+/\/g ; # Remove spaces after $line =~ s/\s+\<\/b\>/\<\/b\>/g ; # Remove space before $line =~ s/\/\n\/g ; # Add newlines before $line =~ s/\(.*?)\<\/b\>/{$tmp=$1;$tmp=~s|\s+|_|g;$tmp;}/gie; # $line =~ s/\(.*?)\s(.*?)\<\/b\>/\1_\2/g ; # Trans fourth bold space $line =~ s/\<.*?\>/ /g ; # Remove HTML, add space $line =~ s/ +/ /g ; # Remove excess spaces $line =~ s/\n /\n/g ; print OUTFILE $line ; } close (INFILE) ; # Close the current input file print OUTFILE "\n"; close ; # Close the current input file } # End the "skipfile" block } # End the fileread block print ("$0 terminated normally\n") ; exit (0);