1#! @PERL@
2
3if ($#ARGV < 0) {
4    die "\nConvert secondary structure file to fasta format\n",
5	"\nUsage: sstofa <sec struct file>\n\n";
6}
7
8$ss_file = shift;
9
10open (SSFILE, $ss_file) || die "Couldn't find $ss_file\n";
11open(SEQFILE,">-");
12$ct = 0;
13
14while ($line = <SSFILE>) {
15    if ($line =~ /^(\S+)\s+(\(\d+\-\d+\))\s+Length:\s(\d+)\sbp/) {
16	$SeqName = $1;
17	$bounds = $2;
18	$SeqLen = $3;
19    }
20    elsif ($line =~ /^Type:\s(\S+)\s+Anticodon:\s(\S+).+Score:\s(\S+)/) {
21	$isotype = $1;
22	$ac = $2;
23	$SeqName .= "-".$isotype.$ac;
24	$score = $3;
25	$SeqDescription = "$bounds  $isotype ($ac) $SeqLen bp  Sc: $score";
26    }
27    elsif ($line =~ /pseudogene/) {
28	$SeqDescription .= "  Pseudo";
29    }
30    elsif ($line =~ /^Seq:\s(\S+)$/) {
31	$Seq = $1;
32	&write_fasta($SeqName,$SeqDescription,length($Seq),
33		     uc($Seq),SEQFILE);
34	$SeqName = "";
35	$bounds = "";
36	$SeqLen = 0;
37	$isotype = "";
38	$ac = "";
39	$score = 0.0;
40	$SeqDescription = "";
41	$Seq = "";
42    }
43}
44
45
46
47# End Main
48
49sub write_fasta {
50    local($name, $description, $length, $sequence,*FAHANDLE) = @_;
51    local($pos, $line);
52
53    print FAHANDLE ">$name $description\n";
54    for ($pos = 0; $pos < $length; $pos += 60)
55    {
56	$line = substr($sequence,$pos,60);
57	print FAHANDLE $line, "\n";
58    }
59    1;
60}
61
62