Skip to content

Instantly share code, notes, and snippets.

@davetang
Last active December 24, 2015 12:09
Show Gist options
  • Save davetang/6795488 to your computer and use it in GitHub Desktop.
Save davetang/6795488 to your computer and use it in GitHub Desktop.
Convert the TRANSFAC matrix into a matrix readable by TESS (Transcription Element Search System).
#!/bin/env perl
use strict;
use warnings;
my $usage = "Usage: $0 <matrix.dat>\n";
my $infile = shift or die $usage;
my $accession = '';
my $start = 0;
my @entry = ();
open(IN, '<', $infile) || die "Could not open $infile: $!\n";
while(<IN>){
chomp;
if (/^AC\s+(.*)$/){
$accession = $1;
}
if (/^NA\s+(.*)$/){
$accession .= "_$1";
}
if (/^P0/){
$start = 1;
$entry[0] = ">$accession";
next;
} elsif (/^XX/ && $start == 1){
$start = 0;
foreach my $line (@entry){
print "$line\n";
}
print "<\n";
@entry = ();
}
if ($start == 1){
my ($junk, $a, $c, $g, $t, $junk2) = split(/\s+/);
$entry[scalar(@entry)] = join("\t", $a, $c, $g, $t);
}
}
close(IN);
exit(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment