On unix or windows systems you could use the redirect options to capture STDOUT into a file like:
command inputfile > outputfile
But that is probably not your question. You want the matrix to be returned?
[edit since this was what you wanted]
I attach an example perl script that will parse an output file given your format into a matrix. You have to specify the number sequences you aligned pair-wise and the inut file. Output will go to STDOUT and can be grabbel by redirects if wanted. The script below will parse this example text file into the shown result;
#!/usr/bin/perl -w
# Parses pairwise alignment data into a tab-delimited matrix
# USAGE: cmd <num_seq> <inputfile>
# output is to STDOUT
#
# alex
use strict;
use warnings;
#get args
my ($num_seq) = $ARGV[0]=~ m/^([A-Z0-9_.-]+)$/ig;
my ($input_file_name) = $ARGV[1]=~ m/^([A-Z0-9_.-]+)$/ig;
open (IN,$input_file_name) || die "Input file error: $!" ;
#grab values
my @values=();
while (<IN>) {
if ($_=~ /Score: ([0-9]+)$/) {
push(@values,$1);
}
}
#print out matrix
my $count=0;
my $score;
for (my $x=1; $x<$num_seq; $x++){
for (my $y=1; $y<=$num_seq; $y++){
if ($y<=$x){
$score="-";
}
else {
$score=$values[$count++];
}
print $score."\t";
}
print "\n";
}
close (IN);
print "\nDone!\n";
for c# the method stays the same. Just some other syntax but the regexp could do all the work.
But why c#? Homework/practise or some other need? Perl if FAST for text.
Well I am used to C# and I am developing a big pipeline which a small part is what I have written here. It is more difficult for me to change my programming language for a small part of the project ;)
I have found an easier way to do it and it is to create a distance matrix which is basically represents the same information as similarity matrix and shows how much protein sequences differ. In order to achieve this you should do the following steps:
1) create the multiple sequence alignment for the input sequences(seq.txt) using the below command line. The multiple sequence alignment is saved in the seq.aln file.
clustalw2.exe -INFILE=seq.txt -OUTORDER=INPUT
2)Then you need to create a distance matrix using the alignment file:
Did the answer below fit your question? No pm possibilities on BioStar :P
sorry for the late reply. I have found a nice way which I have written below.