9.5 years ago by
The Netherlands
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;
INPUT file example:
Start of Pairwise alignments
Aligning...
Sequences (1:2) Aligned. Score: 17
Sequences (1:3) Aligned. Score: 21
Sequences (1:4) Aligned. Score: 16
Sequences (1:5) Aligned. Score: 27
Sequences (2:3) Aligned. Score: 29
Sequences (2:4) Aligned. Score: 23
Sequences (2:5) Aligned. Score: 26
Sequences (3:4) Aligned. Score: 21
Sequences (3:5) Aligned. Score: 22
Sequences (4:5) Aligned. Score: 20
Some other lines here probably
Parsed output:
- 17 21 16 27
- - 29 23 26
- - - 21 22
- - - - 20
Done!
The example code:
#!/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";
•
link
modified 9.5 years ago
•
written
9.5 years ago by
ALchEmiXt • 1.9k
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.