-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathslagan.pl
executable file
·153 lines (129 loc) · 5.14 KB
/
slagan.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/perl -w
use strict;
my $lagandir = $ENV{LAGAN_DIR};
if (@ARGV < 2) {
print ("Usage:\n slagan.pl seqfile1 seqfile2 [-glocal \"glocal flags\"] [-chaos \"chaos flags\"] [-order \"order flags\"] [-recurse \"(wl1,nd1,co1),(wl2,nd2,co2),...\"] [-mfa] [-out \"filename\"] [-maskedonly] [-debug] [-translate] [-fastreject]\n");
exit(1);
}
my ($seq1, $firstName) = ($ARGV[0], $ARGV[0]);
die("$0: File not found: $seq1. Stopped") unless -f $seq1;
my ($seq2, $secondName) = ($ARGV[1], $ARGV[1]);
die("$0: File not found: $seq2. Stopped") unless -f $seq2;
my ($extra1, $extra2) =(0, 0);
if (-e "$seq1.masked") { $seq1 = "$seq1.masked"; $extra1 = 1;}
if (-e "$seq2.masked") { $seq2 = "$seq2.masked"; $extra2 = 1;}
my ($outName1, $outName2) = ($ARGV[0], $ARGV[1]);
$outName1 =~ s/^.*\///;
$outName1 =~ s/\..*//;
$outName2 =~ s/^.*\///;
$outName2 =~ s/\..*//;
my $max_ext = 25000;
my $ext_mul = 1;
my $arglist = "";
my $glocal_fl = " -gapopen 0,1000,2000,2000 -gapcont 0.2,0.06,0.06,0.06 -dist 0,1.0,2.5,2.5";
my $chaos_fl = " -wl 11 -nd 1 -co 10 -ext -rsc 2250 -b";
my $lagan_fl = "";
my $supermap_fl = "-glocal_out=${outName1}_$outName2.out.glocal";
my $outfile = 0;
my $fastrej = 0;
my $lazy = 0;
for (my $i = 2; $i < @ARGV; $i++) {
if ($ARGV[$i] =~ /-glocal_fl/) {
$glocal_fl = $ARGV[++$i];
} elsif ($ARGV[$i] =~ /-chaos_fl/) {
$chaos_fl = $ARGV[++$i];
} elsif ($ARGV[$i] =~ /-lagan_fl/) {
$lagan_fl = $ARGV[++$i];
} elsif ($ARGV[$i] =~ /-max_ext/) {
$max_ext = $ARGV[++$i];
} elsif ($ARGV[$i] =~ /-ext_mul/) {
$ext_mul = $ARGV[++$i];
} elsif ($ARGV[$i] =~ /-out/) {
$outfile = $ARGV[++$i];
if (-e "$outfile") { system("rm $outfile") and exit(1); }
} elsif ($ARGV[$i] =~ /-order/) {
$arglist = $arglist." -order $ARGV[++$i]";
} elsif (($ARGV[$i] =~ /-gs/) || ($ARGV[$i] =~ /-gc/) || ($ARGV[$i] =~ /-mt/) || ($ARGV[$i] =~ /-ms/) || ($ARGV[$i] =~ /-bw/)) {
$arglist = $arglist." ".$ARGV[$i];
$arglist = $arglist." ".$ARGV[++$i];
} elsif ($ARGV[$i] =~ /-ext/) {
$arglist = $arglist." -ext $ARGV[++$i]";
} elsif ($ARGV[$i] =~ /-maskedonly/) {
$arglist = $arglist." -maskedonly";
} elsif ($ARGV[$i] =~ /-lazy/) {
$lazy = 1;
} elsif ($ARGV[$i] =~ /-translate/) {
$arglist = $arglist." -translate";
} elsif ($ARGV[$i] =~ /-fastreject/) {
$fastrej = 1;
# $arglist = $arglist." -fastreject";
} elsif ($ARGV[$i] =~ /-recurse/) {
$arglist = $arglist." -recurse \"".$ARGV[++$i]."\"";
} elsif ($ARGV[$i] =~ /-chaos/) {
$chaos_fl = $chaos_fl." ".$ARGV[++$i];
} else {
die("$0: Invalid option for rlagan: $ARGV[$i]");
}
}
my $seq1len = `$lagandir/utils/getlength $firstName`;
my $seq2len = `$lagandir/utils/getlength $secondName`;
chomp $seq1len;
chomp $seq2len;
if ($lazy && -e "${outName1}_$outName2.chaos") {
`cp ${outName1}_$outName2.chaos chaos.$$`;
}
else {
`$lagandir/chaos $seq1 $seq2 $chaos_fl > chaos.$$`;
if ($?) { exit(1); }
`cat chaos.$$ > ${outName1}_$outName2.chaos`;
}
open(FH, "> seq1len"); print FH $firstName." ".$seq1len."\n"; close FH;
open(FH, "> seq2len"); print FH $secondName." ".$seq2len."\n"; close FH;
my $supermap_outfile = "${outName1}_$outName2.out.smap";
my $supermap_inv = "$lagandir/supermap.pl -sizes1=seq1len -sizes2=seq2len $supermap_fl chaos.$$ -no_clust_run -f -out=$supermap_outfile 1>&2";
#print $supermap_inv."\n";
system($supermap_inv);
open(FH, "< $supermap_outfile");
my @regs = <FH>;
die("$0: Supermap generated no regions. Stopped") unless scalar @regs;
close FH;
unlink "seq1len"; unlink "seq2len"; # unlink $supermap_outfile;
for (my $k = 0; $k < @regs; $k++) {
$regs[$k] =~ /^([^\s]+)\s([\d]+)\s([\d]+)\s\s\s([^\s]+)\s([\d]+)\s([\d]+)\s(\+|\-)\s\((DM|M1|M2),\s([\d]+)\saligns\)$/o;
my ($startreg1, $endreg1, $startreg2, $endreg2, $strand, $type) = ($2, $3, $5, $6, $7, $8);
my $rcf = "";
if ($strand eq "+") {
$rcf = ""
} else {
$rcf = "-rc";
}
#print "$lagandir/utils/fa2xfa $firstName $startreg1 $endreg1 1 > seq1$k.$$\n";
`$lagandir/utils/fa2xfa $firstName $startreg1 $endreg1 1 > seq1$k.$$\n`;
#print "$lagandir/utils/fa2xfa $secondName $startreg2 $endreg2 2 $rcf > seq2$k.$$\n";
`$lagandir/utils/fa2xfa $secondName $startreg2 $endreg2 2 $rcf > seq2$k.$$\n`;
if ($extra1) { `$lagandir/utils/fa2xfa $seq1 $startreg1 $endreg1 1 > seq1$k.$$.masked\n`; }
if ($extra2) { `$lagandir/utils/fa2xfa $seq2 $startreg2 $endreg2 2 $rcf > seq2$k.$$.masked\n`; }
#print "$lagandir/lagan.pl seq1$k.$$ seq2$k.$$ $arglist $lagan_fl -mfa -out lagan.$k.$$\n";
`$lagandir/lagan.pl seq1$k.$$ seq2$k.$$ $arglist $lagan_fl -mfa -out lagan.$k.$$\n`;
my $suff = "";
if ($outfile) { $suff = " >> $outfile"; }
if (-e "lagan.$k.$$") {
if ($fastrej) {
#print "$lagandir/utils/scorealign lagan.$k.$$ 45 -cropxmfa -ibounds $suff\n";
print `$lagandir/utils/scorealign lagan.$k.$$ 45 -cropxmfa -ibounds $suff`;
} else {
#print "$lagandir/utils/scorealign lagan.$k.$$ 45 -ibounds\n";
my $sc = `$lagandir/utils/scorealign lagan.$k.$$ 45 -ibounds`;
chomp($sc);
if ($sc) {
print `cat lagan.$k.$$ $suff`;
print `echo \"=$sc $type\n\" $suff`;
}
}
}
}
####`cat out.$$ > ${outName1}_$outName2.mon`;
unlink(glob("*.$$"));
if ($extra1 || $extra2) { `rm *.$$.masked`; }
exit(0);
# out: .chaos .mon->.smap .xmfa