#!/usr/bin/perl -w # ----------------------------------------------------------------------- # replaceX.pl 1.0 # # This programm replace character A with B from an input textfile # and writes the result to an output textfile. # # For example it is possible to replace all A,C,T,G with the value '1' # and all X and N with value '0'. # # The command line for this is: # ./replaceX.ps input.txt output.txt 'X|N' 0 'A|C|T|G' 1 # # # Copyright by Joern Hameister (2005) # ----------------------------------------------------------------------- if(@ARGV<3) { print "This programm replace character A with B from an input textfile and writes the result to an output textfile.\nParameter 1: Inputfile\nParameter 2: Outputfile\nParameter 3: Character A\nParameter 4: Character B\nFor example: ./replaceX.pl ./inputfile.txt ./outputfile.txt A B\nRegular expressions in the parameters are possible too.\nExample: ./replaceX.pl ./inputfile.txt ./outputfile.txt X 0 'A|C|T|G' 1\nThis command replace all X with 0 and all A or C or T or G with 1."; } else { print "Read from $ARGV[0] (Inputfile)\n"; print "Write to $ARGV[1] (Outputfile)\n"; open(INPUT1 , "<", $ARGV[0]); open(INPUT2 , "<", $ARGV[1]); open(SINK , ">" , $ARGV[2]); while(defined ($line1 = )) { my $line2 = ; chomp($line2); chomp($line1); print "LINE1 = $line1\n"; print "LINE2 = $line2\n"; my $lineAND; my @o1 = split (/\s*/, $line1); my @o2 = split (/\s*/, $line2); my $counter = 0; foreach $bit1s ( @o1 ) { my $bit2s = $o2[$counter]; my $bit1; my $bit2; if ($bit1s=='0') { $bit1 = 0; } else { $bit1 = 1; } if ($bit2s=='0') { $bit2 = 0; } else { $bit2 = 1; } my $bit3 = $bit1 & $bit2; $counter++; $lineAND = $lineAND . $bit3; } print "RESULT= $lineAND\n"; print SINK $lineAND; $lineAND = ""; } }