#!/usr/bin/perl #################################### # # TRfinder2txt -f html-file -o text-file # # Reads Tandem Repeats Finder output as .dat file and writes to text file as tab-delimited # Authors: C. Grunau, 30 mars 2011 ##################################### use diagnostics; use strict; use Carp; use FileHandle; use File::Path; use File::Basename; use Getopt::Std; my @inputlist = (); my @temp = (); my $FILE = FileHandle->new(); my $seqname = ""; my $i = 0; my $j = 0; my $current = ""; my $header = "ID\tStart\tEnd\tPeriod_size\tCopy_number\tConsensus_size\tPercent_matches\tPercent_indels\tScore\tA\tC\tG\tT\tEntropy_\(0\-2\)\tTR_sequence\tComplete_sequence"; $| = 1; #print immediately use vars qw( $opt_f $opt_o ); # Command line parsing # getopts('f:o:'); # # Read input file and split into fasta sequences on the fly # #replace Mac and PC CRLF by UNIX LF system ("perl -pi -e 's/\r/\n/g' $opt_f"); open($FILE,$opt_f) || croak(sprintf("Cannot open file \"%s\"",$opt_f)); while ( <$FILE> ) { chomp; if ( /^Sequence:\s+(\S+)/) { $current=$1; } elsif(/^\d+/) { push(@inputlist,$current." ".$_) } } unshift (@inputlist, $header); close($FILE) || croak(sprintf("Cannot close open file \"%s\"",$opt_f)); print "printing to ".$opt_o."\n"; open($FILE,">".$opt_o) || croak(sprintf("Cannot open file \"%s\"",$opt_o)); for $i (0 .. $#inputlist) { #print [$i]."\n"; @temp = (); @temp=split('\s+',$inputlist[$i]); my $j = 0; for $j (0 .. $#temp) { print $FILE $temp[$j]."\t"; } print $FILE "\n"; } close ($FILE);