From: Fábio Madeira Date: Mon, 10 Apr 2017 09:48:44 +0000 (+0100) Subject: JWS-112 Bumping version of Mafft to version 7.310. X-Git-Url: http://source.jalview.org/gitweb/?p=jabaws.git;a=commitdiff_plain;h=711ff37b582bf25ba17d553008c4bf06cbdb8c84 JWS-112 Bumping version of Mafft to version 7.310. --- diff --git a/binaries/src/mafft/binaries/addsingle b/binaries/src/mafft/binaries/addsingle new file mode 100644 index 0000000..ce79938 Binary files /dev/null and b/binaries/src/mafft/binaries/addsingle differ diff --git a/binaries/src/mafft/binaries/contrafoldwrap b/binaries/src/mafft/binaries/contrafoldwrap index 2a5738d..3f250e2 100644 Binary files a/binaries/src/mafft/binaries/contrafoldwrap and b/binaries/src/mafft/binaries/contrafoldwrap differ diff --git a/binaries/src/mafft/binaries/countlen b/binaries/src/mafft/binaries/countlen index f35eadb..2e9bf04 100644 Binary files a/binaries/src/mafft/binaries/countlen and b/binaries/src/mafft/binaries/countlen differ diff --git a/binaries/src/mafft/binaries/disttbfast b/binaries/src/mafft/binaries/disttbfast index ebaa021..29b4343 100644 Binary files a/binaries/src/mafft/binaries/disttbfast and b/binaries/src/mafft/binaries/disttbfast differ diff --git a/binaries/src/mafft/binaries/dndblast b/binaries/src/mafft/binaries/dndblast index 48b4dd7..f327c06 100644 Binary files a/binaries/src/mafft/binaries/dndblast and b/binaries/src/mafft/binaries/dndblast differ diff --git a/binaries/src/mafft/binaries/dndfast7 b/binaries/src/mafft/binaries/dndfast7 index 00309d4..e4aee96 100644 Binary files a/binaries/src/mafft/binaries/dndfast7 and b/binaries/src/mafft/binaries/dndfast7 differ diff --git a/binaries/src/mafft/binaries/dndpre b/binaries/src/mafft/binaries/dndpre index 40b4a77..6a7860a 100644 Binary files a/binaries/src/mafft/binaries/dndpre and b/binaries/src/mafft/binaries/dndpre differ diff --git a/binaries/src/mafft/binaries/dvtditr b/binaries/src/mafft/binaries/dvtditr index c8a073a..20c3c2f 100644 Binary files a/binaries/src/mafft/binaries/dvtditr and b/binaries/src/mafft/binaries/dvtditr differ diff --git a/binaries/src/mafft/binaries/f2cl b/binaries/src/mafft/binaries/f2cl index 34c6cb1..9c0f8d5 100644 Binary files a/binaries/src/mafft/binaries/f2cl and b/binaries/src/mafft/binaries/f2cl differ diff --git a/binaries/src/mafft/binaries/getlag b/binaries/src/mafft/binaries/getlag index 2bee56b..1b5ab39 100644 Binary files a/binaries/src/mafft/binaries/getlag and b/binaries/src/mafft/binaries/getlag differ diff --git a/binaries/src/mafft/binaries/mafft-distance b/binaries/src/mafft/binaries/mafft-distance index 2dd7778..2193361 100644 Binary files a/binaries/src/mafft/binaries/mafft-distance and b/binaries/src/mafft/binaries/mafft-distance differ diff --git a/binaries/src/mafft/binaries/mafft-profile b/binaries/src/mafft/binaries/mafft-profile index f23b56b..4ec2334 100644 Binary files a/binaries/src/mafft/binaries/mafft-profile and b/binaries/src/mafft/binaries/mafft-profile differ diff --git a/binaries/src/mafft/binaries/mafft.1 b/binaries/src/mafft/binaries/mafft.1 index 8636334..b5344c5 100644 --- a/binaries/src/mafft/binaries/mafft.1 +++ b/binaries/src/mafft/binaries/mafft.1 @@ -11,7 +11,7 @@ .\" disable justification (adjust text to left margin only) .ad l .SH "THIS MANUAL IS FOR V6.2XX (2007)" -Recent versions (v6.8xx; 2010 Nov.) have more features than those described below. +Recent versions (v7.1xx; 2013 Jan.) have more features than those described below. See also the tips page at http://mafft.cbrc.jp/alignment/software/tips0.html .SH "NAME" diff --git a/binaries/src/mafft/binaries/mafftash_premafft.pl b/binaries/src/mafft/binaries/mafftash_premafft.pl new file mode 100644 index 0000000..6dc3b9c --- /dev/null +++ b/binaries/src/mafft/binaries/mafftash_premafft.pl @@ -0,0 +1,464 @@ +#!/usr/bin/perl + +##################################################################### +# Author: KM Amada (kmamada@ifrec.osaka-u.ac.jp) +# +# Ver. Date Changelog +##################################################################### +# 1.0 07.26.13 Initial release +# 2.0 09.03.13 Added extensive warnings and error messages +# 3.0 10.28.13 Fix for retrieving large files. Added STDERR logs +# 3.1 11.08.13 Added LWP failsafe. Made hat3 not a required output +# 3.2 12.08.14 Removed 5-char restriction for own structure files +# +##################################################################### + +use strict; +use Getopt::Long; +use File::Path qw(make_path remove_tree); +use LWP::Simple; +use LWP::UserAgent; + +# to prevent error 'Header line too long (limit is 8192)' [v3.1] +use LWP::Protocol::http; +push(@LWP::Protocol::http::EXTRA_SOCK_OPTS, MaxLineLength => 0); + + + +my $BASEURL = "http://sysimm.ifrec.osaka-u.ac.jp/MAFFTash/REST/service.cgi/premafft"; + +my ( $WORKDIR, $PDBLIST, $OWNLIST, $HAT3FILE, $INSTRFILE ); + +GetOptions +( + 'd=s' => \$WORKDIR, + 'p=s' => \$PDBLIST, + 'o=s' => \$OWNLIST, + 'h=s' => \$HAT3FILE, + 'i=s' => \$INSTRFILE, +); + +print STDERR "[MAFFTash-premafft]\n"; + +# set temp directory +my $TMP = "/tmp/mapremafft$$"; +make_path($TMP) unless -d $TMP; + + + +###### +# validation +&help("Required parameter : atleast one of either '-p' or '-o'") unless ( defined $PDBLIST || defined $OWNLIST); +&help("Required parameter : '-d'") if defined $OWNLIST && ! defined $WORKDIR; + +$HAT3FILE = "hat3" unless defined $HAT3FILE; +$INSTRFILE = "instr" unless defined $INSTRFILE; +chop $WORKDIR if defined $WORKDIR && $WORKDIR =~ m/\/$/g; + + +###### +# prepare inputs +print STDERR "Preparing inputs for service request...\n"; + +my @files = (); +push(@files, "strweight" => "0.5"); +push(@files, "premafft" => "1"); + + +# pdb entries +if ( defined $PDBLIST ) +{ + print STDERR "PDB List defined!\n"; + &bail("Error: Input file $PDBLIST does not exists!") unless -e $PDBLIST; + my $listfile = "$TMP/pdblist.inp"; + + + open(INPF,"<$PDBLIST") or &bail("Error: Cannot open file $PDBLIST for reading!"); + open(OUTF,">$listfile") or &bail("Error: Cannot open temporary file $listfile for writing!"); + + while() + { + chomp; + if ( /^(\w{5})$/ ) + { + print OUTF ">PDBID\n$1\n"; + } + } + + close OUTF; + close INPF; + + push(@files, "inputfile" => ["$listfile"]); +} + + + +# upload own structures +my %ownids = (); + +if ( defined $OWNLIST ) +{ + print STDERR "OWN List defined!\n"; + &bail("Error: Input file $OWNLIST does not exists!") unless -e $OWNLIST; + + + open(OWNINPF,"<$OWNLIST") or &bail("Error: Cannot open file $OWNLIST for reading!"); + + while() + { + chomp; + + if ( /^(\S+)$/ ) + { + my $fileref = "$WORKDIR/$1.pdb"; + + unless (-e $fileref) + { + close OWNINPF; + &bail("Error: File $fileref does not exists!"); + } + + push(@files, "inputownfile[]" => ["$fileref"]); + $ownids{$1} = 1; + } + } + + close OWNINPF; +} + + + +###### +# start rest service +print STDERR "Sending service request...\n"; + +my $browser = LWP::UserAgent->new; +$browser->timeout(0); + + +# post: running a mafftash job +my $postResponse = $browser->post( $BASEURL, \@files, 'Content_Type' => 'form-data' ); +&bail(sprintf("[%d] %s\n", $postResponse->code, &parseError($postResponse->content))) unless($postResponse->is_success); + + +# get response from post request +my ($status, $mafftashid) = &parseResponse($postResponse->content); + + + +my $MAXTRIES = 3; +my $STIMER = 4; +my $longtimer = 0; + +print STDERR "Request sent! Waiting for response...[$mafftashid]\n"; + + +# wait for results until it becomes available +while(1) +{ + $longtimer = $longtimer <= ($STIMER*3) ? $longtimer+$STIMER : $STIMER; + sleep $longtimer; + + + # get: get results for mafftash job + my $getResponse = $browser->get("$BASEURL/$mafftashid"); + + if ( $getResponse->is_success ) + { + + # get response from get request + ($status, $mafftashid) = &parseResponse($getResponse->content); + next unless ( $status eq "done" ); + + + # if job is finished and ready + print STDERR "Results found!\n"; + my $csfile = "$TMP/checksum.tar.gz"; + my $try1 = 1; + + + while(1) + { + print STDERR "Fetching Results... [Trial $try1]\n"; + + if ( is_success(getstore("$BASEURL/getmdlist/$mafftashid", $csfile)) && -e $csfile && -s $csfile ) + { + # get response from get request + my $checklist = &extractchecksum($csfile); + &bail("Error retrieving list of compressed files!") unless ( scalar %$checklist > 0 ); + + + foreach my $id ( keys %$checklist ) + { + my $checkfile = "$TMP/$id"; + my $checkid = $checklist->{$id}; + my $try2 = 1; + + while(1) + { + unlink $checkfile if -e $checkfile; + + if ( is_success(getstore("$BASEURL/get/$mafftashid/$id", $checkfile)) && -e $checkfile && -s $checkfile ) + { + my $hashid = &getchecksum($checkfile); + #print STDERR "[hashid]$hashid [checkid]$checkid\n"; + + if ($hashid ne "" && $hashid ne $checkid ) + { + unlink $checkfile if -e $checkfile; + &bail("Error retrieving compressed file from server! [Checksum Failed]") if $try2 >= $MAXTRIES; + $try2++; + sleep $STIMER; + } + else + { + last; + } + } + else + { + &bail("Error retrieving compressed file from server!") if $try2 >= $MAXTRIES; + $try2++; + sleep $STIMER; + } + } + } + + last; + } + else + { + &bail("Error retrieving list of compressed files from server!") if $try1 >= $MAXTRIES; + $try1++; + sleep $STIMER; + } + } + + last; + + } + else + { + &bail(sprintf("[%d] %s\n", $getResponse->code, &parseError($getResponse->content))); + } + +} + + +# make sure outputs were generated +# decompress +print STDERR "Assembling final results...\n"; + +&backticks("cat $TMP/archive.tar.gz* | tar -zxf - -C $TMP/"); +&backticks("mv -f $TMP/instr $INSTRFILE") if -e "$TMP/instr"; +&backticks("mv -f $TMP/hat3 $HAT3FILE") if -e "$TMP/hat3"; + +# sometimes no hat3 file is generated [v3.1] +#&bail("Error: Output file $HAT3FILE not found!") unless -e $HAT3FILE; +&bail("Error: Output file $INSTRFILE not found!") unless -e $INSTRFILE; + + +# warn if some ownids were ommitted +if ( scalar keys(%ownids) > 0 ) +{ + my %instrids = (); + + open(INSTRF,"<$INSTRFILE") or &bail("Error: Cannot open file $INSTRFILE for reading!"); + + while() + { + chomp; + + if ( /^>\d+_(\S+)$/ ) + { + $instrids{$1} = 1; + } + } + + close INSTRF; + + foreach my $id ( keys %ownids ) + { + warn "Warning: Own structure $id was excluded from instr/hat3.\n" unless $instrids{$id}; + } + +} + + + +&cleanup(); + + + +#################### +#################### + + + +sub parseResponse +{ + my $response = shift; + + #"status":"wait","mafftashid":"Ma8211432R" + + my $status = ""; + my $mafftashid = ""; + + if ( $response =~ /^([^\s:]+):([^\s:]+)$/ ) + { + $mafftashid = $1; + $status = $2; + } + + return ($status, $mafftashid); + +} + + +sub extractchecksum +{ + my $infile = shift; + my %dataset = (); + + open CSUM, "tar -zxf $infile -O|" or return \%dataset; + + while() + { + chomp; + if ( /^(\S+)\s+(\S+)$/ ) + { + $dataset{$2} = $1; + } + + } + + close CSUM; + + return \%dataset; + +} + + +sub parseError +{ + my $response = shift; + + #"error":"Invalid number of inputs found." + my $errorstr = ( $response =~ /\"error\"\s*:\s*\"([^\"]+)\"/ ) ? $1 : ""; + return $errorstr; +} + + +sub getchecksum +{ + my $infile = shift; + + # md5 binary check + my $MD5BIN = ""; + + if ( -x "/usr/bin/md5sum" ) + { + $MD5BIN = "/usr/bin/md5sum"; + } + elsif ( -x "/sbin/md5" ) + { + $MD5BIN = "/sbin/md5 -q"; + } + + return "" if $MD5BIN eq ""; + + + my $checksum = ""; + open MD5EXE, "$MD5BIN $infile|" or return ""; + + while() + { + if (/^(\S+)\s+(\S+)$/) + { + $checksum = $1; + last; + } + elsif (/^(\S+)$/) + { + $checksum = $1; + last; + } + } + + close MD5EXE; + + return $checksum; + +} + + +sub backticks +{ + my $command = shift; + + `$command`; + return ($? == -1) ? 0 : 1; +} + + +sub bail +{ + my $str = shift; + print STDERR "$str\n" if defined $str; + + &cleanup(); + exit(1); +} + + +sub cleanup +{ + return if ($TMP eq "" || !-d $TMP); + + opendir(MAINDIR, $TMP); + my @files = readdir(MAINDIR); + closedir(MAINDIR); + + foreach my $file (@files) + { + unlink "$TMP/$file" if -e "$TMP/$file"; + } + + remove_tree($TMP); + +} + + +sub help +{ + my $str = shift; + + print <<'HELPME'; + +USAGE + ./mafftash_premafft.pl -p [FILE] + ./mafftash_premafft.pl -o [FILE] -d [DIRECTORY] + ./mafftash_premafft.pl -p [FILE] -o [FILE] -d [DIRECTORY] + + +PARAMETERS + -p [FILE] + FILE contains a list of PDBIDs (one entry per line); make sure that the PDBIDs are in the standard 5-character pdbid+chain naming format + + -o [FILE] -d [DIRECTORY] + FILE contains a list of IDs from your own structure/pdb files (one entry per line) + for each ID in the list make sure that a corresponding structure file (same ID with .pdb extension) is stored in DIRECTORY + + -h [HATFILE] + save the output hat3 file in HATFILE; if not set, the output is written to a file named 'hat3' in your current directory + + -i [INSTRFILE] + save the output instr file in INSTRFILE; if not set, the output is written to a file named 'instr' in your current directory + +HELPME + + &bail($str); +} + + + diff --git a/binaries/src/mafft/binaries/makedirectionlist b/binaries/src/mafft/binaries/makedirectionlist new file mode 100644 index 0000000..403a61a Binary files /dev/null and b/binaries/src/mafft/binaries/makedirectionlist differ diff --git a/binaries/src/mafft/binaries/mccaskillwrap b/binaries/src/mafft/binaries/mccaskillwrap index 8f1a46e..086e923 100644 Binary files a/binaries/src/mafft/binaries/mccaskillwrap and b/binaries/src/mafft/binaries/mccaskillwrap differ diff --git a/binaries/src/mafft/binaries/multi2hat3s b/binaries/src/mafft/binaries/multi2hat3s index 96b8a96..fc811b2 100644 Binary files a/binaries/src/mafft/binaries/multi2hat3s and b/binaries/src/mafft/binaries/multi2hat3s differ diff --git a/binaries/src/mafft/binaries/pairash b/binaries/src/mafft/binaries/pairash index abb91cc..5f98f8a 100644 Binary files a/binaries/src/mafft/binaries/pairash and b/binaries/src/mafft/binaries/pairash differ diff --git a/binaries/src/mafft/binaries/pairlocalalign b/binaries/src/mafft/binaries/pairlocalalign index fb7ad4b..a7c6816 100644 Binary files a/binaries/src/mafft/binaries/pairlocalalign and b/binaries/src/mafft/binaries/pairlocalalign differ diff --git a/binaries/src/mafft/binaries/regtable2seq b/binaries/src/mafft/binaries/regtable2seq index b6ecafb..34aefb5 100644 Binary files a/binaries/src/mafft/binaries/regtable2seq and b/binaries/src/mafft/binaries/regtable2seq differ diff --git a/binaries/src/mafft/binaries/replaceu b/binaries/src/mafft/binaries/replaceu index 6e1bdb2..5f05758 100644 Binary files a/binaries/src/mafft/binaries/replaceu and b/binaries/src/mafft/binaries/replaceu differ diff --git a/binaries/src/mafft/binaries/restoreu b/binaries/src/mafft/binaries/restoreu index f57e783..5721b2a 100644 Binary files a/binaries/src/mafft/binaries/restoreu and b/binaries/src/mafft/binaries/restoreu differ diff --git a/binaries/src/mafft/binaries/score b/binaries/src/mafft/binaries/score index f5a362e..66d05c3 100644 Binary files a/binaries/src/mafft/binaries/score and b/binaries/src/mafft/binaries/score differ diff --git a/binaries/src/mafft/binaries/seekquencer_premafft.pl b/binaries/src/mafft/binaries/seekquencer_premafft.pl new file mode 100644 index 0000000..a9040fd --- /dev/null +++ b/binaries/src/mafft/binaries/seekquencer_premafft.pl @@ -0,0 +1,600 @@ +#!/usr/bin/perl + +#################################################################################### +# Author: KM Amada (kmamada@ifrec.osaka-u.ac.jp) +# +# Ver. Date Changelog +#################################################################################### +# 1.0 11.01.13 Initial release +# +# **Skipped version 2 to standardise version numbers to seekquencer.pl script** +# +# 3.0 04.24.14 Added split option -mod for output +# Uses seekquencer_v3 backend +# +# 4.0 05.12.14 Added new options: -run -trd -noin +# Sets -seqa fast in seekquencer.pl +# Uses seekquencer_v4 backend +# +# 4.1 05.19.14 Added a check on running REST requests before proceeding +# to avoid server load problems +# +# 4.2 05.27.14 Seq limit processing done in seekquencer.pl script +# to avoid server load problems +# +# 4.3 07.22.14 Added new option: -seqd +# Blast limit changed from factor of 10 to -blim option +# Timing on sleep changed; added srand() for making seed +# Moved the job limit processing to server side +# +# 4.4 08.05.14 Modified to work in multiple OS +# +# +#################################################################################### + +use strict; +use Getopt::Long; +use File::Path qw(make_path remove_tree); +use Cwd; +use LWP::Simple; +use LWP::UserAgent; + +# to prevent error: Header line too long (limit is 8192) +use LWP::Protocol::http; +push(@LWP::Protocol::http::EXTRA_SOCK_OPTS, MaxLineLength => 0); + + + +my $BASEURL = "http://sysimm.ifrec.osaka-u.ac.jp/seekquencer/REST/service.cgi/premafft"; +my ( $INPUTFILE, $IDLISTFILE, $SEQFASTAFILE, $OUTPUTFILE, $SEQFLAG, $STRFLAG, $EVALFLAG, $NOINFLAG ); +my $OUTTYPE = "mafftash"; + +my $SEQDATABASE = "uniref100"; +my $SEQLIMIT = 100; +my $SEQBLASTLIMIT = 100; + +my $RUNMODE = "normal"; # thread|normal +my $THREADCOUNT = 3; + + +GetOptions +( + 'inp=s' => \$INPUTFILE, + 'idf=s' => \$IDLISTFILE, + 'seqf=s' => \$SEQFASTAFILE, + 'out=s' => \$OUTPUTFILE, + 'str' => \$STRFLAG, + 'seq' => \$SEQFLAG, + 'seqd=s' => \$SEQDATABASE, + 'lim=i' => \$SEQLIMIT, + 'blim=i' => \$SEQBLASTLIMIT, + 'pre' => \$EVALFLAG, + 'noin' => \$NOINFLAG, + 'mod=s' => \$OUTTYPE, + 'run=s' => \$RUNMODE, + 'trd=i' => \$THREADCOUNT, + + +); + +my $ISWINDOWS = ( $^O =~ /^MSWin/ ) ? 1 : 0; +print STDERR "[Seekquencer-premafft 4.4 on $^O]\n"; + + +# set temp directory +my $CWD = getcwd; +my $TMP = "$CWD/seekpremafft$$"; +make_path($TMP) unless -d $TMP; + + + +###### +# validation +help("Required parameter: define input as '-inp' or '-idf' or '-seqf'") if ( !defined $INPUTFILE && !defined $IDLISTFILE && !defined $SEQFASTAFILE ); +help("'-inp' is already defined") if ( defined $INPUTFILE && (defined $IDLISTFILE || defined $SEQFASTAFILE) ); +help("Input file $INPUTFILE does not exist (or filesize is 0)") if ( defined $INPUTFILE && (! -e $INPUTFILE || !-s $INPUTFILE) ); +help("Input file $IDLISTFILE does not exist (or filesize is 0)") if ( defined $IDLISTFILE && (! -e $IDLISTFILE || !-s $IDLISTFILE) ); +help("Input file $SEQFASTAFILE does not exist (or filesize is 0)") if ( defined $SEQFASTAFILE && (! -e $SEQFASTAFILE || !-s $SEQFASTAFILE) ); +help("Required parameter: output file '-out'") unless ( defined $OUTPUTFILE ); +help("Set either '-str' or '-seq' or dont set any at all") if ( defined $STRFLAG && defined $SEQFLAG ); + +help("Invalid value for '-seqd '") if ( $SEQDATABASE ne "uniref100" && $SEQDATABASE ne "uniref90" && $SEQDATABASE ne "uniref70" && $SEQDATABASE ne "uniprot"); +help("Invalid value for '-mod '") if ( $OUTTYPE ne "fasta" && $OUTTYPE ne "mafftash" && $OUTTYPE ne "mafftash-split" ); +help("Invalid value for '-run '") if ( $RUNMODE ne "thread" && $RUNMODE ne "normal" ); +help("Invalid value for '-trd '; count should be between 1 and 5 (inclusive)") if ( $RUNMODE eq "thread" && ($THREADCOUNT <= 0 || $THREADCOUNT > 5) ); + + +###### +# check existing requests +print STDERR "Checking server status...\n"; + +# generate seed +srand($$); + +# sleep a bit to give time for lsf response +sleep(int(rand(6))+1); + + +my $browser = LWP::UserAgent->new; +$browser->timeout(0); + +# get: check if you can send a new request this time +my $jobsResponse = $browser->get("$BASEURL/isAllowed"); + +if ( $jobsResponse->is_success ) +{ + my $status = parseJobQueryResponse($jobsResponse->content); + bail("Max jobs reached. The server cannot process your request right now; try again later.", 0) unless $status > 0; +} +else +{ + bail(sprintf("[%d] %s\n", $jobsResponse->code, parseError($jobsResponse->content))); +} + + +###### +# make a temporary input if lists were provided +unless ( defined $INPUTFILE ) +{ + $INPUTFILE = "$TMP/input.homemade"; + open INPF, ">$INPUTFILE" or bail("Error writing to input file."); + + if ( defined $IDLISTFILE ) + { + open IDLIST, "<$IDLISTFILE" or bail("Error reading input file."); + while( ) + { + chomp; + if ( /(\w{5})/ ) + { + print INPF ">PDBID\n$1\n"; + } + } + close IDLIST; + } + + + if ( defined $SEQFASTAFILE ) + { + open FASTA, "<$SEQFASTAFILE" or bail("Error reading input file."); + while( ) + { + chomp; + print INPF "$_\n"; + } + close FASTA; + } + + close INPF; +} + + +###### +# prepare parameters +print STDERR "Preparing parameters for service request...\n"; + +my @parameters = (); +push(@parameters, "fileinput" => ["$INPUTFILE"]); +push(@parameters, "out_type" => $OUTTYPE); + +push(@parameters, "rest_flag" => "1"); +push(@parameters, "cls_flag" => "1"); +push(@parameters, "pre_flag" => "1") if defined $EVALFLAG; +push(@parameters, "noin_flag" => "1") if defined $NOINFLAG; + +push(@parameters, "run_mode" => $RUNMODE); +push(@parameters, "thread_count" => $THREADCOUNT) if $RUNMODE eq "thread"; + + +if ( defined $STRFLAG ) +{ + push(@parameters, "str_flag" => "1"); + push(@parameters, "ash_flag" => "1"); +} +elsif ( defined $SEQFLAG ) +{ + push(@parameters, "seq_flag" => "1"); + push(@parameters, "seq_algorithm" => "fast"); + push(@parameters, "seq_database" => $SEQDATABASE); + push(@parameters, "seq_blastlimit" => $SEQBLASTLIMIT); + push(@parameters, "seq_outputlimit" => $SEQLIMIT); +} +else +{ + push(@parameters, "str_flag" => "1"); + push(@parameters, "ash_flag" => "1"); + push(@parameters, "seq_flag" => "1"); + push(@parameters, "seq_algorithm" => "fast"); + push(@parameters, "seq_database" => $SEQDATABASE); + push(@parameters, "seq_blastlimit" => $SEQBLASTLIMIT); + push(@parameters, "seq_outputlimit" => $SEQLIMIT); +} + + + +###### +# start rest service +print STDERR "Sending service request...\n"; + +# post: running a mafftash job +my $postResponse = $browser->post( $BASEURL, \@parameters, 'Content_Type' => 'form-data' ); +bail(sprintf("[%d] %s\n", $postResponse->code, parseError($postResponse->content))) unless($postResponse->is_success); + + +# get response from post request +my ($status, $seekid) = parseResponse($postResponse->content); + +my $MAXTRIES = 3; +my $STIMER = 5; +my $timer = 0; + +print STDERR "Request sent! Waiting for response...[$seekid]\n"; + +my $checklist = {}; + +# wait for results until it becomes available +while(1) +{ + # sleeps for 5+random, 10+random, 15+random, 20+random, 25+random, 30+random ,,, 60+random, 60+random,,, + $timer = $timer >= 60 ? 60 : $timer+$STIMER; + sleep($timer+int(rand(4))); + + # get: get results for mafftash job + my $getResponse = $browser->get("$BASEURL/$seekid"); + + if ( $getResponse->is_success ) + { + + # get response from get request + ($status, $seekid) = parseResponse($getResponse->content); + next unless ( $status eq "done" ); + + + # if job is finished and ready + print STDERR "Results found!\n"; + my $csfile = "$TMP/checksum"; + my $try1 = 1; + + + while(1) + { + print STDERR "Fetching Results... [Trial $try1]\n"; + + if ( is_success(getstore("$BASEURL/get/$seekid/checksum", $csfile)) && -e $csfile && -s $csfile ) + { + # get response from get request + $checklist = extractchecksum($csfile); + bail("Error retrieving list of compressed files!") unless ( scalar %$checklist > 0 ); + + + foreach my $id ( sort keys %$checklist ) + { + sleep 1; + my $checkfile = "$TMP/$id"; + my $checkid = $checklist->{$id}; + my $try2 = 1; + + while(1) + { + unlink $checkfile if -e $checkfile; + + if ( is_success(getstore("$BASEURL/get/$seekid/$id", $checkfile)) && -e $checkfile && -s $checkfile ) + { + last if $ISWINDOWS; + + my $hashid = getchecksum($checkfile); + #print STDERR "[hashid]$hashid [checkid]$checkid\n"; + + if ($hashid ne "" && $hashid ne $checkid ) + { + #unlink $checkfile if -e $checkfile; + bail("Error retrieving compressed file from server! [Checksum Failed]") if $try2 >= $MAXTRIES; + $try2++; + sleep $STIMER; + } + else + { + last; + } + } + else + { + bail("Error retrieving compressed file from server!") if $try2 >= $MAXTRIES; + $try2++; + sleep $STIMER; + } + } + } + + last; + } + else + { + bail("Error retrieving list of compressed files from server!") if $try1 >= $MAXTRIES; + $try1++; + sleep $STIMER; + } + } + + last; + + } + else + { + bail(sprintf("[%d] %s\n", $getResponse->code, parseError($getResponse->content))); + } + +} + + +# make sure outputs were generated +# decompress +print STDERR "Assembling final results...\n"; + +foreach my $id ( sort keys %$checklist ) +{ + if ( $id =~ /^$seekid\.out(\.str|\.seq)?/ ) + { + bail("Error: Output file corrupted!") unless -e "$TMP/$id"; + appendToFile("$TMP/$id","$OUTPUTFILE".$1); + } +} + +cleanup(); + + + +#################### +#################### + + +sub parseResponse +{ + my $response = shift; + my $status = ""; + my $seekid = ""; + + if ( $response =~ /^([^\s:]+):([^\s:]+)$/ ) + { + $seekid = $1; + $status = $2; + } + + return ($status, $seekid); +} + + +sub parseJobQueryResponse +{ + my $response = shift; + my $jobs = 100; + + if ( $response =~ /^(\d+)$/ ) + { + $jobs = $1; + } + + return $jobs; +} + + +sub extractchecksum +{ + my $infile = shift; + my %dataset = (); + + #open CSUM, "tar -zxf $infile -O|" or return \%dataset; + open CSUM, "<$infile" or return \%dataset; + + while() + { + chomp; + if ( /^(\S+)\s+(\S+)$/ ) + { + $dataset{$2} = $1; + } + } + + close CSUM; + + return \%dataset; +} + + +sub parseError +{ + my $response = shift; + + #"error":"Invalid number of inputs found." + my $errorstr = ( $response =~ /\"error\"\s*:\s*\"([^\"]+)\"/ ) ? $1 : $response; + return $errorstr; +} + + +sub getchecksum +{ + my $infile = shift; + + # md5 binary check + my $MD5BIN = ""; + + if ( -x "/usr/bin/md5sum" ) + { + $MD5BIN = "/usr/bin/md5sum"; + } + elsif ( -x "/sbin/md5" ) + { + $MD5BIN = "/sbin/md5 -q"; + } + + return "" if $MD5BIN eq ""; + + + my $checksum = ""; + open MD5EXE, "$MD5BIN $infile|" or return ""; + + while() + { + if (/^(\S+)\s+(\S+)$/) + { + $checksum = $1; + last; + } + elsif (/^(\S+)$/) + { + $checksum = $1; + last; + } + } + + close MD5EXE; + + return $checksum; + +} + + +sub backticks +{ + my $command = shift; + + `$command`; + return ($? == -1) ? 0 : 1; +} + + +sub bail +{ + my $str = shift; + my $status = shift; + + #0 for success and 1 for error + $status = 1 unless defined; + + print STDERR "$str\n" if defined $str; + + cleanup(); + + exit($status); +} + + +sub cleanup +{ + return if ($TMP eq "" || !-d $TMP); + + opendir(MAINDIR, $TMP); + my @files = readdir(MAINDIR); + closedir(MAINDIR); + + foreach my $file (@files) + { + unlink "$TMP/$file" if -e "$TMP/$file"; + } + + remove_tree($TMP); + +} + + +sub appendToFile +{ + my $inpfile = shift; + my $outfile = shift; + + open INPF, "<$inpfile" or bail("Server Error: Error in reading file."); + open OUTF, ">>$outfile" or bail("Server Error: Error in writing to file."); + + while() + { + print OUTF $_; + } + + close OUTF; + close INPF; +} + + + +sub help +{ + my $str = shift; + + print <<'HELPME'; + +USAGE + ./seekquencer_premafft.pl -inp -out [-str|-seq] + ./seekquencer_premafft.pl -idf -seqf -out [-str|-seq] + + +PARAMETERS + -inp + INFILE is a FASTA-formatted file + PDB entries are written as: + >PDBID + [5-character pdbid+chain] + + While sequence entries are written as: + >[id] + [sequence] + + -idf + IDLISTFILE is a file containing a list of pdbids + pdbids should be a 5-character pdbid + chain + + -seqf + SEQFASTA is a fasta file + entries are written as: + >[id] + [sequence] + + -out + Results are writen to a file named OUTFILE + + -str + Only structures will be collected by Seekquencer + If neither -str nor -seq is set, both structures and sequences will be collected by Seekquencer + + -seq + Only sequences will be collected by Seekquencer + If neither -str nor -seq is set, both structures and sequences will be collected by Seekquencer + + +OPTIONAL PARAMETERS: + -seqd + Search Database for sequence homologs. Default value: uniref100 + + -lim + this sets the maximum number of sequence homologs collected. Default value: 100 + + -blim + this sets the -b and -v value when running blastall. Default value: 100 + + -pre + When -str is set, this will compare all structures against all using pdp-ash + This would ensure that all structures collected are matching + All structures that do not match will be removed + + -noin + When set, inputs will not be included in the output + + -mod + Defines the output format + mafftash (default) will print a mafftash-formatted fasta file + mafftash-split will make 2 files separating the structures (OUTFILE.str) from sequences (OUTFILE.seq) + fasta will print a regular fasta file + + -run + thread will run simultaneous jobs during blast queries (faster but takes more nodes) + normal will run sequential blast queries (slower but takes less nodes) + Default value: normal + + -trd + if -run is defined, this sets the number of parallel jobs to run. Default value: 3 + + +HELPME + + bail($str); +} + diff --git a/binaries/src/mafft/binaries/seq2regtable b/binaries/src/mafft/binaries/seq2regtable index 2fb8589..86ac2a6 100644 Binary files a/binaries/src/mafft/binaries/seq2regtable and b/binaries/src/mafft/binaries/seq2regtable differ diff --git a/binaries/src/mafft/binaries/setcore b/binaries/src/mafft/binaries/setcore index 8d17ec6..04df7e0 100644 Binary files a/binaries/src/mafft/binaries/setcore and b/binaries/src/mafft/binaries/setcore differ diff --git a/binaries/src/mafft/binaries/setdirection b/binaries/src/mafft/binaries/setdirection new file mode 100644 index 0000000..f8a5257 Binary files /dev/null and b/binaries/src/mafft/binaries/setdirection differ diff --git a/binaries/src/mafft/binaries/sextet5 b/binaries/src/mafft/binaries/sextet5 index 4991fd3..d262fb1 100644 Binary files a/binaries/src/mafft/binaries/sextet5 and b/binaries/src/mafft/binaries/sextet5 differ diff --git a/binaries/src/mafft/binaries/splittbfast b/binaries/src/mafft/binaries/splittbfast index cb91ebb..b6cf2a7 100644 Binary files a/binaries/src/mafft/binaries/splittbfast and b/binaries/src/mafft/binaries/splittbfast differ diff --git a/binaries/src/mafft/binaries/tbfast b/binaries/src/mafft/binaries/tbfast index c9b9167..95d8b22 100644 Binary files a/binaries/src/mafft/binaries/tbfast and b/binaries/src/mafft/binaries/tbfast differ diff --git a/binaries/src/mafft/binaries/version b/binaries/src/mafft/binaries/version new file mode 100644 index 0000000..5b50e9a Binary files /dev/null and b/binaries/src/mafft/binaries/version differ diff --git a/binaries/src/mafft/core/DNA.h b/binaries/src/mafft/core/DNA.h index 5f05fa1..4b08125 100644 --- a/binaries/src/mafft/core/DNA.h +++ b/binaries/src/mafft/core/DNA.h @@ -1,6 +1,6 @@ #define DEFAULTGOP_N -1530 #define DEFAULTGEP_N 0 -#define DEFAULTOFS_N -123 +#define DEFAULTOFS_N -369 #define DEFAULTPAMN 200 #define DEFAULTRNAGOP_N -1530 diff --git a/binaries/src/mafft/core/Dalignmm.c b/binaries/src/mafft/core/Dalignmm.c new file mode 100644 index 0000000..a987c7b --- /dev/null +++ b/binaries/src/mafft/core/Dalignmm.c @@ -0,0 +1,6263 @@ +#include "mltaln.h" +#include "dp.h" + +#define DEBUG 0 + +#define WMCHECK 1 +#define ALGZSTRAIGHT 0 +#define ALGZGAP 0 +#define USEGAPLENMTX 0 +#define USEGAPLENHALF 0 +#define FREEFREQUENTLY 1 + +#define IDATEND 0 + + +#define MACHIGAI 0 +#define OUTGAP0TRY 0 +#define XXXXXXX 0 +#define USE_PENALTY_EX 0 +#define FASTMATCHCALC 1 +#define SLOW 0 + +#define zero 0 +#define one 1 + +#if USEGAPLENHALF +#define USEGAPLENHALFORMTX 1 +#endif +#if USEGAPLENMTX +#define USEGAPLENHALFORMTX 1 +#endif + + +#if WMCHECK +static int PFACERROR = 0; +#endif + + +static TLS double **impmtx = NULL; +static TLS int impalloclen = 0; + +double imp_match_out_scD( int i1, int j1 ) +{ +// fprintf( stderr, "imp+match = %f\n", impmtx[i1][j1] * fastathreshold ); +// fprintf( stderr, "val = %f\n", impmtx[i1][j1] ); + return( impmtx[i1][j1] ); +} + +typedef struct _gaplenvec +{ + int relend; +#if USEGAPLENHALFORMTX + int idatend; +#endif + int idatnext; + int idatprev; + int npat; + int len; // sukoshi muda. + double freq; +} Gaplen; + +#if 0 +static void imp_match_out_vead_gapmap( double *imp, int i1, int lgth2, int *gapmap2 ) +{ +#if FASTMATCHCALC + double *pt = impmtx[i1]; + int *gapmappt = gapmap2; + while( lgth2-- ) + *imp++ += pt[*gapmappt++]; +#else + int j; + double *pt = impmtx[i1]; + for( j=0; j ", match[k], mid ); + match[k] -= matrices[mid][c1][c2] * eff1[i] * eff2[j]; +// fprintf( stderr, "match[k] = %f (mid=%d)\n", match[k], mid ); + } + } +// fprintf( stderr, "done\n" ); + return; +} + +#if SLOW +static void match_calc_slow( int **which, double ***matrices, double *match, int n1, char **seq1, double *eff1, int n2, char **seq2, double *eff2, int i1, int lgth2, double **doublework, int **intwork, int initialize, int flip ) +{ +// osoi! + int i, j, k; + int c1, c2; + int mid; +// fprintf( stderr, "\nmatch_calc_dynamicmtx... %d", i1 ); +// fprintf( stderr, "\nseq1[0]=%s\n", seq1[0] ); +// fprintf( stderr, "\nseq2[0]=%s\n", seq2[0] ); +// for( i=0; i-1 ) + *matchpt += scarr[*cpmxpdnpt++] * *cpmxpdpt++; + matchpt++; + } + } + free( scarr ); +// fprintf( stderr, "done\n" ); +#else + int j, k, l; +// double scarr[26]; + double **cpmxpd = doublework; + int **cpmxpdn = intwork; + double *scarr; + scarr = calloc( nalphabets, sizeof( double ) ); +// simple + if( initialize ) + { + int count = 0; + for( j=0; j-1; k++ ) + match[j] += scarr[cpmxpdn[k][j]] * cpmxpd[k][j]; + } + free( scarr ); +#endif +} + +static void match_calc( double **n_dynamicmtx, double *match, double **cpmx1, double **cpmx2, int i1, int lgth2, double **doublework, int **intwork, int initialize ) +{ +#if FASTMATCHCALC +// fprintf( stderr, "\nmatch_calc... %d", i1 ); + int j, l; +// double scarr[26]; + double **cpmxpd = doublework; + int **cpmxpdn = intwork; + double *matchpt, *cpmxpdpt, **cpmxpdptpt; + int *cpmxpdnpt, **cpmxpdnptpt; + double *scarr; + scarr = calloc( nalphabets, sizeof( double ) ); + if( initialize ) + { + int count = 0; + for( j=0; j-1 ) + *matchpt += scarr[*cpmxpdnpt++] * *cpmxpdpt++; + matchpt++; + } + } + free( scarr ); +// fprintf( stderr, "done\n" ); +#else + int j, k, l; +// double scarr[26]; + double **cpmxpd = doublework; + int **cpmxpdn = intwork; + double *scarr; + scarr = calloc( nalphabets, sizeof( double ) ); +// simple + if( initialize ) + { + int count = 0; + for( j=0; j-1; k++ ) + match[j] += scarr[cpmxpdn[k][j]] * cpmxpd[k][j]; + } + free( scarr ); +#endif +} + +static void Atracking_localhom( double *impwmpt, double *lasthorizontalw, double *lastverticalw, + char **seq1, char **seq2, + char **mseq1, char **mseq2, + int **ijp, int icyc, int jcyc, + int *warpis, int *warpjs, int warpbase ) +{ + int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k, limk; + double wm; + char *gaptable1, *gt1bk; + char *gaptable2, *gt2bk; + lgth1 = strlen( seq1[0] ); + lgth2 = strlen( seq2[0] ); + gt1bk = AllocateCharVec( lgth1+lgth2+1 ); + gt2bk = AllocateCharVec( lgth1+lgth2+1 ); + +#if 0 + for( i=0; i= wm ) + { + wm = lastverticalw[i]; + iin = i; jin = lgth2-1; + ijp[lgth1][lgth2] = +( lgth1 - i ); + } + } + for( j=0; j= wm ) + { + wm = lasthorizontalw[j]; + iin = lgth1-1; jin = j; + ijp[lgth1][lgth2] = -( lgth2 - j ); + } + } + } + + for( i=0; i= warpbase ) + { + ifi = warpis[ijp[iin][jin]-warpbase]; + jfi = warpjs[ijp[iin][jin]-warpbase]; + } + else if( ijp[iin][jin] < 0 ) + { + ifi = iin-1; jfi = jin+ijp[iin][jin]; + } + else if( ijp[iin][jin] > 0 ) + { + ifi = iin-ijp[iin][jin]; jfi = jin-1; + } + else + { + ifi = iin-1; jfi = jin-1; + } + if( ifi == -warpbase && jfi == -warpbase ) + { + l = iin; + while( --l >= 0 ) + { + *--gaptable1 = 'o'; + *--gaptable2 = '-'; + k++; + } + l= jin; + while( --l >= 0 ) + { + *--gaptable1 = '-'; + *--gaptable2 = 'o'; + } + break; + } + else + { + l = iin - ifi; + while( --l ) + { + *--gaptable1 = 'o'; + *--gaptable2 = '-'; + k++; + } + l= jin - jfi; + while( --l ) + { + *--gaptable1 = '-'; + *--gaptable2 = 'o'; + k++; + } + } + if( iin == lgth1 || jin == lgth2 ) + ; + else + { + *impwmpt += (double)imp_match_out_scD( iin, jin ); + +// fprintf( stderr, "impwm = %f (iin=%d, jin=%d) seq1=%c, seq2=%c\n", *impwmpt, iin, jin, seq1[0][iin], seq2[0][jin] ); + } + if( iin <= 0 || jin <= 0 ) break; + *--gaptable1 = 'o'; + *--gaptable2 = 'o'; + k++; + iin = ifi; jin = jfi; + } + + for( i=0; i= wm ) + { + wm = lastverticalw[i]; + iin = i; jin = lgth2-1; + ijp[lgth1][lgth2] = +( lgth1 - i ); + } + } + for( j=0; j= wm ) + { + wm = lasthorizontalw[j]; + iin = lgth1-1; jin = j; + ijp[lgth1][lgth2] = -( lgth2 - j ); + } + } + } + + for( i=0; i= warpbase ) + { + ifi = warpis[ijp[iin][jin]-warpbase]; + jfi = warpjs[ijp[iin][jin]-warpbase]; + } + else if( ijp[iin][jin] < 0 ) + { + ifi = iin-1; jfi = jin+ijp[iin][jin]; + } + else if( ijp[iin][jin] > 0 ) + { + ifi = iin-ijp[iin][jin]; jfi = jin-1; + } + else + { + ifi = iin-1; jfi = jin-1; + } + + if( ifi == -warpbase && jfi == -warpbase ) + { + l = iin; + while( --l >= 0 ) + { + *--gaptable1 = 'o'; + *--gaptable2 = '-'; + k++; + } + l= jin; + while( --l >= 0 ) + { + *--gaptable1 = '-'; + *--gaptable2 = 'o'; + } + break; + } + else + { + l = iin - ifi; + while( --l ) + { + *--gaptable1 = 'o'; + *--gaptable2 = '-'; + k++; + } + l= jin - jfi; + while( --l ) + { + *--gaptable1 = '-'; + *--gaptable2 = 'o'; + k++; + } + } + if( iin <= 0 || jin <= 0 ) break; + *--gaptable1 = 'o'; + *--gaptable2 = 'o'; + k++; + iin = ifi; jin = jfi; + } + + for( i=0; i= first ) + { + if( *s-- != '-' ) return( v ); + v++; + } + if( s == first-1 ) return( v ); + return( -1 ); +} + +static void fillgaplen( Gaplen **mtx, int l ) +{ + int i, j, n, k, len, pos, idatnext; + double freq; + for( i=0; i<=l; i++ ) + { +// reporterr( "i=%d\n", i ); + if( mtx[i] == NULL ) continue; + for( n=0; (len=mtx[i][n].len)!=-1; n++ ) + { + freq = mtx[i][n].freq; + idatnext = n; + for( j=0; j 0 ) + { + if( known[gl] ) + { + ; + } + else + { + nknown++; + } + } + } + val += nknown; + } + free( known ); + + return( val ); +} + + +static void gaplencount( int n, int l, Gaplen **mtx, char **seq, double *eff ) +{ + int i, j, k, gl, *known, nknown; + known = calloc( l+1, sizeof( int ) ); +// for( i=0; i 0 ) + { + if( known[gl] ) + { +// reporterr( "gl=%d, Known!\n", gl ); + for( k=0; mtx[j][k].len!=-1; k++ ) if( mtx[j][k].len == gl ) break; + if( mtx[j][k].len == -1 ) + { + reporterr( "Unexpected error!\n" ); + exit( 1 ); + } + mtx[j][k].freq += eff[i]; + } + else + { +// reporterr( "gl=%d, First!\n", gl ); + mtx[j] = realloc( mtx[j], sizeof( Gaplen ) * (nknown+2) ); + mtx[j][nknown].len = gl; + mtx[j][nknown].relend = 0; + mtx[j][nknown].freq = eff[i]; + mtx[j][nknown].idatnext = -2; + mtx[j][nknown+1].len = -1; + mtx[j][nknown+1].idatnext = -1; + mtx[j][nknown+1].relend = -1; + mtx[j][nknown+1].freq = 0.0; + mtx[j][nknown+1].npat = -1; +#if USEGAPLENHALFORMTX + mtx[j][nknown].idatend = nknown; + mtx[j][nknown+1].idatend = -1; +#endif + known[gl]++; + nknown++; + mtx[j][0].npat = nknown; + } + } + } + } + fillgaplen( mtx, l ); +#if 0 + reporterr( "Gaplen:\n" ); + for( i=0; i<=l; i++ ) + { +// reporterr( "i=%d, gaplen[i] = %p\n", i, mtx[i] ); + if( mtx[i] ) + { + for( j=0; mtx[i][j].len!=-1; j++ ) + reporterr( "i=%d, len = %d, relend = %d, freq = %f\n", i, mtx[i][j].len, mtx[i][j].relend, mtx[i][j].freq ); + } + } + +#endif + + free( known ); +} + + +#if DEBUG +static void showgaplen( Gaplen **mtx, int seqlen ) +{ + int i, l; +#if USEGAPLENHALFORMTX + int id, pos; +#endif +// for( i=0; i<=seqlen; i++ ) + for( i=0; ; i++ ) + { +// reporterr( "chain[%d] = %d\n", i, chain[i] ); + if( mtx[i] == NULL ) continue; + if( mtx[i] == (Gaplen *)1 ) break; + for( l=0; mtx[i][l].idatnext!=-1; l++ ) + { +#if USEGAPLENHALFORMTX + reporterr( "i=%d, l=%d, len=%d, relend=%d, idatend=%d, idatnext=%d, idatprev=%d, freq=%f\n", i, l, mtx[i][l].len, mtx[i][l].relend, mtx[i][l].idatend, mtx[i][l].idatnext, mtx[i][l].idatprev, mtx[i][l].freq ); + pos = mtx[i][l].relend; + id = mtx[i][l].idatend; + if( mtx[i+pos] == NULL ) + { +// reporterr( "Error in SOURCE\n" ); + reporterr( ".len and .freq were lost when i=%d!\n", i ); +// exit( 1 ); + } +#else + reporterr( "i=%d, l=%d, len=%d, relend=%d, idatnext=%d, idatprev=%d, freq=%f\n", i, l, mtx[i][l].len, mtx[i][l].relend, mtx[i][l].idatnext, mtx[i][l].idatprev, mtx[i][l].freq ); +#endif + } + } +} +#endif + +#if WMCHECK +static int pairgapcount( char *s1, char *s2 ) +{ + char **tmpseq; + int i, len, st, k; + int v = 0; + + len = strlen( s1 ); + tmpseq = calloc( sizeof( char * ), 2 ); + tmpseq[0] = malloc( sizeof( char ) * ( len + 1 ) ); + tmpseq[1] = malloc( sizeof( char ) * ( len + 1 ) ); + + strcpy( tmpseq[0], s1 ); + strcpy( tmpseq[1], s2 ); + + commongappick( 2, tmpseq ); + len = strlen( tmpseq[0] ); + + + for( k=0; k<2; k++ ) + { + st = 0; + for( i=0; iidatnext!=-1; k++ ) + { + pos1 = g1->relend; + if( pos1 != 0 ) + { + pfac2 = 0.0; + if( gaplen2j ) for( l=0; (g2=gaplen2j+l)->idatnext!=-1; l++ ) + { + pos2 = g2->relend; + if( pos2 == 0 && g2->len >g1->len - (pos1) + newgaplen ) + { + pfac2 += g2->freq; +// reporterr( "hit! pfac2=%f, .freq=%f\n", pfac2, gaplen2[j][l].freq ); + } +// else +// reporterr( "does not hit! pfac2=%f, gaplen1[i][k].len=%d, gaplen[i][k].relend=%d, newgaplen=%d\n", pfac2, gaplen1[i][k].len, gaplen1[i][k].relend, newgaplen ); + } + pfac += pfac2 * g1->freq; + pfac1 += g1->freq; + } + else if( pos1 == 0 ) + { + pfac2 = 1.0; + if( gaplen2j ) for( l=0; (g2=gaplen2j+l)->idatnext!=-1; l++ ) + { + pos2 = g2->relend; + if( pos2 == 0 && g2->len == g1->len+newgaplen ) pfac2 -= g2->freq;// kokode shuryou suru gap, gaplen1 ha kangaenai. + if( pos2 != 0 && g2->len - (pos2-1) > g1->len+newgaplen ) pfac2 -= g2->freq;// keizoku suru gap, gaplen1 ha kangaenai. + } +// reporterr( "pfac2 in line 1056 = %f\n", pfac2 ); + pfac += pfac2 * g1->freq; + pfac10 += g1->freq; + } + } +#if DEBUG + reporterr( "pfac1 (step2) = %f\n", pfac1 ); + reporterr( "pfac10 (step2) = %f\n", pfac10 ); + reporterr( "pfac (step2) = %f\n", pfac ); +#endif + + pfac1 = 1.0 - pfac1 - pfac10; + pfac2 = 1.0; + if( gaplen2j ) for( l=0; (g2=gaplen2j+l)->idatnext!=-1; l++ ) + { + pos2 = g2->relend; + if( pos2 == 0 && g2->len == newgaplen ) pfac2 -= g2->freq;// kokode shuryou suru gap, gaplen1 ha kangaenai. + if( pos2 != 0 && g2->len - (pos2-1) > newgaplen ) pfac2 -= g2->freq;// keizoku suru gap, gaplen1 ha kangaenai. + } +#if DEBUG + reporterr( "pfac1 (type3) = %f\n", pfac1 ); + reporterr( "pfac2 (type3) = %f\n", pfac2 ); + reporterr( "pfac (step3) = %f\n", pfac ); +#endif + pfac += pfac1 * pfac2; +#if DEBUG + reporterr( "incomplete pfac = %f, pfac1,pfac2 (%c%d,%c%d) = %f, %f\n", pfac, seq1[i], i, seq2[j], j, pfac1, pfac2 ); +#endif + + + return( pfac ); + +#else + + double pfac, pfac1, pfac10, pfac2; + int k, l, pos1, pos2, id1, id2; + Gaplen *gaplen1i, *gaplen2j; + +#if 0 // .len no shouryaku ni taiou shiteinai + int gl; + if( disp ) + { + reporterr( "calcpfac_gap_noidatend, %c (%d) - %c (%d)\n", seq1[i], i, seq2[j], j ); + reporterr( "newgaplen = %d\n", newgaplen ); + reporterr( "In calcpfac_gap, gaplen1[%d(%c)] = \n", i, seq1[i] ); + for( k=0; gaplen1[i]&&(id1=gaplen1[i][k].idatend)!=-1; k++ ) + { + pos1 = gaplen1[i][k].relend; + reporterr( ".len=%d, .relend=%d, .freq=%f\n", gaplen1[i+pos1][id1].len, gaplen1[i][k].relend, gaplen1[i+pos1][id1].freq[0] ); + } + reporterr( "In calcpfac_gap, gaplen2[%d(%c)] = \n", j, seq2[j] ); + showgaplen( gaplen2, strlen(seq2) ); + for( k=0; gaplen2[j]&&(id2=gaplen2[j][k].idatend)!=-1; k++ ) + { + pos2 = gaplen2[j][k].relend; + reporterr( ".len=%d, .relend=%d, .freq=%f\n", gaplen2[j+pos2][id2].len, gaplen2[j][k].relend, gaplen2[j+pos2][id2].freq[0] ); + } + } +#endif + gaplen2j = gaplen2[j]; + gaplen1i = gaplen1[i]; + + pfac = 0.0; + pfac1 = 0.0; + pfac10 = 0.0; + if( gaplen1i ) for( k=0; (gaplen1i[k].idatnext)!=-1; k++ ) + { + pos1 = gaplen1i[k].relend; + if( pos1 != 0 ) + { + pfac2 = 0.0; + if( gaplen2j ) for( l=0; (gaplen2j[l].idatnext)!=-1; l++ ) + { + pos2 = gaplen2j[l].relend; + if( pos2 == 0 && gaplen2j[l].len > gaplen1i[k].len - (pos1) + newgaplen ) + { + pfac2 += gaplen2j[l].freq; +// reporterr( "hit! pfac2=%f, .freq=%f\n", pfac2, gaplen2[j][l].freq ); + } +// else +// reporterr( "does not hit! pfac2=%f, gaplen1[i][k].len=%d, gaplen[i][k].relend=%d, newgaplen=%d\n", pfac2, gaplen1[i][k].len, gaplen1[i][k].relend, newgaplen ); + } + pfac += pfac2 * gaplen1i[k].freq; + pfac1 += gaplen1i[k].freq; + } + else if( pos1 == 0 ) + { + pfac2 = 1.0; + if( gaplen2j ) for( l=0; (gaplen2j[l].idatnext)!=-1; l++ ) + { + pos2 = gaplen2j[l].relend; + if( pos2 == 0 && gaplen2j[l].len == gaplen1i[k].len+newgaplen ) pfac2 -= gaplen2j[l].freq;// kokode shuryou suru gap, gaplen1 ha kangaenai. + if( pos2 != 0 && gaplen2j[l].len - (pos2-1) > gaplen1i[k].len+newgaplen ) pfac2 -= gaplen2j[l].freq;// keizoku suru gap, gaplen1 ha kangaenai. + } +// reporterr( "pfac2 in line 1056 = %f\n", pfac2 ); + pfac += pfac2 * gaplen1i[k].freq; + pfac10 += gaplen1i[k].freq; + } + } +#if DEBUG + reporterr( "pfac1 (step2) = %f\n", pfac1 ); + reporterr( "pfac10 (step2) = %f\n", pfac10 ); + reporterr( "pfac (step2) = %f\n", pfac ); +#endif + + pfac1 = 1.0 - pfac1 - pfac10; + pfac2 = 1.0; + if( gaplen2j ) for( l=0; (gaplen2j[l].idatnext)!=-1; l++ ) + { + pos2 = gaplen2j[l].relend; + if( pos2 == 0 && gaplen2j[l].len == newgaplen ) pfac2 -= gaplen2j[l].freq;// kokode shuryou suru gap, gaplen1 ha kangaenai. + if( pos2 != 0 && gaplen2j[l].len - (pos2-1) > newgaplen ) pfac2 -= gaplen2j[l].freq;// keizoku suru gap, gaplen1 ha kangaenai. + } +#if DEBUG + reporterr( "pfac1 (type3) = %f\n", pfac1 ); + reporterr( "pfac2 (type3) = %f\n", pfac2 ); + reporterr( "pfac (step3) = %f\n", pfac ); +#endif + pfac += pfac1 * pfac2; +#if DEBUG + reporterr( "incomplete pfac = %f, pfac1,pfac2 (%c%d,%c%d) = %f, %f\n", pfac, seq1[i], i, seq2[j], j, pfac1, pfac2 ); +#endif + + + return( pfac ); + +#endif +} + +#if USEGAPLENHALFORMTX + +static double calcpfac_gap_incomplete( Gaplen **gaplen1, Gaplen **gaplen2, int newgaplen, int i, int j, char *seq1, char *seq2, int disp ) // seq1 to seq2 ha debug you +{ + double pfac, pfac1, pfac10, pfac2; + int k, l, pos1, pos2, id1, id2; + Gaplen *gapend1, *gapend2; + Gaplen *gaplen1i, *gaplen2j; + +#if 0 // .len no shouryaku ni taiou shiteinai + int gl; + if( disp ) + { + reporterr( "calcpfac_gap_incomplete, %c (%d) - %c (%d)\n", seq1[i], i, seq2[j], j ); + reporterr( "newgaplen = %d\n", newgaplen ); + reporterr( "In calcpfac_gap, gaplen1[%d(%c)] = \n", i, seq1[i] ); + for( k=0; gaplen1[i]&&(id1=gaplen1[i][k].idatend)!=-1; k++ ) + { + pos1 = gaplen1[i][k].relend; + reporterr( ".len=%d, .relend=%d, .freq=%f\n", gaplen1[i+pos1][id1].len, gaplen1[i][k].relend, gaplen1[i+pos1][id1].freq[0] ); + } + reporterr( "In calcpfac_gap, gaplen2[%d(%c)] = \n", j, seq2[j] ); + showgaplen( gaplen2, strlen(seq2) ); + for( k=0; gaplen2[j]&&(id2=gaplen2[j][k].idatend)!=-1; k++ ) + { + pos2 = gaplen2[j][k].relend; + reporterr( ".len=%d, .relend=%d, .freq=%f\n", gaplen2[j+pos2][id2].len, gaplen2[j][k].relend, gaplen2[j+pos2][id2].freq[0] ); + } + } +#endif + gaplen2j = gaplen2[j]; + gaplen1i = gaplen1[i]; + + pfac = 0.0; + pfac1 = 0.0; + pfac10 = 0.0; + if( gaplen1i ) for( k=0; (id1=gaplen1i[k].idatend)!=-1; k++ ) + { + pos1 = gaplen1i[k].relend; + gapend1 = gaplen1[i+pos1]+id1; + if( pos1 != 0 ) + { + pfac2 = 0.0; + if( gaplen2j ) for( l=0; (id2=gaplen2j[l].idatend)!=-1; l++ ) + { + pos2 = gaplen2j[l].relend; + gapend2 = gaplen2[j+pos2]+id2; +// if( pos2 == 0 && gapend2->len + 1 > gapend1->len - (pos1-1) + newgaplen ) + if( pos2 == 0 && gapend2->len > gapend1->len - (pos1) + newgaplen ) + { + pfac2 += gapend2->freq; +// reporterr( "hit! pfac2=%f, .freq=%f\n", pfac2, gaplen2[j][l].freq ); + } +// else +// reporterr( "does not hit! pfac2=%f, gaplen1[i][k].len=%d, gaplen[i][k].relend=%d, newgaplen=%d\n", pfac2, gaplen1[i][k].len, gaplen1[i][k].relend, newgaplen ); + } + pfac += pfac2 * gapend1->freq; + pfac1 += gapend1->freq; + } + else if( pos1 == 0 ) + { + pfac2 = 1.0; + if( gaplen2j ) for( l=0; (id2=gaplen2j[l].idatend)!=-1; l++ ) + { + pos2 = gaplen2j[l].relend; + gapend2 = gaplen2[j+pos2]+id2; + if( pos2 == 0 && gapend2->len == gapend1->len+newgaplen ) pfac2 -= gapend2->freq;// kokode shuryou suru gap, gaplen1 ha kangaenai. + if( pos2 != 0 && gapend2->len - (pos2-1) > gapend1->len+newgaplen ) pfac2 -= gapend2->freq;// keizoku suru gap, gaplen1 ha kangaenai. + } +// reporterr( "pfac2 in line 1056 = %f\n", pfac2 ); + pfac += pfac2 * gapend1->freq; + pfac10 += gapend1->freq; + } + } +#if DEBUG + reporterr( "pfac1 (step2) = %f\n", pfac1 ); + reporterr( "pfac10 (step2) = %f\n", pfac10 ); + reporterr( "pfac (step2) = %f\n", pfac ); +#endif + + pfac1 = 1.0 - pfac1 - pfac10; + pfac2 = 1.0; + if( gaplen2j ) for( l=0; (id2=gaplen2j[l].idatend)!=-1; l++ ) + { + pos2 = gaplen2j[l].relend; + gapend2 = gaplen2[j+pos2]+id2; + if( pos2 == 0 && gapend2->len == newgaplen ) pfac2 -= gapend2->freq;// kokode shuryou suru gap, gaplen1 ha kangaenai. + if( pos2 != 0 && gapend2->len - (pos2-1) > newgaplen ) pfac2 -= gapend2->freq;// keizoku suru gap, gaplen1 ha kangaenai. + } +#if DEBUG + reporterr( "pfac1 (type3) = %f\n", pfac1 ); + reporterr( "pfac2 (type3) = %f\n", pfac2 ); + reporterr( "pfac (step3) = %f\n", pfac ); +#endif + pfac += pfac1 * pfac2; +#if DEBUG + reporterr( "incomplete pfac = %f, pfac1,pfac2 (%c%d,%c%d) = %f, %f\n", pfac, seq1[i], i, seq2[j], j, pfac1, pfac2 ); +#endif + + + return( pfac ); + +} + +static double calcpfac_gapex( Gaplen **gaplen1, Gaplen **gaplen2, int i, int j, int newgaplen, char *seq1, char *seq2, int disp ) +{ + double pfac, pfac1, pfac2, pfac10; + int k, l, id1, id2, pos1, pos2; + Gaplen *gapend1, *gapend2; + Gaplen *gaplen1i, *gaplen2j; + + gaplen1i = gaplen1[i]; + gaplen2j = gaplen2[j]; + + pfac = 0.0; + pfac2 = 0.0; +// for( k=0; gaplen2[j]&&(gl=gaplen2[j][k].len)!=-1; k++ ) // ososugi! hash ni atode henkou + if( gaplen2j ) for( k=0; (id2=gaplen2j[k].idatend)!=-1; k++ ) // ososugi! hash ni atode henkou + { +#if DEBUG + int gl; + pos2 = gaplen2j[k].relend; + id2 = gaplen2j[k].idatend; + gl = gaplen2[j+pos2][id2].len; + if( disp ) reporterr( "gaplen2[][].len=%d, .relend=%d, .freq=%f\n", gaplen2[j+pos2][id2].len, gaplen2[j][k].relend, gaplen2[j+pos2][id2].freq ); + if( disp ) reporterr( "gl = %d, newgaplen=%d\n", gl, newgaplen ); +#endif + if( (pos2=gaplen2[j][k].relend) != 0 ) continue; + + gapend2 = gaplen2[j+pos2]+id2; + pfac1 = 1.0; + pfac10 = 1.0; + if( gaplen1i ) for( l=0; (id1=gaplen1i[l].idatend)!=-1; l++ ) // ososugi! hash ni atode henkou + { + pos1 = gaplen1i[l].relend; + gapend1 = gaplen1[i+pos1]+id1; + pfac10 -= gapend1->freq; +#if DEBUG + if( disp ) reporterr( "gaplen1[][].len=%d, .relend=%d, .freq=%f\n", gaplen1[i+pos1][id1].len, gaplen1[i][l].relend, gaplen1[i+pos1][id1].freq ); +#endif + if( newgaplen + gapend1->len - (pos1) > gapend2->len - (pos2) ) pfac1 -= gapend1->freq; +// reporterr( "pfac1 = %f\n", pfac1 ); + } + pfac += pfac1 * gapend2->freq; + + +/* ???? */ + if( newgaplen >= gapend2->len - (pos2-1) ) // >= or >?? + { + pfac -= pfac10 * gapend2->freq; +// reporterr( "Hit! pfac1 = %f\n", pfac1 ); + } +/* ???? */ + + +// if( gaplen2[j][k].relend == -1 ) pfac += gaplen2[j][k].freq; + } + + return( pfac ); +} + +static double calcpfac( Gaplen **gaplen1, Gaplen **gaplen2, int i, int j, char *seq1, char *seq2, int disp ) // seq1 to seq2 ha debug you +{ + double pfac, pfac1, pfac2; + int k, l, pos1, pos2, id1, id2; + Gaplen *gapend1, *gapend2; + Gaplen *gaplen1i, *gaplen2j; + + gaplen1i = gaplen1[i]; + gaplen2j = gaplen2[j]; + +#if DEBUG + if( disp ) + { + reporterr( "seq1[0] = %s\n", seq1 ); + reporterr( "seq2[0] = %s\n", seq2 ); + reporterr( "i,j=%d,%d\n", i, j ); + + reporterr( "In calcpfac(), gaplen1[%d(%c)] = \n", i, seq1[i] ); +// showgaplen( gaplen1, seqlen( seq1 ) ); + for( k=0; gaplen1[i]&&(id1=gaplen1[i][k].idatend)!=-1; k++ ) + { + pos1 = gaplen1[i][k].relend; + reporterr( "pos1=%d, id1=%d\n", pos1, id1 ); + reporterr( ".len=%d, .relend=%d, .freq=%f\n", gaplen1[i+pos1][id1].len, gaplen1[i][k].relend, gaplen1[i+pos1][id1].freq ); + } + + reporterr( "In calcpfac(), gaplen2[%d(%c)] = \n", j, seq2[j] ); +// showgaplen( gaplen2, seqlen( seq2 ) ); + for( k=0; gaplen2[j]&&(id2=gaplen2[j][k].idatend)!=-1; k++ ) + { + pos2 = gaplen2[j][k].relend; + reporterr( "j=%d, k=%d, id2=%d, pos2=%d\n", j, k, id2, pos2 ); + reporterr( ".len=%d, .relend=%d\n", gaplen2[j+pos2][id2].len, gaplen2[j][k].relend ); + reporterr( ".freq=%f\n", gaplen2[j+pos2][id2].freq ); + } + } +#endif + + pfac1 = pfac2 = 0.0; + if( gaplen1i ) for( k=0; (id1=gaplen1i[k].idatend)!=-1; k++ ) + { + if( (pos1=gaplen1i[k].relend) == 0 ) pfac1 += gaplen1[i+pos1][id1].freq; + } + + if( gaplen2j ) for( l=0; (id2=gaplen2j[l].idatend)!=-1; l++ ) // ososugi! hash ni atode henkou + { + if( (pos2=gaplen2j[l].relend) == 0 ) pfac2 += gaplen2[j+pos2][id2].freq; + } +#if DEBUG + reporterr( "\n\nInitial pfac1,pfac2 (%c%d,%c%d) = %f, %f\n", seq1[i], i, seq2[j], j, pfac1, pfac2 ); +#endif + pfac = pfac1 * pfac2 + pfac1 * (1-pfac2) + pfac2 * (1-pfac1); +#if DEBUG + reporterr( "\n\nInitial pfac (%d,%d) = %f\n", i, j, pfac ); +#endif + +#if 1 +// if( pfac ) reporterr( "i,j=%d,%d, Cancel (eq len)? pfac = %f -> ", i, j, pfac ); + if( gaplen1i ) for( k=0; (id1=gaplen1i[k].idatend)!=-1; k++ ) // ososugi! hash ni atode henkou + { + pos1=gaplen1i[k].relend; + gapend1 = gaplen1[i+pos1]+id1; + if( gaplen2j ) for( l=0; (id2=gaplen2j[l].idatend)!=-1; l++ ) // ososugi! hash ni atode henkou + { + pos2 = gaplen2j[l].relend; + gapend2 = gaplen2[j+pos2]+id2; + if ( pos1 == 0 && pos2 == 0 && gapend1->len == gapend2->len ) pfac -= gapend1->freq * gapend2->freq; + else if( pos1 == 0 && pos2 != 0 && gapend2->len - (pos2-1) > gapend1->len ) pfac -= gapend1->freq * gapend2->freq; + else if( pos1 != 0 && pos2 == 0 && gapend1->len - (pos1-1) > gapend2->len ) pfac -= gapend1->freq * gapend2->freq; + } + } + +#if DEBUG + reporterr( "\n\nFinal pfac1,pfac2 (%c%d,%c%d, straight) = %f\n\n", seq1[i], i, seq2[j], j, pfac ); +#endif +#else +#endif + return( pfac ); +} +#endif + +static double calcpfac_gapex_noidatend( Gaplen **gaplen1, Gaplen **gaplen2, int i, int j, int newgaplen, char *seq1, char *seq2, int disp ) +{ +#if 1 + double pfac, pfac1, pfac2, pfac10; + int k, l, pos1, pos2; + Gaplen *gaplen1i, *gaplen2j, *g1, *g2; + + gaplen1i = gaplen1[i]; + gaplen2j = gaplen2[j]; + + pfac = 0.0; + pfac2 = 0.0; + if( gaplen2j ) for( k=0; (g2=gaplen2j+k)->idatnext!=-1; k++ ) + { +#if DEBUG + int gl; + pos2 = gaplen2j[k].relend; + gl = gaplen2j[k].len; + if( disp ) reporterr( "gaplen2[][].len=%d, .relend=%d, .freq=%f\n", gaplen2[j][k].len, gaplen2[j][k].relend, gaplen2[j][k].freq ); + if( disp ) reporterr( "gl = %d, newgaplen=%d\n", gl, newgaplen ); +#endif + if( (pos2=g2->relend) != 0 ) continue; + + pfac1 = 1.0; + pfac10 = 1.0; + if( gaplen1i ) for( l=0; (g1=gaplen1i+l)->idatnext!=-1; l++ ) + { + pos1 = g1->relend; + pfac10 -= g1->freq; +#if DEBUG + if( disp ) reporterr( "gaplen1[][].len=%d, .relend=%d, .freq=%f\n", gaplen1[i][l].len, gaplen1[i][l].relend, gaplen1[i][l].freq ); +#endif + if( newgaplen + g1->len - (pos1) > g2->len - (pos2) ) pfac1 -= g1->freq; +// reporterr( "pfac1 = %f\n", pfac1 ); + } + pfac += pfac1 * g2->freq; + + +/* ???? */ + if( newgaplen >= g2->len - (pos2-1) ) // >= or >?? + { + pfac -= pfac10 * g2->freq; +// reporterr( "Hit! pfac1 = %f\n", pfac1 ); + } +/* ???? */ + + +// if( gaplen2[j][k].relend == -1 ) pfac += gaplen2[j][k].freq; + } + + return( pfac ); +#else + double pfac, pfac1, pfac2, pfac10; + int k, l, id1, id2, pos1, pos2; + Gaplen *gaplen1i, *gaplen2j; + + gaplen1i = gaplen1[i]; + gaplen2j = gaplen2[j]; + + pfac = 0.0; + pfac2 = 0.0; +// for( k=0; gaplen2[j]&&(gl=gaplen2[j][k].len)!=-1; k++ ) // ososugi! hash ni atode henkou + if( gaplen2j ) for( k=0; (gaplen2j[k].idatnext)!=-1; k++ ) // ososugi! hash ni atode henkou + { +#if DEBUG + int gl; + pos2 = gaplen2j[k].relend; + gl = gaplen2j[k].len; + if( disp ) reporterr( "gaplen2[][].len=%d, .relend=%d, .freq=%f\n", gaplen2[j][k].len, gaplen2[j][k].relend, gaplen2[j][k].freq ); + if( disp ) reporterr( "gl = %d, newgaplen=%d\n", gl, newgaplen ); +#endif + if( (pos2=gaplen2[j][k].relend) != 0 ) continue; + + pfac1 = 1.0; + pfac10 = 1.0; + if( gaplen1i ) for( l=0; (gaplen1i[l].idatnext)!=-1; l++ ) // ososugi! hash ni atode henkou + { + pos1 = gaplen1i[l].relend; + pfac10 -= gaplen1i[l].freq; +#if DEBUG + if( disp ) reporterr( "gaplen1[][].len=%d, .relend=%d, .freq=%f\n", gaplen1[i][l].len, gaplen1[i][l].relend, gaplen1[i][l].freq ); +#endif + if( newgaplen + gaplen1i[l].len - (pos1) > gaplen2j[k].len - (pos2) ) pfac1 -= gaplen1i[l].freq; +// reporterr( "pfac1 = %f\n", pfac1 ); + } + pfac += pfac1 * gaplen2j[k].freq; + + +/* ???? */ + if( newgaplen >= gaplen2j[k].len - (pos2-1) ) // >= or >?? + { + pfac -= pfac10 * gaplen2j[k].freq; +// reporterr( "Hit! pfac1 = %f\n", pfac1 ); + } +/* ???? */ + + +// if( gaplen2[j][k].relend == -1 ) pfac += gaplen2[j][k].freq; + } + + return( pfac ); + +#endif +} + + +static double calcpfacnoidatend( Gaplen **gaplen1, Gaplen **gaplen2, int i, int j, char *seq1, char *seq2, int disp ) // seq1 to seq2 ha debug you +{ + double pfac, pfac1, pfac2; + int k, l, pos1, pos2; + Gaplen *gaplen1i, *gaplen2j, *g1, *g2; + + gaplen1i = gaplen1[i]; + gaplen2j = gaplen2[j]; + +#if DEBUG + if( disp ) + { + reporterr( "seq1[0] = %s\n", seq1 ); + reporterr( "seq2[0] = %s\n", seq2 ); + reporterr( "i,j=%d,%d\n", i, j ); + + reporterr( "In calcpfacnoidatend(), gaplen1[%d(%c)] = \n", i, seq1[i] ); + showgaplen( gaplen1, seqlen( seq1 ) ); + for( k=0; gaplen1[i]&&gaplen1[i][k].idatnext!=-1; k++ ) + { + pos1 = gaplen1[i][k].relend; + reporterr( ".len=%d, .relend=%d, .freq=%f (i=%d)\n", gaplen1[i][k].len, gaplen1[i][k].relend, gaplen1[i][k].freq, i ); + } + + reporterr( "In calcpfacnoidatend(), gaplen2[%d(%c)] = \n", j, seq2[j] ); + showgaplen( gaplen2, seqlen( seq2 ) ); + for( k=0; gaplen2[j]&&gaplen2[j][k].idatnext!=-1; k++ ) + { + pos2 = gaplen2[j][k].relend; + reporterr( ".len=%d, .relend=%d (j=%d)\n", gaplen2[j][k].len, gaplen2[j][k].relend, j ); + reporterr( ".freq=%f\n", gaplen2[j][k].freq ); + } + } +#endif + +#if 1 + pfac1 = pfac2 = 0.0; + if( gaplen1i ) for( k=0; (g1=gaplen1i+k)->idatnext!=-1; k++ ) + { + if( (pos1=g1->relend) == 0 ) pfac1 += g1->freq; + } + + if( gaplen2j ) for( l=0; (g2=gaplen2j+l)->idatnext!=-1; l++ ) // ososugi! hash ni atode henkou + { + if( (pos2=g2->relend) == 0 ) pfac2 += g2->freq; + } +#if DEBUG + reporterr( "\n\nInitial pfac1,pfac2 (%c%d,%c%d) = %f, %f\n", seq1[i], i, seq2[j], j, pfac1, pfac2 ); +#endif + pfac = pfac1 * pfac2 + pfac1 * (1-pfac2) + pfac2 * (1-pfac1); +#if DEBUG + reporterr( "\n\nInitial pfac (%d,%d) = %f\n", i, j, pfac ); +#endif + +// if( pfac ) reporterr( "i,j=%d,%d, Cancel (eq len)? pfac = %f -> ", i, j, pfac ); + if( gaplen1i ) for( k=0; (g1=gaplen1i+k)->idatnext!=-1; k++ ) // ososugi! hash ni atode henkou + { + pos1=g1->relend; + if( gaplen2j ) for( l=0; (g2=gaplen2j+l)->idatnext!=-1; l++ ) // ososugi! hash ni atode henkou + { + pos2 = gaplen2j[l].relend; + if ( pos1 == 0 && pos2 == 0 && g1->len == g2->len ) pfac -= g1->freq * g2->freq; + else if( pos1 == 0 && pos2 != 0 && g2->len - (pos2-1) > g1->len ) pfac -= g1->freq * g2->freq; + else if( pos1 != 0 && pos2 == 0 && g1->len - (pos1-1) > g2->len ) pfac -= g1->freq * g2->freq; + } + } + +#else + + pfac1 = pfac2 = 0.0; + if( gaplen1i ) for( k=0; (gaplen1i[k].idatnext)!=-1; k++ ) + { + if( gaplen1i[k].relend == 0 ) pfac1 += gaplen1[i][k].freq; + } + + if( gaplen2j ) for( l=0; (gaplen2j[l].idatnext)!=-1; l++ ) // ososugi! hash ni atode henkou + { + if( gaplen2j[l].relend == 0 ) pfac2 += gaplen2[j][l].freq; + } +#if DEBUG + reporterr( "\n\nInitial pfac1,pfac2 (%c%d,%c%d) = %f, %f\n", seq1[i], i, seq2[j], j, pfac1, pfac2 ); +#endif + pfac = pfac1 * pfac2 + pfac1 * (1-pfac2) + pfac2 * (1-pfac1); +#if DEBUG + reporterr( "\n\nInitial pfac (%d,%d) = %f\n", i, j, pfac ); +#endif + +#if 1 +// if( pfac ) reporterr( "i,j=%d,%d, Cancel (eq len)? pfac = %f -> ", i, j, pfac ); + if( gaplen1i ) for( k=0; (gaplen1i[k].idatnext)!=-1; k++ ) // ososugi! hash ni atode henkou + { + pos1=gaplen1i[k].relend; + if( gaplen2j ) for( l=0; (gaplen2j[l].idatnext)!=-1; l++ ) // ososugi! hash ni atode henkou + { + pos2 = gaplen2j[l].relend; + if ( pos1 == 0 && pos2 == 0 && gaplen1i[k].len == gaplen2j[l].len ) pfac -= gaplen1i[k].freq * gaplen2j[l].freq; + else if( pos1 == 0 && pos2 != 0 && gaplen2j[l].len - (pos2-1) > gaplen1i[k].len ) pfac -= gaplen1i[k].freq * gaplen2j[l].freq; + else if( pos1 != 0 && pos2 == 0 && gaplen1i[k].len - (pos1-1) > gaplen2j[l].len ) pfac -= gaplen1i[k].freq * gaplen2j[l].freq; + } + } +#endif +#endif + +#if DEBUG + reporterr( "\n\nFinal pfac1,pfac2 (%c%d,%c%d, straight) = %f\n\n", seq1[i], i, seq2[j], j, pfac ); +#endif + return( pfac ); +} + + +static void extendgaplencompactx( Gaplen **cpy, Gaplen **orig, int start ) +{ + Gaplen *opt, *cpt; + int l, id; +#if DEBUG + Gaplen cpybk; +#endif + +// if( start < 0 ) start = 0; + + if( orig[start] == NULL ) + { + if( cpy[start] ) + { + free( cpy[start] ); + cpy[start] = NULL; + } + return; + } + + +#if DEBUG + reporterr( "At first, cpy -> \n" ); + showgaplen( cpy, 100 ); + reporterr( "Look at %d \n", start ); +#endif + + if( cpy[start] == NULL ) + { + l = orig[start][0].npat; + + cpy[start] = realloc( cpy[start], (l+2) * sizeof( Gaplen ) ); + +#if 0 + for( l=0; (gl=orig[start][l].idatend)!=-1; l++ ) + cpy[start][l] = orig[start][l]; // freq ha pointer de copy + cpy[start][l] = orig[start][l]; // dekiru? +#else + for( opt = orig[start],cpt = cpy[start]; opt->idatnext!=-1; ) + *cpt++ = *opt++; + *cpt = *opt; +#endif + } + +#if DEBUG + cpybk = cpy[start][0]; +#endif + +#if 0 + for( l=0; (opt=orig[start]+l)->idatend!=-1; l++ ) + { + if( (pos=opt->relend) == 0 ) continue; + + if( cpy[posplus=start+pos] != NULL ) + { + id = opt->idatend; +// reporterr( "cpy[%d][%d].len: %d -> %d (relend=%d)\n", start, l, cpy[start][l].len, cpy[posplus][id].len, pos ); + cpy[start][l].len = cpy[posplus][id].len; // Ato de posplus wo tsukawanaiyouni henkou. + continue; // HITSUYOU!!! + } + else + { +// reporterr( "cpy[%d][%d].len: %d (relend=%d)\n", start, l, cpy[start][l].len, pos ); + } + +#if 0 + for( k=0; orig[start+pos][k].idatend!=-1; k++ ) + ; +#else + optplus = orig[posplus]; + k = optplus->npat; +#endif + + + cptplus = cpy[posplus] = realloc( cpy[posplus], (k+2) * sizeof( Gaplen ) ); +// cptplus = realloc( cptplus, (k+2) * sizeof( Gaplen ) ); + +#if 0 + for( k=0; optplus[k].idatend!=-1; k++ ) + { + cptplus[k] = optplus[k]; // dekiru? + } + cptplus[k] = optplus[k]; // dekiru? +#else + while( optplus->idatend!=-1 ) *cptplus++ = *optplus++; + *cptplus = *optplus; +#endif + } +#endif + + + if( start == 0 ) return; + if( cpy[start-1] == NULL ) return; + +#if DEBUG + reporterr( "cpy -> \n" ); + showgaplen( cpy, 100 ); + reporterr( "Look at %d \n", start ); +#endif + + for( l=0; orig[start][l].idatnext!=-1; l++ ) + { + if( (id=orig[start][l].idatprev) == -1 ) continue; + +// if( cpy[start][l].relend != 0 ) cpy[start][l].len = cpy[start-1][id].len; // Shinchou ni + cpy[start][l].len = cpy[start-1][id].len; // Shinchou ni + +// if( cpy[start][l].len != cpy[start-1][id].len ) +#if DEBUG + if( 1 || cpy[start][l].len != cpy[start-1][id].len ) + { + reporterr( "Check!! cpy[%d][%d].len=%d, but [start-1][].len=%d, relend=%d\n", start, l, cpy[start][l].len, cpy[start-1][id].len, cpy[start][l].relend ); + reporterr( "orig[%d][%d].len=%d, relend=%d\n", start, l, orig[start][l].len, orig[start][l].relend ); + reporterr( "cpybk.len=%d, relend=%d\n", cpybk.len, cpybk.relend ); + + } + else + { +// reporterr( "OK, cpy[%d][%d].len=%d, relend=%d\n", start, l, cpy[start][l].len, cpy[start][l].relend ); + } +#endif + } + +} + + +#if USEGAPLENHALFORMTX +static void extendgaplenpartly( Gaplen **cpy, Gaplen **orig, int start, int end ) +{ + int i, l, gl, extrascope; + Gaplen *pt; + + if( start < 0 ) start = 0; +// for( i=start; i<=end; i++ ) +// { +// if( cpy[i] == (Gaplen *)1 ) +// { +// end = i-1; +// break; +//// reporterr( "Okashii! i=%d\n", i ); +//// exit( 1 ); +// } +// if( cpy[i] ) free( cpy[i] ); +// cpy[i] = NULL; +// } + + + extrascope = 0; +#if 0 + for( i=start; i<=end; i++ ) if( orig[i] ) + { + for( pt=orig[i]; (pt->idatend)!=-1; ) + { + if( (gl=pt++->relend) > extrascope ) extrascope = i+gl-end+1; + } +// extrascope = 10; // Kinji + + } +#else + if( orig[end] ) + { + for( pt=orig[end]; (pt->idatend)!=-1; ) + { + if( (gl=pt++->relend) > extrascope ) extrascope = gl; + } +// extrascope = 10; // Kinji + + } +#endif + end += extrascope; + + for( i=start; i<=end; i++ ) + { + if( cpy[i] != NULL ) continue; + + if( orig[i] == NULL ) + { + if( cpy[i] ) free( cpy[i] ); // muda dakedo + cpy[i] = NULL; + continue; + } + + for( l=0; (gl=orig[i][l].idatend)!=-1; l++ ) + ; + + cpy[i] = realloc( cpy[i], (l+2) * sizeof( Gaplen ) ); +// cpy[i] = calloc( sizeof( Gaplen ), l+2 ); + + for( l=0; (gl=orig[i][l].idatend)!=-1; l++ ) + { +#if 1 + cpy[i][l] = orig[i][l]; // freq ha pointer de copy +#else + cpy[i][l].len = gl; + cpy[i][l].relend = orig[i][l].relend; + cpy[i][l].freq = orig[i][l].freq; + cpy[i][l].gapidatend = orig[i][l].gapidatend; +#endif + +// reporterr( "i=%d, l=%d, len=%d, freq=%f, relend=%d\n", i, l, cpy[i][l].len, cpy[i][l].freq, cpy[i][l].relend ); + } + cpy[i][l] = orig[i][l]; // dekiru? +// cpy[i][l].relend = -1; +// cpy[i][l].len = -1; + } + +} +#endif + +static void duplicategaplencompactx( Gaplen **cpy, Gaplen **orig, int maxlen, int start, int end ) +{ + int i, l; + + + if( start < 0 ) start = 0; + for( i=start; i<=end; i++ ) + { +// reporterr( "i=%d / %d\n", i, maxlen ); + if( cpy[i] == (Gaplen *)1 ) + { + end = i-1; + break; +// reporterr( "Okashii! i=%d\n", i ); +// exit( 1 ); + } + if( cpy[i] ) free( cpy[i] ); + cpy[i] = NULL; + } + + for( i=start; i<=end; i++ ) + { + if( orig[i] == NULL ) + { + if( cpy[i] ) free( cpy[i] ); // muda dakedo + cpy[i] = NULL; + continue; + } + +#if 0 + for( l=0; (gl=orig[i][l].idatend)!=-1; l++ ) + ; +#else + l = orig[i][0].npat; +#endif + + cpy[i] = realloc( cpy[i], (l+2) * sizeof( Gaplen ) ); +// cpy[i] = calloc( sizeof( Gaplen ), l+2 ); + + for( l=0; orig[i][l].idatnext!=-1; l++ ) + { + cpy[i][l] = orig[i][l]; // freq ha pointer de copy +// reporterr( "i=%d, l=%d, len=%d, freq=%f, relend=%d\n", i, l, cpy[i][l].len, cpy[i][l].freq, cpy[i][l].relend ); + } + cpy[i][l] = orig[i][l]; // dekiru? +// cpy[i][l].relend = -1; +// cpy[i][l].len = -1; + } + + return; +} + + + +#if USEGAPLENHALFORMTX +static void duplicategaplenpartly( Gaplen **cpy, Gaplen **orig, int start, int end ) +{ + int i, l, gl, extrascope; + Gaplen *pt; + + if( start < 0 ) start = 0; + for( i=start; i<=end; i++ ) + { + if( cpy[i] == (Gaplen *)1 ) + { + end = i-1; + break; +// reporterr( "Okashii! i=%d\n", i ); +// exit( 1 ); + } + if( cpy[i] ) free( cpy[i] ); + cpy[i] = NULL; + } + + + extrascope = 0; +#if 0 + for( i=start; i<=end; i++ ) if( orig[i] ) + { + for( pt=orig[i]; (pt->idatend)!=-1; ) + { + if( (gl=pt++->relend) > extrascope ) extrascope = i+gl-end+1; + } +// extrascope = 10; // Kinji + + } +#else + if( orig[end] ) + { + for( pt=orig[end]; (pt->idatend)!=-1; ) + { + if( (gl=pt++->relend) > extrascope ) extrascope = gl; + } +// extrascope = 10; // Kinji + + } +#endif + end += extrascope; + + for( i=start; i<=end; i++ ) + { + if( orig[i] == NULL ) + { + if( cpy[i] ) free( cpy[i] ); // muda dakedo + cpy[i] = NULL; + continue; + } + + for( l=0; (gl=orig[i][l].idatend)!=-1; l++ ) + ; + + cpy[i] = realloc( cpy[i], (l+2) * sizeof( Gaplen ) ); +// cpy[i] = calloc( sizeof( Gaplen ), l+2 ); + + for( l=0; (gl=orig[i][l].idatend)!=-1; l++ ) + { +#if 1 + cpy[i][l] = orig[i][l]; // freq ha pointer de copy +#else + cpy[i][l].len = gl; + cpy[i][l].relend = orig[i][l].relend; + cpy[i][l].freq = orig[i][l].freq; + cpy[i][l].gapidatend = orig[i][l].gapidatend; +#endif + +// reporterr( "i=%d, l=%d, len=%d, freq=%f, relend=%d\n", i, l, cpy[i][l].len, cpy[i][l].freq, cpy[i][l].relend ); + } + cpy[i][l] = orig[i][l]; // dekiru? +// cpy[i][l].relend = -1; +// cpy[i][l].len = -1; + } + +} +#endif + + +static void gaplenextendnoidatend( Gaplen **cpy, int gapstartpos, int insertionlen ) +{ + int l, id, idn, pos, len; + +#if 0 +// reporterr( "inserting %d gaps at position %d\n", insertionlen, gapstartpos ); + for( l=0; cpy[gapstartpos] && (id=cpy[gapstartpos][l].idatend) !=-1; l++ ) + { + pos = cpy[gapstartpos][l].relend; + cpy[gapstartpos+pos][id].len += insertionlen; + } +#endif + +#if 1 + for( l=0; cpy[gapstartpos] && (id=cpy[gapstartpos][l].idatnext) !=-1; l++ ) + { + len = cpy[gapstartpos][l].len + insertionlen; +// reporterr( "ext\n" ); + for( pos=gapstartpos, idn=l; cpy[pos] != NULL && cpy[pos][idn].relend != 0; pos++ ) + { +// reporterr( "%d, plus %d %d->%d\n", pos, insertionlen, cpy[pos][idn].len, cpy[pos][idn].len+insertionlen ); + cpy[pos][idn].len = len; + idn = cpy[pos][idn].idatnext; +// if( pos == gapstartpos + 1 ) break; + break; + } +// reporterr( "end\n" ); + + idn = cpy[gapstartpos][l].idatprev; + if( gapstartpos != 0 && idn != -1 && cpy[gapstartpos-1] ) cpy[gapstartpos-1][idn].len = len; + } +#endif +} + + +#if USEGAPLENHALFORMTX + +static void gaplenextend( Gaplen **cpy, int gapstartpos, int insertionlen ) +{ + int l, id, idn, pos, len; + +#if 1 +// reporterr( "inserting %d gaps at position %d\n", insertionlen, gapstartpos ); + for( l=0; cpy[gapstartpos] && (id=cpy[gapstartpos][l].idatend) !=-1; l++ ) + { + pos = cpy[gapstartpos][l].relend; + cpy[gapstartpos+pos][id].len += insertionlen; + } +#endif + +#if 1 + for( l=0; cpy[gapstartpos] && (id=cpy[gapstartpos][l].idatend) !=-1; l++ ) + { + len = cpy[gapstartpos][l].len + insertionlen; +// reporterr( "ext\n" ); + for( pos=gapstartpos, idn=l; cpy[pos] != NULL && cpy[pos][idn].relend != 0; pos++ ) + { +// reporterr( "%d, plus %d %d->%d\n", pos, insertionlen, cpy[pos][idn].len, cpy[pos][idn].len+insertionlen ); + cpy[pos][idn].len = len; + idn = cpy[pos][idn].idatnext; +// if( pos == gapstartpos + 1 ) break; +// break; + } +// reporterr( "end\n" ); + + idn = cpy[gapstartpos][l].idatprev; + if( gapstartpos != 0 && idn != -1 && cpy[gapstartpos-1] ) cpy[gapstartpos-1][idn].len = len; + } +#endif +} +#endif + +static void copygaplencompactx( Gaplen **cpy, Gaplen **orig, int seqlen, int gapstartpos, int insertionlen, int posincopy, int posinori ) +{ + Gaplen *pt, *cpt; + + + +#if DEBUG + reporterr( "At the head of copygaplencompactx, cpy=\n" ); + showgaplen( cpy+posincopy, 100 ); + reporterr( "At the head of copygaplencompactx, orig=\n" ); + showgaplen( orig+posinori, 100 ); + reporterr( "posinori=%d\n", posinori ); +#endif + + if( orig[posinori] == NULL ) return; + +// for( pt=orig[posinori],cpt=cpy[posincopy]; pt->relend==0; ) // zenhan ni relend=0 ga matomatteirukara. + for( pt=orig[posinori],cpt=cpy[posincopy]; pt->idatnext!=-1; ) // kouhan mo copy + { + cpt++->len = pt++->len; + } + + +#if 0 + for( l=0; (id=orig[posinori][l].idatend)!=-1; l++ ) + { + pos = orig[posinori][l].relend; + if( pos == 0 ) continue; + if( orig[posinori+pos] == NULL ) + { + reporterr( "Okashii\n" ); + PFACERROR = 1; + continue; + } + +#if 0 + for( k=0; orig[posinori+pos][k].relend==0; k++ ) // zenhan dake + { + cpy[posincopy+pos][k].len = orig[posinori+pos][k].len; // dekiru? + } +#else + cpy[posincopy+pos][id].len = orig[posinori+pos][id].len; // dekiru? +#endif + } +#endif + + + if( gapstartpos == -1 ) gapstartpos = posincopy; + gaplenextendnoidatend( cpy, gapstartpos, insertionlen ); + +#if DEBUG + reporterr( "At the end of copygaplencompactx, cpy=\n" ); + showgaplen( cpy+posincopy, 100 ); +#endif +} + + +#if USEGAPLENHALF +static void copygaplenrestricted_zurasu( Gaplen **cpy, Gaplen **orig, int seqlen, int gapstartpos, int insertionlen, int startincopy, int endincopy, int startinori, int endinori ) +{ + int i, extrascope, gl, j; + int zure, newend; + Gaplen *pt, *cpt; +// int ncopied = 0; + +#if 0 +// mae houkou nimo renzoku gap de enchou suru hitsuyou ga aru to omou. + for( i=startinori-1; 0<=i&&i<=seqlen; i-- ) + { +// reporterr( "i=%d\n", i ); + if( orig[i] == NULL ) break; + for( pt=orig[i],cpt=cpy[i]; (gl=pt++->len)!=-1; ) cpt++->len = gl; + } +#endif + + zure = startincopy - startinori; // end ha check shinai + +// int ncopied = 0; + if( orig[endinori] ) + { + extrascope = 0; + for( pt=orig[endinori]; (pt->idatend)!=-1; ) + { + if( (gl=pt++->relend) > extrascope ) extrascope = gl; + } +// extrascope = 10; // Kinji + + newend = endinori + extrascope; + } + else newend = endinori; + +// reporterr( "ncopy = %d\n", newend - startinori ); +// +#if 0 // extra end wo shizen ni kimereba iranai + if( newend > seqlen ) newend = seqlen; +// if( startinori < 0 ) startinori = 0; +#endif + + for( i=startinori, j=startincopy; i<=newend; i++, j++ ) + { + if( orig[i] == NULL ) continue; + +// ncopied += 1; + +#if 0 + for( pt=orig[i],cpt=cpy[i]; (gl=pt++->len)!=-1; ) + cpt++->len = gl; +#else + for( pt=orig[i],cpt=cpy[j]; pt->relend==0; ) // zenhan ni relend=0 ga matomatteirukara. +// int k; +// for( k=0; orig[i][k].relend==0; k++ ) // zenhan ni relend=0 ga matomatteirukara. + { + cpt++->len = pt++->len; +// reporterr( "i=%d, k=%d\n", i, k ); +// cpy[i][k].len = orig[i][k].len; + } +#endif + } + + + +#if 0 + for( i=0; i<=seqlen; i++ ) + { + for( l=0; cpy[i]&&(gl=cpy[i][l].len)!=-1; l++ ) + reporterr( "after copy, i=%d, l=%d, len=%d, freq=%f, relend=%d\n", i, l, cpy[i][l].len, cpy[i][l].freq, cpy[i][l].relend ); + } +#endif + + if( gapstartpos < 0 ) return; + + gaplenextend( cpy, gapstartpos, insertionlen ); + + + +// return; + + +// TEST +// for( i=endinori+1; i<=newend; i++ ) + for( i=endincopy+1; i<=newend+zure; i++ ) + { + if( cpy[i] == NULL ) continue; + for( j=0; cpy[i][j].idatend!=-1; j++ ) + { + if( cpy[i][j].relend == 0 ) + { + break; + } + } + if( cpy[i][j].idatend == -1 ) + { + free( cpy[i] ); + cpy[i] = NULL; + } + } + + + + + + +#if 0 + reporterr( "\n" ); + for( i=0; i<=seqlen; i++ ) + { + for( l=0; cpy[i]&&(gl=cpy[i][l].len)!=-1; l++ ) + reporterr( "after add, i=%d, l=%d, len=%d, freq=%f, relend=%d\n", i, l, cpy[i][l].len, cpy[i][l].freq, cpy[i][l].relend ); + } +#endif +} +#endif + +#if USEGAPLENHALFORMTX +static void copygaplenrestricted( Gaplen **cpy, Gaplen **orig, int seqlen, int gapstartpos, int insertionlen, int scopestart, int scopeend ) +{ + int i, j, extrascope, gl, endinori, newend; + Gaplen *pt, *cpt; +// int ncopied = 0; + +#if 0 +// mae houkou nimo renzoku gap de enchou suru hitsuyou ga aru to omou. + for( i=scopestart-1; 0<=i&&i<=seqlen; i-- ) + { +// reporterr( "i=%d\n", i ); + if( orig[i] == NULL ) break; + for( pt=orig[i],cpt=cpy[i]; (gl=pt++->len)!=-1; ) cpt++->len = gl; + } +#endif + +// int ncopied = 0; + endinori = scopeend; + if( orig[scopeend] ) + { + extrascope = 0; + for( pt=orig[scopeend]; (pt->idatend)!=-1; ) + { + if( (gl=pt++->relend) > extrascope ) extrascope = gl; + } +// extrascope = 10; // Kinji + + scopeend += extrascope; + } + newend = scopeend; + +// reporterr( "ncopy = %d\n", scopeend - scopestart ); +// +#if 0 // extra end wo shizen ni kimereba iranai + if( scopeend > seqlen ) scopeend = seqlen; +// if( scopestart < 0 ) scopestart = 0; +#endif + + if( scopestart < 0 ) scopestart = 0; + for( i=scopestart; i<=scopeend; i++ ) + { + if( orig[i] == NULL ) continue; + +// ncopied += 1; + +#if 0 + for( pt=orig[i],cpt=cpy[i]; (gl=pt++->len)!=-1; ) + cpt++->len = gl; +#else + for( pt=orig[i],cpt=cpy[i]; pt->relend==0; ) // zenhan ni relend=0 ga matomatteirukara. +// int k; +// for( k=0; orig[i][k].relend==0; k++ ) // zenhan ni relend=0 ga matomatteirukara. + { + cpt++->len = pt++->len; +// reporterr( "i=%d, k=%d\n", i, k ); +// cpy[i][k].len = orig[i][k].len; + } +#endif + } + + + +#if 0 + for( i=0; i<=seqlen; i++ ) + { + for( l=0; cpy[i]&&(gl=cpy[i][l].len)!=-1; l++ ) + reporterr( "after copy, i=%d, l=%d, len=%d, freq=%f, relend=%d\n", i, l, cpy[i][l].len, cpy[i][l].freq, cpy[i][l].relend ); + } +#endif + + if( gapstartpos < 0 ) return; + + gaplenextend( cpy, gapstartpos, insertionlen ); + + return; + +// TEST extra scope de tsukaunoha end dake? + for( i=endinori+1; i<=newend; i++ ) + { + if( cpy[i] == NULL ) continue; + for( j=0; cpy[i][j].idatend!=-1; j++ ) + { + if( cpy[i][j].relend == 0 ) break; + } + if( cpy[i][j].idatend == -1 ) + { + free( cpy[i] ); + cpy[i] = NULL; + } + } + + + +#if 0 + reporterr( "\n" ); + for( i=0; i<=seqlen; i++ ) + { + for( l=0; cpy[i]&&(gl=cpy[i][l].len)!=-1; l++ ) + reporterr( "after add, i=%d, l=%d, len=%d, freq=%f, relend=%d\n", i, l, cpy[i][l].len, cpy[i][l].freq, cpy[i][l].relend ); + } +#endif +} +#endif + +#if 1 +static void freegaplenpartly( Gaplen **mtx, int startpos, int endpos ) +{ + int i; + Gaplen **pt; + if( startpos < 0 ) startpos = 0; + + for( i=startpos; i<=endpos; i++ ) + { + if( *(pt=mtx+i) == (Gaplen *)1 ) break; + if( *pt ) free( *pt ); + *pt = NULL; + } +} +#else +static void freegaplenpartly( Gaplen **mtx, int startpos, int endpos ) +{ + int i; + if( startpos < 0 ) startpos = 0; + + for( i=startpos; i<=endpos; i++ ) + { + if( mtx[i] == (Gaplen *)1 ) break; + if( mtx[i] ) free( mtx[i] ); + mtx[i] = NULL; + } +} +#endif + + +double D__align( double **n_dynamicmtx, char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, double *impmatch, char *sgap1, char *sgap2, char *egap1, char *egap2, int *chudanpt, int chudanref, int *chudanres, int headgp, int tailgp ) +/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */ +{ + +// int k; + register int i, j; + + + + + int lasti, lastj; /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */ + int lgth1, lgth2; + int resultlen; + double wm = 0.0; /* int ?????? */ + double g; + double *currentw, *previousw; +// double fpenalty = (double)penalty; +#if USE_PENALTY_EX + double fpenalty_ex = (double)penalty_ex; +#endif +#if 1 + double *wtmp; + int *ijppt; + double *mjpt, *prept, *curpt; + int *mpjpt; +#endif + static TLS double mi, *m; + static TLS int **ijp; + static TLS int mpi, *mp; + static TLS double *w1, *w2; + static TLS double *match; + static TLS double *initverticalw; /* kufuu sureba iranai */ + static TLS double *lastverticalw; /* kufuu sureba iranai */ + static TLS char **mseq1; + static TLS char **mseq2; + static TLS char **mseq; + static TLS double **cpmx1; + static TLS double **cpmx2; + static TLS int **intwork; + static TLS double **doublework; + static TLS int orlgth1 = 0, orlgth2 = 0; +#if USEGAPLENHALF + Gaplen ****gaplen1half = NULL; // NULL ga iru to omou. + Gaplen ****gaplen2half = NULL; // NULL ga iru to omou. +#endif +#if USEGAPLENMTX + Gaplen ****gaplen1mtx = NULL; // NULL ga iru to omou. + Gaplen ****gaplen2mtx = NULL; // NULL ga iru to omou. +#endif + static TLS Gaplen **gaplen1 = NULL; // NULL ga iru to omou. + static TLS Gaplen **gaplen2 = NULL; // NULL ga iru to omou. + static TLS Gaplen ***gaplen1jprev = NULL; + static TLS Gaplen ***gaplen2jprev = NULL; + static TLS Gaplen ***gaplen1jcurr = NULL; + static TLS Gaplen ***gaplen2jcurr = NULL; + static TLS Gaplen ***gaplen1icurr = NULL; + static TLS Gaplen ***gaplen2icurr = NULL; + static TLS Gaplen ***gaplen1jbestkamo = NULL; + static TLS Gaplen ***gaplen2jbestkamo = NULL; + static TLS Gaplen ***gaplen1ibestkamo = NULL; + static TLS Gaplen ***gaplen2ibestkamo = NULL; + static TLS Gaplen ***gaplen1jbest = NULL; + static TLS Gaplen ***gaplen2jbest = NULL; + double fpenalty = (double)penalty; + double fpenalty_shift = (double)penalty_shift; + static TLS Gaplen ****gaplens = NULL; + + Gaplen ***gaplentmp = NULL; + int *warpis = NULL; + int *warpjs = NULL; + int *warpi = NULL; + int *warpj = NULL; + int *prevwarpi = NULL; + int *prevwarpj = NULL; + double *wmrecords = NULL; + double *prevwmrecords = NULL; + int warpn = 0; + int warpbase; + double curm = 0.0; + double *wmrecordspt, *wmrecords1pt, *prevwmrecordspt; + int *warpipt, *warpjpt; + int k; + double pfac, pfactmp; + int newgaplen; + +// for( i=0; i orlgth1 || lgth2 > orlgth2 ) + { + int ll1, ll2; + + + if( orlgth1 > 0 && orlgth2 > 0 ) + { + FreeFloatVec( w1 ); + FreeFloatVec( w2 ); + FreeFloatVec( match ); + FreeFloatVec( initverticalw ); + FreeFloatVec( lastverticalw ); + + FreeFloatVec( m ); + FreeIntVec( mp ); + + FreeCharMtx( mseq ); + + FreeFloatMtx( cpmx1 ); + FreeFloatMtx( cpmx2 ); + + FreeFloatMtx( doublework ); + FreeIntMtx( intwork ); + + + free( gaplens ); + + if( gaplen1ibestkamo ) FreeGaplenCub( gaplen1ibestkamo ); gaplen1ibestkamo = NULL; + if( gaplen2ibestkamo ) FreeGaplenCub( gaplen2ibestkamo ); gaplen2ibestkamo = NULL; + if( gaplen1icurr ) FreeGaplenCub( gaplen1icurr ); gaplen1icurr = NULL; + if( gaplen2icurr ) FreeGaplenCub( gaplen2icurr ); gaplen2icurr = NULL; + + if( gaplen1jcurr ) FreeGaplenCub( gaplen1jcurr ); gaplen1jcurr = NULL; + if( gaplen1jprev ) FreeGaplenCub( gaplen1jprev ); gaplen1jprev = NULL; + if( gaplen2jcurr ) FreeGaplenCub( gaplen2jcurr ); gaplen2jcurr = NULL; + if( gaplen2jprev ) FreeGaplenCub( gaplen2jprev ); gaplen2jprev = NULL; + if( gaplen1jbestkamo ) FreeGaplenCub( gaplen1jbestkamo ); gaplen1jbestkamo = NULL; + if( gaplen2jbestkamo ) FreeGaplenCub( gaplen2jbestkamo ); gaplen2jbestkamo = NULL; + if( gaplen1jbest ) FreeGaplenCub( gaplen1jbest ); gaplen1jbest = NULL; + if( gaplen2jbest ) FreeGaplenCub( gaplen2jbest ); gaplen2jbest = NULL; + if( gaplen1 ) FreeGaplenMtx( gaplen1, 1 ); gaplen1 = NULL; + if( gaplen2 ) FreeGaplenMtx( gaplen2, 1 ); gaplen2 = NULL; + + + } + + ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100; + ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100; + +#if DEBUG + fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 ); +#endif + + w1 = AllocateFloatVec( ll2+2 ); + w2 = AllocateFloatVec( ll2+2 ); + match = AllocateFloatVec( ll2+2 ); + + initverticalw = AllocateFloatVec( ll1+2 ); + lastverticalw = AllocateFloatVec( ll1+2 ); + + m = AllocateFloatVec( ll2+2 ); + mp = AllocateIntVec( ll2+2 ); + + mseq = AllocateCharMtx( njob, ll1+ll2 ); + + cpmx1 = AllocateFloatMtx( nalphabets, ll1+2 ); + cpmx2 = AllocateFloatMtx( nalphabets, ll2+2 ); + +#if FASTMATCHCALC + doublework = AllocateFloatMtx( MAX( ll1, ll2 )+2, nalphabets ); + intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, nalphabets+1 ); +#else + doublework = AllocateFloatMtx( nalphabets, MAX( ll1, ll2 )+2 ); + intwork = AllocateIntMtx( nalphabets, MAX( ll1, ll2 )+2 ); +#endif + +#if DEBUG + fprintf( stderr, "succeeded\n" ); +#endif + + orlgth1 = ll1 - 100; + orlgth2 = ll2 - 100; + + +// reporterr( "Allocating gaplen1 and gaplen2\n" ); + gaplen1 = (Gaplen ** )calloc( ll1+2, sizeof( Gaplen * ) ); + gaplen1[ll1+1] = (Gaplen *)1; + gaplen2 = (Gaplen ** )calloc( ll2+2, sizeof( Gaplen * ) ); + gaplen2[ll2+1] = (Gaplen *)1; + + +// reporterr( "Allocating gaplen*\n" ); + gaplen1ibestkamo = (Gaplen ***)calloc( (ll1+2), sizeof( Gaplen **) ); + gaplen2ibestkamo = (Gaplen ***)calloc( (ll1+2), sizeof( Gaplen **) ); + gaplen1icurr = (Gaplen ***)calloc( (ll1+2), sizeof( Gaplen **) ); + gaplen2icurr = (Gaplen ***)calloc( (ll1+2), sizeof( Gaplen **) ); + gaplen1jbestkamo = (Gaplen ***)calloc( (ll2+2), sizeof( Gaplen **) ); + gaplen2jbestkamo = (Gaplen ***)calloc( (ll2+2), sizeof( Gaplen **) ); + gaplen1jbest = (Gaplen ***)calloc( (ll2+2), sizeof( Gaplen **) ); + gaplen2jbest = (Gaplen ***)calloc( (ll2+2), sizeof( Gaplen **) ); + gaplen1jcurr = (Gaplen ***)calloc( (ll2+2), sizeof( Gaplen **) ); + gaplen2jcurr = (Gaplen ***)calloc( (ll2+2), sizeof( Gaplen **) ); + gaplen1jprev = (Gaplen ***)calloc( (ll2+2), sizeof( Gaplen **) ); + gaplen2jprev = (Gaplen ***)calloc( (ll2+2), sizeof( Gaplen **) ); + + gaplens = calloc( sizeof( Gaplen ***), 12 ); + gaplens[0] = gaplen1ibestkamo; + gaplens[1] = gaplen2ibestkamo; + gaplens[2] = gaplen1icurr; + gaplens[3] = gaplen2icurr; + gaplens[4] = gaplen1jbestkamo; + gaplens[5] = gaplen2jbestkamo; + gaplens[6] = gaplen1jbest; + gaplens[7] = gaplen2jbest; + gaplens[8] = gaplen1jcurr; + gaplens[9] = gaplen2jcurr; + gaplens[10] = gaplen1jprev; + gaplens[11] = gaplen2jprev; +// reporterr( "Allocation end\n" ); + } + + { + int ll1 = lgth1; + int ll2 = lgth2; + +// reporterr( "Allocating gaplen*i\n" ); + for(i=0; i commonAlloc1 || orlgth2 > commonAlloc2 ) + { + int ll1, ll2; + + if( commonAlloc1 && commonAlloc2 ) + { + FreeIntMtx( commonIP ); + } + + ll1 = MAX( orlgth1, commonAlloc1 ); + ll2 = MAX( orlgth2, commonAlloc2 ); + +#if DEBUG + fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 ); +#endif + + commonIP = AllocateIntMtx( ll1+10, ll2+10 ); + +#if DEBUG + fprintf( stderr, "succeeded\n\n" ); +#endif + + commonAlloc1 = ll1; + commonAlloc2 = ll2; + } + ijp = commonIP; + +#if 0 + { + double t = 0.0; + for( i=0; i zurasu -> error? + + +// duplicategaplencompactx( gaplen1ibestkamo[i], gaplen1, lgth1, 0, 1 ); +// duplicategaplencompactx( gaplen1ibestkamo[i], gaplen1+i, lgth1-i, 0, 1 ); // half + duplicategaplencompactx( gaplen1ibestkamo[i], gaplen1+i, lgth1-i, 0, 0 ); // half +// duplicategaplencompactx( gaplen2ibestkamo[i], gaplen2, lgth2, 0, lgth2 ); + duplicategaplencompactx( gaplen2ibestkamo[i], gaplen2, lgth2, 0, 0 ); +// copygaplenrestricted( gaplen2ibestkamo[i], gaplen2, lgth2, 0, i, 0, 0 ); // -> zurasu -> error? +// copygaplenrestricted_zurasu( gaplen2ibestkamo[i], gaplen2, lgth2, 0, i, 0, lgth2, 0, lgth2 ); // -> zurasu -> error? + copygaplencompactx( gaplen2ibestkamo[i], gaplen2, lgth2, 0, i, 0, 0 ); // -> zurasu -> error? + } + +// reporterr( "Duplicating gaplen*j*curr \n" ); +// int nduplicated = 0; + for( j=0; j tbfast.c + if( localhom ) + imp_match_calc( n_dynamicmtx, currentw, icyc, jcyc, lgth1, lgth2, seq1, seq2, eff1, eff2, localhom, 1, 0 ); + +#endif + + for( j=1; j ", seq1[0][0], seq2[0][j], j, currentw[j] ); + currentw[j] += fpenalty * pfac; // tekitou +// reporterr( " %f\n", currentw[j] ); + } + for( i=1; ifull, 2j->half +#if USEGAPLENMTX +//reporterr( "#### FULL, i,j=%d,%d\n", i, j ); + pfactmp = calcpfac( gaplen1mtx[i-1][j-1], gaplen2mtx[i-1][j-1], i, j, seq1[0], seq2[0], one ); +#endif +#if USEGAPLENHALF +//reporterr( "#### HALF, i,j=%d/%d,%d/%d\n", i, lgth1, j, lgth2 ); +// showgaplen( gaplen2half[i-1][j-1], lgth2-j ); + pfactmp = calcpfac( gaplen1half[i-1][j-1], gaplen2half[i-1][j-1], 1, 1, seq1[0]+i, seq2[0]+j, zero ); +#endif +#if USEGAPLENMTX + USEGAPLENHALF + if( pfac != pfactmp ) + { + reporterr( "(straight) pfac=%f, but pfactmp=%f (i,j=%d,%d)\n", pfac, pfactmp, i, j ); + PFACERROR = 1; + exit( 1 ); + } +#endif +//if( i==50 && j==135 ) exit( 1 ); + + +// reporterr( "i,j=%d,%d, *prept = %f\n", i, j, *prept ); + +#if ALGZSTRAIGHT + wm = *prept; // Machigai!! +#else + wm = *prept + fpenalty * pfac; +#endif + *ijppt = 0; + + +#if DEBUG + if( i == j ) + { + fprintf( stderr, "\n i=%d, j=%d %c, %c ", i, j, seq1[0][i], seq2[0][j] ); + fprintf( stderr, "%5.0f, pfac for straight =%f\n", wm, pfac ); + } +#endif + newgaplen = j-mpi-1; + + +//if( i == 53 && j == 93 ) exit( 1 ); + + + + +// pfac = calcpfac_gap_incomplete( gaplen1ibestkamo[i-1], gaplen2ibestkamo[i-1], newgaplen, i, j, seq1[0], seq2[0], 0 ); // i-1 + pfac = calcpfac_gap_noidatend( gaplen1ibestkamo[i-1], gaplen2ibestkamo[i-1], newgaplen, 1, j, seq1[0]+i-1, seq2[0], 0 ); // i-1 +#if USEGAPLENMTX + pfactmp = calcpfac_gap_incomplete( gaplen1mtx[i-1][mpi], gaplen2mtx[i-1][mpi], newgaplen, i, j, seq1[0], seq2[0], 1 ); +#endif +#if USEGAPLENHALF + pfactmp = calcpfac_gap_incomplete( gaplen1half[i-1][mpi], gaplen2half[i-1][mpi], newgaplen, 1, j-mpi, seq1[0]+i-1, seq2[0]+mpi, 1 ); +#endif +#if USEGAPLENMTX || USEGAPLENHALF + if( pfac != pfactmp ) + { + reporterr( "(igap) pfac=%f, but pfactmp=%f (i,j=%d,%d)\n", pfac, pfactmp, i, j ); + PFACERROR = 1; + } +#endif + + +#if DEBUG + reporterr( "%c-%c pfac for igap end incomplete = %f\n", seq1[0][i], seq2[0][j], pfac ); + reporterr( "mi when igap end checking = %f\n", mi ); + reporterr( "wm = %f, mi+fpenalty*pfac=%f\n", wm, mi+fpenalty*pfac ); +#endif + + +#if ALGZGAP + if( (g=mi+*fgcp2pt*gf1va) > wm ) +#else + if( (g=mi+fpenalty*pfac) > wm ) +#endif + { + wm = g; + *ijppt = -( j - mpi ); +#if DEBUG80 + reporterr( "Selected as igap end! wm = %f, mi = %f\n", wm, mi ); + fprintf( stderr, "Jump from %d-%d (%c-%c) to %d (%c-%c)!\n", i, j, seq1[0][i], seq2[0][j], mpi, seq1[0][i-1], seq2[0][mpi] ); +#endif + } + + +#if 0 + fprintf( stderr, "%5.0f->", wm ); +#endif +// if( (g=*mjpt+ fgcp1va* *gf2pt) > wm ) + +#if 0 +// reporterr( "Checking %c, (current pos = %c)\n", seq2[0][j+1], seq2[0][j] ); + sfac = 1.0; + for( k=0; gaplen2[j+1]&&(gl=gaplen2[j+1][k].len)!=-1; k++ ) // ososugi! hash ni atode henkou + { +// reporterr( ".len = %d, .relend = %d\n", gaplen2[j+1][k].len, gaplen2[j+1][k].relend ); + if( gl - 1 == gaplen2[j+1][k].relend ) + { + sfac -= gaplen2[j+1][k].freq; +// reporterr( "Hit! sfac = %f\n", sfac ); + } + } + sfac2 = 1.0; + for( k=0; gaplen1[i+1]&&(gl=gaplen1[i+1][k].len)!=-1; k++ ) // ososugi! hash ni atode henkou + if( gaplen1[i+1][k].relend != -1 ) sfac2 -= gaplen1[i+1][k].freq; + sfac *= sfac2; +#else +// sfac = 0.0; +#endif + + + +#if ALGZGAP + if( (g=*prept+*ogcp2pt*gf1vapre) >= mi ) +#else +// if( (g=*prept + fpenalty * sfac ) >= mi ) + if( (g=*prept ) >= mi ) +#endif + { +// mpibk = mpi; +// mi = g - fpenalty * sfac; + mi = g; + mpi = j-1; +#if DEBUG80 + reporterr( "Selected as igap start! %c%d-%c%d, mi=%f, g=%f\n", seq1[0][i-1], i-1, seq2[0][mpi], mpi, mi, g ); +#endif + +#if FREEFREQUENTLY +// freegaplenpartly( gaplen1ibestkamo[i-1], 0, i-1 ); + freegaplenpartly( gaplen2ibestkamo[i-1], j-3, j-2 ); +#endif +// freegaplenpartly( gaplen1jprev[mpibk], 0, lgth2 ); // full +// freegaplenpartly( gaplen2jprev[mpibk], 0, lgth2-mpibk ); // half +// if( gaplen1jprev[mpibk] ) FreeGaplenMtx( gaplen1jprev[mpibk], 0 ); +// gaplen1jprev[mpibk] = NULL; +// if( gaplen2jprev[mpibk] ) FreeGaplenMtx( gaplen2jprev[mpibk], 0 ); +// gaplen2jprev[mpibk] = NULL; + + +// addnewgaplen( gaplen1ibestkamo[i-1], gaplen1jprev[j-1], gaplen1, lgth1, -1, 0 ); +// addnewgaplen( gaplen2ibestkamo[i-1], gaplen2jprev[j-1], gaplen2, lgth2, -1, 0 ); +// copygaplenrestricted( gaplen1ibestkamo[i-1], gaplen1jprev[j-1], lgth1, -1, 0, i, i ); // i-1, i + copygaplencompactx( gaplen1ibestkamo[i-1], gaplen1jprev[j-1], lgth1, -1, 0, 1, i ); // half +// copygaplenrestricted( gaplen2ibestkamo[i-1], gaplen2jprev[j-1], lgth2, -1, 0, j, j ); // mpi, j + copygaplencompactx( gaplen2ibestkamo[i-1], gaplen2jprev[j-1], lgth2, -1, 0, j, 1 ); //half + + + } + + + + + + +// reporterr( "g=%f, *prept=%f, mi=%f\n", g, *prept, mi ); + + +#if USE_PENALTY_EX + mi += fpenalty_ex; +#endif + +#if ALGZGAP + pfac = 0.0; // CHUUI! +#else + +// pfac = calcpfac_gapex( gaplen1ibestkamo[i-1], gaplen2ibestkamo[i-1], i, j, j-mpi, seq1[0], seq2[0], 1 ); // i-1 + pfac = calcpfac_gapex_noidatend( gaplen1ibestkamo[i-1], gaplen2ibestkamo[i-1], 1, j, j-mpi, seq1[0]+i, seq2[0], 1 ); // 1ibest->half, 2ibest->full +#if USEGAPLENMTX + pfactmp = calcpfac_gapex( gaplen1mtx[i-1][mpi], gaplen2mtx[i-1][mpi], i, j, j-mpi, seq1[0], seq2[0], 1 ); +#endif +#if USEGAPLENHALF + pfactmp = calcpfac_gapex( gaplen1half[i-1][mpi], gaplen2half[i-1][mpi], 1, j-mpi, j-mpi, seq1[0]+i, seq2[0]+mpi, 1 ); +#endif +#if USEGAPLENMTX || USEGAPLENHALF + if( pfac != pfactmp ) + { + reporterr( "(igapex) pfac=%f, but pfactmp=%f (i,j=%d,%d)\n", pfac, pfactmp, i, j ); + PFACERROR = 1; + } +#endif + + + + + + + +#if DEBUG + reporterr( "%c-%c, igap extension check, pfac = %f\n\n", '=', seq2[0][j], pfac ); +#endif +#endif +// reporterr( "mi = %f -> ", mi ); + mi += fpenalty * pfac; +// reporterr( "mi = %f\n", mi ); + + +// reporterr( "using %d-%d, %d, %d\n", *mpjpt, j-1, i, j ); + newgaplen = i-*mpjpt-1; +// pfac = calcpfac_gap_incomplete( gaplen2jbestkamo[j-1], gaplen1jbestkamo[j-1], newgaplen, j, i, seq2[0], seq1[0], 0 ); // j-1 deha??? + + + pfac = calcpfac_gap_noidatend( gaplen2jbestkamo[j-1], gaplen1jbestkamo[j-1], newgaplen, 1, i, seq2[0]+j-1, seq1[0], 1 ); // 2jbestkamo->half, 1jbestkamo->full +#if USEGAPLENMTX + pfactmp = calcpfac_gap_incomplete( gaplen2mtx[*mpjpt][j-1], gaplen1mtx[*mpjpt][j-1], newgaplen, j, i, seq2[0], seq1[0], 1 ); +#endif +#if USEGAPLENHALF + pfactmp = calcpfac_gap_incomplete( gaplen2half[*mpjpt][j-1], gaplen1half[*mpjpt][j-1], newgaplen, 1, i-*mpjpt, seq2[0]+j-1, seq1[0]+*mpjpt, 1 ); +#endif +#if USEGAPLENMTX || USEGAPLENHALF + if( pfac != pfactmp ) + { + reporterr( "(jgap) pfac=%f, but pfactmp=%f (i,j=%d,%d)\n", pfac, pfactmp, i, j ); +// exit( 1 ); + PFACERROR = 1; + } +#endif + +#if ALGZGAP + if( (g=*mjpt+ fgcp1va* *gf2pt) > wm ) +#else + if( (g=*mjpt + fpenalty*pfac) > wm ) +#endif + { + wm = g; + *ijppt = +( i - *mpjpt ); + + +#if FREEFREQUENTLY + freegaplenpartly( gaplen1jbest[j-1], i-3, i-2 ); +// freegaplenpartly( gaplen2jbest[j-1], j-3, j-2 ); +#endif + + +#if DEBUG + reporterr( "Selected as jgap end!, pfac = %f\n", pfac ); + fprintf( stderr, "Jump from %d (%c) to %d (%c)!\n", j, seq1[0][j], *mpjpt, seq1[0][*mpjpt] ); +#endif +// addnewgaplen( gaplen1jbest[j-1], gaplen1jbestkamo[j-1], gaplen1, lgth1, -1, 0 ); +// addnewgaplen( gaplen2jbest[j-1], gaplen2jbestkamo[j-1], gaplen2, lgth2, -1, 0 ); + copygaplencompactx( gaplen1jbest[j-1], gaplen1jbestkamo[j-1], lgth1, -1, 0, i, i );// *mpjpt, i +// copygaplenrestricted( gaplen2jbest[j-1], gaplen2jbestkamo[j-1], lgth2, -1, 0, j, j ); // j-1, j + copygaplencompactx( gaplen2jbest[j-1], gaplen2jbestkamo[j-1], lgth2, -1, 0, 1, 1 ); // half! + + + + + } + + +// extendgaplenpartly( gaplen1jbest[j-1], gaplen1, i, i ); // tmptmptmp +// extendgaplenpartly( gaplen2jbest[j-1], gaplen2, 0, 0 ); // tmptmptmp + +#if 0 + sfac = 1.0; + for( l=0; gaplen1[i+1]&&(gl=gaplen1[i+1][l].len)!=-1; l++ ) // ososugi! hash ni atode henkou + if( gl - 1 == gaplen1[i+1][l].relend ) sfac -= gaplen1[i+1][l].freq; + sfac2 = 1.0; + for( k=0; gaplen2[j+1]&&(gl=gaplen2[j+1][k].len)!=-1; k++ ) // ososugi! hash ni atode henkou + if( gaplen2[j+1][k].relend != -1 ) sfac2 -= gaplen2[j+1][k].freq; + sfac *= sfac2; +#else +// sfac = 0.0; +#endif + +#if DEBUG + reporterr( " (jgap start check i=%d) -> *prept=%f, *mjpt=%f\n", i, seq1[0][i], seq2[0][j], *prept, *mjpt ); +#endif + +#if ALGZGAP + if( (g=*prept+ ogcp1va* *gf2ptpre) >= *mjpt ) +#else +// if( (g=*prept + fpenalty * sfac ) >= *mjpt ) + if( (g=*prept ) >= *mjpt ) +#endif + { +// *mjpt = g - fpenalty * sfac; + *mjpt = g; + *mpjpt = i-1; +#if DEBUG + reporterr( "Selected as jgap start!\n" ); +#endif + + +#if FREEFREQUENTLY + freegaplenpartly( gaplen1jbestkamo[j-1], i-3, i-2 ); +// freegaplenpartly( gaplen2jbestkamo[j-1], j-3, j-2 ); +#endif + + +// addnewgaplen( gaplen1jbestkamo[j-1], gaplen1jprev[j-1], gaplen1, lgth1, -1, 0 ); +// addnewgaplen( gaplen2jbestkamo[j-1], gaplen2jprev[j-1], gaplen2, lgth2, -1, 0 ); +// reporterr( "copying gaplen1jbestkamo[%d-1] from galpen1jprev, j=%d, i=%d\n", j, j, i ); + copygaplencompactx( gaplen1jbestkamo[j-1], gaplen1jprev[j-1], lgth1, -1, 0, i, i ); // *mpjpt, i +// copygaplenrestricted( gaplen2jbestkamo[j-1], gaplen2jprev[j-1], lgth2, -1, 0, j, j ); // j-1, j +// copygaplencompactx( gaplen2jbestkamo[j-1], gaplen2jprev[j-1], lgth2, -1, 0, j, 1 ); // half! +// reporterr( "copying gaplen2jbestkamo[%d-1] from galpen2jprev\n", j ); + copygaplencompactx( gaplen2jbestkamo[j-1], gaplen2jprev[j-1], lgth2-j, -1, 0, 1, 1 ); // ryouhou half! + + +// if( j==2 && i==1 ) exit( 1 ); + + + + } + +// extendgaplenpartly( gaplen1ibestkamo[i-1], gaplen1, 0, 0 ); // tmptmptmp +// extendgaplenpartly( gaplen2ibestkamo[i-1], gaplen2, j, j ); // tmptmptmp + + +// extendgaplenpartly( gaplen1jbestkamo[j-1], gaplen1, i, i ); // tmptmptmp +// extendgaplenpartly( gaplen2jbestkamo[j-1], gaplen2, 0, 0 ); // tmptmptmp + + +#if USE_PENALTY_EX + m[j] += fpenalty_ex; +#endif + +#if ALGZGAP + pfac = 0.0; +#else + +// pfactmp = calcpfac_gapex( gaplen2jbestkamo[j-1], gaplen1jbestkamo[j-1], j, i, i-*mpjpt, seq2[0], seq1[0], 0 ); // j-1 + pfactmp = calcpfac_gapex_noidatend( gaplen2jbestkamo[j-1], gaplen1jbestkamo[j-1], 1, i, i-*mpjpt, seq2[0]+j, seq1[0], 0 ); // 2jbestkamo->half, 1jbestkamo->full +#if USEGAPLENMTX + pfac = calcpfac_gapex( gaplen2mtx[*mpjpt][j-1], gaplen1mtx[*mpjpt][j-1], j, i, i-*mpjpt, seq2[0], seq1[0], 0 ); +#endif +#if USEGAPLENHALF + pfac = calcpfac_gapex( gaplen2half[*mpjpt][j-1], gaplen1half[*mpjpt][j-1], 1, i-*mpjpt, i-*mpjpt, seq2[0]+j, seq1[0]+*mpjpt, 0 ); +#endif +#if USEGAPLENMTX || USEGAPLENHALF + if( pfac != pfactmp ) + { + reporterr( "(jgapex) pfac=%f, but pfactmp=%f (i,j=%d,%d) diff=%f\n", pfac, pfactmp, i, j, pfac-pfactmp ); +// exit( 1 ); + PFACERROR = 1; + } +#endif + pfac = pfactmp; +#if DEBUG + reporterr( "%c-%c, jgap extension check (j=%d), pfac = %f\n", seq1[0][i], '=', j, pfac ); +#endif +#endif + m[j] += fpenalty * pfac; + + + + if( trywarp ) + { +#if USE_PENALTY_EX + if( ( g=*prevwmrecordspt++ + fpenalty_shift + fpenalty_ex * ( i - prevwarpi[j-1] + j - prevwarpj[j-1] ) ) > wm ) // naka ha osokute kamawanai +#else + if( ( g=*prevwmrecordspt++ + fpenalty_shift ) > wm ) // naka ha osokute kamawanai +#endif + { +// fprintf( stderr, "WARP!!\n" ); + if( warpn && prevwarpi[j-1] == warpis[warpn-1] && prevwarpj[j-1] == warpjs[warpn-1] ) + { + *ijppt = warpbase + warpn - 1; + } + else + { + *ijppt = warpbase + warpn; + warpis = realloc( warpis, sizeof(int) * ( warpn+1 ) ); + warpjs = realloc( warpjs, sizeof(int) * ( warpn+1 ) ); + warpis[warpn] = prevwarpi[j-1]; + warpjs[warpn] = prevwarpj[j-1]; + warpn++; + } + wm = g; + } + +#if 0 + fprintf( stderr, "%5.0f ", wm ); +#endif + curm = *curpt + wm; + + if( *wmrecords1pt > *wmrecordspt ) + { + *wmrecordspt = *wmrecords1pt; + *warpipt = *(warpipt-1); + *warpjpt = *(warpjpt-1); + } + if( curm > *wmrecordspt ) + { + *wmrecordspt = curm; + *warpipt = i; + *warpjpt = j; + } + wmrecordspt++; + wmrecords1pt++; + warpipt++; + warpjpt++; + } + +#if DEBUG + reporterr( "extention-x 1j???, before extention-x, j=%d\n", j ); + showgaplen( gaplen1jcurr[j], 100 ); +#endif + extendgaplencompactx( gaplen1jcurr[j], gaplen1, i ); + +#if DEBUG + reporterr( "after extention-x\n" ); + showgaplen( gaplen1jcurr[j], 100 ); + reporterr( "extention-x 2j???\n" ); +#endif + extendgaplencompactx( gaplen2jcurr[j], gaplen2+j, 0 ); + + +#if 1 + if( *ijppt < 0 ) + { +#if DEBUG + reporterr( "Path: %d-%d->%d-%d, i=%d (%c), j=%d (%c), *ijppt=%d\n", i, j, i-1, j+*ijppt, i, seq1[0][i], j, seq2[0][j], *ijppt ); + reporterr( "Inserting %d gaps to gaplen1 and copying gaplen2 (%c%d-%c%d)\n", -*ijppt-1, seq1[0][i], i, seq2[0][j], j ); +#endif +#if USEGAPLENMTX +// addnewgaplen( gaplen1mtx[i][j], gaplen1mtx[i-1][j+*ijppt], gaplen1, lgth1, i, -*ijppt-1 ); +// addnewgaplen( gaplen2mtx[i][j], gaplen2mtx[i-1][j+*ijppt], gaplen2, lgth2, -1, 0 ); + copygaplenrestricted( gaplen1mtx[i][j], gaplen1mtx[i-1][j+*ijppt], lgth1, i, -*ijppt-1, i, i ); // 0, lgth1 + copygaplenrestricted( gaplen2mtx[i][j], gaplen2mtx[i-1][j+*ijppt], lgth2, -1, 0, j, j ); // 0, lgth2 +#endif +#if USEGAPLENHALF + copygaplenrestricted_zurasu( gaplen1half[i][j], gaplen1half[i-1][j+*ijppt], lgth1, 0, -*ijppt-1, 0, 0, 1, 1 ); // 0, lgth1 + copygaplenrestricted_zurasu( gaplen2half[i][j], gaplen2half[i-1][j+*ijppt], lgth2, -1, 0, 0, 0, -*ijppt, -*ijppt ); // 0, lgth2 +#endif +// addnewgaplen( gaplen1jcurr[j], gaplen1jprev[j+*ijppt], gaplen1, lgth1, i, -*ijppt-1 ); +// addnewgaplen( gaplen2jcurr[j], gaplen2jprev[j+*ijppt], gaplen2, lgth2, -1, 0 ); +// reporterr( "copying gaplen1jcurr from gaplen1jbest, with a %d insertion\n", -*ijppt-1 ); + copygaplencompactx( gaplen1jcurr[j], gaplen1jprev[j+*ijppt], lgth1, i, -*ijppt-1, i, i ); // scope: i+*ijppt+1, i ? +// reporterr( "copy end\n" ); +// copygaplenrestricted( gaplen2jcurr[j], gaplen2jprev[j+*ijppt], lgth2, -1, 0, j, j ); + copygaplencompactx( gaplen2jcurr[j], gaplen2jprev[j+*ijppt], lgth2, -1, 0, 0, -*ijppt ); // half! ryouho zureteru + } + else if( *ijppt > 0 ) + { +#if DEBUG + reporterr( "Path: %d-%d->%d-%d, i=%d (%c), j=%d (%c), *ijppt=%d\n", i, j, i-*ijppt, j-1, i, seq1[0][i], j, seq2[0][j], *ijppt ); + reporterr( "Copying gaplen1 inserting %d gaps to gaplen2 (%c%d-%c%d)\n", *ijppt-1, seq1[0][i], i, seq2[0][j], j ); +#endif +#if USEGAPLENMTX +// addnewgaplen( gaplen1mtx[i][j], gaplen1mtx[i-*ijppt][j-1], gaplen1, lgth1, -1, 0 ); +// addnewgaplen( gaplen2mtx[i][j], gaplen2mtx[i-*ijppt][j-1], gaplen2, lgth2, j, *ijppt-1 ); + copygaplenrestricted( gaplen1mtx[i][j], gaplen1mtx[i-*ijppt][j-1], lgth1, -1, 0, i, i ); // 0, lgth1 + copygaplenrestricted( gaplen2mtx[i][j], gaplen2mtx[i-*ijppt][j-1], lgth2, j, *ijppt-1, j, j ); // 0, lgth2 +#endif +#if USEGAPLENHALF + copygaplenrestricted_zurasu( gaplen1half[i][j], gaplen1half[i-*ijppt][j-1], lgth1, -1, 0, 0, 0, *ijppt, *ijppt ); // 0, lgth1 + copygaplenrestricted_zurasu( gaplen2half[i][j], gaplen2half[i-*ijppt][j-1], lgth2, 0, *ijppt-1, 0, 0, 1, 1 ); // 0, lgth2 +#endif +// addnewgaplen( gaplen1jcurr[j], gaplen1jbest[j-1], gaplen1, lgth1, -1, 0 ); +// addnewgaplen( gaplen2jcurr[j], gaplen2jbest[j-1], gaplen2, lgth2, j, *ijppt-1 ); + copygaplencompactx( gaplen1jcurr[j], gaplen1jbest[j-1], lgth1, -1, 0, i, i ); +// copygaplenrestricted( gaplen2jcurr[j], gaplen2jbest[j-1], lgth2, j, *ijppt-1, j, j ); // j-*ijppt+1? +// copygaplenrestricted_zurasu( gaplen2jcurr[j], gaplen2jbest[j-1], lgth2, 0, *ijppt-1, 0, 0, j, j ); // 2jcurr->half, but 2jbest->full, imanotokoro + copygaplencompactx( gaplen2jcurr[j], gaplen2jbest[j-1], lgth2, 0, *ijppt-1, 0, 1 ); //ryouhou half + + } + else +#endif + { +#if DEBUG + reporterr( "Path: %d-%d->%d-%d, i=%d (%c), j=%d (%c), *ijppt=%d\n", i, j, i-1, j-1, i, seq1[0][i], j, seq2[0][j], *ijppt ); + reporterr( "Copying gaplen1 and gaplen2 (%c%d-%c%d)\n", seq1[0][i], i, seq2[0][j], j ); +#endif +#if USEGAPLENMTX +// addnewgaplen( gaplen1mtx[i][j], gaplen1mtx[i-1][j-1], gaplen1, lgth1, -1, 0 ); +// addnewgaplen( gaplen2mtx[i][j], gaplen2mtx[i-1][j-1], gaplen2, lgth2, -1, 0 ); + copygaplenrestricted( gaplen1mtx[i][j], gaplen1mtx[i-1][j-1], lgth1, -1, 0, i, i ); // 0, lgth1 + copygaplenrestricted( gaplen2mtx[i][j], gaplen2mtx[i-1][j-1], lgth2, -1, 0, j, j ); // 0, lgth2 +#endif +#if USEGAPLENHALF + copygaplenrestricted_zurasu( gaplen1half[i][j], gaplen1half[i-1][j-1], lgth1, -1, 0, 0, 0, 1, 1 ); // 0, lgth1 + copygaplenrestricted_zurasu( gaplen2half[i][j], gaplen2half[i-1][j-1], lgth2, -1, 0, 0, 0, 1, 1 ); // 0, lgth2 +#endif +// addnewgaplen( gaplen1jcurr[j], gaplen1jprev[j-1], gaplen1, lgth1, -1, 0 ); +// addnewgaplen( gaplen2jcurr[j], gaplen2jprev[j-1], gaplen2, lgth2, -1, 0 ); + copygaplencompactx( gaplen1jcurr[j], gaplen1jprev[j-1], lgth1, -1, 0, i, i ); +// copygaplenrestricted( gaplen2jcurr[j], gaplen2jprev[j-1], lgth2, -1, 0, j, j ); + copygaplencompactx( gaplen2jcurr[j], gaplen2jprev[j-1], lgth2, -1, 0, 0, 1 ); // half + } + +#if DEBUG + reporterr( "at the end of j loop, gaplen1jcurr[%d] = \n", j ); + showgaplen( gaplen1jcurr[j], 100 ); + reporterr( "at the end of j loop, gaplen1prev[%d] = \n", j ); + showgaplen( gaplen1jprev[j], 100 ); +#endif + + + +#if 1 + freegaplenpartly( gaplen1jcurr[j-1], i-3, i-2 ); // -1 dehanaku -2?? +// freegaplenpartly( gaplen2jcurr[j-1], j-3, j-2 ); // -1 dehanaku -2?? +// freegaplenpartly( gaplen2jcurr[j-1], j-3, j-2 ); // half! + freegaplenpartly( gaplen1jbestkamo[j-1], i-3, i-2 ); // -1 dehanaku -2?? +// freegaplenpartly( gaplen2jbestkamo[j-1], j-3, j-2 ); // -1 dehanaku -2?? + freegaplenpartly( gaplen1jbest[j-1], i-3, i-2 ); // -1 dehanaku -2?? +// freegaplenpartly( gaplen2jbest[j-1], j-3, j-2 ); // -1 dehanaku -2?? +#else + freegaplenpartly( gaplen1jprev[j-1], 0, i-2 ); // -1 dehanaku -2?? + freegaplenpartly( gaplen1jcurr[j-1], 0, i-2 ); // -1 dehanaku -2?? +// freegaplenpartly( gaplen2jcurr[j-1], j-3, j-2 ); // -1 dehanaku -2?? +// freegaplenpartly( gaplen2jcurr[j-1], j-3, j-2 ); // half! + freegaplenpartly( gaplen1jbestkamo[j-1], 0, i-2 ); // -1 dehanaku -2?? +// freegaplenpartly( gaplen2jbestkamo[j-1], j-3, j-2 ); // -1 dehanaku -2?? + freegaplenpartly( gaplen1jbest[j-1], 0, i-2 ); // -1 dehanaku -2?? +// freegaplenpartly( gaplen2jbest[j-1], j-3, j-2 ); // -1 dehanaku -2?? +#endif + + +#if USEGAPLENMTX +// freegaplenpartly( gaplen1mtx[i-1][j-1], 0, i-2 ); +// freegaplenpartly( gaplen2mtx[i-1][j-1], 0, j-2 ); +#endif + + + *curpt++ += wm; + ijppt++; + mjpt++; + prept++; + mpjpt++; + } + lastverticalw[i] = currentw[lgth2-1]; + +#if 1 +// freegaplenpartly( gaplen1icurr[i-1], i-1, i-1 ); + freegaplenpartly( gaplen1icurr[i-1], 0, lgth1-i ); + freegaplenpartly( gaplen2icurr[i-1], 0, lgth2 ); +// freegaplenpartly( gaplen1ibestkamo[i-1], i-1, i-1 ); + freegaplenpartly( gaplen1ibestkamo[i-1], 0, lgth1-i ); + freegaplenpartly( gaplen2ibestkamo[i-1], 0, lgth2 ); +#endif + + if( trywarp ) + { + fltncpy( prevwmrecords, wmrecords, lastj ); + intncpy( prevwarpi, warpi, lastj ); + intncpy( prevwarpj, warpj, lastj ); + } +#if 0 + fprintf( stderr, "i=%d, %15.5f \n", i, wm ); +#endif +//if( i == 2 ) exit( 1 ); + } + + if( trywarp ) + { +// fprintf( stderr, "wm = %f\n", wm ); +// fprintf( stderr, "warpn = %d\n", warpn ); + free( wmrecords ); + free( prevwmrecords ); + free( warpi ); + free( warpj ); + free( prevwarpi ); + free( prevwarpj ); + } + + +#if OUTGAP0TRY + if( !outgap ) + { + for( j=1; j" ); + for( i=0; i N ) + { + fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N ); + ErrorExit( "LENGTH OVER!\n" ); + } + + + for( i=0; i %f\n", kenzan, (double)kenzan /( icyc*jcyc ) ); + + double pairscore, nogappairscore; + char **pseq; + pseq = AllocateCharMtx( 2, strlen( seq1[0] ) + 1 ); + pairscore = nogappairscore = 0.0; + for( i=0; i 0.01 ) || PFACERROR ) +// if( abs( pairscore - wm +*impmatch ) > 0.01 ) +#else + if( abs( pairscore - wm +*impmatch ) > 0.01 ) +#endif +// if( abs( pairscore - wm +*impmatch ) > 0.01 ) + { + for( i=0; igroup1\n%s\n", seq1[i] ); + for( j=0; jgroup2\n%s\n", seq2[j] ); + exit( 1 ); + } +#else + reporterr( "\n" ); +#endif + +#if 0 +// if( strlen( seq1[0] ) - lgth1 > 100 && icyc > 1 || strlen( seq2[0] ) - lgth2 > 100 & jcyc > 1 ) + if( strstr( seq1[0], "LNDDAT" ) && icyc == 1 || strstr( seq2[0], "LNDDAT" ) && jcyc==1) + { + for( i=0; igroup1\n%s\n", seq1[i] ); + for( j=0; jgroup2\n%s\n", seq2[j] ); + exit( 1 ); + } +#endif + + + return( wm ); +} + + +double D__align_ls( double **n_dynamicmtx, char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, double *impmatch, char *sgap1, char *sgap2, char *egap1, char *egap2, int *chudanpt, int chudanref, int *chudanres, int headgp, int tailgp ) +{ + int v1, v2; + double val; + +#if 1 + v1 = gapvariety( icyc, strlen( seq1[0] ), seq1 ); + v2 = gapvariety( jcyc, strlen( seq2[0] ), seq2 ); +#else + v1 = icyc; + v2 = jcyc; +#endif + +// reporterr( "\nicyc,jcyc = %d,%d\n", icyc, jcyc ); + reporterr( " v1,v2 = %d,%d\n", v1, v2 ); + + if( v1 >= v2 ) + { + val = D__align( n_dynamicmtx, seq1, seq2, eff1, eff2, icyc, jcyc, alloclen, localhom, impmatch, sgap1, sgap2, egap1, egap2, chudanpt, chudanref, chudanres, headgp, tailgp ); + } + else + { + val = D__align( n_dynamicmtx, seq2, seq1, eff2, eff1, jcyc, icyc, alloclen, localhom, impmatch, sgap2, sgap1, egap2, egap1, chudanpt, chudanref, chudanres, headgp, tailgp ); + } + return val; +} + + + +double D__align_gapmap( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, double *impmatch, int *gapmap1, int *gapmap2 ) +/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */ +{ + fprintf( stderr, "Unexpected error. Please contact kazutaka.katoh@aist.go.jp\n" ); + exit( 1 ); +} + + +double D__align_variousdist( int **which, double ***matrices, double **n_dynamicmtx, char **seq1, char **seq2, double *eff1, double *eff2, double **eff1s, double **eff2s, int icyc, int jcyc, int alloclen, LocalHom ***localhom, double *impmatch, char *sgap1, char *sgap2, char *egap1, char *egap2, int *chudanpt, int chudanref, int *chudanres, int headgp, int tailgp ) +/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */ +{ + +// int k; + register int i, j, c; + int lasti, lastj; /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */ + int lgth1, lgth2; + int resultlen; + double wm = 0.0; /* int ?????? */ + double g; + double *currentw, *previousw; +// double fpenalty = (double)penalty; +#if USE_PENALTY_EX + double fpenalty_ex = (double)penalty_ex; +#endif +#if 1 + double *wtmp; + int *ijppt; + double *mjpt, *prept, *curpt; + int *mpjpt; +#endif + static TLS double mi, *m; + static TLS int **ijp; + static TLS int mpi, *mp; + static TLS double *w1, *w2; + static TLS double *match; + static TLS double *initverticalw; /* kufuu sureba iranai */ + static TLS double *lastverticalw; /* kufuu sureba iranai */ + static TLS char **mseq1; + static TLS char **mseq2; + static TLS char **mseq; + static TLS double ***cpmx1s; + static TLS double ***cpmx2s; + static TLS int ***intwork; + static TLS double ***doublework; + static TLS int orlgth1 = 0, orlgth2 = 0; +#if USEGAPLENHALF + Gaplen ****gaplen1half = NULL; // NULL ga iru to omou. + Gaplen ****gaplen2half = NULL; // NULL ga iru to omou. +#endif +#if USEGAPLENMTX + Gaplen ****gaplen1mtx = NULL; // NULL ga iru to omou. + Gaplen ****gaplen2mtx = NULL; // NULL ga iru to omou. +#endif + static TLS Gaplen **gaplen1 = NULL; // NULL ga iru to omou. + static TLS Gaplen **gaplen2 = NULL; // NULL ga iru to omou. + static TLS Gaplen ***gaplen1jprev = NULL; + static TLS Gaplen ***gaplen2jprev = NULL; + static TLS Gaplen ***gaplen1jcurr = NULL; + static TLS Gaplen ***gaplen2jcurr = NULL; + static TLS Gaplen ***gaplen1icurr = NULL; + static TLS Gaplen ***gaplen2icurr = NULL; + static TLS Gaplen ***gaplen1jbestkamo = NULL; + static TLS Gaplen ***gaplen2jbestkamo = NULL; + static TLS Gaplen ***gaplen1ibestkamo = NULL; + static TLS Gaplen ***gaplen2ibestkamo = NULL; + static TLS Gaplen ***gaplen1jbest = NULL; + static TLS Gaplen ***gaplen2jbest = NULL; + double fpenalty = (double)penalty; + double fpenalty_shift = (double)penalty_shift; + static TLS Gaplen ****gaplens = NULL; + + Gaplen ***gaplentmp = NULL; + int *warpis = NULL; + int *warpjs = NULL; + int *warpi = NULL; + int *warpj = NULL; + int *prevwarpi = NULL; + int *prevwarpj = NULL; + double *wmrecords = NULL; + double *prevwmrecords = NULL; + int warpn = 0; + int warpbase; + double curm = 0.0; + double *wmrecordspt, *wmrecords1pt, *prevwmrecordspt; + int *warpipt, *warpjpt; + int k; + double pfac, pfactmp; + int newgaplen; + int **masklist1 = NULL, **masklist2 = NULL; + int *nmask; + +// for( i=0; i orlgth1 || lgth2 > orlgth2 ) + { + int ll1, ll2; + + + if( orlgth1 > 0 && orlgth2 > 0 ) + { + FreeFloatVec( w1 ); + FreeFloatVec( w2 ); + FreeFloatVec( match ); + FreeFloatVec( initverticalw ); + FreeFloatVec( lastverticalw ); + + FreeFloatVec( m ); + FreeIntVec( mp ); + + FreeCharMtx( mseq ); + + FreeFloatCub( cpmx1s ); + FreeFloatCub( cpmx2s ); + + FreeFloatCub( doublework ); + FreeIntCub( intwork ); + + + free( gaplens ); + + if( gaplen1ibestkamo ) FreeGaplenCub( gaplen1ibestkamo ); gaplen1ibestkamo = NULL; + if( gaplen2ibestkamo ) FreeGaplenCub( gaplen2ibestkamo ); gaplen2ibestkamo = NULL; + if( gaplen1icurr ) FreeGaplenCub( gaplen1icurr ); gaplen1icurr = NULL; + if( gaplen2icurr ) FreeGaplenCub( gaplen2icurr ); gaplen2icurr = NULL; + + if( gaplen1jcurr ) FreeGaplenCub( gaplen1jcurr ); gaplen1jcurr = NULL; + if( gaplen1jprev ) FreeGaplenCub( gaplen1jprev ); gaplen1jprev = NULL; + if( gaplen2jcurr ) FreeGaplenCub( gaplen2jcurr ); gaplen2jcurr = NULL; + if( gaplen2jprev ) FreeGaplenCub( gaplen2jprev ); gaplen2jprev = NULL; + if( gaplen1jbestkamo ) FreeGaplenCub( gaplen1jbestkamo ); gaplen1jbestkamo = NULL; + if( gaplen2jbestkamo ) FreeGaplenCub( gaplen2jbestkamo ); gaplen2jbestkamo = NULL; + if( gaplen1jbest ) FreeGaplenCub( gaplen1jbest ); gaplen1jbest = NULL; + if( gaplen2jbest ) FreeGaplenCub( gaplen2jbest ); gaplen2jbest = NULL; + if( gaplen1 ) FreeGaplenMtx( gaplen1, 1 ); gaplen1 = NULL; + if( gaplen2 ) FreeGaplenMtx( gaplen2, 1 ); gaplen2 = NULL; + + } + + ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100; + ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100; + +#if DEBUG + fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 ); +#endif + + w1 = AllocateFloatVec( ll2+2 ); + w2 = AllocateFloatVec( ll2+2 ); + match = AllocateFloatVec( ll2+2 ); + + initverticalw = AllocateFloatVec( ll1+2 ); + lastverticalw = AllocateFloatVec( ll1+2 ); + + m = AllocateFloatVec( ll2+2 ); + mp = AllocateIntVec( ll2+2 ); + + mseq = AllocateCharMtx( njob, ll1+ll2 ); + + cpmx1s = AllocateFloatCub( maxdistclass, nalphabets, ll1+2 ); + cpmx2s = AllocateFloatCub( maxdistclass, nalphabets, ll2+2 ); + + doublework = AllocateFloatCub( maxdistclass, MAX( ll1, ll2 )+2, nalphabets ); + intwork = AllocateIntCub( maxdistclass, MAX( ll1, ll2 )+2, nalphabets+1 ); + +#if DEBUG + fprintf( stderr, "succeeded\n" ); +#endif + + orlgth1 = ll1 - 100; + orlgth2 = ll2 - 100; + + +// reporterr( "Allocating gaplen1 and gaplen2\n" ); + gaplen1 = (Gaplen ** )calloc( ll1+2, sizeof( Gaplen * ) ); + gaplen1[ll1+1] = (Gaplen *)1; + gaplen2 = (Gaplen ** )calloc( ll2+2, sizeof( Gaplen * ) ); + gaplen2[ll2+1] = (Gaplen *)1; + + +// reporterr( "Allocating gaplen*\n" ); + gaplen1ibestkamo = (Gaplen ***)calloc( (ll1+2), sizeof( Gaplen **) ); + gaplen2ibestkamo = (Gaplen ***)calloc( (ll1+2), sizeof( Gaplen **) ); + gaplen1icurr = (Gaplen ***)calloc( (ll1+2), sizeof( Gaplen **) ); + gaplen2icurr = (Gaplen ***)calloc( (ll1+2), sizeof( Gaplen **) ); + gaplen1jbestkamo = (Gaplen ***)calloc( (ll2+2), sizeof( Gaplen **) ); + gaplen2jbestkamo = (Gaplen ***)calloc( (ll2+2), sizeof( Gaplen **) ); + gaplen1jbest = (Gaplen ***)calloc( (ll2+2), sizeof( Gaplen **) ); + gaplen2jbest = (Gaplen ***)calloc( (ll2+2), sizeof( Gaplen **) ); + gaplen1jcurr = (Gaplen ***)calloc( (ll2+2), sizeof( Gaplen **) ); + gaplen2jcurr = (Gaplen ***)calloc( (ll2+2), sizeof( Gaplen **) ); + gaplen1jprev = (Gaplen ***)calloc( (ll2+2), sizeof( Gaplen **) ); + gaplen2jprev = (Gaplen ***)calloc( (ll2+2), sizeof( Gaplen **) ); + + gaplens = calloc( sizeof( Gaplen ***), 12 ); + gaplens[0] = gaplen1ibestkamo; + gaplens[1] = gaplen2ibestkamo; + gaplens[2] = gaplen1icurr; + gaplens[3] = gaplen2icurr; + gaplens[4] = gaplen1jbestkamo; + gaplens[5] = gaplen2jbestkamo; + gaplens[6] = gaplen1jbest; + gaplens[7] = gaplen2jbest; + gaplens[8] = gaplen1jcurr; + gaplens[9] = gaplen2jcurr; + gaplens[10] = gaplen1jprev; + gaplens[11] = gaplen2jprev; +// reporterr( "Allocation end\n" ); + } + + { + int ll1 = lgth1; + int ll2 = lgth2; + +// reporterr( "Allocating gaplen*i\n" ); + for(i=0; i commonAlloc1 || orlgth2 > commonAlloc2 ) + { + int ll1, ll2; + + if( commonAlloc1 && commonAlloc2 ) + { + FreeIntMtx( commonIP ); + } + + ll1 = MAX( orlgth1, commonAlloc1 ); + ll2 = MAX( orlgth2, commonAlloc2 ); + +#if DEBUG + fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 ); +#endif + + commonIP = AllocateIntMtx( ll1+10, ll2+10 ); + +#if DEBUG + fprintf( stderr, "succeeded\n\n" ); +#endif + + commonAlloc1 = ll1; + commonAlloc2 = ll2; + } + ijp = commonIP; + +#if 0 + { + double t = 0.0; + for( i=0; i zurasu -> error? + + +// duplicategaplencompactx( gaplen1ibestkamo[i], gaplen1, lgth1, 0, 1 ); +// duplicategaplencompactx( gaplen1ibestkamo[i], gaplen1+i, lgth1-i, 0, 1 ); // half + duplicategaplencompactx( gaplen1ibestkamo[i], gaplen1+i, lgth1-i, 0, 0 ); // half +// duplicategaplencompactx( gaplen2ibestkamo[i], gaplen2, lgth2, 0, lgth2 ); + duplicategaplencompactx( gaplen2ibestkamo[i], gaplen2, lgth2, 0, 0 ); +// copygaplenrestricted( gaplen2ibestkamo[i], gaplen2, lgth2, 0, i, 0, 0 ); // -> zurasu -> error? +// copygaplenrestricted_zurasu( gaplen2ibestkamo[i], gaplen2, lgth2, 0, i, 0, lgth2, 0, lgth2 ); // -> zurasu -> error? + copygaplencompactx( gaplen2ibestkamo[i], gaplen2, lgth2, 0, i, 0, 0 ); // -> zurasu -> error? + } + +// reporterr( "Duplicating gaplen*j*curr \n" ); +// int nduplicated = 0; + for( j=0; j tbfast.c + if( localhom ) + imp_match_calc( n_dynamicmtx, currentw, icyc, jcyc, lgth1, lgth2, seq1, seq2, eff1, eff2, localhom, 1, 0 ); + +#endif + + for( j=1; j ", seq1[0][0], seq2[0][j], j, currentw[j] ); + currentw[j] += fpenalty * pfac; // tekitou +// reporterr( " %f\n", currentw[j] ); + } + for( i=1; ifull, 2j->half +#if USEGAPLENMTX +//reporterr( "#### FULL, i,j=%d,%d\n", i, j ); + pfactmp = calcpfac( gaplen1mtx[i-1][j-1], gaplen2mtx[i-1][j-1], i, j, seq1[0], seq2[0], one ); +#endif +#if USEGAPLENHALF +//reporterr( "#### HALF, i,j=%d/%d,%d/%d\n", i, lgth1, j, lgth2 ); +// showgaplen( gaplen2half[i-1][j-1], lgth2-j ); + pfactmp = calcpfac( gaplen1half[i-1][j-1], gaplen2half[i-1][j-1], 1, 1, seq1[0]+i, seq2[0]+j, zero ); +#endif +#if USEGAPLENMTX + USEGAPLENHALF + if( pfac != pfactmp ) + { + reporterr( "(straight) pfac=%f, but pfactmp=%f (i,j=%d,%d)\n", pfac, pfactmp, i, j ); + PFACERROR = 1; + exit( 1 ); + } +#endif +//if( i==50 && j==135 ) exit( 1 ); + + +// reporterr( "i,j=%d,%d, *prept = %f\n", i, j, *prept ); + +#if ALGZSTRAIGHT + wm = *prept; // Machigai!! +#else + wm = *prept + fpenalty * pfac; +#endif + *ijppt = 0; + + +#if DEBUG + if( i == j ) + { + fprintf( stderr, "\n i=%d, j=%d %c, %c ", i, j, seq1[0][i], seq2[0][j] ); + fprintf( stderr, "%5.0f, pfac for straight =%f\n", wm, pfac ); + } +#endif + newgaplen = j-mpi-1; + + +//if( i == 53 && j == 93 ) exit( 1 ); + + + + +// pfac = calcpfac_gap_incomplete( gaplen1ibestkamo[i-1], gaplen2ibestkamo[i-1], newgaplen, i, j, seq1[0], seq2[0], 0 ); // i-1 + pfac = calcpfac_gap_noidatend( gaplen1ibestkamo[i-1], gaplen2ibestkamo[i-1], newgaplen, 1, j, seq1[0]+i-1, seq2[0], 0 ); // i-1 +#if USEGAPLENMTX + pfactmp = calcpfac_gap_incomplete( gaplen1mtx[i-1][mpi], gaplen2mtx[i-1][mpi], newgaplen, i, j, seq1[0], seq2[0], 1 ); +#endif +#if USEGAPLENHALF + pfactmp = calcpfac_gap_incomplete( gaplen1half[i-1][mpi], gaplen2half[i-1][mpi], newgaplen, 1, j-mpi, seq1[0]+i-1, seq2[0]+mpi, 1 ); +#endif +#if USEGAPLENMTX || USEGAPLENHALF + if( pfac != pfactmp ) + { + reporterr( "(igap) pfac=%f, but pfactmp=%f (i,j=%d,%d)\n", pfac, pfactmp, i, j ); + PFACERROR = 1; + } +#endif + + +#if DEBUG + reporterr( "%c-%c pfac for igap end incomplete = %f\n", seq1[0][i], seq2[0][j], pfac ); + reporterr( "mi when igap end checking = %f\n", mi ); + reporterr( "wm = %f, mi+fpenalty*pfac=%f\n", wm, mi+fpenalty*pfac ); +#endif + + +#if ALGZGAP + if( (g=mi+*fgcp2pt*gf1va) > wm ) +#else + if( (g=mi+fpenalty*pfac) > wm ) +#endif + { + wm = g; + *ijppt = -( j - mpi ); +#if DEBUG80 + reporterr( "Selected as igap end! wm = %f, mi = %f\n", wm, mi ); + fprintf( stderr, "Jump from %d-%d (%c-%c) to %d (%c-%c)!\n", i, j, seq1[0][i], seq2[0][j], mpi, seq1[0][i-1], seq2[0][mpi] ); +#endif + } + + +#if 0 + fprintf( stderr, "%5.0f->", wm ); +#endif +// if( (g=*mjpt+ fgcp1va* *gf2pt) > wm ) + +#if 0 +// reporterr( "Checking %c, (current pos = %c)\n", seq2[0][j+1], seq2[0][j] ); + sfac = 1.0; + for( k=0; gaplen2[j+1]&&(gl=gaplen2[j+1][k].len)!=-1; k++ ) // ososugi! hash ni atode henkou + { +// reporterr( ".len = %d, .relend = %d\n", gaplen2[j+1][k].len, gaplen2[j+1][k].relend ); + if( gl - 1 == gaplen2[j+1][k].relend ) + { + sfac -= gaplen2[j+1][k].freq; +// reporterr( "Hit! sfac = %f\n", sfac ); + } + } + sfac2 = 1.0; + for( k=0; gaplen1[i+1]&&(gl=gaplen1[i+1][k].len)!=-1; k++ ) // ososugi! hash ni atode henkou + if( gaplen1[i+1][k].relend != -1 ) sfac2 -= gaplen1[i+1][k].freq; + sfac *= sfac2; +#else +// sfac = 0.0; +#endif + + + +#if ALGZGAP + if( (g=*prept+*ogcp2pt*gf1vapre) >= mi ) +#else +// if( (g=*prept + fpenalty * sfac ) >= mi ) + if( (g=*prept ) >= mi ) +#endif + { +// mpibk = mpi; +// mi = g - fpenalty * sfac; + mi = g; + mpi = j-1; +#if DEBUG80 + reporterr( "Selected as igap start! %c%d-%c%d, mi=%f, g=%f\n", seq1[0][i-1], i-1, seq2[0][mpi], mpi, mi, g ); +#endif + +#if FREEFREQUENTLY +// freegaplenpartly( gaplen1ibestkamo[i-1], 0, i-1 ); + freegaplenpartly( gaplen2ibestkamo[i-1], j-3, j-2 ); +#endif +// freegaplenpartly( gaplen1jprev[mpibk], 0, lgth2 ); // full +// freegaplenpartly( gaplen2jprev[mpibk], 0, lgth2-mpibk ); // half +// if( gaplen1jprev[mpibk] ) FreeGaplenMtx( gaplen1jprev[mpibk], 0 ); +// gaplen1jprev[mpibk] = NULL; +// if( gaplen2jprev[mpibk] ) FreeGaplenMtx( gaplen2jprev[mpibk], 0 ); +// gaplen2jprev[mpibk] = NULL; + + +// addnewgaplen( gaplen1ibestkamo[i-1], gaplen1jprev[j-1], gaplen1, lgth1, -1, 0 ); +// addnewgaplen( gaplen2ibestkamo[i-1], gaplen2jprev[j-1], gaplen2, lgth2, -1, 0 ); +// copygaplenrestricted( gaplen1ibestkamo[i-1], gaplen1jprev[j-1], lgth1, -1, 0, i, i ); // i-1, i + copygaplencompactx( gaplen1ibestkamo[i-1], gaplen1jprev[j-1], lgth1, -1, 0, 1, i ); // half +// copygaplenrestricted( gaplen2ibestkamo[i-1], gaplen2jprev[j-1], lgth2, -1, 0, j, j ); // mpi, j + copygaplencompactx( gaplen2ibestkamo[i-1], gaplen2jprev[j-1], lgth2, -1, 0, j, 1 ); //half + + + } + + + + + + +// reporterr( "g=%f, *prept=%f, mi=%f\n", g, *prept, mi ); + + +#if USE_PENALTY_EX + mi += fpenalty_ex; +#endif + +#if ALGZGAP + pfac = 0.0; // CHUUI! +#else + +// pfac = calcpfac_gapex( gaplen1ibestkamo[i-1], gaplen2ibestkamo[i-1], i, j, j-mpi, seq1[0], seq2[0], 1 ); // i-1 + pfac = calcpfac_gapex_noidatend( gaplen1ibestkamo[i-1], gaplen2ibestkamo[i-1], 1, j, j-mpi, seq1[0]+i, seq2[0], 1 ); // 1ibest->half, 2ibest->full +#if USEGAPLENMTX + pfactmp = calcpfac_gapex( gaplen1mtx[i-1][mpi], gaplen2mtx[i-1][mpi], i, j, j-mpi, seq1[0], seq2[0], 1 ); +#endif +#if USEGAPLENHALF + pfactmp = calcpfac_gapex( gaplen1half[i-1][mpi], gaplen2half[i-1][mpi], 1, j-mpi, j-mpi, seq1[0]+i, seq2[0]+mpi, 1 ); +#endif +#if USEGAPLENMTX || USEGAPLENHALF + if( pfac != pfactmp ) + { + reporterr( "(igapex) pfac=%f, but pfactmp=%f (i,j=%d,%d)\n", pfac, pfactmp, i, j ); + PFACERROR = 1; + } +#endif + + + + + + + +#if DEBUG + reporterr( "%c-%c, igap extension check, pfac = %f\n\n", '=', seq2[0][j], pfac ); +#endif +#endif +// reporterr( "mi = %f -> ", mi ); + mi += fpenalty * pfac; +// reporterr( "mi = %f\n", mi ); + + +// reporterr( "using %d-%d, %d, %d\n", *mpjpt, j-1, i, j ); + newgaplen = i-*mpjpt-1; +// pfac = calcpfac_gap_incomplete( gaplen2jbestkamo[j-1], gaplen1jbestkamo[j-1], newgaplen, j, i, seq2[0], seq1[0], 0 ); // j-1 deha??? + + + pfac = calcpfac_gap_noidatend( gaplen2jbestkamo[j-1], gaplen1jbestkamo[j-1], newgaplen, 1, i, seq2[0]+j-1, seq1[0], 1 ); // 2jbestkamo->half, 1jbestkamo->full +#if USEGAPLENMTX + pfactmp = calcpfac_gap_incomplete( gaplen2mtx[*mpjpt][j-1], gaplen1mtx[*mpjpt][j-1], newgaplen, j, i, seq2[0], seq1[0], 1 ); +#endif +#if USEGAPLENHALF + pfactmp = calcpfac_gap_incomplete( gaplen2half[*mpjpt][j-1], gaplen1half[*mpjpt][j-1], newgaplen, 1, i-*mpjpt, seq2[0]+j-1, seq1[0]+*mpjpt, 1 ); +#endif +#if USEGAPLENMTX || USEGAPLENHALF + if( pfac != pfactmp ) + { + reporterr( "(jgap) pfac=%f, but pfactmp=%f (i,j=%d,%d)\n", pfac, pfactmp, i, j ); +// exit( 1 ); + PFACERROR = 1; + } +#endif + +#if ALGZGAP + if( (g=*mjpt+ fgcp1va* *gf2pt) > wm ) +#else + if( (g=*mjpt + fpenalty*pfac) > wm ) +#endif + { + wm = g; + *ijppt = +( i - *mpjpt ); + + +#if FREEFREQUENTLY + freegaplenpartly( gaplen1jbest[j-1], i-3, i-2 ); +// freegaplenpartly( gaplen2jbest[j-1], j-3, j-2 ); +#endif + + +#if DEBUG + reporterr( "Selected as jgap end!, pfac = %f\n", pfac ); + fprintf( stderr, "Jump from %d (%c) to %d (%c)!\n", j, seq1[0][j], *mpjpt, seq1[0][*mpjpt] ); +#endif +// addnewgaplen( gaplen1jbest[j-1], gaplen1jbestkamo[j-1], gaplen1, lgth1, -1, 0 ); +// addnewgaplen( gaplen2jbest[j-1], gaplen2jbestkamo[j-1], gaplen2, lgth2, -1, 0 ); + copygaplencompactx( gaplen1jbest[j-1], gaplen1jbestkamo[j-1], lgth1, -1, 0, i, i );// *mpjpt, i +// copygaplenrestricted( gaplen2jbest[j-1], gaplen2jbestkamo[j-1], lgth2, -1, 0, j, j ); // j-1, j + copygaplencompactx( gaplen2jbest[j-1], gaplen2jbestkamo[j-1], lgth2, -1, 0, 1, 1 ); // half! + + + + + } + + +// extendgaplenpartly( gaplen1jbest[j-1], gaplen1, i, i ); // tmptmptmp +// extendgaplenpartly( gaplen2jbest[j-1], gaplen2, 0, 0 ); // tmptmptmp + +#if 0 + sfac = 1.0; + for( l=0; gaplen1[i+1]&&(gl=gaplen1[i+1][l].len)!=-1; l++ ) // ososugi! hash ni atode henkou + if( gl - 1 == gaplen1[i+1][l].relend ) sfac -= gaplen1[i+1][l].freq; + sfac2 = 1.0; + for( k=0; gaplen2[j+1]&&(gl=gaplen2[j+1][k].len)!=-1; k++ ) // ososugi! hash ni atode henkou + if( gaplen2[j+1][k].relend != -1 ) sfac2 -= gaplen2[j+1][k].freq; + sfac *= sfac2; +#else +// sfac = 0.0; +#endif + +#if DEBUG + reporterr( " (jgap start check i=%d) -> *prept=%f, *mjpt=%f\n", i, seq1[0][i], seq2[0][j], *prept, *mjpt ); +#endif + +#if ALGZGAP + if( (g=*prept+ ogcp1va* *gf2ptpre) >= *mjpt ) +#else +// if( (g=*prept + fpenalty * sfac ) >= *mjpt ) + if( (g=*prept ) >= *mjpt ) +#endif + { +// *mjpt = g - fpenalty * sfac; + *mjpt = g; + *mpjpt = i-1; +#if DEBUG + reporterr( "Selected as jgap start!\n" ); +#endif + + +#if FREEFREQUENTLY + freegaplenpartly( gaplen1jbestkamo[j-1], i-3, i-2 ); +// freegaplenpartly( gaplen2jbestkamo[j-1], j-3, j-2 ); +#endif + + +// addnewgaplen( gaplen1jbestkamo[j-1], gaplen1jprev[j-1], gaplen1, lgth1, -1, 0 ); +// addnewgaplen( gaplen2jbestkamo[j-1], gaplen2jprev[j-1], gaplen2, lgth2, -1, 0 ); +// reporterr( "copying gaplen1jbestkamo[%d-1] from galpen1jprev, j=%d, i=%d\n", j, j, i ); + copygaplencompactx( gaplen1jbestkamo[j-1], gaplen1jprev[j-1], lgth1, -1, 0, i, i ); // *mpjpt, i +// copygaplenrestricted( gaplen2jbestkamo[j-1], gaplen2jprev[j-1], lgth2, -1, 0, j, j ); // j-1, j +// copygaplencompactx( gaplen2jbestkamo[j-1], gaplen2jprev[j-1], lgth2, -1, 0, j, 1 ); // half! +// reporterr( "copying gaplen2jbestkamo[%d-1] from galpen2jprev\n", j ); + copygaplencompactx( gaplen2jbestkamo[j-1], gaplen2jprev[j-1], lgth2-j, -1, 0, 1, 1 ); // ryouhou half! + + +// if( j==2 && i==1 ) exit( 1 ); + + + + } + +// extendgaplenpartly( gaplen1ibestkamo[i-1], gaplen1, 0, 0 ); // tmptmptmp +// extendgaplenpartly( gaplen2ibestkamo[i-1], gaplen2, j, j ); // tmptmptmp + + +// extendgaplenpartly( gaplen1jbestkamo[j-1], gaplen1, i, i ); // tmptmptmp +// extendgaplenpartly( gaplen2jbestkamo[j-1], gaplen2, 0, 0 ); // tmptmptmp + + +#if USE_PENALTY_EX + m[j] += fpenalty_ex; +#endif + +#if ALGZGAP + pfac = 0.0; +#else + +// pfactmp = calcpfac_gapex( gaplen2jbestkamo[j-1], gaplen1jbestkamo[j-1], j, i, i-*mpjpt, seq2[0], seq1[0], 0 ); // j-1 + pfactmp = calcpfac_gapex_noidatend( gaplen2jbestkamo[j-1], gaplen1jbestkamo[j-1], 1, i, i-*mpjpt, seq2[0]+j, seq1[0], 0 ); // 2jbestkamo->half, 1jbestkamo->full +#if USEGAPLENMTX + pfac = calcpfac_gapex( gaplen2mtx[*mpjpt][j-1], gaplen1mtx[*mpjpt][j-1], j, i, i-*mpjpt, seq2[0], seq1[0], 0 ); +#endif +#if USEGAPLENHALF + pfac = calcpfac_gapex( gaplen2half[*mpjpt][j-1], gaplen1half[*mpjpt][j-1], 1, i-*mpjpt, i-*mpjpt, seq2[0]+j, seq1[0]+*mpjpt, 0 ); +#endif +#if USEGAPLENMTX || USEGAPLENHALF + if( pfac != pfactmp ) + { + reporterr( "(jgapex) pfac=%f, but pfactmp=%f (i,j=%d,%d) diff=%f\n", pfac, pfactmp, i, j, pfac-pfactmp ); +// exit( 1 ); + PFACERROR = 1; + } +#endif + pfac = pfactmp; +#if DEBUG + reporterr( "%c-%c, jgap extension check (j=%d), pfac = %f\n", seq1[0][i], '=', j, pfac ); +#endif +#endif + m[j] += fpenalty * pfac; + + + + if( trywarp ) + { +#if USE_PENALTY_EX + if( ( g=*prevwmrecordspt++ + fpenalty_shift + fpenalty_ex * ( i - prevwarpi[j-1] + j - prevwarpj[j-1] ) ) > wm ) // naka ha osokute kamawanai +#else + if( ( g=*prevwmrecordspt++ + fpenalty_shift ) > wm ) // naka ha osokute kamawanai +#endif + { +// fprintf( stderr, "WARP!!\n" ); + if( warpn && prevwarpi[j-1] == warpis[warpn-1] && prevwarpj[j-1] == warpjs[warpn-1] ) + { + *ijppt = warpbase + warpn - 1; + } + else + { + *ijppt = warpbase + warpn; + warpis = realloc( warpis, sizeof(int) * ( warpn+1 ) ); + warpjs = realloc( warpjs, sizeof(int) * ( warpn+1 ) ); + warpis[warpn] = prevwarpi[j-1]; + warpjs[warpn] = prevwarpj[j-1]; + warpn++; + } + wm = g; + } + +#if 0 + fprintf( stderr, "%5.0f ", wm ); +#endif + curm = *curpt + wm; + + if( *wmrecords1pt > *wmrecordspt ) + { + *wmrecordspt = *wmrecords1pt; + *warpipt = *(warpipt-1); + *warpjpt = *(warpjpt-1); + } + if( curm > *wmrecordspt ) + { + *wmrecordspt = curm; + *warpipt = i; + *warpjpt = j; + } + wmrecordspt++; + wmrecords1pt++; + warpipt++; + warpjpt++; + } + +#if DEBUG + reporterr( "extention-x 1j???, before extention-x, j=%d\n", j ); + showgaplen( gaplen1jcurr[j], 100 ); +#endif + extendgaplencompactx( gaplen1jcurr[j], gaplen1, i ); + +#if DEBUG + reporterr( "after extention-x\n" ); + showgaplen( gaplen1jcurr[j], 100 ); + reporterr( "extention-x 2j???\n" ); +#endif + extendgaplencompactx( gaplen2jcurr[j], gaplen2+j, 0 ); + + +#if 1 + if( *ijppt < 0 ) + { +#if DEBUG + reporterr( "Path: %d-%d->%d-%d, i=%d (%c), j=%d (%c), *ijppt=%d\n", i, j, i-1, j+*ijppt, i, seq1[0][i], j, seq2[0][j], *ijppt ); + reporterr( "Inserting %d gaps to gaplen1 and copying gaplen2 (%c%d-%c%d)\n", -*ijppt-1, seq1[0][i], i, seq2[0][j], j ); +#endif +#if USEGAPLENMTX +// addnewgaplen( gaplen1mtx[i][j], gaplen1mtx[i-1][j+*ijppt], gaplen1, lgth1, i, -*ijppt-1 ); +// addnewgaplen( gaplen2mtx[i][j], gaplen2mtx[i-1][j+*ijppt], gaplen2, lgth2, -1, 0 ); + copygaplenrestricted( gaplen1mtx[i][j], gaplen1mtx[i-1][j+*ijppt], lgth1, i, -*ijppt-1, i, i ); // 0, lgth1 + copygaplenrestricted( gaplen2mtx[i][j], gaplen2mtx[i-1][j+*ijppt], lgth2, -1, 0, j, j ); // 0, lgth2 +#endif +#if USEGAPLENHALF + copygaplenrestricted_zurasu( gaplen1half[i][j], gaplen1half[i-1][j+*ijppt], lgth1, 0, -*ijppt-1, 0, 0, 1, 1 ); // 0, lgth1 + copygaplenrestricted_zurasu( gaplen2half[i][j], gaplen2half[i-1][j+*ijppt], lgth2, -1, 0, 0, 0, -*ijppt, -*ijppt ); // 0, lgth2 +#endif +// addnewgaplen( gaplen1jcurr[j], gaplen1jprev[j+*ijppt], gaplen1, lgth1, i, -*ijppt-1 ); +// addnewgaplen( gaplen2jcurr[j], gaplen2jprev[j+*ijppt], gaplen2, lgth2, -1, 0 ); +// reporterr( "copying gaplen1jcurr from gaplen1jbest, with a %d insertion\n", -*ijppt-1 ); + copygaplencompactx( gaplen1jcurr[j], gaplen1jprev[j+*ijppt], lgth1, i, -*ijppt-1, i, i ); // scope: i+*ijppt+1, i ? +// reporterr( "copy end\n" ); +// copygaplenrestricted( gaplen2jcurr[j], gaplen2jprev[j+*ijppt], lgth2, -1, 0, j, j ); + copygaplencompactx( gaplen2jcurr[j], gaplen2jprev[j+*ijppt], lgth2, -1, 0, 0, -*ijppt ); // half! ryouho zureteru + } + else if( *ijppt > 0 ) + { +#if DEBUG + reporterr( "Path: %d-%d->%d-%d, i=%d (%c), j=%d (%c), *ijppt=%d\n", i, j, i-*ijppt, j-1, i, seq1[0][i], j, seq2[0][j], *ijppt ); + reporterr( "Copying gaplen1 inserting %d gaps to gaplen2 (%c%d-%c%d)\n", *ijppt-1, seq1[0][i], i, seq2[0][j], j ); +#endif +#if USEGAPLENMTX +// addnewgaplen( gaplen1mtx[i][j], gaplen1mtx[i-*ijppt][j-1], gaplen1, lgth1, -1, 0 ); +// addnewgaplen( gaplen2mtx[i][j], gaplen2mtx[i-*ijppt][j-1], gaplen2, lgth2, j, *ijppt-1 ); + copygaplenrestricted( gaplen1mtx[i][j], gaplen1mtx[i-*ijppt][j-1], lgth1, -1, 0, i, i ); // 0, lgth1 + copygaplenrestricted( gaplen2mtx[i][j], gaplen2mtx[i-*ijppt][j-1], lgth2, j, *ijppt-1, j, j ); // 0, lgth2 +#endif +#if USEGAPLENHALF + copygaplenrestricted_zurasu( gaplen1half[i][j], gaplen1half[i-*ijppt][j-1], lgth1, -1, 0, 0, 0, *ijppt, *ijppt ); // 0, lgth1 + copygaplenrestricted_zurasu( gaplen2half[i][j], gaplen2half[i-*ijppt][j-1], lgth2, 0, *ijppt-1, 0, 0, 1, 1 ); // 0, lgth2 +#endif +// addnewgaplen( gaplen1jcurr[j], gaplen1jbest[j-1], gaplen1, lgth1, -1, 0 ); +// addnewgaplen( gaplen2jcurr[j], gaplen2jbest[j-1], gaplen2, lgth2, j, *ijppt-1 ); + copygaplencompactx( gaplen1jcurr[j], gaplen1jbest[j-1], lgth1, -1, 0, i, i ); +// copygaplenrestricted( gaplen2jcurr[j], gaplen2jbest[j-1], lgth2, j, *ijppt-1, j, j ); // j-*ijppt+1? +// copygaplenrestricted_zurasu( gaplen2jcurr[j], gaplen2jbest[j-1], lgth2, 0, *ijppt-1, 0, 0, j, j ); // 2jcurr->half, but 2jbest->full, imanotokoro + copygaplencompactx( gaplen2jcurr[j], gaplen2jbest[j-1], lgth2, 0, *ijppt-1, 0, 1 ); //ryouhou half + + } + else +#endif + { +#if DEBUG + reporterr( "Path: %d-%d->%d-%d, i=%d (%c), j=%d (%c), *ijppt=%d\n", i, j, i-1, j-1, i, seq1[0][i], j, seq2[0][j], *ijppt ); + reporterr( "Copying gaplen1 and gaplen2 (%c%d-%c%d)\n", seq1[0][i], i, seq2[0][j], j ); +#endif +#if USEGAPLENMTX +// addnewgaplen( gaplen1mtx[i][j], gaplen1mtx[i-1][j-1], gaplen1, lgth1, -1, 0 ); +// addnewgaplen( gaplen2mtx[i][j], gaplen2mtx[i-1][j-1], gaplen2, lgth2, -1, 0 ); + copygaplenrestricted( gaplen1mtx[i][j], gaplen1mtx[i-1][j-1], lgth1, -1, 0, i, i ); // 0, lgth1 + copygaplenrestricted( gaplen2mtx[i][j], gaplen2mtx[i-1][j-1], lgth2, -1, 0, j, j ); // 0, lgth2 +#endif +#if USEGAPLENHALF + copygaplenrestricted_zurasu( gaplen1half[i][j], gaplen1half[i-1][j-1], lgth1, -1, 0, 0, 0, 1, 1 ); // 0, lgth1 + copygaplenrestricted_zurasu( gaplen2half[i][j], gaplen2half[i-1][j-1], lgth2, -1, 0, 0, 0, 1, 1 ); // 0, lgth2 +#endif +// addnewgaplen( gaplen1jcurr[j], gaplen1jprev[j-1], gaplen1, lgth1, -1, 0 ); +// addnewgaplen( gaplen2jcurr[j], gaplen2jprev[j-1], gaplen2, lgth2, -1, 0 ); + copygaplencompactx( gaplen1jcurr[j], gaplen1jprev[j-1], lgth1, -1, 0, i, i ); +// copygaplenrestricted( gaplen2jcurr[j], gaplen2jprev[j-1], lgth2, -1, 0, j, j ); + copygaplencompactx( gaplen2jcurr[j], gaplen2jprev[j-1], lgth2, -1, 0, 0, 1 ); // half + } + +#if DEBUG + reporterr( "at the end of j loop, gaplen1jcurr[%d] = \n", j ); + showgaplen( gaplen1jcurr[j], 100 ); + reporterr( "at the end of j loop, gaplen1prev[%d] = \n", j ); + showgaplen( gaplen1jprev[j], 100 ); +#endif + + + +#if 1 + freegaplenpartly( gaplen1jcurr[j-1], i-3, i-2 ); // -1 dehanaku -2?? +// freegaplenpartly( gaplen2jcurr[j-1], j-3, j-2 ); // -1 dehanaku -2?? +// freegaplenpartly( gaplen2jcurr[j-1], j-3, j-2 ); // half! + freegaplenpartly( gaplen1jbestkamo[j-1], i-3, i-2 ); // -1 dehanaku -2?? +// freegaplenpartly( gaplen2jbestkamo[j-1], j-3, j-2 ); // -1 dehanaku -2?? + freegaplenpartly( gaplen1jbest[j-1], i-3, i-2 ); // -1 dehanaku -2?? +// freegaplenpartly( gaplen2jbest[j-1], j-3, j-2 ); // -1 dehanaku -2?? +#else + freegaplenpartly( gaplen1jprev[j-1], 0, i-2 ); // -1 dehanaku -2?? + freegaplenpartly( gaplen1jcurr[j-1], 0, i-2 ); // -1 dehanaku -2?? +// freegaplenpartly( gaplen2jcurr[j-1], j-3, j-2 ); // -1 dehanaku -2?? +// freegaplenpartly( gaplen2jcurr[j-1], j-3, j-2 ); // half! + freegaplenpartly( gaplen1jbestkamo[j-1], 0, i-2 ); // -1 dehanaku -2?? +// freegaplenpartly( gaplen2jbestkamo[j-1], j-3, j-2 ); // -1 dehanaku -2?? + freegaplenpartly( gaplen1jbest[j-1], 0, i-2 ); // -1 dehanaku -2?? +// freegaplenpartly( gaplen2jbest[j-1], j-3, j-2 ); // -1 dehanaku -2?? +#endif + + +#if USEGAPLENMTX +// freegaplenpartly( gaplen1mtx[i-1][j-1], 0, i-2 ); +// freegaplenpartly( gaplen2mtx[i-1][j-1], 0, j-2 ); +#endif + + + *curpt++ += wm; + ijppt++; + mjpt++; + prept++; + mpjpt++; + } + lastverticalw[i] = currentw[lgth2-1]; + +#if 1 +// freegaplenpartly( gaplen1icurr[i-1], i-1, i-1 ); + freegaplenpartly( gaplen1icurr[i-1], 0, lgth1-i ); + freegaplenpartly( gaplen2icurr[i-1], 0, lgth2 ); +// freegaplenpartly( gaplen1ibestkamo[i-1], i-1, i-1 ); + freegaplenpartly( gaplen1ibestkamo[i-1], 0, lgth1-i ); + freegaplenpartly( gaplen2ibestkamo[i-1], 0, lgth2 ); +#endif + + if( trywarp ) + { + fltncpy( prevwmrecords, wmrecords, lastj ); + intncpy( prevwarpi, warpi, lastj ); + intncpy( prevwarpj, warpj, lastj ); + } +#if 0 + fprintf( stderr, "i=%d, %15.5f \n", i, wm ); +#endif +//if( i == 2 ) exit( 1 ); + } + + if( trywarp ) + { +// fprintf( stderr, "wm = %f\n", wm ); +// fprintf( stderr, "warpn = %d\n", warpn ); + free( wmrecords ); + free( prevwmrecords ); + free( warpi ); + free( warpj ); + free( prevwarpi ); + free( prevwarpj ); + } + + +#if OUTGAP0TRY + if( !outgap ) + { + for( j=1; j" ); + for( i=0; i N ) + { + fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N ); + ErrorExit( "LENGTH OVER!\n" ); + } + + + for( i=0; i %f\n", kenzan, (double)kenzan /( icyc*jcyc ) ); + + double pairscore, nogappairscore, diff; + char **pseq; + pseq = AllocateCharMtx( 2, strlen( seq1[0] ) + 1 ); + pairscore = nogappairscore = 0.0; +#if 1 + for( i=0; i 0.01 ) || PFACERROR ) +// if( abs( pairscore - wm +*impmatch ) > 0.01 ) +#else + if( abs( pairscore - wm +*impmatch ) > 0.01 ) +#endif +// if( abs( pairscore - wm +*impmatch ) > 0.01 ) + { + for( i=0; igroup1\n%s\n", seq1[i] ); + for( j=0; jgroup2\n%s\n", seq2[j] ); + exit( 1 ); + } +#else + reporterr( "\n" ); +#endif + +#if 0 +// if( strlen( seq1[0] ) - lgth1 > 100 && icyc > 1 || strlen( seq2[0] ) - lgth2 > 100 & jcyc > 1 ) + if( strstr( seq1[0], "LNDDAT" ) && icyc == 1 || strstr( seq2[0], "LNDDAT" ) && jcyc==1) + { + for( i=0; igroup1\n%s\n", seq1[i] ); + for( j=0; jgroup2\n%s\n", seq2[j] ); + exit( 1 ); + } +#endif + + + return( wm ); +} diff --git a/binaries/src/mafft/core/Dalignmm.o b/binaries/src/mafft/core/Dalignmm.o new file mode 100644 index 0000000..2b7277e Binary files /dev/null and b/binaries/src/mafft/core/Dalignmm.o differ diff --git a/binaries/src/mafft/core/Falign.c b/binaries/src/mafft/core/Falign.c index 250a0fa..71fd84c 100644 --- a/binaries/src/mafft/core/Falign.c +++ b/binaries/src/mafft/core/Falign.c @@ -159,7 +159,9 @@ static void mymergesort( int first, int last, Segment **seg ) if( seg == NULL ) { - free( work ); work = NULL; + if( work ) free( work ); + work = NULL; + allo = 0; return; } @@ -190,7 +192,9 @@ static void mymergesort( int first, int last, Segment **seg ) } -double Fgetlag( char **seq1, char **seq2, +double Fgetlag( + double **n_dynamicmtx, + char **seq1, char **seq2, double *eff1, double *eff2, int clus1, int clus2, int alloclen ) @@ -231,7 +235,7 @@ double Fgetlag( char **seq1, char **seq2, int count, count0; int len1, len2; int totallen; - float dumfl = 0.0; + double dumdb = 0.0; int headgp, tailgp; len1 = strlen( seq1[0] ); @@ -704,25 +708,13 @@ system( "/usr/bin/gnuplot list.plot" ); Aalign( tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen ); break; case( 'M' ): - MSalignmm( tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, NULL, NULL, NULL, NULL, NULL, 0, NULL, headgp, tailgp ); + MSalignmm( n_dynamicmtx, tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, NULL, NULL, NULL, NULL, NULL, 0, NULL, headgp, tailgp ); break; case( 'A' ): if( clus1 == 1 && clus2 == 1 ) - G__align11( tmpres1, tmpres2, alloclen, headgp, tailgp ); + G__align11( n_dynamicmtx, tmpres1, tmpres2, alloclen, headgp, tailgp ); else - A__align( tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL, NULL, 0, NULL, headgp, tailgp ); - break; - case( 'H' ): - if( clus1 == 1 && clus2 == 1 ) - G__align11( tmpres1, tmpres2, alloclen, headgp, tailgp ); - else - H__align( tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL ); - break; - case( 'Q' ): - if( clus1 == 1 && clus2 == 1 ) - G__align11( tmpres1, tmpres2, alloclen, headgp, tailgp ); - else - Q__align( tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL ); + A__align( n_dynamicmtx, tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, NULL, &dumdb, NULL, NULL, NULL, NULL, NULL, 0, NULL, headgp, tailgp, -1, -1 ); break; default: fprintf( stderr, "alg = %c\n", alg ); @@ -771,8 +763,10 @@ system( "/usr/bin/gnuplot list.plot" ); -float Falign( char **seq1, char **seq2, +double Falign( int **whichmtx, double ***scoringmatrices, double **n_dynamicmtx, + char **seq1, char **seq2, double *eff1, double *eff2, + double **eff1s, double **eff2s, int clus1, int clus2, int alloclen, int *fftlog, int *chudanpt, int chudanref, int *chudanres ) @@ -815,8 +809,8 @@ float Falign( char **seq1, char **seq2, int count, count0; int len1, len2; int totallen; - float totalscore; - float dumfl = 0.0; + double totalscore; + double dumdb = 0.0; int headgp, tailgp; @@ -826,14 +820,20 @@ float Falign( char **seq1, char **seq2, { // fprintf( stderr, "Freeing localarrays in Falign\n" ); localalloclen = 0; + prevalloclen = 0; + crossscoresize = 0; mymergesort( 0, 0, NULL ); alignableReagion( 0, 0, NULL, NULL, NULL, NULL, NULL ); fft( 0, NULL, 1 ); - A__align( NULL, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0 ); - G__align11( NULL, NULL, 0, 0, 0 ); + A__align( NULL, NULL, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0, -1, -1 ); + D__align( NULL, NULL, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0 ); + A__align_variousdist( NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0 ); + D__align_variousdist( NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0 ); + G__align11( NULL, NULL, NULL, 0, 0, 0 ); blockAlign2( NULL, NULL, NULL, NULL, NULL, NULL ); if( crossscore ) FreeDoubleMtx( crossscore ); - FreeCharMtx( result1 ); + crossscore = NULL; + FreeCharMtx( result1 ); result1 = NULL; FreeCharMtx( result2 ); FreeCharMtx( tmpres1 ); FreeCharMtx( tmpres2 ); @@ -1167,6 +1167,7 @@ system( "less seqVec2 < /dev/tty > /dev/tty" ); + #define CAND 0 #if CAND fftfp = fopen( "cand", "w" ); @@ -1510,31 +1511,41 @@ system( "less seqVec2 < /dev/tty > /dev/tty" ); totalscore += Aalign( tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen ); break; case( 'M' ): - totalscore += MSalignmm( tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, sgap1, sgap2, egap1, egap2, chudanpt, chudanref, chudanres, headgp, tailgp ); + if( scoringmatrices ) // called by tditeration.c + totalscore += MSalignmm_variousdist( NULL, scoringmatrices, NULL, tmpres1, tmpres2, eff1, eff2, eff1s, eff2s, clus1, clus2, alloclen, sgap1, sgap2, egap1, egap2, chudanpt, chudanref, chudanres, headgp, tailgp ); + else + totalscore += MSalignmm( n_dynamicmtx, tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, sgap1, sgap2, egap1, egap2, chudanpt, chudanref, chudanres, headgp, tailgp ); +// totalscore += MSalignmm( n_dis_consweight_multi, tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, sgap1, sgap2, egap1, egap2, chudanpt, chudanref, chudanres, headgp, tailgp ); break; - case( 'A' ): + case( 'd' ): if( clus1 == 1 && clus2 == 1 ) { - totalscore += G__align11( tmpres1, tmpres2, alloclen, headgp, tailgp ); + totalscore += G__align11( n_dynamicmtx, tmpres1, tmpres2, alloclen, headgp, tailgp ); } else - totalscore += A__align( tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, NULL, &dumfl, sgap1, sgap2, egap1, egap2, chudanpt, chudanref, chudanres, headgp, tailgp ); - break; - case( 'H' ): - if( clus1 == 1 && clus2 == 1 ) { - totalscore += G__align11( tmpres1, tmpres2, alloclen, headgp, tailgp ); + if( scoringmatrices ) // called by tditeration.c + { + totalscore += D__align_variousdist( whichmtx, scoringmatrices, NULL, tmpres1, tmpres2, eff1, eff2, eff1s, eff2s, clus1, clus2, alloclen, NULL, &dumdb, sgap1, sgap2, egap1, egap2, chudanpt, chudanref, chudanres, headgp, tailgp ); + } + else + totalscore += D__align( n_dynamicmtx, tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, NULL, &dumdb, sgap1, sgap2, egap1, egap2, chudanpt, chudanref, chudanres, headgp, tailgp ); } - else - totalscore += H__align( tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, NULL, &dumfl, sgap1, sgap2, egap1, egap2 ); break; - case( 'Q' ): + case( 'A' ): if( clus1 == 1 && clus2 == 1 ) { - totalscore += G__align11( tmpres1, tmpres2, alloclen, headgp, tailgp ); + totalscore += G__align11( n_dynamicmtx, tmpres1, tmpres2, alloclen, headgp, tailgp ); } else - totalscore += Q__align( tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, NULL, &dumfl, sgap1, sgap2, egap1, egap2 ); + { + if( scoringmatrices ) // called by tditeration.c + { + totalscore += A__align_variousdist( whichmtx, scoringmatrices, NULL, tmpres1, tmpres2, eff1, eff2, eff1s, eff2s, clus1, clus2, alloclen, NULL, &dumdb, sgap1, sgap2, egap1, egap2, chudanpt, chudanref, chudanres, headgp, tailgp ); + } + else + totalscore += A__align( n_dynamicmtx, tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, NULL, &dumdb, sgap1, sgap2, egap1, egap2, chudanpt, chudanref, chudanres, headgp, tailgp, -1, -1 ); + } break; default: fprintf( stderr, "alg = %c\n", alg ); @@ -1560,7 +1571,7 @@ system( "less seqVec2 < /dev/tty > /dev/tty" ); for( j=0; j /dev/tty" ); #if 0 for( j=0; j /dev/tty" ); /* sakujo wo kentou (2010/10/05) */ -float Falign_udpari_long( char **seq1, char **seq2, +double Falign_udpari_long( + int **whichmtx, double ***scoringmatrices, + double **n_dynamicmtx, + char **seq1, char **seq2, double *eff1, double *eff2, + double **eff1s, double **eff2s, int clus1, int clus2, int alloclen, int *fftlog ) { @@ -1647,10 +1662,65 @@ float Falign_udpari_long( char **seq1, char **seq2, int count, count0; int len1, len2; int totallen; - float totalscore; + double totalscore; int nkouho = 0; int headgp, tailgp; -// float dumfl = 0.0; +// double dumfl = 0.0; + + if( seq1 == NULL ) + { + if( result1 ) + { +// fprintf( stderr, "### Freeing localarrays in Falign\n" ); + localalloclen = 0; + prevalloclen = 0; + crossscoresize = 0; + mymergesort( 0, 0, NULL ); + alignableReagion( 0, 0, NULL, NULL, NULL, NULL, NULL ); + fft( 0, NULL, 1 ); + A__align( NULL, NULL, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0, -1, -1 ); + A__align_variousdist( NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0 ); + D__align_variousdist( NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0 ); + G__align11( NULL, NULL, NULL, 0, 0, 0 ); + blockAlign2( NULL, NULL, NULL, NULL, NULL, NULL ); + if( crossscore ) FreeDoubleMtx( crossscore ); + crossscore = NULL; // reallocate sareru kanousei ga arunode. + FreeCharMtx( result1 ); result1 = NULL; + FreeCharMtx( result2 ); + FreeCharMtx( tmpres1 ); + FreeCharMtx( tmpres2 ); + FreeCharMtx( tmpseq1 ); + FreeCharMtx( tmpseq2 ); + free( sgap1 ); + free( egap1 ); + free( sgap2 ); + free( egap2 ); + free( kouho ); + free( cut1 ); + free( cut2 ); + free( tmpptr1 ); + free( tmpptr2 ); + free( segment ); + free( segment1 ); + free( segment2 ); + free( sortedseg1 ); + free( sortedseg2 ); + if( !kobetsubunkatsu ) + { + FreeFukusosuuMtx ( seqVector1 ); + FreeFukusosuuMtx ( seqVector2 ); + FreeFukusosuuVec( naisekiNoWa ); + FreeFukusosuuMtx( naiseki ); + FreeDoubleVec( soukan ); + } + } + else + { +// fprintf( stderr, "Did not allocate localarrays in Falign\n" ); + } + + return( 0.0 ); + } @@ -2322,7 +2392,10 @@ system( "less seqVec2 < /dev/tty > /dev/tty" ); switch( alg ) { case( 'M' ): - totalscore += MSalignmm( tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, sgap1, sgap2, egap1, egap2, NULL, 0, NULL, headgp, tailgp ); + if( scoringmatrices ) // called by tditeration.c + totalscore += MSalignmm_variousdist( NULL, scoringmatrices, NULL, tmpres1, tmpres2, eff1, eff2, eff1s, eff2s, clus1, clus2, alloclen, sgap1, sgap2, egap1, egap2, NULL, 0, NULL, headgp, tailgp ); + else + totalscore += MSalignmm( n_dynamicmtx, tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, sgap1, sgap2, egap1, egap2, NULL, 0, NULL, headgp, tailgp ); break; default: fprintf( stderr, "alg = %c\n", alg ); diff --git a/binaries/src/mafft/core/Falign.o b/binaries/src/mafft/core/Falign.o new file mode 100644 index 0000000..722629d Binary files /dev/null and b/binaries/src/mafft/core/Falign.o differ diff --git a/binaries/src/mafft/core/Falign_localhom.c b/binaries/src/mafft/core/Falign_localhom.c index ba2dee3..061300c 100644 --- a/binaries/src/mafft/core/Falign_localhom.c +++ b/binaries/src/mafft/core/Falign_localhom.c @@ -45,7 +45,7 @@ static void seq_vec_2( Fukusosuu *result, double *score, double incr, char *seq static TLS int n; for( ; *seq; result++ ) { - n = amino_n[(int)*seq++]; + n = amino_n[(unsigned char)*seq++]; if( n < 20 && n >= 0 ) result->R += incr * score[n]; #if 0 fprintf( stderr, "n=%d, score=%f, inc=%f R=%f\n",n, score[n], incr * score[n], result->R ); @@ -59,7 +59,7 @@ static void seq_vec_3( Fukusosuu **result, double incr, char *seq ) int n; for( i=0; *seq; i++ ) { - n = amino_n[(int)*seq++]; + n = amino_n[(unsigned char)*seq++]; if( n < n20or4or2 && n >= 0 ) result[n][i].R += incr; } } @@ -160,11 +160,13 @@ static void mymergesort( int first, int last, Segment **seg ) } -float Falign_localhom( char **seq1, char **seq2, +double Falign_localhom( int **whichmtx, double ***scoringmatrices, double **n_dynamicmtx, + char **seq1, char **seq2, double *eff1, double *eff2, + double **eff1s, double **eff2s, int clus1, int clus2, int alloclen, - LocalHom ***localhom, float *totalimpmatch, + LocalHom ***localhom, double *totalimpmatch, int *gapmap1, int *gapmap2, int *chudanpt, int chudanref, int *chudanres ) { @@ -207,8 +209,8 @@ float Falign_localhom( char **seq1, char **seq2, int count, count0; int len1, len2; int totallen; - float totalscore; - float impmatch; + double totalscore; + double impmatch; extern Fukusosuu *AllocateFukusosuuVec(); extern Fukusosuu **AllocateFukusosuuMtx(); @@ -219,12 +221,14 @@ float Falign_localhom( char **seq1, char **seq2, { // fprintf( stderr, "Freeing localarrays in Falign\n" ); localalloclen = 0; + crossscoresize = 0; mymergesort( 0, 0, NULL ); alignableReagion( 0, 0, NULL, NULL, NULL, NULL, NULL ); fft( 0, NULL, 1 ); - A__align( NULL, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0 ); - G__align11( NULL, NULL, 0, 0, 0 ); +// A__align( NULL, NULL, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0, -1, -1 ); // iru? + G__align11( NULL, NULL, NULL, 0, 0, 0 ); partA__align( NULL, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL ); + partA__align_variousdist( NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL ); blockAlign2( NULL, NULL, NULL, NULL, NULL, NULL ); if( crossscore ) FreeDoubleMtx( crossscore ); FreeCharMtx( result1 ); @@ -802,13 +806,13 @@ system( "less seqVec2 < /dev/tty > /dev/tty" ); case( 'a' ): totalscore += Aalign( tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen ); break; - case( 'Q' ): - totalscore += partQ__align( tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, localhom, &impmatch, cut1[i], cut1[i+1]-1, cut2[i], cut2[i+1]-1, gapmap1, gapmap2, sgap1, sgap2, egap1, egap2 ); - *totalimpmatch += impmatch; -// fprintf( stderr, "*totalimpmatch in Falign_localhom = %f\n", *totalimpmatch ); - break; case( 'A' ): - totalscore += partA__align( tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, localhom, &impmatch, cut1[i], cut1[i+1]-1, cut2[i], cut2[i+1]-1, gapmap1, gapmap2, sgap1, sgap2, egap1, egap2, chudanpt, chudanref, chudanres ); + if( scoringmatrices ) // called by tditeration.c + { + totalscore += partA__align_variousdist( whichmtx, scoringmatrices, NULL, tmpres1, tmpres2, eff1, eff2, eff1s, eff2s, clus1, clus2, alloclen, localhom, &impmatch, cut1[i], cut1[i+1]-1, cut2[i], cut2[i+1]-1, gapmap1, gapmap2, sgap1, sgap2, egap1, egap2, chudanpt, chudanref, chudanres ); + } + else + totalscore += partA__align( tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, localhom, &impmatch, cut1[i], cut1[i+1]-1, cut2[i], cut2[i+1]-1, gapmap1, gapmap2, sgap1, sgap2, egap1, egap2, chudanpt, chudanref, chudanres ); *totalimpmatch += impmatch; // fprintf( stderr, "*totalimpmatch in Falign_localhom = %f\n", *totalimpmatch ); diff --git a/binaries/src/mafft/core/Falign_localhom.o b/binaries/src/mafft/core/Falign_localhom.o new file mode 100644 index 0000000..0adede7 Binary files /dev/null and b/binaries/src/mafft/core/Falign_localhom.o differ diff --git a/binaries/src/mafft/core/Galign11.c b/binaries/src/mafft/core/Galign11.c index 2ee7ce0..ae5e3fc 100644 --- a/binaries/src/mafft/core/Galign11.c +++ b/binaries/src/mafft/core/Galign11.c @@ -5,26 +5,17 @@ #define XXXXXXX 0 #define USE_PENALTY_EX 1 - #if 1 -static void match_calc( float *match, char **s1, char **s2, int i1, int lgth2 ) +static void match_calc_mtx( double **mtx, double *match, char **s1, char **s2, int i1, int lgth2 ) { char *seq2 = s2[0]; - int *intptr = amino_dis[(int)s1[0][i1]]; + double *doubleptr = mtx[(unsigned char)s1[0][i1]]; while( lgth2-- ) - *match++ = intptr[(int)*seq2++]; -} -static void match_calc_mtx( int mtx[0x80][0x80], float *match, char **s1, char **s2, int i1, int lgth2 ) -{ - char *seq2 = s2[0]; - int *intptr = mtx[(int)s1[0][i1]]; - - while( lgth2-- ) - *match++ = intptr[(int)*seq2++]; + *match++ = doubleptr[(unsigned char)*seq2++]; } #else -static void match_calc( float *match, char **s1, char **s2, int i1, int lgth2 ) +static void match_calc( double *match, char **s1, char **s2, int i1, int lgth2 ) { int j; @@ -33,11 +24,12 @@ static void match_calc( float *match, char **s1, char **s2, int i1, int lgth2 ) } #endif -static float Atracking( float *lasthorizontalw, float *lastverticalw, +static double Atracking( double *lasthorizontalw, double *lastverticalw, char **seq1, char **seq2, char **mseq1, char **mseq2, int **ijp, - int tailgp ) + int tailgp, + int *warpis, int *warpjs, int warpbase ) { int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k, limk; // char gap[] = "-"; @@ -45,7 +37,7 @@ static float Atracking( float *lasthorizontalw, float *lastverticalw, gap = newgapstr; lgth1 = strlen( seq1[0] ); lgth2 = strlen( seq2[0] ); - float wm; + double wm; #if 0 @@ -64,6 +56,7 @@ static float Atracking( float *lasthorizontalw, float *lastverticalw, ijp[0][j] = -( j + 1 ); } +// if( tailgp == 1 || ijp[lgth1][lgth2] >= warpbase ) if( tailgp == 1 ) ; else @@ -97,11 +90,18 @@ static float Atracking( float *lasthorizontalw, float *lastverticalw, *mseq2[0] = 0; + iin = lgth1; jin = lgth2; limk = lgth1+lgth2 + 1; for( k=0; k= warpbase ) + { +// fprintf( stderr, "WARP!\n" ); + ifi = warpis[ijp[iin][jin]-warpbase]; + jfi = warpjs[ijp[iin][jin]-warpbase]; + } + else if( ijp[iin][jin] < 0 ) { ifi = iin-1; jfi = jin+ijp[iin][jin]; } @@ -113,19 +113,41 @@ static float Atracking( float *lasthorizontalw, float *lastverticalw, { ifi = iin-1; jfi = jin-1; } - l = iin - ifi; - while( --l ) + + if( ifi == -warpbase && jfi == -warpbase ) { - *--mseq1[0] = seq1[0][ifi+l]; - *--mseq2[0] = *gap; - k++; + l = iin; + while( --l >= 0 ) + { + *--mseq1[0] = seq1[0][l]; + *--mseq2[0] = *gap; + k++; + } + l= jin; + while( --l >= 0 ) + { + *--mseq1[0] = *gap; + *--mseq2[0] = seq2[0][l]; + k++; + } + break; } - l= jin - jfi; - while( --l ) + else { - *--mseq1[0] = *gap; - *--mseq2[0] = seq2[0][jfi+l]; - k++; + l = iin - ifi; + while( --l > 0 ) + { + *--mseq1[0] = seq1[0][ifi+l]; + *--mseq2[0] = *gap; + k++; + } + l= jin - jfi; + while( --l > 0 ) + { + *--mseq1[0] = *gap; + *--mseq2[0] = seq2[0][jfi+l]; + k++; + } } if( iin <= 0 || jin <= 0 ) break; *--mseq1[0] = seq1[0][ifi]; @@ -133,44 +155,68 @@ static float Atracking( float *lasthorizontalw, float *lastverticalw, k++; iin = ifi; jin = jfi; } + +// fprintf( stderr, "%s\n", mseq1[0] ); +// fprintf( stderr, "%s\n", mseq2[0] ); return( 0.0 ); } -float G__align11( char **seq1, char **seq2, int alloclen, int headgp, int tailgp ) -/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */ +double G__align11( double **n_dynamicmtx, char **seq1, char **seq2, int alloclen, int headgp, int tailgp ) { // int k; register int i, j; int lasti; /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */ + int lastj; int lgth1, lgth2; int resultlen; - float wm; /* int ?????? */ - float g; - float *currentw, *previousw; - float fpenalty = (float)penalty; + double wm; /* int ?????? */ + double g; + double *currentw, *previousw; + double fpenalty = (double)penalty; + double fpenalty_shift = (double)penalty_shift; + double fpenalty_tmp; #if USE_PENALTY_EX - float fpenalty_ex = (float)penalty_ex; + double fpenalty_ex = (double)penalty_ex; #endif #if 1 - float *wtmp; + double *wtmp; int *ijppt; - float *mjpt, *prept, *curpt; + double *mjpt, *prept, *curpt; int *mpjpt; #endif - static TLS float mi, *m; - static TLS int **ijp; - static TLS int mpi, *mp; - static TLS float *w1, *w2; - static TLS float *match; - static TLS float *initverticalw; /* kufuu sureba iranai */ - static TLS float *lastverticalw; /* kufuu sureba iranai */ - static TLS char **mseq1; - static TLS char **mseq2; - static TLS char **mseq; - static TLS int **intwork; - static TLS float **floatwork; + static TLS double mi = 0.0; + static TLS double *m = NULL; + static TLS int **ijp = NULL; + static TLS int mpi = 0; + static TLS int *mp = NULL; + static TLS double *w1 = NULL; + static TLS double *w2 = NULL; + static TLS double *match = NULL; + static TLS double *initverticalw = NULL; /* kufuu sureba iranai */ + static TLS double *lastverticalw = NULL; /* kufuu sureba iranai */ + static TLS char **mseq1 = NULL; + static TLS char **mseq2 = NULL; + static TLS char **mseq = NULL; + static TLS int **intwork = NULL; + static TLS double **doublework = NULL; static TLS int orlgth1 = 0, orlgth2 = 0; + static TLS double **amino_dynamicmtx = NULL; // ?? + + int *warpis = NULL; + int *warpjs = NULL; + int *warpi = NULL; + int *warpj = NULL; + int *prevwarpi = NULL; + int *prevwarpj = NULL; + double *wmrecords = NULL; + double *prevwmrecords = NULL; + int warpn = 0; + int warpbase; + double curm = 0.0; + double *wmrecordspt, *wmrecords1pt, *prevwmrecordspt; + int *warpipt, *warpjpt; + if( seq1 == NULL ) { @@ -178,34 +224,69 @@ float G__align11( char **seq1, char **seq2, int alloclen, int headgp, int tailgp { orlgth1 = 0; orlgth2 = 0; - free( mseq1 ); - free( mseq2 ); - FreeFloatVec( w1 ); - FreeFloatVec( w2 ); - FreeFloatVec( match ); - FreeFloatVec( initverticalw ); - FreeFloatVec( lastverticalw ); + if( mseq1 ) free( mseq1 ); mseq1 = NULL; + if( mseq2 ) free( mseq2 ); mseq2 = NULL; + if( w1 ) FreeFloatVec( w1 ); w1 = NULL; + if( w2 ) FreeFloatVec( w2 ); w2 = NULL; + if( match ) FreeFloatVec( match ); match = NULL; + if( initverticalw ) FreeFloatVec( initverticalw ); initverticalw = NULL; + if( lastverticalw ) FreeFloatVec( lastverticalw ); lastverticalw = NULL; - FreeFloatVec( m ); - FreeIntVec( mp ); + if( m ) FreeFloatVec( m ); m = NULL; + if( mp ) FreeIntVec( mp ); mp = NULL; - FreeCharMtx( mseq ); + if( mseq ) FreeCharMtx( mseq ); mseq = NULL; - FreeFloatMtx( floatwork ); - FreeIntMtx( intwork ); + if( doublework ) FreeFloatMtx( doublework ); doublework = NULL; + if( intwork ) FreeIntMtx( intwork ); intwork = NULL; + + if( amino_dynamicmtx ) FreeDoubleMtx( amino_dynamicmtx ); amino_dynamicmtx = NULL; } + orlgth1 = 0; + orlgth2 = 0; return( 0.0 ); } + + lgth1 = strlen( seq1[0] ); lgth2 = strlen( seq2[0] ); + warpbase = lgth1 + lgth2; + warpis = NULL; + warpjs = NULL; + warpn = 0; + if( trywarp ) + { +// fprintf( stderr, "IN G__align11\n" ); + if( headgp == 0 || tailgp == 0 ) + { + fprintf( stderr, "At present, headgp and tailgp must be 1.\n" ); + exit( 1 ); + } + + wmrecords = AllocateFloatVec( lgth2+1 ); + warpi = AllocateIntVec( lgth2+1 ); + warpj = AllocateIntVec( lgth2+1 ); + prevwmrecords = AllocateFloatVec( lgth2+1 ); + prevwarpi = AllocateIntVec( lgth2+1 ); + prevwarpj = AllocateIntVec( lgth2+1 ); + for( i=0; i wm ) + if( ( g=*prevwmrecordspt++ + fpenalty_tmp )> wm ) // naka ha osokute kamawanai + { +// fprintf( stderr, "Yes! Warp!! from %d-%d (%c-%c) to %d-%d (%c-%c) fpenalty_tmp = %f! warpn = %d\n", i, j, seq1[0][i], seq2[0][j-1], prevwarpi[j-1], prevwarpj[j-1],seq1[0][prevwarpi[j-1]], seq2[0][prevwarpj[j-1]], fpenalty_tmp, warpn ); + if( warpn && prevwarpi[j-1] == warpis[warpn-1] && prevwarpj[j-1] == warpjs[warpn-1] ) + { + *ijppt = warpbase + warpn - 1; + } + else + { + *ijppt = warpbase + warpn; + warpis = realloc( warpis, sizeof(int) * ( warpn+1 ) ); + warpjs = realloc( warpjs, sizeof(int) * ( warpn+1 ) ); + warpis[warpn] = prevwarpi[j-1]; + warpjs[warpn] = prevwarpj[j-1]; + warpn++; + } + wm = g; + } + else + { + } + + curm = *curpt + wm; + +// fprintf( stderr, "###### curm = %f at %c-%c, i=%d, j=%d\n", curm, seq1[0][i], seq2[0][j], i, j ); + +// fprintf( stderr, "copy from i, j-1? %f > %f?\n", wmrecords[j-1], curm ); +// if( wmrecords[j-1] > wmrecords[j] ) + if( *wmrecords1pt > *wmrecordspt ) + { +// fprintf( stderr, "yes\n" ); +// wmrecords[j] = wmrecords[j-1]; + *wmrecordspt = *wmrecords1pt; +// warpi[j] = warpi[j-1]; +// warpj[j] = warpj[j-1]; + *warpipt = *(warpipt-1); + *warpjpt = *(warpjpt-1); +// fprintf( stderr, "warpi[j]=%d, warpj[j]=%d wmrecords[j] = %f\n", warpi[j], warpj[j], wmrecords[j] ); + } +// else +// { +// fprintf( stderr, "no\n" ); +// } + +// fprintf( stderr, " curm = %f at %c-%c\n", curm, seq1[0][i], seq2[0][j] ); +// fprintf( stderr, " wmrecords[%d] = %f\n", j, wmrecords[j] ); +// fprintf( stderr, "replace?\n" ); + +// if( curm > wmrecords[j] ) + if( curm > *wmrecordspt ) + { +// fprintf( stderr, "yes at %d-%d (%c-%c), replaced warp: warpi[j]=%d, warpj[j]=%d warpn=%d, wmrecords[j] = %f -> %f\n", i, j, seq1[0][i], seq2[0][j], i, j, warpn, wmrecords[j], curm ); +// wmrecords[j] = curm; + *wmrecordspt = curm; +// warpi[j] = i; +// warpj[j] = j; + *warpipt = i; + *warpjpt = j; + } +// else +// { +// fprintf( stderr, "No! warpi[j]=%d, warpj[j]=%d wmrecords[j] = %f\n", warpi[j], warpj[j], wmrecords[j] ); +// } +// fprintf( stderr, "%d-%d (%c-%c) curm = %5.0f, wmrecords[j]=%f\n", i, j, seq1[0][i], seq2[0][j], curm, wmrecords[j] ); + wmrecordspt++; + wmrecords1pt++; + warpipt++; + warpjpt++; + } #endif + *curpt++ += wm; ijppt++; mjpt++; @@ -469,9 +638,31 @@ fprintf( stderr, "\n" ); mpjpt++; } lastverticalw[i] = currentw[lgth2-1]; // lgth2==0 no toki error + + if( trywarp ) + { + fltncpy( prevwmrecords, wmrecords, lastj ); + intncpy( prevwarpi, warpi, lastj ); + intncpy( prevwarpj, warpj, lastj ); + } } - Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, ijp, tailgp ); + if( trywarp ) + { +// fprintf( stderr, "\nwm = %f\n", wm ); +// fprintf( stderr, "warpn = %d\n", warpn ); + free( wmrecords ); + free( prevwmrecords ); + free( warpi ); + free( warpj ); + free( prevwarpi ); + free( prevwarpj ); + } + + Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, ijp, tailgp, warpis, warpjs, warpbase ); + if( warpis ) free( warpis ); + if( warpjs ) free( warpjs ); + resultlen = strlen( mseq1[0] ); if( alloclen < resultlen || resultlen > N ) @@ -493,34 +684,35 @@ fprintf( stderr, "\n" ); return( wm ); } -float G__align11_noalign( int scoremtx[0x80][0x80], int penal, int penal_ex, char **seq1, char **seq2, int alloclen ) -/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */ +double G__align11_noalign( double **n_dynamicmtx, int penal, int penal_ex, char **seq1, char **seq2, int alloclen ) +/* warp mitaiou */ { // int k; register int i, j; int lasti; /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */ int lgth1, lgth2; // int resultlen; - float wm; /* int ?????? */ - float g; - float *currentw, *previousw; - float fpenalty = (float)penal; + double wm; /* int ?????? */ + double g; + double *currentw, *previousw; + double fpenalty = (double)penal; #if USE_PENALTY_EX - float fpenalty_ex = (float)penal_ex; + double fpenalty_ex = (double)penal_ex; #endif #if 1 - float *wtmp; - float *mjpt, *prept, *curpt; + double *wtmp; + double *mjpt, *prept, *curpt; // int *mpjpt; #endif - static TLS float mi, *m; - static TLS float *w1, *w2; - static TLS float *match; - static TLS float *initverticalw; /* kufuu sureba iranai */ - static TLS float *lastverticalw; /* kufuu sureba iranai */ + static TLS double mi, *m; + static TLS double *w1, *w2; + static TLS double *match; + static TLS double *initverticalw; /* kufuu sureba iranai */ + static TLS double *lastverticalw; /* kufuu sureba iranai */ static TLS int **intwork; - static TLS float **floatwork; + static TLS double **doublework; static TLS int orlgth1 = 0, orlgth2 = 0; + static TLS double **amino_dynamicmtx; if( seq1 == NULL ) { @@ -536,12 +728,14 @@ float G__align11_noalign( int scoremtx[0x80][0x80], int penal, int penal_ex, cha free( m ); - FreeFloatMtx( floatwork ); + FreeFloatMtx( doublework ); FreeIntMtx( intwork ); + FreeDoubleMtx( amino_dynamicmtx ); } return( 0.0 ); } + wm = 0.0; @@ -551,10 +745,12 @@ float G__align11_noalign( int scoremtx[0x80][0x80], int penal, int penal_ex, cha +#if 0 if( lgth1 <= 0 || lgth2 <= 0 ) { fprintf( stderr, "WARNING (g11): lgth1=%d, lgth2=%d\n", lgth1, lgth2 ); } +#endif if( lgth1 > orlgth1 || lgth2 > orlgth2 ) { @@ -573,8 +769,10 @@ float G__align11_noalign( int scoremtx[0x80][0x80], int penal, int penal_ex, cha - FreeFloatMtx( floatwork ); + FreeFloatMtx( doublework ); FreeIntMtx( intwork ); + + FreeDoubleMtx( amino_dynamicmtx ); } ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100; @@ -595,9 +793,11 @@ float G__align11_noalign( int scoremtx[0x80][0x80], int penal, int penal_ex, cha - floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 ); - intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 ); + doublework = AllocateFloatMtx( nalphabets, MAX( ll1, ll2 )+2 ); + intwork = AllocateIntMtx( nalphabets, MAX( ll1, ll2 )+2 ); + + amino_dynamicmtx = AllocateDoubleMtx( 0x80, 0x80 ); #if DEBUG fprintf( stderr, "succeeded\n" ); #endif @@ -607,6 +807,8 @@ float G__align11_noalign( int scoremtx[0x80][0x80], int penal, int penal_ex, cha } + for( i=0; i= warpbase ) + { +// fprintf( stderr, "WARP!\n" ); + ifi = warpis[ijp[iin][jin]-warpbase]; + jfi = warpjs[ijp[iin][jin]-warpbase]; + } + else if( ijp[iin][jin] < 0 ) { ifi = iin-1; jfi = jin+ijp[iin][jin]; } @@ -138,21 +144,47 @@ static float Ltracking( float *lasthorizontalw, float *lastverticalw, { ifi = iin-1; jfi = jin-1; } - l = iin - ifi; - while( --l ) + + +#if 1 // sentou de warp? + if( ifi == -warpbase && jfi == -warpbase ) { - *--mseq1[0] = seq1[0][ifi+l]; - *--mseq2[0] = *gap; - k++; + l = iin; + while( --l >= 0 ) + { + *--mseq1[0] = seq1[0][l]; + *--mseq2[0] = *gap; + k++; + } + l= jin; + while( --l >= 0 ) + { + *--mseq1[0] = *gap; + *--mseq2[0] = seq2[0][l]; + k++; + } + break; } - l= jin - jfi; - while( --l ) + else +#endif { - *--mseq1[0] = *gap; - *--mseq2[0] = seq2[0][jfi+l]; - k++; + l = iin - ifi; + while( --l > 0 ) + { + *--mseq1[0] = seq1[0][ifi+l]; + *--mseq2[0] = *gap; + k++; + } + l= jin - jfi; + while( --l > 0 ) + { + *--mseq1[0] = *gap; + *--mseq2[0] = seq2[0][jfi+l]; + k++; + } } + if( iin <= 0 || jin <= 0 ) break; *--mseq1[0] = seq1[0][ifi]; *--mseq2[0] = seq2[0][jfi]; @@ -164,51 +196,73 @@ static float Ltracking( float *lasthorizontalw, float *lastverticalw, if( jfi == -1 ) *off2pt = 0; else *off2pt = jfi; // fprintf( stderr, "ifn = %d, jfn = %d\n", ifi, jfi ); +// fprintf( stderr, "\n" ); +// fprintf( stderr, "%s\n", mseq1[0] ); +// fprintf( stderr, "%s\n", mseq2[0] ); return( 0.0 ); } -float L__align11( char **seq1, char **seq2, int alloclen, int *off1pt, int *off2pt ) +double L__align11( double **n_dynamicmtx, double scoreoffset, char **seq1, char **seq2, int alloclen, int *off1pt, int *off2pt ) /* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */ { // int k; - register int i, j; + int i, j; int lasti, lastj; /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */ int lgth1, lgth2; int resultlen; - float wm = 0.0; /* int ?????? */ - float g; - float *currentw, *previousw; + double wm = 0.0; /* int ?????? */ + double g; + double *currentw, *previousw; #if 1 - float *wtmp; + double *wtmp; int *ijppt; - float *mjpt, *prept, *curpt; + double *mjpt, *prept, *curpt; int *mpjpt; #endif - static TLS float mi, *m; + static TLS double mi, *m; static TLS int **ijp; static TLS int mpi, *mp; - static TLS float *w1, *w2; - static TLS float *match; - static TLS float *initverticalw; /* kufuu sureba iranai */ - static TLS float *lastverticalw; /* kufuu sureba iranai */ + static TLS double *w1, *w2; + static TLS double *match; + static TLS double *initverticalw; /* kufuu sureba iranai */ + static TLS double *lastverticalw; /* kufuu sureba iranai */ static TLS char **mseq1; static TLS char **mseq2; static TLS char **mseq; // static TLS int **intwork; -// static TLS float **floatwork; +// static TLS double **doublework; static TLS int orlgth1 = 0, orlgth2 = 0; - float maxwm; + static TLS double **amino_dynamicmtx = NULL; // ?? + double maxwm; int endali = 0, endalj = 0; // by D.Mathog, a guess // int endali, endalj; - float localthr = -offset; - float localthr2 = -offset; -// float localthr = 100; -// float localthr2 = 100; - float fpenalty = (float)penalty; - float fpenalty_ex = (float)penalty_ex; + double localthr = -offset + scoreoffset * 600; // 2013/12/13 + double localthr2 = -offset + scoreoffset * 600; // 2013/12/13 +// double localthr = -offset; +// double localthr2 = -offset; + double fpenalty = (double)penalty; + double fpenalty_ex = (double)penalty_ex; + double fpenalty_shift = (double)penalty_shift; + double fpenalty_tmp; // atode kesu + + int *warpis = NULL; + int *warpjs = NULL; + int *warpi = NULL; + int *warpj = NULL; + int *prevwarpi = NULL; + int *prevwarpj = NULL; + double *wmrecords = NULL; + double *prevwmrecords = NULL; + int warpn = 0; + int warpbase; + double curm = 0.0; + double *wmrecordspt, *wmrecords1pt, *prevwmrecordspt; + int *warpipt, *warpjpt; + + if( seq1 == NULL ) { @@ -228,6 +282,7 @@ float L__align11( char **seq1, char **seq2, int alloclen, int *off1pt, int *off2 FreeIntVec( mp ); FreeCharMtx( mseq ); + if( amino_dynamicmtx ) FreeDoubleMtx( amino_dynamicmtx ); amino_dynamicmtx = NULL; } return( 0.0 ); @@ -244,6 +299,28 @@ float L__align11( char **seq1, char **seq2, int alloclen, int *off1pt, int *off2 lgth1 = strlen( seq1[0] ); lgth2 = strlen( seq2[0] ); + + warpbase = lgth1 + lgth2; + warpis = NULL; + warpjs = NULL; + warpn = 0; + if( trywarp ) + { + wmrecords = AllocateFloatVec( lgth2+1 ); + warpi = AllocateIntVec( lgth2+1 ); + warpj = AllocateIntVec( lgth2+1 ); + prevwmrecords = AllocateFloatVec( lgth2+1 ); + prevwarpi = AllocateIntVec( lgth2+1 ); + prevwarpj = AllocateIntVec( lgth2+1 ); + for( i=0; i orlgth1 || lgth2 > orlgth2 ) { int ll1, ll2; @@ -260,10 +337,10 @@ float L__align11( char **seq1, char **seq2, int alloclen, int *off1pt, int *off2 FreeIntVec( mp ); FreeCharMtx( mseq ); + if( amino_dynamicmtx ) FreeDoubleMtx( amino_dynamicmtx ); amino_dynamicmtx = NULL; - -// FreeFloatMtx( floatwork ); +// FreeFloatMtx( doublework ); // FreeIntMtx( intwork ); } @@ -287,17 +364,20 @@ float L__align11( char **seq1, char **seq2, int alloclen, int *off1pt, int *off2 mseq = AllocateCharMtx( njob, ll1+ll2 ); -// floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 ); -// intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 ); +// doublework = AllocateFloatMtx( nalphabets, MAX( ll1, ll2 )+2 ); +// intwork = AllocateIntMtx( nalphabets, MAX( ll1, ll2 )+2 ); #if DEBUG fprintf( stderr, "succeeded\n" ); #endif - + amino_dynamicmtx = AllocateDoubleMtx( 0x100, 0x100 ); orlgth1 = ll1 - 100; orlgth2 = ll2 - 100; } + for( i=0; i wm ) + if( ( g=*prevwmrecordspt++ + fpenalty_tmp )> wm ) // naka ha osokute kamawanai + { +// fprintf( stderr, "Yes! Warp!! from %d-%d (%c-%c) to %d-%d (%c-%c) fpenalty_tmp = %f! warpn = %d\n", i, j, seq1[0][i], seq2[0][j-1], prevwarpi[j-1], prevwarpj[j-1],seq1[0][prevwarpi[j-1]], seq2[0][prevwarpj[j-1]], fpenalty_tmp, warpn ); + if( warpn && prevwarpi[j-1] == warpis[warpn-1] && prevwarpj[j-1] == warpjs[warpn-1] ) + { + *ijppt = warpbase + warpn - 1; + } + else + { + *ijppt = warpbase + warpn; + warpis = realloc( warpis, sizeof(int) * ( warpn+1 ) ); + warpjs = realloc( warpjs, sizeof(int) * ( warpn+1 ) ); + warpis[warpn] = prevwarpi[j-1]; + warpjs[warpn] = prevwarpj[j-1]; + warpn++; + } + wm = g; + } + else + { + } + + curm = *curpt + wm; + +// fprintf( stderr, "###### curm = %f at %c-%c, i=%d, j=%d\n", curm, seq1[0][i], seq2[0][j], i, j ); + +// fprintf( stderr, "copy from i, j-1? %f > %f?\n", wmrecords[j-1], curm ); +// if( wmrecords[j-1] > wmrecords[j] ) + if( *wmrecords1pt > *wmrecordspt ) + { +// fprintf( stderr, "yes\n" ); +// wmrecords[j] = wmrecords[j-1]; + *wmrecordspt = *wmrecords1pt; +// warpi[j] = warpi[j-1]; +// warpj[j] = warpj[j-1]; + *warpipt = *(warpipt-1); + *warpjpt = *(warpjpt-1); +// fprintf( stderr, "warpi[j]=%d, warpj[j]=%d wmrecords[j] = %f\n", warpi[j], warpj[j], wmrecords[j] ); + } +// else +// { +// fprintf( stderr, "no\n" ); +// } + +// fprintf( stderr, " curm = %f at %c-%c\n", curm, seq1[0][i], seq2[0][j] ); +// fprintf( stderr, " wmrecords[%d] = %f\n", j, wmrecords[j] ); +// fprintf( stderr, "replace?\n" ); + +// if( curm > wmrecords[j] ) + if( curm > *wmrecordspt ) + { +// fprintf( stderr, "yes at %d-%d (%c-%c), replaced warp: warpi[j]=%d, warpj[j]=%d warpn=%d, wmrecords[j] = %f -> %f\n", i, j, seq1[0][i], seq2[0][j], i, j, warpn, wmrecords[j], curm ); +// wmrecords[j] = curm; + *wmrecordspt = curm; +// warpi[j] = i; +// warpj[j] = j; + *warpipt = i; + *warpjpt = j; + } +// else +// { +// fprintf( stderr, "No! warpi[j]=%d, warpj[j]=%d wmrecords[j] = %f\n", warpi[j], warpj[j], wmrecords[j] ); +// } +// fprintf( stderr, "%d-%d (%c-%c) curm = %5.0f, wmrecords[j]=%f\n", i, j, seq1[0][i], seq2[0][j], curm, wmrecords[j] ); + wmrecordspt++; + wmrecords1pt++; + warpipt++; + warpjpt++; + } *curpt++ += wm; ijppt++; @@ -514,8 +679,25 @@ fprintf( stderr, "\n" ); #endif lastverticalw[i] = currentw[lgth2-1]; - } + if( trywarp ) + { + fltncpy( prevwmrecords, wmrecords, lastj ); + intncpy( prevwarpi, warpi, lastj ); + intncpy( prevwarpj, warpj, lastj ); + } + } +// fprintf( stderr, "\nwm = %f\n", wm ); + if( trywarp ) + { +// if( warpn ) fprintf( stderr, "warpn = %d\n", warpn ); + free( wmrecords ); + free( prevwmrecords ); + free( warpi ); + free( warpj ); + free( prevwarpi ); + free( prevwarpj ); + } #if 0 fprintf( stderr, "maxwm = %f\n", maxwm ); @@ -528,10 +710,13 @@ fprintf( stderr, "\n" ); strcpy( seq1[0], "" ); strcpy( seq2[0], "" ); *off1pt = *off2pt = 0; + fprintf( stderr, "maxwm <- 0.0 \n" ); return( 0.0 ); } - Ltracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, ijp, off1pt, off2pt, endali, endalj ); + Ltracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, ijp, off1pt, off2pt, endali, endalj, warpis, warpjs, warpbase ); + if( warpis ) free( warpis ); + if( warpjs ) free( warpjs ); resultlen = strlen( mseq1[0] ); @@ -550,6 +735,8 @@ fprintf( stderr, "\n" ); fprintf( stderr, ">\n%s\n", mseq1[0] ); fprintf( stderr, ">\n%s\n", mseq2[0] ); + fprintf( stderr, "*off1pt = %d, *off2pt = %d\n", *off1pt, *off2pt ); + fprintf( stderr, "maxwm = %f\n", maxwm ); fprintf( stderr, " wm = %f\n", wm ); #endif @@ -557,3 +744,409 @@ fprintf( stderr, "\n" ); return( maxwm ); } + +double L__align11_noalign( double **n_dynamicmtx, char **seq1, char **seq2 ) +// warp mitaiou +{ +// int k; + int i, j; + int lasti, lastj; /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */ + int lgth1, lgth2; +// int resultlen; + double wm = 0.0; /* int ?????? */ + double g; + double *currentw, *previousw; +#if 1 + double *wtmp; +// int *ijppt; + double *mjpt, *prept, *curpt; +// int *mpjpt; +#endif + static TLS double mi, *m; +// static TLS int **ijp; +// static TLS int mpi, *mp; + static TLS double *w1, *w2; + static TLS double *match; + static TLS double *initverticalw; /* kufuu sureba iranai */ + static TLS double *lastverticalw; /* kufuu sureba iranai */ +// static TLS char **mseq1; +// static TLS char **mseq2; +// static TLS char **mseq; +// static TLS int **intwork; +// static TLS double **doublework; + static TLS int orlgth1 = 0, orlgth2 = 0; + static TLS double **amino_dynamicmtx = NULL; // ?? + double maxwm; +// int endali = 0, endalj = 0; // by D.Mathog, a guess +// int endali, endalj; + double localthr = -offset; + double localthr2 = -offset; +// double localthr = 100; +// double localthr2 = 100; + double fpenalty = (double)penalty; + double fpenalty_ex = (double)penalty_ex; + + if( seq1 == NULL ) + { + if( orlgth1 > 0 && orlgth2 > 0 ) + { + orlgth1 = 0; + orlgth2 = 0; +// free( mseq1 ); +// free( mseq2 ); + FreeFloatVec( w1 ); + FreeFloatVec( w2 ); + FreeFloatVec( match ); + FreeFloatVec( initverticalw ); + FreeFloatVec( lastverticalw ); + + FreeFloatVec( m ); +// FreeIntVec( mp ); + +// FreeCharMtx( mseq ); + if( amino_dynamicmtx ) FreeDoubleMtx( amino_dynamicmtx ); amino_dynamicmtx = NULL; + + } + return( 0.0 ); + } + + +// if( orlgth1 == 0 ) +// { +// mseq1 = AllocateCharMtx( njob, 0 ); +// mseq2 = AllocateCharMtx( njob, 0 ); +// } + + + lgth1 = strlen( seq1[0] ); + lgth2 = strlen( seq2[0] ); + + if( lgth1 > orlgth1 || lgth2 > orlgth2 ) + { + int ll1, ll2; + + if( orlgth1 > 0 && orlgth2 > 0 ) + { + FreeFloatVec( w1 ); + FreeFloatVec( w2 ); + FreeFloatVec( match ); + FreeFloatVec( initverticalw ); + FreeFloatVec( lastverticalw ); + + FreeFloatVec( m ); +// FreeIntVec( mp ); + +// FreeCharMtx( mseq ); + + + +// FreeFloatMtx( doublework ); +// FreeIntMtx( intwork ); + if( amino_dynamicmtx ) FreeDoubleMtx( amino_dynamicmtx ); amino_dynamicmtx = NULL; + } + + ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100; + ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100; + +#if DEBUG + fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 ); +#endif + + w1 = AllocateFloatVec( ll2+2 ); + w2 = AllocateFloatVec( ll2+2 ); + match = AllocateFloatVec( ll2+2 ); + + initverticalw = AllocateFloatVec( ll1+2 ); + lastverticalw = AllocateFloatVec( ll1+2 ); + + m = AllocateFloatVec( ll2+2 ); +// mp = AllocateIntVec( ll2+2 ); + +// mseq = AllocateCharMtx( njob, ll1+ll2 ); + + +// doublework = AllocateFloatMtx( nalphabets, MAX( ll1, ll2 )+2 ); +// intwork = AllocateIntMtx( nalphabets, MAX( ll1, ll2 )+2 ); + +#if DEBUG + fprintf( stderr, "succeeded\n" ); +#endif + amino_dynamicmtx = AllocateDoubleMtx( 0x80, 0x80 ); + orlgth1 = ll1 - 100; + orlgth2 = ll2 - 100; + } + + for( i=0; i commonAlloc1 || orlgth2 > commonAlloc2 ) +// { +// int ll1, ll2; +// +// if( commonAlloc1 && commonAlloc2 ) +// { +// FreeIntMtx( commonIP ); +// } +// +// ll1 = MAX( orlgth1, commonAlloc1 ); +// ll2 = MAX( orlgth2, commonAlloc2 ); + +#if DEBUG +// fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 ); +#endif + +// commonIP = AllocateIntMtx( ll1+10, ll2+10 ); + +#if DEBUG +// fprintf( stderr, "succeeded\n\n" ); +#endif + +// commonAlloc1 = ll1; +// commonAlloc2 = ll2; +// } +// ijp = commonIP; + + +#if 0 + for( i=0; i", wm ); +#endif +#if 0 + fprintf( stderr, "%5.0f?", g ); +#endif + if( (g=mi+fpenalty) > wm ) + { + wm = g; +// *ijppt = -( j - mpi ); + } + if( *prept > mi ) + { + mi = *prept; +// mpi = j-1; + } + +#if USE_PENALTY_EX + mi += fpenalty_ex; +#endif + +#if 0 + fprintf( stderr, "%5.0f?", g ); +#endif + if( (g=*mjpt+fpenalty) > wm ) + { + wm = g; +// *ijppt = +( i - *mpjpt ); + } + if( *prept > *mjpt ) + { + *mjpt = *prept; +// *mpjpt = i-1; + } +#if USE_PENALTY_EX + *mjpt += fpenalty_ex; +#endif + + if( maxwm < wm ) + { + maxwm = wm; +// endali = i; +// endalj = j; + } +#if 1 + if( wm < localthr ) + { +// fprintf( stderr, "stop i=%d, j=%d, curpt=%f\n", i, j, *curpt ); +// *ijppt = localstop; + wm = localthr2; + } +#endif +#if 0 + fprintf( stderr, "%5.0f ", *curpt ); +#endif +#if DEBUG2 + fprintf( stderr, "%5.0f ", wm ); +// fprintf( stderr, "%c-%c *ijppt = %d, localstop = %d\n", seq1[0][i], seq2[0][j], *ijppt, localstop ); +#endif + + *curpt++ += wm; +// ijppt++; + mjpt++; + prept++; +// mpjpt++; + } +#if DEBUG2 + fprintf( stderr, "\n" ); +#endif + + lastverticalw[i] = currentw[lgth2-1]; + } + + +#if 0 + fprintf( stderr, "maxwm = %f\n", maxwm ); + fprintf( stderr, "endali = %d\n", endali ); + fprintf( stderr, "endalj = %d\n", endalj ); +#endif + + +#if 0 // IRUKAMO!!!! + if( ijp[endali][endalj] == localstop ) + { + strcpy( seq1[0], "" ); + strcpy( seq2[0], "" ); + *off1pt = *off2pt = 0; + fprintf( stderr, "maxwm <- 0.0 \n" ); + return( 0.0 ); + } +#else + if( maxwm < localthr ) + { + fprintf( stderr, "maxwm <- 0.0 \n" ); + return( 0.0 ); + } +#endif + +// Ltracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, ijp, off1pt, off2pt, endali, endalj ); + + +// resultlen = strlen( mseq1[0] ); +// if( alloclen < resultlen || resultlen > N ) +// { +// fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N ); +// ErrorExit( "LENGTH OVER!\n" ); +// } + + +// strcpy( seq1[0], mseq1[0] ); +// strcpy( seq2[0], mseq2[0] ); + +#if 0 + fprintf( stderr, "wm=%f\n", wm ); + fprintf( stderr, ">\n%s\n", mseq1[0] ); + fprintf( stderr, ">\n%s\n", mseq2[0] ); + + fprintf( stderr, "maxwm = %f\n", maxwm ); + fprintf( stderr, " wm = %f\n", wm ); +#endif + + return( maxwm ); +} diff --git a/binaries/src/mafft/core/Lalign11.o b/binaries/src/mafft/core/Lalign11.o new file mode 100644 index 0000000..c7895e1 Binary files /dev/null and b/binaries/src/mafft/core/Lalign11.o differ diff --git a/binaries/src/mafft/core/Lalignmm.c b/binaries/src/mafft/core/Lalignmm.c index 19f26ec..4346bf1 100644 --- a/binaries/src/mafft/core/Lalignmm.c +++ b/binaries/src/mafft/core/Lalignmm.c @@ -13,17 +13,17 @@ static int reccycle = 0; -static float localthr; +static double localthr; -static void match_ribosum( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize ) +static void match_ribosum( double *match, double **cpmx1, double **cpmx2, int i1, int lgth2, double **doublework, int **intwork, int initialize ) { int j, k, l; - float scarr[38]; - float **cpmxpd = floatwork; + double scarr[38]; + double **cpmxpd = doublework; int **cpmxpdn = intwork; int count = 0; - float *matchpt; - float **cpmxpdpt; + double *matchpt; + double **cpmxpdpt; int **cpmxpdnpt; int cpkd; @@ -53,9 +53,9 @@ static void match_ribosum( float *match, float **cpmx1, float **cpmx2, int i1, i scarr[l] += ribosumdis[k][l] * cpmx1[i1][k]; } } -#if 0 /* ¤³¤ì¤ò»È¤¦¤È¤­¤Ïfloatwork¤Î¥¢¥í¥±¡¼¥È¤òµÕ¤Ë¤¹¤ë */ +#if 0 /* ¤³¤ì¤ò»È¤¦¤È¤­¤Ïdoublework¤Î¥¢¥í¥±¡¼¥È¤òµÕ¤Ë¤¹¤ë */ { - float *fpt, **fptpt, *fpt2; + double *fpt, **fptpt, *fpt2; int *ipt, **iptpt; fpt2 = match; iptpt = cpmxpdn; @@ -91,24 +91,26 @@ static void match_ribosum( float *match, float **cpmx1, float **cpmx2, int i1, i #endif } -static void match_calc( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize ) +static void match_calc( double *match, double **cpmx1, double **cpmx2, int i1, int lgth2, double **doublework, int **intwork, int initialize ) { int j, k, l; - float scarr[26]; - float **cpmxpd = floatwork; +// double scarr[26]; + double **cpmxpd = doublework; int **cpmxpdn = intwork; int count = 0; - float *matchpt; - float **cpmxpdpt; + double *matchpt; + double **cpmxpdpt; int **cpmxpdnpt; int cpkd; + double *scarr; + scarr = calloc( nalphabets, sizeof( double ) ); if( initialize ) { for( j=0; j 0 ) - { - for( i=0; i 0 ) - { - for( i=0; i 1 || maxwm - value > 1 ) - { - fprintf( stderr, "WARNING value = %f, but maxwm = %f\n", value, maxwm ); - for( i=0; i1-%d\n%s\n", i, mseq1[i] ); - fprintf( stderr, "%s\n", aseq1[i] ); - } - for( i=0; i2-%d\n%s\n", i, mseq2[i] ); - fprintf( stderr, "%s\n", aseq2[i] ); - } - -// exit( 1 ); - } - else - { - fprintf( stderr, "value = %.0f, maxwm = %.0f -> ok\n", value, maxwm ); - } -#endif - -#if MEMSAVE -#else - for( i=0; i -1 ) + *fpt2 += scarr[*ipt++] * *fpt++; + fpt2++,iptpt++,fptpt++; + } + } + for( j=0; j-1; k++ ) + match[j] += scarr[cpmxpdn[j][k]] * cpmxpd[j][k]; + } +#else + matchpt = match; + cpmxpdnpt = cpmxpdn; + cpmxpdpt = cpmxpd; + while( lgth2-- ) + { +// *matchpt = 0.0; // add dakara + for( k=0; (cpkd=(*cpmxpdnpt)[k])>-1; k++ ) + *matchpt += scarr[cpkd] * (*cpmxpdpt)[k]; + matchpt++; + cpmxpdnpt++; + cpmxpdpt++; + } +#endif + free( scarr ); +} +static void match_calc( double **n_dynamicmtx, double *match, double **cpmx1, double **cpmx2, int i1, int lgth2, double **doublework, int **intwork, int initialize ) +{ + int j, k, l; +// double scarr[26]; + double **cpmxpd = doublework; + int **cpmxpdn = intwork; + int count = 0; + double *matchpt; + double **cpmxpdpt; + int **cpmxpdnpt; + int cpkd; + double *scarr; + scarr = calloc( nalphabets, sizeof( double ) ); if( initialize ) { for( j=0; j 0 ) headgapfreq1 = gapfreq1f[-1]; + else headgapfreq1 = headgapfreq1_g; + if( jst > 0 ) headgapfreq2 = gapfreq2f[-1]; + else headgapfreq2 = headgapfreq2_g; #if STOREWM char ttt1[10000], ttt2[10000]; @@ -326,8 +419,8 @@ static float MSalignmm_tanni( int icyc, int jcyc, double *eff1, double *eff2, ch m = AllocateFloatVec( ll2+2 ); mp = AllocateIntVec( ll2+2 ); - floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 27 ); - intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 27 ); + doublework = AllocateFloatMtx( MAX( ll1, ll2 )+2, nalphabets+1 ); + intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, nalphabets+1 ); intmtx = AllocateIntMtx( ll1+1, ll2+1 ); @@ -337,28 +430,28 @@ static float MSalignmm_tanni( int icyc, int jcyc, double *eff1, double *eff2, ch currentw = w1; previousw = w2; - match_calc( initverticalw, cpmx2+jst, cpmx1+ist, 0, lgth1, floatwork, intwork, 1 ); + match_calc( n_dynamicmtx, initverticalw, cpmx2+jst, cpmx1+ist, 0, lgth1, doublework, intwork, 1 ); - match_calc( currentw, cpmx1+ist, cpmx2+jst, 0, lgth2, floatwork, intwork, 1 ); + match_calc( n_dynamicmtx, currentw, cpmx1+ist, cpmx2+jst, 0, lgth2, doublework, intwork, 1 ); if( headgp || ist != 0 ) { for( i=1; i", wm ); #endif - g = mi + fgcp2[j-1]; + g = mi + fgcp2[j-1] * gapfreq1f[i]; #if 0 fprintf( stderr, "%5.0f?", g ); #endif @@ -405,7 +498,7 @@ static float MSalignmm_tanni( int icyc, int jcyc, double *eff1, double *eff2, ch wm = g; *ijppt = -( j - mpi ); } - g = *prept + ogcp2[j]; + g = *prept + ogcp2[j] * gapfreq1f[i-1]; if( g >= mi ) { mi = g; @@ -415,7 +508,7 @@ static float MSalignmm_tanni( int icyc, int jcyc, double *eff1, double *eff2, ch mi += fpenalty_ex; #endif - g = *mjpt + fgcp1[i-1]; + g = *mjpt + fgcp1[i-1] * gapfreq2f[j]; #if 0 fprintf( stderr, "%5.0f?", g ); #endif @@ -424,7 +517,7 @@ static float MSalignmm_tanni( int icyc, int jcyc, double *eff1, double *eff2, ch wm = g; *ijppt = +( i - *mpjpt ); } - g = *prept + ogcp1[i]; + g = *prept + ogcp1[i] * gapfreq2f[j-1]; if( g >= *mjpt ) { *mjpt = g; @@ -472,7 +565,7 @@ static float MSalignmm_tanni( int icyc, int jcyc, double *eff1, double *eff2, ch FreeIntVec( mp ); - FreeFloatMtx( floatwork ); + FreeFloatMtx( doublework ); FreeIntMtx( intwork ); FreeIntMtx( intmtx ); @@ -489,13 +582,13 @@ static float MSalignmm_tanni( int icyc, int jcyc, double *eff1, double *eff2, ch } static void freearrays_rec1( - float *w1, float *w2, float *initverticalw, float *lastverticalw, - float *midw, float *midm, float *midn, + double *w1, double *w2, double *initverticalw, double *lastverticalw, + double *midw, double *midm, double *midn, int *jumpbacki, int *jumpbackj, int *jumpforwi, int *jumpforwj, int *jumpdummi, int *jumpdummj, - float *m, int *mp, - float **floatwork, int **intwork + double *m, int *mp, + double **doublework, int **intwork #if STOREWM - , float **WMMTX, float **WMMTX2 + , double **WMMTX, double **WMMTX2 #endif ) { @@ -518,7 +611,7 @@ static void freearrays_rec1( FreeFloatVec( m ); FreeIntVec( mp ); - FreeFloatMtx( floatwork ); + FreeFloatMtx( doublework ); FreeIntMtx( intwork ); #if STOREWM @@ -539,48 +632,48 @@ static void freearrays_rec2( char *gaps, char **aseq1, char **aseq2 ) #endif } -static float MSalignmm_rec( int icyc, int jcyc, double *eff1, double *eff2, char **seq1, char **seq2, float **cpmx1, float **cpmx2, int ist, int ien, int jst, int jen, int alloclen, int fulllen1, int fulllen2, char **mseq1, char **mseq2, int depth, float **gapinfo, int *chudanpt, int chudanref, int *chudanres, int headgp, int tailgp ) +static double MSalignmm_rec( double **n_dynamicmtx, int icyc, int jcyc, double *eff1, double *eff2, char **seq1, char **seq2, double **cpmx1, double **cpmx2, int ist, int ien, int jst, int jen, int alloclen, int fulllen1, int fulllen2, char **mseq1, char **mseq2, int depth, double **gapinfo, int *chudanpt, int chudanref, int *chudanres, int headgp, int tailgp, double headgapfreq1_g, double headgapfreq2_g ) /* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */ { // int k; int alnlen; - float value = 0.0; + double value = 0.0; register int i, j; char **aseq1, **aseq2; int ll1, ll2, l, len; int lasti, lastj, imid; int jmid = 0; // by D.Mathog, a guess - float wm = 0.0; /* int ?????? */ - float g; - float *currentw, *previousw; + double wm = 0.0; /* int ?????? */ + double g; + double *currentw, *previousw; #if USE_PENALTY_EX - float fpenalty_ex = (float)penalty_ex; + double fpenalty_ex = (double)penalty_ex; #endif - float *wtmp; + double *wtmp; // short *ijppt; int *mpjpt; // short **ijp; int *mp; int mpi; - float *mjpt, *prept, *curpt; - float mi; - float *m; - float *w1, *w2; -// float *match; - float *initverticalw; /* kufuu sureba iranai */ - float *lastverticalw; /* kufuu sureba iranai */ + double *mjpt, *prept, *curpt; + double mi; + double *m; + double *w1, *w2; +// double *match; + double *initverticalw; /* kufuu sureba iranai */ + double *lastverticalw; /* kufuu sureba iranai */ int **intwork; - float **floatwork; + double **doublework; // short **shortmtx; #if STOREWM - float **WMMTX; - float **WMMTX2; + double **WMMTX; + double **WMMTX2; #endif - float *midw; - float *midm; - float *midn; + double *midw; + double *midm; + double *midn; int lgth1, lgth2; - float maxwm; + double maxwm; int *jumpforwi; int *jumpforwj; int *jumpbacki; @@ -590,16 +683,20 @@ static float MSalignmm_rec( int icyc, int jcyc, double *eff1, double *eff2, char int jumpi, jumpj = 0; // by D.Mathog, a guess char *gaps; int ijpi, ijpj; - float *ogcp1; - float *fgcp1; - float *ogcp2; - float *fgcp2; - float firstm; + double *ogcp1; + double *fgcp1; + double *ogcp2; + double *fgcp2; + double firstm; int firstmp; #if STOREWM static TLS char ttt1[50000]; static TLS char ttt2[50000]; #endif + double *gapfreq1f; + double *gapfreq2f; + double headgapfreq1; + double headgapfreq2; #if 0 int nglen1, nglen2; @@ -613,6 +710,13 @@ static float MSalignmm_rec( int icyc, int jcyc, double *eff1, double *eff2, char fgcp1 = gapinfo[1] + ist; ogcp2 = gapinfo[2] + jst; fgcp2 = gapinfo[3] + jst; + gapfreq1f = gapinfo[4] + ist; + gapfreq2f = gapinfo[5] + jst; + + if( ist > 0 ) headgapfreq1 = gapfreq1f[-1]; + else headgapfreq1 = headgapfreq1_g; + if( jst > 0 ) headgapfreq2 = gapfreq2f[-1]; + else headgapfreq2 = headgapfreq2_g; depth++; reccycle++; @@ -649,7 +753,8 @@ static float MSalignmm_rec( int icyc, int jcyc, double *eff1, double *eff2, char { mseq2[i][0] = 0; for( j=0; j", wm ); #endif - g = mi + fgcp2[j-1]; + g = mi + fgcp2[j-1] * gapfreq1f[i]; // g = mi + fpenalty; #if 0 fprintf( stderr, "%5.0f?", g ); @@ -857,7 +963,7 @@ static float MSalignmm_rec( int icyc, int jcyc, double *eff1, double *eff2, char wm = g; // *ijppt = -( j - mpi ); } - g = *prept + ogcp2[j]; + g = *prept + ogcp2[j] * gapfreq1f[i-1]; // g = *prept; if( g >= mi ) { @@ -868,7 +974,7 @@ static float MSalignmm_rec( int icyc, int jcyc, double *eff1, double *eff2, char mi += fpenalty_ex; #endif - g = *mjpt + fgcp1[i-1]; + g = *mjpt + fgcp1[i-1] * gapfreq2f[j]; // g = *mjpt + fpenalty; #if 0 fprintf( stderr, "%5.0f?", g ); @@ -880,7 +986,7 @@ static float MSalignmm_rec( int icyc, int jcyc, double *eff1, double *eff2, char } - g = *prept + ogcp1[i]; + g = *prept + ogcp1[i] * gapfreq2f[j-1]; // g = *prept; if( g >= *mjpt ) { @@ -960,18 +1066,18 @@ static float MSalignmm_rec( int icyc, int jcyc, double *eff1, double *eff2, char // gyakudp - match_calc( initverticalw, cpmx2+jst, cpmx1+ist, lgth2-1, lgth1, floatwork, intwork, 1 ); - match_calc( currentw, cpmx1+ist, cpmx2+jst, lgth1-1, lgth2, floatwork, intwork, 1 ); + match_calc( n_dynamicmtx, initverticalw, cpmx2+jst, cpmx1+ist, lgth2-1, lgth1, doublework, intwork, 1 ); + match_calc( n_dynamicmtx, currentw, cpmx1+ist, cpmx2+jst, lgth1-1, lgth2, doublework, intwork, 1 ); for( i=0; i0; --j ) { m[j-1] = currentw[j] + fgcp2[lgth2-2]; // m[j-1] = currentw[j]; mp[j] = lgth1-1; } +#else + for( j=lgth2-1; j>-1; --j ) + { + m[j] = currentw[j+1] + fgcp1[lgth1-2] * gapfreq2f[j+1]; +// m[j-1] = currentw[j]; + mp[j] = lgth1-1; + } +#endif // for( j=0; j wm ) { @@ -1067,7 +1182,7 @@ static float MSalignmm_rec( int icyc, int jcyc, double *eff1, double *eff2, char ijpi = i+1; } - g = *prept + fgcp2[j]; + g = *prept + fgcp2[j] * gapfreq1f[i+1]; // g = *prept; if( g >= mi ) { @@ -1081,7 +1196,7 @@ static float MSalignmm_rec( int icyc, int jcyc, double *eff1, double *eff2, char #endif // fprintf( stderr, "i,j=%d,%d *mpjpt = %d\n", i, j, *mpjpt ); - g = *mjpt + ogcp1[i+1]; + g = *mjpt + ogcp1[i+1] * gapfreq2f[j]; // g = *mjpt + fpenalty; if( g > wm ) { @@ -1091,7 +1206,7 @@ static float MSalignmm_rec( int icyc, int jcyc, double *eff1, double *eff2, char } // if( i == imid )fprintf( stderr, "i,j=%d,%d \n", i, j ); - g = *prept + fgcp1[i]; + g = *prept + fgcp1[i] * gapfreq2f[j+1]; // g = *prept; if( g >= *mjpt ) { @@ -1379,7 +1494,7 @@ static float MSalignmm_rec( int icyc, int jcyc, double *eff1, double *eff2, char w1, w2, initverticalw, lastverticalw, midw, midm, midn, jumpbacki, jumpbackj, jumpforwi, jumpforwj, jumpdummi, jumpdummj, m, mp, - floatwork, intwork + doublework, intwork #if STOREWM , WMMTX, WMMTX2 #endif @@ -1388,7 +1503,7 @@ static float MSalignmm_rec( int icyc, int jcyc, double *eff1, double *eff2, char // fprintf( stderr, "==== calling myself (first)\n" ); - value = MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist, ist+jumpi, jst, jst+jumpj, alloclen, fulllen1, fulllen2, aseq1, aseq2, depth, gapinfo, NULL, 0, NULL, headgp, tailgp ); // chudan mada + value = MSalignmm_rec( n_dynamicmtx, icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist, ist+jumpi, jst, jst+jumpj, alloclen, fulllen1, fulllen2, aseq1, aseq2, depth, gapinfo, NULL, 0, NULL, headgp, tailgp, headgapfreq1_g, headgapfreq2_g ); // chudan mada #if 0 fprintf( stderr, "aseq1[0] = %s\n", aseq1[0] ); fprintf( stderr, "aseq2[0] = %s\n", aseq2[0] ); @@ -1408,7 +1523,8 @@ static float MSalignmm_rec( int icyc, int jcyc, double *eff1, double *eff2, char // fprintf( stderr, "l=%d\n", l ); if( l > 0 ) { - for( i=0; i 0 ) { - for( i=0; i 0 ) headgapfreq1 = gapfreq1f[-1]; + else headgapfreq1 = headgapfreq1_g; + if( jst > 0 ) headgapfreq2 = gapfreq2f[-1]; + else headgapfreq2 = headgapfreq2_g; + +#if STOREWM + char ttt1[10000], ttt2[10000]; +#endif + + + lgth1 = ien-ist+1; + lgth2 = jen-jst+1; + +#if STOREWM + strncpy( ttt1, seq1[0]+ist, lgth1 ); ttt1[lgth1] = 0; + strncpy( ttt2, seq2[0]+jst, lgth2 ); ttt2[lgth2] = 0; + + fprintf( stderr, "in _tanni ist,ien = %d,%d, lgth1=%d\n", ist, ien, lgth1 ); + fprintf( stderr, "in _tanni jst,jen = %d,%d, lgth2=%d\n", jst, jen, lgth2 ); + fprintf( stderr, "ttt1 = %s\n", ttt1 ); + fprintf( stderr, "ttt2 = %s\n", ttt2 ); +#endif + +#if 0 + fprintf( stderr, "in _tanni ist,ien = %d,%d, fulllen1=%d\n", ist, ien, fulllen1 ); + fprintf( stderr, "in _tanni jst,jen = %d,%d, fulllen2=%d\n", jst, jen, fulllen2 ); + fprintf( stderr, "in _tanni seq1[0] = %-*.*s\n", ien-ist+1, ien-ist+1, seq1[0]+ist ); + fprintf( stderr, "in _tanni seq2[0] = %-*.*s\n", jen-jst+1, jen-jst+1, seq2[0]+jst ); +#endif + + + ll1 = ( (int)(lgth1) ) + 100; + ll2 = ( (int)(lgth2) ) + 100; + +// aseq1 = AllocateCharMtx( icyc, 0 ); +// aseq2 = AllocateCharMtx( jcyc, 0 ); +// aseq1bk = AllocateCharMtx( icyc, lgth1+lgth2+100 ); +// aseq2bk = AllocateCharMtx( jcyc, lgth1+lgth2+100 ); +// for( i=0; i", wm ); +#endif + g = mi + fgcp2[j-1] * gapfreq1f[i]; +#if 0 + fprintf( stderr, "%5.0f?", g ); +#endif + if( g > wm ) + { + wm = g; + *ijppt = -( j - mpi ); + } + g = *prept + ogcp2[j] * gapfreq1f[i-1]; + if( g >= mi ) + { + mi = g; + mpi = j-1; + } +#if USE_PENALTY_EX + mi += fpenalty_ex; +#endif + + g = *mjpt + fgcp1[i-1] * gapfreq2f[j]; +#if 0 + fprintf( stderr, "%5.0f?", g ); +#endif + if( g > wm ) + { + wm = g; + *ijppt = +( i - *mpjpt ); + } + g = *prept + ogcp1[i] * gapfreq2f[j-1]; + if( g >= *mjpt ) + { + *mjpt = g; + *mpjpt = i-1; + } +#if USE_PENALTY_EX + m[j] += fpenalty_ex; +#endif + +#if 0 + fprintf( stderr, "%5.0f ", wm ); +#endif + *curpt += wm; + + + ijppt++; + mjpt++; + prept++; + mpjpt++; + curpt++; + } + lastverticalw[i] = currentw[lgth2-1]; + } + +// fprintf( stderr, "wm = %f\n", wm ); + + Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, ijp, icyc, jcyc, ist, ien, jst, jen, fulllen1, fulllen2, tailgp ); +#if 0 + fprintf( stderr, "res in _tanni mseq1[0] = %s\n", mseq1[0] ); + fprintf( stderr, "res in _tanni mseq2[0] = %s\n", mseq2[0] ); +#endif + +// for( i=0; i 0 ) headgapfreq1 = gapfreq1f[-1]; + else headgapfreq1 = headgapfreq1_g; + if( jst > 0 ) headgapfreq2 = gapfreq2f[-1]; + else headgapfreq2 = headgapfreq2_g; + + depth++; + reccycle++; + + lgth1 = ien-ist+1; + lgth2 = jen-jst+1; + +// if( lgth1 < 5 ) +// fprintf( stderr, "\nWARNING: lgth1 = %d\n", lgth1 ); +// if( lgth2 < 5 ) +// fprintf( stderr, "\nWARNING: lgth2 = %d\n", lgth2 ); +// + + +#if STOREWM + fprintf( stderr, "==== MSalign (depth=%d, reccycle=%d), ist=%d, ien=%d, jst=%d, jen=%d\n", depth, reccycle, ist, ien, jst, jen ); + strncpy( ttt1, seq1[0]+ist, lgth1 ); + strncpy( ttt2, seq2[0]+jst, lgth2 ); + ttt1[lgth1] = 0; + ttt2[lgth2] = 0; + fprintf( stderr, "seq1 = %s\n", ttt1 ); + fprintf( stderr, "seq2 = %s\n", ttt2 ); +#endif + if( lgth2 <= 0 ) // lgth1 <= 0 ha? + { +// fprintf( stderr, "\n\n==== jimei\n\n" ); +// exit( 1 ); + for( i=0; i", wm ); +#endif + g = mi + fgcp2[j-1] * gapfreq1f[i]; +// g = mi + fpenalty; +#if 0 + fprintf( stderr, "%5.0f?", g ); +#endif + if( g > wm ) + { + wm = g; +// *ijppt = -( j - mpi ); + } + g = *prept + ogcp2[j] * gapfreq1f[i-1]; +// g = *prept; + if( g >= mi ) + { + mi = g; + mpi = j-1; + } +#if USE_PENALTY_EX + mi += fpenalty_ex; +#endif + + g = *mjpt + fgcp1[i-1] * gapfreq2f[j]; +// g = *mjpt + fpenalty; +#if 0 + fprintf( stderr, "%5.0f?", g ); +#endif + if( g > wm ) + { + wm = g; +// *ijppt = +( i - *mpjpt ); + } + + + g = *prept + ogcp1[i] * gapfreq2f[j-1]; +// g = *prept; + if( g >= *mjpt ) + { + *mjpt = g; + *mpjpt = i-1; + } +#if USE_PENALTY_EX + m[j] += fpenalty_ex; +#endif + +#if 0 + fprintf( stderr, "%5.0f ", wm ); +#endif + *curpt += wm; + +#if STOREWM + WMMTX[i][j] = *curpt; + WMMTX2[i][j] = *mjpt; +#endif + + if( i == imid ) //muda + { + jumpbackj[j] = *mpjpt; // muda atode matomeru + jumpbacki[j] = mpi; // muda atode matomeru +// fprintf( stderr, "jumpbackj[%d] in forward dp is %d\n", j, *mpjpt ); +// fprintf( stderr, "jumpbacki[%d] in forward dp is %d\n", j, mpi ); + midw[j] = *curpt; + midm[j] = *mjpt; + midn[j] = mi; + } + +// fprintf( stderr, "m[%d] = %f\n", j, m[j] ); + mjpt++; + prept++; + mpjpt++; + curpt++; + + } + lastverticalw[i] = currentw[lgth2-1]; + +#if STOREWM + WMMTX2[i][lgth2] = m[lgth2-1]; +#endif + +#if 0 // ue + if( i == imid ) + { + for( j=0; j0; --j ) + { + m[j-1] = currentw[j] + fgcp2[lgth2-2]; +// m[j-1] = currentw[j]; + mp[j] = lgth1-1; + } +#else + for( j=lgth2-1; j>-1; --j ) + { + m[j] = currentw[j+1] + fgcp1[lgth1-2] * gapfreq2f[j+1]; +// m[j-1] = currentw[j]; + mp[j] = lgth1-1; + } +#endif + +// for( j=0; j=imid; i-- ) + firstm = -9999999.9; +// firstmp = lgth1-1; + firstmp = lgth1; + for( i=lgth1-2; i>-1; i-- ) + { +#ifdef enablemultithread +// fprintf( stderr, "chudan = %d, %d\n", *chudanpt, chudanref ); + if( chudanpt && *chudanpt != chudanref ) + { +// fprintf( stderr, "\n\n## CHUUDAN!!! kouhan\n" ); + *chudanres = 1; + freearrays_rec1_variousdist + ( + w1, w2, initverticalw, lastverticalw, midw, midm, midn, + jumpbacki, jumpbackj, jumpforwi, jumpforwj, jumpdummi, jumpdummj, + m, mp, + doublework, intwork +#if STOREWM + , WMMTX, WMMTX2 +#endif + ); + freearrays_rec2( gaps, aseq1, aseq2 ); + return( -1.0 ); + } +#endif + wtmp = previousw; + previousw = currentw; + currentw = wtmp; + previousw[lgth2-1] = initverticalw[i+1]; +#if 0 + match_calc( n_dynamicmtx, currentw, cpmx1+ist, cpmx2+jst, i, lgth2, doublework, intwork, 0 ); +#else + fillzero( currentw, lgth2 ); + for( c=0; c-1; j-- ) + { + wm = *prept; + ijpi = i+1; + ijpj = j+1; + + g = mi + ogcp2[j+1] * gapfreq1f[i]; +// g = mi + fpenalty; + if( g > wm ) + { + wm = g; + ijpj = mpi; + ijpi = i+1; + } + + g = *prept + fgcp2[j] * gapfreq1f[i+1]; +// g = *prept; + if( g >= mi ) + { +// fprintf( stderr, "i,j=%d,%d - renewed! mpi = %d\n", i, j, j+1 ); + mi = g; + mpi = j + 1; + } + +#if USE_PENALTY_EX + mi += fpenalty_ex; +#endif + +// fprintf( stderr, "i,j=%d,%d *mpjpt = %d\n", i, j, *mpjpt ); + g = *mjpt + ogcp1[i+1] * gapfreq2f[j]; +// g = *mjpt + fpenalty; + if( g > wm ) + { + wm = g; + ijpi = *mpjpt; + ijpj = j+1; + } + +// if( i == imid )fprintf( stderr, "i,j=%d,%d \n", i, j ); + g = *prept + fgcp1[i] * gapfreq2f[j+1]; +// g = *prept; + if( g >= *mjpt ) + { + *mjpt = g; + *mpjpt = i + 1; + } + +#if USE_PENALTY_EX + m[j] += fpenalty_ex; +#endif + + if( i == jumpi || i == imid - 1 ) + { + jumpforwi[j] = ijpi; //muda + jumpforwj[j] = ijpj; //muda +// fprintf( stderr, "jumpfori[%d] = %d\n", j, ijpi ); +// fprintf( stderr, "jumpforj[%d] = %d\n", j, ijpj ); + } + if( i == imid ) // muda + { + midw[j] += wm; +// midm[j+1] += *mjpt + fpenalty; //?????? + midm[j+1] += *mjpt; //?????? + } + if( i == imid - 1 ) + { +// midn[j] += mi + fpenalty; //???? + midn[j] += mi; //???? + } +#if STOREWM + WMMTX[i][j] += wm; +// WMMTX2[i][j+1] += *mjpt + fpenalty; + WMMTX2[i][j+1] += *mjpt; +#endif + *curpt += wm; + + mjpt--; + prept--; + mpjpt--; + curpt--; + } +// fprintf( stderr, "adding *mjpt (=%f) to WMMTX2[%d][%d]\n", *mjpt, i, j+1 ); + g = *prept + fgcp1[i]; + if( firstm < g ) + { + firstm = g; + firstmp = i + 1; + } +#if STOREWM + WMMTX2[i][j+1] += firstm; +#endif + if( i == imid ) midm[j+1] += firstm; + + + if( i == imid - 1 ) + { + maxwm = midw[1]; + jmid = 0; +// if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm ); + for( j=2; j maxwm ) + { + jmid = j; + maxwm = wm; + } +// if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm ); + } + for( j=0; j maxwm ) + { + jmid = j; + maxwm = wm; + } +// if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm ); + } + +// if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm ); + + +// fprintf( stderr, "### imid=%d, jmid=%d\n", imid, jmid ); + wm = midw[jmid]; + jumpi = imid-1; + jumpj = jmid-1; + if( jmid > 0 && midn[jmid-1] > wm ) //060413 + { + jumpi = imid-1; + jumpj = jumpbacki[jmid]; + wm = midn[jmid-1]; +// fprintf( stderr, "rejump (n)\n" ); + } + if( midm[jmid] > wm ) + { + jumpi = jumpbackj[jmid]; + jumpj = jmid-1; + wm = midm[jmid]; +// fprintf( stderr, "rejump (m) jumpi=%d\n", jumpi ); + } + + +// fprintf( stderr, "--> imid=%d, jmid=%d\n", imid, jmid ); +// fprintf( stderr, "--> jumpi=%d, jumpj=%d\n", jumpi, jumpj ); +#if STOREWM + fprintf( stderr, "imid = %d\n", imid ); + fprintf( stderr, "midn = \n" ); + for( j=0; j 100 ) // naze 100 + if( imid < firstmp-1 ) // naze 100 + { + jumpi = firstmp; + imid = firstmp+1; + } +#if 0 + else + { + jumpi = 0; + imid = 1; + } +#endif +#endif + } + +#if 0 + else if( jmid == lgth2 ) + { + fprintf( stderr, "CHUI1!\n" ); + jumpi=0; jumpj=0; + imid=jumpforwi[0]; jmid=lgth2-1; + } +#else // 060414 + else if( jmid >= lgth2 ) + { +// fprintf( stderr, "CHUI1!\n" ); + jumpi=imid-1; jmid=lgth2; + jumpj = lgth2-1; + } +#endif + else + { +// fprintf( stderr, "#### CHUI3!\n" ); + imid = jumpforwi[jumpj]; + jmid = jumpforwj[jumpj]; + if( imid == jumpi ) jumpi = imid-1; + } +#if 0 + fprintf( stderr, "jumpi -> %d\n", jumpi ); + fprintf( stderr, "jumpj -> %d\n", jumpj ); + fprintf( stderr, "imid -> %d\n", imid ); + fprintf( stderr, "jmid -> %d\n", jmid ); +#endif +// fprintf( stderr, "#### FINAL i=%d, jumpi N ) + { + fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N ); + ErrorExit( "LENGTH OVER!\n" ); + } +#endif + + + +#if 0 + fprintf( stderr, "jumpi = %d, imid = %d\n", jumpi, imid ); + fprintf( stderr, "jumpj = %d, jmid = %d\n", jumpj, jmid ); + + fprintf( stderr, "imid = %d\n", imid ); + fprintf( stderr, "jmid = %d\n", jmid ); +#endif + + freearrays_rec1_variousdist + ( + w1, w2, initverticalw, lastverticalw, midw, midm, midn, + jumpbacki, jumpbackj, jumpforwi, jumpforwj, jumpdummi, jumpdummj, + m, mp, + doublework, intwork +#if STOREWM + , WMMTX, WMMTX2 +#endif + ); + + +// fprintf( stderr, "==== calling myself (first)\n" ); + + value = MSalignmm_rec_variousdist( matrices, icyc, jcyc, seq1, seq2, cpmx1s, cpmx2s, ist, ist+jumpi, jst, jst+jumpj, alloclen, fulllen1, fulllen2, aseq1, aseq2, depth, gapinfo, NULL, 0, NULL, headgp, tailgp, headgapfreq1_g, headgapfreq2_g ); // chudan mada +#if 0 + fprintf( stderr, "aseq1[0] = %s\n", aseq1[0] ); + fprintf( stderr, "aseq2[0] = %s\n", aseq2[0] ); +#endif +#if MEMSAVE +#else + for( i=0; i 0 ) + { +// for( i=0; i 0 ) + { +// for( i=0; i 1 || maxwm - value > 1 ) + { + fprintf( stderr, "WARNING value = %f, but maxwm = %f\n", value, maxwm ); + for( i=0; i1-%d\n%s\n", i, mseq1[i] ); + fprintf( stderr, "%s\n", aseq1[i] ); + } + for( i=0; i2-%d\n%s\n", i, mseq2[i] ); + fprintf( stderr, "%s\n", aseq2[i] ); + } + +// exit( 1 ); + } + else + { + fprintf( stderr, "value = %.0f, maxwm = %.0f -> ok\n", value, maxwm ); + } +#endif + +#if MEMSAVE +#else + for( i=0; i%d of GROUP1\n", i ); + fprintf( stdout, "%s\n", seq1[i] ); + } + for( i=0; i%d of GROUP2\n", i ); + fprintf( stdout, "%s\n", seq2[i] ); + } + fflush( stdout ); +#endif + + wm = MSalignmm_rec_variousdist( matrices, icyc, jcyc, seq1, seq2, cpmx1s, cpmx2s, 0, lgth1-1, 0, lgth2-1, alloclen, lgth1, lgth2, mseq1, mseq2, 0, gapinfo, chudanpt, chudanref, chudanres, headgp, tailgp, headgapfreq1, headgapfreq2 ); +#ifdef enablemultithread + if( chudanres && *chudanres ) + { +// fprintf( stderr, "\n\n## CHUUDAN!!! relay\n" ); + *chudanres = 1; + freearrays_variousdist( ogcp1, ogcp2, fgcp1, fgcp2, cpmx1s, cpmx2s, gapfreq1f, gapfreq2f, gapinfo, mseq1, mseq2 ); + return( -1.0 ); + } +#endif + +#if 0 + fprintf( stderr, "\n" ); + fprintf( stderr, " seq1[0] = %s\n", seq1[0] ); + fprintf( stderr, " seq2[0] = %s\n", seq2[0] ); + fprintf( stderr, "mseq1[0] = %s\n", mseq1[0] ); + fprintf( stderr, "mseq2[0] = %s\n", mseq2[0] ); + fprintf( stderr, "\n" ); +#endif + +// fprintf( stderr, "wm = %f\n", wm ); + + + for( i=0; i univscript -mafft: mafft.tmpl +mafft: mafft.tmpl mltaln.h sed "s:_LIBDIR:$(LIBDIR):" mafft.tmpl > mafft mafft-homologs.rb: mafft-homologs.tmpl # cp mafft-homologs.tmpl mafft-homologs.rb sed "s:_BINDIR:$(BINDIR):" mafft-homologs.tmpl > mafft-homologs.rb +mafft-sparsecore.rb: mafft-sparsecore.tmpl +# cp mafft-sparsecore.tmpl mafft-sparsecore.rb + sed "s:_BINDIR:$(BINDIR):" mafft-sparsecore.tmpl > mafft-sparsecore.rb + mltaln.h : functions.h touch mltaln.h +version : version.c mltaln.h + $(CC) -o $@ version.c $(MYCFLAGS) $(LDFLAGS) + tbfast : $(OBJTBFAST) - $(CC) -o $@ $(OBJTBFAST) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJTBFAST) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +addsingle : $(OBJADDSINGLE) + $(CC) -o $@ $(OBJADDSINGLE) $(MYCFLAGS) $(LDFLAGS) $(LIBS) tbfast2 : $(OBJTBFAST2) - $(CC) -o $@ $(OBJTBFAST2) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJTBFAST2) $(MYCFLAGS) $(LDFLAGS) $(LIBS) disttbfast : $(OBJDISTTBFAST) - $(CC) -o $@ $(OBJDISTTBFAST) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJDISTTBFAST) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +libdisttbfast.so : $(OBJDISTTBFAST) + $(CC) -shared -o $@ $(OBJDISTTBFAST) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +libdisttbfast.dylib : $(OBJDISTTBFAST) + $(CC) -dynamiclib -o $@ $(OBJDISTTBFAST) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +libdisttbfast.dll : $(OBJDISTTBFAST) + $(CC) -shared -o $@ $(OBJDISTTBFAST) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +makedirectionlist : $(OBJMAKEDIRECTIONLIST) + $(CC) -o $@ $(OBJMAKEDIRECTIONLIST) $(MYCFLAGS) $(LDFLAGS) $(LIBS) splittbfast : $(OBJSPLITTBFAST) - $(CC) -o $@ $(OBJSPLITTBFAST) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJSPLITTBFAST) $(MYCFLAGS) $(LDFLAGS) $(LIBS) splitfromaln : $(OBJSPLITFROMALN) - $(CC) -o $@ $(OBJSPLITFROMALN) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJSPLITFROMALN) $(MYCFLAGS) $(LDFLAGS) $(LIBS) splittbfast2 : $(OBJSPLITTBFAST2) - $(CC) -o $@ $(OBJSPLITTBFAST2) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJSPLITTBFAST2) $(MYCFLAGS) $(LDFLAGS) $(LIBS) dummy : $(OBJDUMMY) - $(CC) -o $@ $(OBJDUMMY) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJDUMMY) $(MYCFLAGS) $(LDFLAGS) $(LIBS) setcore : $(OBJSETCORE) - $(CC) -o $@ $(OBJSETCORE) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJSETCORE) $(MYCFLAGS) $(LDFLAGS) $(LIBS) countlen : $(OBJCOUNTLEN) - $(CC) -o $@ $(OBJCOUNTLEN) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJCOUNTLEN) $(MYCFLAGS) $(LDFLAGS) $(LIBS) seq2regtable : $(OBJSEQ2REGTABLE) - $(CC) -o $@ $(OBJSEQ2REGTABLE) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJSEQ2REGTABLE) $(MYCFLAGS) $(LDFLAGS) $(LIBS) regtable2seq : $(OBJREGTABLE2SEQ) - $(CC) -o $@ $(OBJREGTABLE2SEQ) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJREGTABLE2SEQ) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +setdirection : $(OBJSETDIRECTION) + $(CC) -o $@ $(OBJSETDIRECTION) $(MYCFLAGS) $(LDFLAGS) $(LIBS) replaceu : $(OBJREPLACEU) - $(CC) -o $@ $(OBJREPLACEU) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJREPLACEU) $(MYCFLAGS) $(LDFLAGS) $(LIBS) restoreu : $(OBJRESTOREU) - $(CC) -o $@ $(OBJRESTOREU) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJRESTOREU) $(MYCFLAGS) $(LDFLAGS) $(LIBS) f2cl : $(OBJF2CL) - $(CC) -o $@ $(OBJF2CL) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJF2CL) $(MYCFLAGS) $(LDFLAGS) $(LIBS) mccaskillwrap : $(OBJMCCASKILLWRAP) - $(CC) -o $@ $(OBJMCCASKILLWRAP) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJMCCASKILLWRAP) $(MYCFLAGS) $(LDFLAGS) $(LIBS) contrafoldwrap : $(OBJCONTRAFOLDWRAP) - $(CC) -o $@ $(OBJCONTRAFOLDWRAP) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJCONTRAFOLDWRAP) $(MYCFLAGS) $(LDFLAGS) $(LIBS) pairlocalalign : $(OBJPAIRLOCALALIGN) - $(CC) -o $@ $(OBJPAIRLOCALALIGN) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJPAIRLOCALALIGN) $(MYCFLAGS) $(LDFLAGS) $(LIBS) pairash : $(OBJPAIRASH) - $(CC) -o $@ $(OBJPAIRASH) $(MYCFLAGS) $(LIBS) - -rnatest : $(OBJRNATEST) - $(CC) -o $@ $(OBJRNATEST) $(MYCFLAGS) $(LIBS) - -pair2hat3s : $(OBJPAIR2HAT3S) - $(CC) -o $@ $(OBJPAIR2HAT3S) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJPAIRASH) $(MYCFLAGS) $(LDFLAGS) $(LIBS) multi2hat3s : $(OBJMULTI2HAT3S) - $(CC) -o $@ $(OBJMULTI2HAT3S) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJMULTI2HAT3S) $(MYCFLAGS) $(LDFLAGS) $(LIBS) getlag : $(OBJGETLAG) - $(CC) -o $@ $(OBJGETLAG) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJGETLAG) $(MYCFLAGS) $(LDFLAGS) $(LIBS) tditr : $(OBJTDITR) - $(CC) -o $@ $(OBJTDITR) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJTDITR) $(MYCFLAGS) $(LDFLAGS) $(LIBS) dvtditr : $(OBJDVTDITR) - $(CC) -o $@ $(OBJDVTDITR) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJDVTDITR) $(MYCFLAGS) $(LDFLAGS) $(LIBS) mafft-profile : $(OBJGALN) - $(CC) -o $@ $(OBJGALN) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJGALN) $(MYCFLAGS) $(LDFLAGS) $(LIBS) gapfill : $(OBJGAPFILL) - $(CC) -o $@ $(OBJGAPFILL) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJGAPFILL) $(MYCFLAGS) $(LDFLAGS) $(LIBS) dndfast4 : $(OBJDNDFAST4) - $(CC) -o $@ $(OBJDNDFAST4) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJDNDFAST4) $(MYCFLAGS) $(LDFLAGS) $(LIBS) dndfast5 : $(OBJDNDFAST5) - $(CC) -o $@ $(OBJDNDFAST5) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJDNDFAST5) $(MYCFLAGS) $(LDFLAGS) $(LIBS) dndfast6 : $(OBJDNDFAST6) - $(CC) -o $@ $(OBJDNDFAST6) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJDNDFAST6) $(MYCFLAGS) $(LDFLAGS) $(LIBS) dndfast7 : $(OBJDNDFAST7) - $(CC) -o $@ $(OBJDNDFAST7) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJDNDFAST7) $(MYCFLAGS) $(LDFLAGS) $(LIBS) dndblast : $(OBJDNDBLAST) - $(CC) -o $@ $(OBJDNDBLAST) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJDNDBLAST) $(MYCFLAGS) $(LDFLAGS) $(LIBS) dndfast3 : $(OBJDNDFAST3) - $(CC) -o $@ $(OBJDNDFAST3) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJDNDFAST3) $(MYCFLAGS) $(LDFLAGS) $(LIBS) triplet : $(OBJTRIPLET) - $(CC) -o $@ $(OBJTRIPLET) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJTRIPLET) $(MYCFLAGS) $(LDFLAGS) $(LIBS) triplet3 : $(OBJTRIPLET3) - $(CC) -o $@ $(OBJTRIPLET3) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJTRIPLET3) $(MYCFLAGS) $(LDFLAGS) $(LIBS) sextet3 : $(OBJSEXTET3) - $(CC) -o $@ $(OBJSEXTET3) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJSEXTET3) $(MYCFLAGS) $(LDFLAGS) $(LIBS) sextet4 : $(OBJSEXTET4) - $(CC) -o $@ $(OBJSEXTET4) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJSEXTET4) $(MYCFLAGS) $(LDFLAGS) $(LIBS) sextet5 : $(OBJSEXTET5) - $(CC) -o $@ $(OBJSEXTET5) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJSEXTET5) $(MYCFLAGS) $(LDFLAGS) $(LIBS) mafft-distance : $(OBJDISTANCE) - $(CC) -o $@ $(OBJDISTANCE) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJDISTANCE) $(MYCFLAGS) $(LDFLAGS) $(LIBS) triplet5 : $(OBJTRIPLET5) - $(CC) -o $@ $(OBJTRIPLET5) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJTRIPLET5) $(MYCFLAGS) $(LDFLAGS) $(LIBS) triplet6 : $(OBJTRIPLET6) - $(CC) -o $@ $(OBJTRIPLET6) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJTRIPLET6) $(MYCFLAGS) $(LDFLAGS) $(LIBS) octet4 : $(OBJOCTET4) - $(CC) -o $@ $(OBJOCTET4) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJOCTET4) $(MYCFLAGS) $(LDFLAGS) $(LIBS) dndpre : $(OBJDNDPRE) - $(CC) -o $@ $(OBJDNDPRE) $(MYCFLAGS) $(LIBS) - -dndpre2 : $(OBJDNDPRESCORE) - $(CC) -o $@ $(OBJDNDPRESCORE) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJDNDPRE) $(MYCFLAGS) $(LDFLAGS) $(LIBS) score : $(OBJSCORE) - $(CC) -o $@ $(OBJSCORE) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJSCORE) $(MYCFLAGS) $(LDFLAGS) $(LIBS) genMtx : $(OBJGENMTX) - $(CC) -o $@ $(OBJGENMTX) $(MYCFLAGS) $(LIBS) + $(CC) -o $@ $(OBJGENMTX) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +mafftash_premafft.pl : mafftash_premafft.tmpl + cp mafftash_premafft.tmpl mafftash_premafft.pl + +seekquencer_premafft.pl : seekquencer_premafft.tmpl + cp seekquencer_premafft.tmpl seekquencer_premafft.pl gapfill.o : gapfill.c $(HEADER) $(CC) $(MYCFLAGS) -c gapfill.c @@ -285,14 +333,8 @@ defs.o : defs.c Salignmm.o : Salignmm.c $(HEADER) $(CC) $(MYCFLAGS) -c Salignmm.c -Halignmm.o : Halignmm.c $(HEADER) - $(CC) $(MYCFLAGS) -c Halignmm.c - -Ralignmm.o : Ralignmm.c $(HEADER) - $(CC) $(MYCFLAGS) -c Ralignmm.c - -Qalignmm.o : Qalignmm.c $(HEADER) - $(CC) $(MYCFLAGS) -c Qalignmm.c +Dalignmm.o : Dalignmm.c $(HEADER) + $(CC) $(MYCFLAGS) -c Dalignmm.c MSalignmm.o : MSalignmm.c $(HEADER) $(CC) $(MYCFLAGS) -c MSalignmm.c @@ -300,18 +342,12 @@ MSalignmm.o : MSalignmm.c $(HEADER) partSalignmm.o : partSalignmm.c $(HEADER) $(CC) $(MYCFLAGS) -c partSalignmm.c -partQalignmm.o : partQalignmm.c $(HEADER) - $(CC) $(MYCFLAGS) -c partQalignmm.c - Lalign11.o : Lalign11.c $(HEADER) $(CC) $(MYCFLAGS) -c Lalign11.c genalign11.o : genalign11.c $(HEADER) $(CC) $(MYCFLAGS) -c genalign11.c -genGalign11.o : genGalign11.c $(HEADER) - $(CC) $(MYCFLAGS) -c genGalign11.c - suboptalign11.o : suboptalign11.c $(HEADER) $(CC) $(MYCFLAGS) -c suboptalign11.c @@ -342,6 +378,9 @@ splittbfast.o : splittbfast.c $(HEADER) $(FFTHEADER) splittbfast2.o : splittbfast2.c $(HEADER) $(FFTHEADER) $(CC) $(MYCFLAGS) -c splittbfast2.c +makedirectionlist.o : makedirectionlist.c $(HEADER) $(FFTHEADER) + $(CC) $(MYCFLAGS) -c makedirectionlist.c + disttbfast_dummy.o : disttbfast_dummy.c $(HEADER) $(FFTHEADER) $(CC) $(MYCFLAGS) -c disttbfast_dummy.c @@ -351,6 +390,9 @@ dummy.o : dummy.c $(HEADER) $(FFTHEADER) tbfast.o : tbfast.c $(HEADER) $(FFTHEADER) $(CC) $(MYCFLAGS) -c tbfast.c +addsingle.o : addsingle.c $(HEADER) $(FFTHEADER) + $(CC) $(MYCFLAGS) -c addsingle.c + tbfast2.o : tbfast2.c $(HEADER) $(FFTHEADER) $(CC) $(MYCFLAGS) -c tbfast2.c @@ -405,6 +447,9 @@ regtable2seq.o : regtable2seq.c $(HEADER) f2cl.o : f2cl.c $(HEADER) $(CC) $(MYCFLAGS) -c f2cl.c +setdirection.o : setdirection.c $(HEADER) + $(CC) $(MYCFLAGS) -c setdirection.c + replaceu.o : replaceu.c $(HEADER) $(CC) $(MYCFLAGS) -c replaceu.c @@ -420,21 +465,15 @@ contrafoldwrap.o : contrafoldwrap.c $(HEADER) pairlocalalign.o : pairlocalalign.c $(HEADER) $(FFTHEADER) $(CC) $(MYCFLAGS) -c pairlocalalign.c +pairlocalalignmain.o : pairlocalalignmain.c $(HEADER) $(FFTHEADER) + $(CC) $(MYCFLAGS) -c pairlocalalignmain.c + pairash.o : pairash.c $(HEADER) $(FFTHEADER) $(CC) $(MYCFLAGS) -c pairash.c -rnatest.o : rnatest.c $(HEADER) $(FFTHEADER) - $(CC) $(MYCFLAGS) -c rnatest.c - multi2hat3s.o : multi2hat3s.c $(HEADER) $(FFTHEADER) $(CC) $(MYCFLAGS) -c multi2hat3s.c -pair2hat3s.o : pair2hat3s.c $(HEADER) $(FFTHEADER) - $(CC) $(MYCFLAGS) -c pair2hat3s.c - -dndpre2.o : dndpre2.c $(HEADER) - $(CC) $(MYCFLAGS) -c dndpre2.c - io.o : io.c $(HEADER) $(FFTHEADER) $(CC) $(MYCFLAGS) -c io.c @@ -478,23 +517,24 @@ score.o : score.c $(HEADER) $(CC) $(MYCFLAGS) -c score.c clean : - rm -f *.o *.a *.exe *~ $(PROGS) $(SCRIPTS) + rm -f *.o *.a *.exe *~ $(PERLPROGS) $(PROGS) $(SCRIPTS) $(SOS) $(DYLIBS) $(DLLS) *.gcda *.gcno # rm -f ../binaries/* ../scripts/* install : all - mkdir -p $(LIBDIR) - chmod 755 $(LIBDIR) - mkdir -p $(BINDIR) - chmod 755 $(BINDIR) + mkdir -p $(DESTDIR)$(LIBDIR) + chmod 755 $(DESTDIR)$(LIBDIR) + mkdir -p $(DESTDIR)$(BINDIR) + chmod 755 $(DESTDIR)$(BINDIR) chmod 755 $(SCRIPTS) - $(INSTALL) $(SCRIPTS) $(BINDIR) - chmod 755 $(PROGS) - $(INSTALL) $(PROGS) $(LIBDIR) - $(INSTALL) -m 644 $(MANPAGES) $(LIBDIR) + $(INSTALL) $(SCRIPTS) $(DESTDIR)$(BINDIR) + chmod 755 $(PROGS) ||: # in MinGW, it's ok if this fails + $(INSTALL) -s $(PROGS) $(DESTDIR)$(LIBDIR) + $(INSTALL) $(PERLPROGS) $(DESTDIR)$(LIBDIR) + $(INSTALL) -m 644 $(MANPAGES) $(DESTDIR)$(LIBDIR) - ( cd $(BINDIR); \ + ( cd $(DESTDIR)$(BINDIR); \ rm -f linsi ginsi einsi fftns fftnsi nwns nwnsi xinsi qinsi; \ -rm -f mafft-linsi mafft-ginsi mafft-einsi mafft-fftns mafft-fftnsi mafft-nwns mafft-nwnsi mafft-xinsi mafft-qinsi; \ +rm -f mafft-linsi mafft-ginsi mafft-einsi mafft-fftns mafft-fftnsi mafft-nwns mafft-nwnsi mafft-xinsi mafft-qinsi mafft-randomcore.rb ; \ ln -s mafft linsi; ln -s mafft ginsi; ln -s mafft fftns; \ ln -s mafft fftnsi; ln -s mafft nwns; ln -s mafft nwnsi; \ ln -s mafft einsi; \ @@ -504,8 +544,8 @@ ln -s mafft mafft-einsi; ln -s mafft mafft-xinsi; ln -s mafft mafft-qinsi;\ rm -f mafft-profile mafft-profile.exe; ln -s $(LIBDIR)/mafft-profile .; \ rm -f mafft-distance mafft-distance.exe; ln -s $(LIBDIR)/mafft-distance . ) - mkdir -p $(MANDIR) - chmod 755 $(MANDIR) - $(INSTALL) -m 644 $(MANPAGES) $(MANDIR) + mkdir -p $(DESTDIR)$(MANDIR) + chmod 755 $(DESTDIR)$(MANDIR) + $(INSTALL) -m 644 $(MANPAGES) $(DESTDIR)$(MANDIR) # remove incorrectly installed manpages by previous versions # rm -f /usr/local/man/man1/mafft.1 /usr/local/man/man1/mafft-homologs.1 diff --git a/binaries/src/mafft/core/Makefile.sos b/binaries/src/mafft/core/Makefile.sos new file mode 100644 index 0000000..c0ce323 --- /dev/null +++ b/binaries/src/mafft/core/Makefile.sos @@ -0,0 +1,545 @@ +PREFIX = /usr/local +LIBDIR = $(PREFIX)/libexec/mafft +BINDIR = $(PREFIX)/bin +MANDIR = $(PREFIX)/share/man/man1 + +#MNO_CYGWIN = -mno-cygwin + +ENABLE_MULTITHREAD = -Denablemultithread +# Comment out the above line if your compiler +# does not support TLS (thread-local strage). + +CC = gcc +#CFLAGS = -O3 +#CFLAGS = -O3 -fPIC +# add -fPIC when building .so files + +#CC = icc +#CFLAGS = -fast +# if you have icc, use this. + +#CFLAGS = -O0 -fPIC -pedantic -Wall -std=c99 -g -pg -DMALLOC_CHECK_=3 +CFLAGS = -fPIC -O0 -fPIC -pedantic -Wall -std=c99 -g -DMALLOC_CHECK_=3 # for shark, valgrind + + +MYCFLAGS = $(MNO_CYGWIN) $(ENABLE_MULTITHREAD) $(CFLAGS) + +ifdef ENABLE_MULTITHREAD +LIBS = -lm -lpthread +else +LIBS = -lm +endif + +INSTALL = install + +PROGS = dvtditr dndfast7 dndblast sextet5 mafft-distance pairlocalalign \ + pair2hat3s multi2hat3s pairash addsingle \ + splittbfast disttbfast tbfast mafft-profile f2cl mccaskillwrap contrafoldwrap countlen \ + seq2regtable regtable2seq score getlag dndpre setcore replaceu restoreu setdirection makedirectionlist version +SOS = libdisttbfast.so +DLLS = libdisttbfast.dll +DYLIBS = libdisttbfast.dylib + +PERLPROGS = mafftash_premafft.pl seekquencer_premafft.pl +SCRIPTS = mafft mafft-homologs.rb +OBJSETDIRECTION = mtxutl.o io.o setdirection.o defs.o mltaln9.o +OBJREPLACEU = mtxutl.o io.o replaceu.o defs.o mltaln9.o +OBJRESTOREU = mtxutl.o io.o restoreu.o defs.o mltaln9.o +OBJREGTABLE2SEQ = mtxutl.o io.o regtable2seq.o defs.o mltaln9.o +OBJSEQ2REGTABLE = mtxutl.o io.o seq2regtable.o defs.o +OBJCOUNTLEN = mtxutl.o io.o countlen.o defs.o +OBJF2CL = mtxutl.o io.o f2cl.o constants.o defs.o +OBJMCCASKILLWRAP = mtxutl.o io.o mccaskillwrap.o constants.o defs.o mltaln9.o +OBJCONTRAFOLDWRAP = mtxutl.o io.o contrafoldwrap.o constants.o defs.o mltaln9.o +OBJMULTI2HAT3S = mtxutl.o io.o mltaln9.o tddis.o constants.o \ + multi2hat3s.o defs.o fft.o fftFunctions.o +OBJPAIR2HAT3S = mtxutl.o io.o mltaln9.o tddis.o constants.o \ + pair2hat3s.o defs.o fft.o fftFunctions.o +OBJPAIRASH = mtxutl.o io.o mltaln9.o tddis.o constants.o partSalignmm.o Lalignmm.o rna.o Salignmm.o \ + Falign.o MSalignmm.o Galign11.o MSalign11.o suboptalign11.o genalign11.o Lalign11.o SAalignmm.o \ + pairash.o defs.o fft.o fftFunctions.o +OBJPAIRLOCALALIGN = mtxutl.o io.o mltaln9.o tddis.o constants.o partSalignmm.o Lalignmm.o rna.o Salignmm.o \ + Falign.o MSalignmm.o Galign11.o MSalign11.o suboptalign11.o genalign11.o Lalign11.o SAalignmm.o \ + pairlocalalign.o defs.o fft.o fftFunctions.o +OBJDUMMY = mtxutl.o io.o mltaln9.o tddis.o constants.o partSalignmm.o Lalignmm.o rna.o Salignmm.o \ + Falign.o Falign_localhom.o Galign11.o SAalignmm.o MSalignmm.o \ + disttbfast_dummy.o dummy.o defs.o fft.o fftFunctions.o +OBJSPLITFROMALN = mtxutl.o io.o mltaln9.o tddis.o constants.o partSalignmm.o Lalignmm.o rna.o Salignmm.o \ + Falign.o Falign_localhom.o Galign11.o SAalignmm.o MSalignmm.o \ + Lalign11.o splitfromaln.o defs.o fft.o fftFunctions.o +OBJSPLITTBFAST = mtxutl.o io.o mltaln9.o tddis.o constants.o partSalignmm.o Lalignmm.o rna.o Salignmm.o \ + Falign.o Falign_localhom.o Galign11.o SAalignmm.o MSalignmm.o \ + Lalign11.o splittbfast.o defs.o fft.o fftFunctions.o +OBJSPLITTBFAST2 = mtxutl.o io.o mltaln9.o tddis.o constants.o partSalignmm.o Lalignmm.o rna.o Salignmm.o \ + Falign.o Falign_localhom.o Galign11.o SAalignmm.o MSalignmm.o \ + Lalign11.o splittbfast2.o defs.o fft.o fftFunctions.o +OBJSPLITTBFASTP = mtxutl.o io.o mltaln9.o tddis.o constants.o partSalignmm.o Lalignmm.o rna.o Salignmm.o \ + Falign.o Falign_localhom.o Galign11.o SAalignmm.o MSalignmm.o \ + Lalign11.o defs.o fft.o fftFunctions.o +OBJDISTTBFAST = mtxutl.o io.o mltaln9.o tddis.o constants.o partSalignmm.o Lalignmm.o rna.o Salignmm.o \ + Falign.o Falign_localhom.o Galign11.o SAalignmm.o MSalignmm.o \ + disttbfast.o defs.o fft.o fftFunctions.o addfunctions.o +OBJMAKEDIRECTIONLIST = mtxutl.o io.o mltaln9.o tddis.o constants.o partSalignmm.o Lalignmm.o rna.o Salignmm.o \ + Falign.o Falign_localhom.o Galign11.o SAalignmm.o MSalignmm.o \ + Lalign11.o makedirectionlist.o defs.o fft.o fftFunctions.o addfunctions.o +OBJTBFAST = mtxutl.o io.o mltaln9.o tddis.o constants.o MSalignmm.o partSalignmm.o Lalignmm.o rna.o Salignmm.o \ + Falign.o Falign_localhom.o Galign11.o SAalignmm.o \ + tbfast.o defs.o fft.o fftFunctions.o addfunctions.o +OBJADDSINGLE = mtxutl.o io.o mltaln9.o tddis.o constants.o MSalignmm.o partSalignmm.o Lalignmm.o rna.o Salignmm.o \ + Falign.o Falign_localhom.o Galign11.o SAalignmm.o \ + addsingle.o defs.o fft.o fftFunctions.o addfunctions.o +OBJTBFAST2 = mtxutl.o io.o mltaln9.o tddis.o constants.o partSalignmm.o Lalignmm.o rna.o Salignmm.o MSalignmm.o \ + Falign.o Falign_localhom.o Galign11.o SAalignmm.o \ + tbfast2.o defs.o fft.o fftFunctions.o +OBJSETCORE = mtxutl.o io.o mltaln9.o tddis.o constants.o partSalignmm.o Lalignmm.o rna.o Salignmm.o \ + Falign.o Falign_localhom.o Galign11.o SAalignmm.o MSalignmm.o \ + setcore.o defs.o fft.o fftFunctions.o +OBJTDITR = mtxutl.o io.o mltaln9.o tddis.o constants.o nj.o partSalignmm.o Lalignmm.o rna.o Salignmm.o \ + Falign.o Falign_localhom.o Galign11.o fftFunctions.o fft.o \ + tditeration.o tditr.o defs.o SAalignmm.o treeOperation.o +OBJDVTDITR = mtxutl.o io.o mltaln9.o tddis.o constants.o nj.o partSalignmm.o Lalignmm.o rna.o Salignmm.o \ + Falign.o Falign_localhom.o Galign11.o MSalignmm.o fftFunctions.o fft.o \ + tditeration.o dvtditr.o defs.o SAalignmm.o treeOperation.o addfunctions.o +OBJGETLAG = mtxutl.o io.o mltaln9.o tddis.o constants.o partSalignmm.o Lalignmm.o rna.o Salignmm.o \ + Falign.o Falign_localhom.o Galign11.o SAalignmm.o MSalignmm.o \ + getlag.o defs.o fft.o fftFunctions.o +OBJGAPFILL = mtxutl.o io.o constants.o gapfill.o defs.o +OBJDNDFAST5 = dndfast5.o io.o constants.o mtxutl.o mltaln9.o tddis.o defs.o +OBJDNDBLAST = dndblast.o io.o constants.o mtxutl.o mltaln9.o tddis.o defs.o +OBJDNDFAST7 = dndfast7.o io.o constants.o mtxutl.o mltaln9.o tddis.o defs.o +OBJDNDFAST6 = dndfast6.o io.o constants.o mtxutl.o mltaln9.o tddis.o defs.o +OBJDNDFAST4 = dndfast4.o io.o constants.o mtxutl.o mltaln9.o tddis.o defs.o +OBJDNDFAST6 = dndfast6.o io.o constants.o mtxutl.o mltaln9.o tddis.o defs.o +OBJSEXTET5 = io.o constants.o mtxutl.o mltaln9.o tddis.o sextet5.o defs.o +OBJDISTANCE = io.o constants.o mtxutl.o mltaln9.o tddis.o mafft-distance.o defs.o +OBJTRIPLET6 = io.o constants.o mtxutl.o mltaln9.o tddis.o triplet6.o defs.o +OBJTRIPLET5 = io.o constants.o mtxutl.o mltaln9.o tddis.o triplet5.o defs.o +OBJOCTET4 = io.o constants.o mtxutl.o mltaln9.o tddis.o octet4.o defs.o +OBJDNDPRE = dndpre.o io.o constants.o mtxutl.o mltaln9.o defs.o +OBJGALN = io.o mtxutl.o mltaln9.o tddis.o constants.o partSalignmm.o MSalignmm.o Lalignmm.o rna.o Salignmm.o \ + SAalignmm.o Galign11.o Falign.o Falign_localhom.o fftFunctions.o fft.o mafft-profile.o defs.o +OBJSCORE = io.o mtxutl.o mltaln9.o score.o constants.o defs.o + +HEADER = mltaln.h mtxutl.h mafft.h +FFTHEADER = fft.h + +MANPAGES = mafft.1 mafft-homologs.1 + + + + +all : $(PERLPROGS) $(PROGS) $(SCRIPTS) + cp $(SCRIPTS) ../scripts + chmod 755 ../scripts/* + cp $(PERLPROGS) $(PROGS) ../binaries + chmod 755 ../binaries/* + cp $(MANPAGES) ../binaries + @echo done. + +sos : $(SOS) +dylibs : $(DYLIBS) +dlls : $(DLLS) + +univscript: univscript.tmpl Makefile + sed "s:_PROGS:$(PROGS):" univscript.tmpl > univscript + +mafft: mafft.tmpl mltaln.h + sed "s:_LIBDIR:$(LIBDIR):" mafft.tmpl > mafft + +mafft-homologs.rb: mafft-homologs.tmpl +# cp mafft-homologs.tmpl mafft-homologs.rb + sed "s:_BINDIR:$(BINDIR):" mafft-homologs.tmpl > mafft-homologs.rb + +mltaln.h : functions.h + touch mltaln.h + +version : version.c mltaln.h + $(CC) -o $@ version.c $(MYCFLAGS) $(LDFLAGS) + +tbfast : $(OBJTBFAST) + $(CC) -o $@ $(OBJTBFAST) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +addsingle : $(OBJADDSINGLE) + $(CC) -o $@ $(OBJADDSINGLE) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +tbfast2 : $(OBJTBFAST2) + $(CC) -o $@ $(OBJTBFAST2) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +disttbfast : $(OBJDISTTBFAST) + $(CC) -o $@ $(OBJDISTTBFAST) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +libdisttbfast.so : $(OBJDISTTBFAST) + $(CC) -shared -o $@ $(OBJDISTTBFAST) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +libdisttbfast.dylib : $(OBJDISTTBFAST) + $(CC) -dynamiclib -o $@ $(OBJDISTTBFAST) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +libdisttbfast.dll : $(OBJDISTTBFAST) + $(CC) -shared -o $@ $(OBJDISTTBFAST) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +makedirectionlist : $(OBJMAKEDIRECTIONLIST) + $(CC) -o $@ $(OBJMAKEDIRECTIONLIST) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +splittbfast : $(OBJSPLITTBFAST) + $(CC) -o $@ $(OBJSPLITTBFAST) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +splitfromaln : $(OBJSPLITFROMALN) + $(CC) -o $@ $(OBJSPLITFROMALN) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +splittbfast2 : $(OBJSPLITTBFAST2) + $(CC) -o $@ $(OBJSPLITTBFAST2) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +dummy : $(OBJDUMMY) + $(CC) -o $@ $(OBJDUMMY) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +setcore : $(OBJSETCORE) + $(CC) -o $@ $(OBJSETCORE) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +countlen : $(OBJCOUNTLEN) + $(CC) -o $@ $(OBJCOUNTLEN) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +seq2regtable : $(OBJSEQ2REGTABLE) + $(CC) -o $@ $(OBJSEQ2REGTABLE) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +regtable2seq : $(OBJREGTABLE2SEQ) + $(CC) -o $@ $(OBJREGTABLE2SEQ) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +setdirection : $(OBJSETDIRECTION) + $(CC) -o $@ $(OBJSETDIRECTION) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +replaceu : $(OBJREPLACEU) + $(CC) -o $@ $(OBJREPLACEU) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +restoreu : $(OBJRESTOREU) + $(CC) -o $@ $(OBJRESTOREU) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +f2cl : $(OBJF2CL) + $(CC) -o $@ $(OBJF2CL) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +mccaskillwrap : $(OBJMCCASKILLWRAP) + $(CC) -o $@ $(OBJMCCASKILLWRAP) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +contrafoldwrap : $(OBJCONTRAFOLDWRAP) + $(CC) -o $@ $(OBJCONTRAFOLDWRAP) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +pairlocalalign : $(OBJPAIRLOCALALIGN) + $(CC) -o $@ $(OBJPAIRLOCALALIGN) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +pairash : $(OBJPAIRASH) + $(CC) -o $@ $(OBJPAIRASH) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +pair2hat3s : $(OBJPAIR2HAT3S) + $(CC) -o $@ $(OBJPAIR2HAT3S) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +multi2hat3s : $(OBJMULTI2HAT3S) + $(CC) -o $@ $(OBJMULTI2HAT3S) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +getlag : $(OBJGETLAG) + $(CC) -o $@ $(OBJGETLAG) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +tditr : $(OBJTDITR) + $(CC) -o $@ $(OBJTDITR) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +dvtditr : $(OBJDVTDITR) + $(CC) -o $@ $(OBJDVTDITR) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +mafft-profile : $(OBJGALN) + $(CC) -o $@ $(OBJGALN) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +gapfill : $(OBJGAPFILL) + $(CC) -o $@ $(OBJGAPFILL) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +dndfast4 : $(OBJDNDFAST4) + $(CC) -o $@ $(OBJDNDFAST4) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +dndfast5 : $(OBJDNDFAST5) + $(CC) -o $@ $(OBJDNDFAST5) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +dndfast6 : $(OBJDNDFAST6) + $(CC) -o $@ $(OBJDNDFAST6) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +dndfast7 : $(OBJDNDFAST7) + $(CC) -o $@ $(OBJDNDFAST7) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +dndblast : $(OBJDNDBLAST) + $(CC) -o $@ $(OBJDNDBLAST) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +dndfast3 : $(OBJDNDFAST3) + $(CC) -o $@ $(OBJDNDFAST3) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +triplet : $(OBJTRIPLET) + $(CC) -o $@ $(OBJTRIPLET) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +triplet3 : $(OBJTRIPLET3) + $(CC) -o $@ $(OBJTRIPLET3) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +sextet3 : $(OBJSEXTET3) + $(CC) -o $@ $(OBJSEXTET3) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +sextet4 : $(OBJSEXTET4) + $(CC) -o $@ $(OBJSEXTET4) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +sextet5 : $(OBJSEXTET5) + $(CC) -o $@ $(OBJSEXTET5) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +mafft-distance : $(OBJDISTANCE) + $(CC) -o $@ $(OBJDISTANCE) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +triplet5 : $(OBJTRIPLET5) + $(CC) -o $@ $(OBJTRIPLET5) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +triplet6 : $(OBJTRIPLET6) + $(CC) -o $@ $(OBJTRIPLET6) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +octet4 : $(OBJOCTET4) + $(CC) -o $@ $(OBJOCTET4) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +dndpre : $(OBJDNDPRE) + $(CC) -o $@ $(OBJDNDPRE) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +score : $(OBJSCORE) + $(CC) -o $@ $(OBJSCORE) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +genMtx : $(OBJGENMTX) + $(CC) -o $@ $(OBJGENMTX) $(MYCFLAGS) $(LDFLAGS) $(LIBS) + +mafftash_premafft.pl : mafftash_premafft.tmpl + cp mafftash_premafft.tmpl mafftash_premafft.pl + +seekquencer_premafft.pl : seekquencer_premafft.tmpl + cp seekquencer_premafft.tmpl seekquencer_premafft.pl + +gapfill.o : gapfill.c $(HEADER) + $(CC) $(MYCFLAGS) -c gapfill.c + +mltaln9.o : mltaln9.c $(HEADER) + $(CC) $(MYCFLAGS) -c mltaln9.c + +tddis.o : tddis.c $(HEADER) + $(CC) $(MYCFLAGS) -c tddis.c + +constants.o : constants.c miyata.h miyata5.h blosum.c DNA.h JTT.c $(HEADER) + $(CC) $(MYCFLAGS) -c constants.c + +defs.o : defs.c + $(CC) $(MYCFLAGS) -c defs.c + +#A+++alignmm.o : SA+++alignmm.c $(HEADER) +# $(CC) $(MYCFLAGS) -c SA+++alignmm.c -o A+++alignmm.o + +Salignmm.o : Salignmm.c $(HEADER) + $(CC) $(MYCFLAGS) -c Salignmm.c + +MSalignmm.o : MSalignmm.c $(HEADER) + $(CC) $(MYCFLAGS) -c MSalignmm.c + +partSalignmm.o : partSalignmm.c $(HEADER) + $(CC) $(MYCFLAGS) -c partSalignmm.c + +Lalign11.o : Lalign11.c $(HEADER) + $(CC) $(MYCFLAGS) -c Lalign11.c + +genalign11.o : genalign11.c $(HEADER) + $(CC) $(MYCFLAGS) -c genalign11.c + +suboptalign11.o : suboptalign11.c $(HEADER) + $(CC) $(MYCFLAGS) -c suboptalign11.c + +Galign11.o : Galign11.c $(HEADER) + $(CC) $(MYCFLAGS) -c Galign11.c + +MSalign11.o : MSalign11.c $(HEADER) + $(CC) $(MYCFLAGS) -c MSalign11.c + +SAalignmm.o : SAalignmm.c $(HEADER) + $(CC) $(MYCFLAGS) -c SAalignmm.c -o SAalignmm.o + +Lalignmm.o : Lalignmm.c $(HEADER) + $(CC) $(MYCFLAGS) -c Lalignmm.c + +rna.o : rna.c $(HEADER) + $(CC) $(MYCFLAGS) -c rna.c + +disttbfast.o : disttbfast.c $(HEADER) $(FFTHEADER) + $(CC) $(MYCFLAGS) -c disttbfast.c + +splitfromaln.o : splitfromaln.c $(HEADER) $(FFTHEADER) + $(CC) $(MYCFLAGS) -c splitfromaln.c + +splittbfast.o : splittbfast.c $(HEADER) $(FFTHEADER) + $(CC) $(MYCFLAGS) -c splittbfast.c + +splittbfast2.o : splittbfast2.c $(HEADER) $(FFTHEADER) + $(CC) $(MYCFLAGS) -c splittbfast2.c + +makedirectionlist.o : makedirectionlist.c $(HEADER) $(FFTHEADER) + $(CC) $(MYCFLAGS) -c makedirectionlist.c + +disttbfast_dummy.o : disttbfast_dummy.c $(HEADER) $(FFTHEADER) + $(CC) $(MYCFLAGS) -c disttbfast_dummy.c + +dummy.o : dummy.c $(HEADER) $(FFTHEADER) + $(CC) $(MYCFLAGS) -c dummy.c + +tbfast.o : tbfast.c $(HEADER) $(FFTHEADER) + $(CC) $(MYCFLAGS) -c tbfast.c + +addsingle.o : addsingle.c $(HEADER) $(FFTHEADER) + $(CC) $(MYCFLAGS) -c addsingle.c + +tbfast2.o : tbfast2.c $(HEADER) $(FFTHEADER) + $(CC) $(MYCFLAGS) -c tbfast2.c + +setcore.o : setcore.c $(HEADER) $(FFTHEADER) + $(CC) $(MYCFLAGS) -c setcore.c + +getlag.o : getlag.c $(HEADER) $(FFTHEADER) + $(CC) $(MYCFLAGS) -c getlag.c + +tditr.o : tditr.c $(HEADER) + $(CC) $(MYCFLAGS) -c tditr.c + +dvtditr.o : dvtditr.c $(HEADER) + $(CC) $(MYCFLAGS) -c dvtditr.c + +tditeration.o : tditeration.c $(HEADER) + $(CC) $(MYCFLAGS) -c tditeration.c + +mafft-profile.o : mafft-profile.c $(HEADER) $(MTXHEADER) + $(CC) $(MYCFLAGS) -c mafft-profile.c + +dndfast4.o : dndfast4.c $(HEADER) $(MTXHEADER) + $(CC) $(MYCFLAGS) -c dndfast4.c + +dndfast5.o : dndfast5.c $(HEADER) $(MTXHEADER) + $(CC) $(MYCFLAGS) -c dndfast5.c + +dndfast6.o : dndfast6.c $(HEADER) $(MTXHEADER) + $(CC) $(MYCFLAGS) -c dndfast6.c + +dndfast7.o : dndfast7.c $(HEADER) $(MTXHEADER) + $(CC) $(MYCFLAGS) -c dndfast7.c + +dndblast.o : dndblast.c $(HEADER) $(MTXHEADER) + $(CC) $(MYCFLAGS) -c dndblast.c + +dndfast3.o : dndfast3.c $(HEADER) $(MTXHEADER) + $(CC) $(MYCFLAGS) -c dndfast3.c + +dndpre.o : dndpre.c $(HEADER) + $(CC) $(MYCFLAGS) -c dndpre.c + +countlen.o : countlen.c $(HEADER) + $(CC) $(MYCFLAGS) -c countlen.c + +seq2regtable.o : seq2regtable.c $(HEADER) + $(CC) $(MYCFLAGS) -c seq2regtable.c + +regtable2seq.o : regtable2seq.c $(HEADER) + $(CC) $(MYCFLAGS) -c regtable2seq.c + +f2cl.o : f2cl.c $(HEADER) + $(CC) $(MYCFLAGS) -c f2cl.c + +setdirection.o : setdirection.c $(HEADER) + $(CC) $(MYCFLAGS) -c setdirection.c + +replaceu.o : replaceu.c $(HEADER) + $(CC) $(MYCFLAGS) -c replaceu.c + +restoreu.o : restoreu.c $(HEADER) + $(CC) $(MYCFLAGS) -c restoreu.c + +mccaskillwrap.o : mccaskillwrap.c $(HEADER) + $(CC) $(MYCFLAGS) -c mccaskillwrap.c + +contrafoldwrap.o : contrafoldwrap.c $(HEADER) + $(CC) $(MYCFLAGS) -c contrafoldwrap.c + +pairlocalalign.o : pairlocalalign.c $(HEADER) $(FFTHEADER) + $(CC) $(MYCFLAGS) -c pairlocalalign.c + +pairash.o : pairash.c $(HEADER) $(FFTHEADER) + $(CC) $(MYCFLAGS) -c pairash.c + +multi2hat3s.o : multi2hat3s.c $(HEADER) $(FFTHEADER) + $(CC) $(MYCFLAGS) -c multi2hat3s.c + +pair2hat3s.o : pair2hat3s.c $(HEADER) $(FFTHEADER) + $(CC) $(MYCFLAGS) -c pair2hat3s.c + +io.o : io.c $(HEADER) $(FFTHEADER) + $(CC) $(MYCFLAGS) -c io.c + +nj.o : nj.c $(HEADER) + $(CC) $(MYCFLAGS) -c nj.c + +treeOperation.o : treeOperation.c $(HEADER) + $(CC) $(MYCFLAGS) -c treeOperation.c + +sextet5.o : sextet5.c $(HEADER) $(MTXHEADER) + $(CC) $(MYCFLAGS) -c sextet5.c + +mafft-distance.o : mafft-distance.c $(HEADER) $(MTXHEADER) + $(CC) $(MYCFLAGS) -c mafft-distance.c + +triplet5.o : triplet5.c $(HEADER) $(MTXHEADER) + $(CC) $(MYCFLAGS) -c triplet5.c + +triplet6.o : triplet6.c $(HEADER) $(MTXHEADER) + $(CC) $(MYCFLAGS) -c triplet6.c + +fft.o : fft.c $(HEADER) $(FFTHEADER) + $(CC) $(MYCFLAGS) -c fft.c + +fftFunctions.o : fftFunctions.c $(HEADER) $(FFTHEADER) + $(CC) $(MYCFLAGS) -c fftFunctions.c + +Falign.o : Falign.c $(HEADER) $(FFTHEADER) $(MTXHEADER) + $(CC) $(MYCFLAGS) -c Falign.c + +Falign_localhom.o : Falign_localhom.c $(HEADER) $(FFTHEADER) $(MTXHEADER) + $(CC) $(MYCFLAGS) -c Falign_localhom.c + +mtxutl.o : mtxutl.c + $(CC) $(MYCFLAGS) -c mtxutl.c + +addfunctions.o : addfunctions.c $(HEADER) + $(CC) $(MYCFLAGS) -c addfunctions.c + +score.o : score.c $(HEADER) + $(CC) $(MYCFLAGS) -c score.c + +clean : + rm -f *.o *.a *.exe *~ $(PERLPROGS) $(PROGS) $(SCRIPTS) $(SOS) $(DYLIBS) $(DLLS) +# rm -f ../binaries/* ../scripts/* + +install : all + mkdir -p $(LIBDIR) + chmod 755 $(LIBDIR) + mkdir -p $(BINDIR) + chmod 755 $(BINDIR) + chmod 755 $(SCRIPTS) + $(INSTALL) $(SCRIPTS) $(BINDIR) + chmod 755 $(PROGS) + $(INSTALL) -s $(PROGS) $(LIBDIR) + $(INSTALL) $(PERLPROGS) $(LIBDIR) + $(INSTALL) -m 644 $(MANPAGES) $(LIBDIR) + + ( cd $(BINDIR); \ +rm -f linsi ginsi einsi fftns fftnsi nwns nwnsi xinsi qinsi; \ +rm -f mafft-linsi mafft-ginsi mafft-einsi mafft-fftns mafft-fftnsi mafft-nwns mafft-nwnsi mafft-xinsi mafft-qinsi; \ +ln -s mafft linsi; ln -s mafft ginsi; ln -s mafft fftns; \ +ln -s mafft fftnsi; ln -s mafft nwns; ln -s mafft nwnsi; \ +ln -s mafft einsi; \ +ln -s mafft mafft-linsi; ln -s mafft mafft-ginsi; ln -s mafft mafft-fftns; \ +ln -s mafft mafft-fftnsi; ln -s mafft mafft-nwns; ln -s mafft mafft-nwnsi; \ +ln -s mafft mafft-einsi; ln -s mafft mafft-xinsi; ln -s mafft mafft-qinsi;\ +rm -f mafft-profile mafft-profile.exe; ln -s $(LIBDIR)/mafft-profile .; \ +rm -f mafft-distance mafft-distance.exe; ln -s $(LIBDIR)/mafft-distance . ) + + mkdir -p $(MANDIR) + chmod 755 $(MANDIR) + $(INSTALL) -m 644 $(MANPAGES) $(MANDIR) +# remove incorrectly installed manpages by previous versions +# rm -f /usr/local/man/man1/mafft.1 /usr/local/man/man1/mafft-homologs.1 diff --git a/binaries/src/mafft/core/SAalignmm.c b/binaries/src/mafft/core/SAalignmm.c index 9fc05df..c7c5c47 100644 --- a/binaries/src/mafft/core/SAalignmm.c +++ b/binaries/src/mafft/core/SAalignmm.c @@ -3,20 +3,22 @@ #define DEBUG 0 -static void match_calc( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize ) +static void match_calc( double *match, double **cpmx1, double **cpmx2, int i1, int lgth2, double **doublework, int **intwork, int initialize ) { int j, k, l; - float scarr[26]; - float **cpmxpd = floatwork; +// double scarr[26]; + double **cpmxpd = doublework; int **cpmxpdn = intwork; int count = 0; + double *scarr; + scarr = calloc( nalphabets, sizeof( double ) ); if( initialize ) { for( j=0; j -1; k++ ) match[j] += scarr[cpmxpdn[k][j]] * cpmxpd[k][j]; } + free( scarr ); } -static float Atracking( float *lasthorizontalw, float *lastverticalw, +static double Atracking( double *lasthorizontalw, double *lastverticalw, char **seq1, char **seq2, char **mseq1, char **mseq2, - float **cpmx1, float **cpmx2, + double **cpmx1, double **cpmx2, int **ijp, int icyc, int jcyc ) { int i, j, k, l, iin, jin, ifi, jfi, lgth1, lgth2; // char gap[] = "-"; char *gap; - float wm; + double wm; gap = newgapstr; lgth1 = strlen( seq1[0] ); lgth2 = strlen( seq2[0] ); @@ -153,31 +156,31 @@ static float Atracking( float *lasthorizontalw, float *lastverticalw, } -float Aalign( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen ) +double Aalign( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen ) /* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */ { register int i, j; int lasti; /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */ int lgth1, lgth2; int resultlen; - float wm = 0.0; /* int ?????? */ - float g; - float x; - static TLS float mi, *m; + double wm = 0.0; /* int ?????? */ + double g; + double x; + static TLS double mi, *m; static TLS int **ijp; static TLS int mpi, *mp; - static TLS float *currentw; - static TLS float *previousw; - static TLS float *match; - static TLS float *initverticalw; /* kufuu sureba iranai */ - static TLS float *lastverticalw; /* kufuu sureba iranai */ + static TLS double *currentw; + static TLS double *previousw; + static TLS double *match; + static TLS double *initverticalw; /* kufuu sureba iranai */ + static TLS double *lastverticalw; /* kufuu sureba iranai */ static TLS char **mseq1; static TLS char **mseq2; static TLS char **mseq; - static TLS float **cpmx1; - static TLS float **cpmx2; + static TLS double **cpmx1; + static TLS double **cpmx2; static TLS int **intwork; - static TLS float **floatwork; + static TLS double **doublework; static TLS int orlgth1 = 0, orlgth2 = 0; #if DEBUG @@ -213,7 +216,7 @@ float Aalign( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, in FreeFloatMtx( cpmx1 ); FreeFloatMtx( cpmx2 ); - FreeFloatMtx( floatwork ); + FreeFloatMtx( doublework ); FreeIntMtx( intwork ); } @@ -234,11 +237,11 @@ float Aalign( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, in mseq = AllocateCharMtx( njob, ll1+ll2 ); - cpmx1 = AllocateFloatMtx( 26, ll1+2 ); - cpmx2 = AllocateFloatMtx( 26, ll2+2 ); + cpmx1 = AllocateFloatMtx( nalphabets, ll1+2 ); + cpmx2 = AllocateFloatMtx( nalphabets, ll2+2 ); - floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 ); - intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 ); + doublework = AllocateFloatMtx( nalphabets, MAX( ll1, ll2 )+2 ); + intwork = AllocateIntMtx( nalphabets, MAX( ll1, ll2 )+2 ); fprintf( stderr, "succeeded\n" ); @@ -276,8 +279,8 @@ float Aalign( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, in cpmx_calc( seq1, cpmx1, eff1, strlen( seq1[0] ), icyc ); cpmx_calc( seq2, cpmx2, eff2, strlen( seq2[0] ), jcyc ); - match_calc( initverticalw, cpmx2, cpmx1, 0, lgth1, floatwork, intwork, 1 ); - match_calc( currentw, cpmx1, cpmx2, 0, lgth2, floatwork, intwork, 1 ); + match_calc( initverticalw, cpmx2, cpmx1, 0, lgth1, doublework, intwork, 1 ); + match_calc( currentw, cpmx1, cpmx2, 0, lgth2, doublework, intwork, 1 ); if( outgap == 1 ) { @@ -303,10 +306,10 @@ float Aalign( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, in for( i=1; istart1 ); -// fprintf( stderr, "end1 = %d\n", tmpptr->end1 ); -// fprintf( stderr, "i = %d, seq1 = \n%s\n", i, seq1[i] ); -// fprintf( stderr, "j = %d, seq2 = \n%s\n", j, seq2[j] ); - pt = seq1[i]; - tmpint = -1; - while( *pt != 0 ) - { - if( *pt++ != '-' ) tmpint++; - if( tmpint == tmpptr->start1 ) break; - } - start1 = pt - seq1[i] - 1; - - if( tmpptr->start1 == tmpptr->end1 ) end1 = start1; - else - { -#if MACHIGAI - while( *pt != 0 ) - { -// fprintf( stderr, "tmpint = %d, end1 = %d pos = %d\n", tmpint, tmpptr->end1, pt-seq1[i] ); - if( tmpint == tmpptr->end1 ) break; - if( *pt++ != '-' ) tmpint++; - } - end1 = pt - seq1[i] - 0; -#else - while( *pt != 0 ) - { -// fprintf( stderr, "tmpint = %d, end1 = %d pos = %d\n", tmpint, tmpptr->end1, pt-seq1[i] ); - if( *pt++ != '-' ) tmpint++; - if( tmpint == tmpptr->end1 ) break; - } - end1 = pt - seq1[i] - 1; -#endif - } - - pt = seq2[j]; - tmpint = -1; - while( *pt != 0 ) - { - if( *pt++ != '-' ) tmpint++; - if( tmpint == tmpptr->start2 ) break; - } - start2 = pt - seq2[j] - 1; - if( tmpptr->start2 == tmpptr->end2 ) end2 = start2; - else - { -#if MACHIGAI - while( *pt != 0 ) - { - if( tmpint == tmpptr->end2 ) break; - if( *pt++ != '-' ) tmpint++; - } - end2 = pt - seq2[j] - 0; -#else - while( *pt != 0 ) - { - if( *pt++ != '-' ) tmpint++; - if( tmpint == tmpptr->end2 ) break; - } - end2 = pt - seq2[j] - 1; -#endif - } -// fprintf( stderr, "start1 = %d (%c), end1 = %d (%c), start2 = %d (%c), end2 = %d (%c)\n", start1, seq1[i][start1], end1, seq1[i][end1], start2, seq2[j][start2], end2, seq2[j][end2] ); -// fprintf( stderr, "step 0\n" ); - if( end1 - start1 != end2 - start2 ) - { -// fprintf( stderr, "CHUUI!!, start1 = %d, end1 = %d, start2 = %d, end2 = %d\n", start1, end1, start2, end2 ); - } - -#if 1 - k1 = start1; k2 = start2; - pt1 = seq1[i] + k1; - pt2 = seq2[j] + k2; - while( *pt1 && *pt2 ) - { - if( *pt1 != '-' && *pt2 != '-' ) - { -// ½Å¤ß¤òÆó½Å¤Ë¤«¤±¤Ê¤¤¤è¤¦¤ËÃí°Õ¤·¤Æ²¼¤µ¤¤¡£ -// impmtx[k1][k2] += tmpptr->wimportance * fastathreshold; -// impmtx[k1][k2] += tmpptr->importance * effij; -// impmtx[k1][k2] += tmpptr->fimportance * effij; - if( tmpptr->korh == 'k' ) - impmtx[k1][k2] += tmpptr->fimportance * effij_kozo; - else - impmtx[k1][k2] += tmpptr->fimportance * effij; - -// fprintf( stderr, "#### impmtx[k1][k2] = %f, tmpptr->fimportance=%f, effij=%f\n", impmtx[k1][k2], tmpptr->fimportance, effij ); -// fprintf( stderr, "mark, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 ); -// fprintf( stderr, "%d (%c) - %d (%c) - %f\n", k1, *pt1, k2, *pt2, tmpptr->fimportance * effij ); - k1++; k2++; - pt1++; pt2++; - } - else if( *pt1 != '-' && *pt2 == '-' ) - { -// fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 ); - k2++; pt2++; - } - else if( *pt1 == '-' && *pt2 != '-' ) - { -// fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 ); - k1++; pt1++; - } - else if( *pt1 == '-' && *pt2 == '-' ) - { -// fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 ); - k1++; pt1++; - k2++; pt2++; - } - if( k1 > end1 || k2 > end2 ) break; - } -#else - while( k1 <= end1 && k2 <= end2 ) - { - fprintf( stderr, "k1,k2=%d,%d - ", k1, k2 ); - if( !nocount1[k1] && !nocount2[k2] ) - { - impmtx[k1][k2] += tmpptr->wimportance * eff1[i] * eff2[j] * fastathreshold; - fprintf( stderr, "marked\n" ); - } - else - fprintf( stderr, "no count\n" ); - k1++; k2++; - } -#endif - tmpptr = tmpptr->next; - } - } - } - -#if 0 - if( clus1 == 1 && clus2 == 1 ) - { - fprintf( stderr, "writing impmtx\n" ); - fprintf( stderr, "\n" ); - fprintf( stderr, "seq1[0] = %s\n", seq1[0] ); - fprintf( stderr, "seq2[0] = %s\n", seq2[0] ); - fprintf( stderr, "impmtx = \n" ); - for( k2=0; k2 ", match[k], mid ); + match[k] -= matrices[mid][c1][c2] * eff1[i] * eff2[j]; +// fprintf( stderr, "match[k] = %f (mid=%d)\n", match[k], mid ); } -// exit( 1 ); } -#endif +// fprintf( stderr, "done\n" ); + return; } -#if 0 -void imp_match_init( float *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, LocalHom ***localhom ) -{ - int dif, i, j, k1, k2, tmpint, start1, start2, end1, end2; - static TLS int impalloclen = 0; - char *pt; - int allgap; - static TLS char *nocount1 = NULL; - static TLS char *nocount2 = NULL; - - if( impalloclen < lgth1 + 2 || impalloclen < lgth2 + 2 ) - { - if( impmtx ) FreeFloatMtx( impmtx ); - if( nocount1 ) free( nocount1 ); - if( nocount2 ) free( nocount2 ); - impalloclen = MAX( lgth1, lgth2 ) + 2; - impmtx = AllocateFloatMtx( impalloclen, impalloclen ); - nocount1 = AllocateCharVec( impalloclen ); - nocount2 = AllocateCharVec( impalloclen ); - } - for( i=0; istart1 ); - fprintf( stderr, "end1 = %d\n", localhom[i][j]->end1 ); - fprintf( stderr, "j = %d, seq2 = %s\n", j, seq2[j] ); - pt = seq1[i]; - tmpint = -1; - while( *pt != 0 ) - { - if( *pt++ != '-' ) tmpint++; - if( tmpint == localhom[i][j]->start1 ) break; - } - start1 = pt - seq1[i] - 1; - - while( *pt != 0 ) - { -// fprintf( stderr, "tmpint = %d, end1 = %d pos = %d\n", tmpint, localhom[i][j].end1, pt-seq1[i] ); - if( *pt++ != '-' ) tmpint++; - if( tmpint == localhom[i][j]->end1 ) break; - } - end1 = pt - seq1[i] - 1; - - pt = seq2[j]; - tmpint = -1; - while( *pt != 0 ) - { - if( *pt++ != '-' ) tmpint++; - if( tmpint == localhom[i][j]->start2 ) break; - } - start2 = pt - seq2[j] - 1; - while( *pt != 0 ) - { - if( *pt++ != '-' ) tmpint++; - if( tmpint == localhom[i][j]->end2 ) break; - } - end2 = pt - seq2[j] - 1; -// fprintf( stderr, "start1 = %d, end1 = %d, start2 = %d, end2 = %d\n", start1, end1, start2, end2 ); - k1 = start1; - k2 = start2; - fprintf( stderr, "step 0\n" ); - while( k1 <= end1 && k2 <= end2 ) - { -#if 0 - if( !nocount1[k1] && !nocount2[k2] ) - impmtx[k1][k2] += localhom[i][j].wimportance * eff1[i] * eff2[j]; - k1++; k2++; -#else - if( !nocount1[k1] && !nocount2[k2] ) - impmtx[k1][k2] += localhom[i][j]->wimportance * eff1[i] * eff2[j]; - k1++; k2++; -#endif - } - - dif = ( end1 - start1 ) - ( end2 - start2 ); - fprintf( stderr, "dif = %d\n", dif ); - if( dif > 0 ) + count = 0; + for( l=0; lwimportance * eff1[i] * eff2[j]; - k1++; k2++; - } + cpmxpd[j][count] = cpmx2[l][j]; + cpmxpdn[j][count] = l; + count++; } - while( dif-- ); } - else + cpmxpdn[j][count] = -1; + } + } + + { + for( l=0; l-1 ) + *matchpt += scarr[*cpmxpdnpt++] * *cpmxpdpt++; + matchpt++; + } + } + free( scarr ); +// fprintf( stderr, "done\n" ); +#else + int j, k, l; +// double scarr[26]; + double **cpmxpd = doublework; + int **cpmxpdn = intwork; + double *scarr; + scarr = calloc( nalphabets, sizeof( double ) ); +// simple + if( initialize ) + { + int count = 0; + for( j=0; j= 0 && k1 >= start1 && !nocount1[k1] && !nocount2[k2] ) - impmtx[k1][k2] = localhom[i][j]->wimportance * eff1[i] * eff2[j]; - k1++; k2++; - } + cpmxpd[count][j] = cpmx2[l][j]; + cpmxpdn[count][j] = l; + count++; } - while( dif++ ); } + cpmxpdn[count][j] = -1; } } -#if 0 - fprintf( stderr, "impmtx = \n" ); - for( k2=0; k2-1; k++ ) + match[j] += scarr[cpmxpdn[k][j]] * cpmxpd[k][j]; + } + free( scarr ); #endif } -#endif - -static void match_calc( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize ) +static void match_calc( double **n_dynamicmtx, double *match, double **cpmx1, double **cpmx2, int i1, int lgth2, double **doublework, int **intwork, int initialize ) { #if FASTMATCHCALC +// fprintf( stderr, "\nmatch_calc... %d", i1 ); int j, l; - float scarr[26]; - float **cpmxpd = floatwork; +// double scarr[26]; + double **cpmxpd = doublework; int **cpmxpdn = intwork; - float *matchpt, *cpmxpdpt, **cpmxpdptpt; + double *matchpt, *cpmxpdpt, **cpmxpdptpt; int *cpmxpdnpt, **cpmxpdnptpt; + double *scarr; + scarr = calloc( nalphabets, sizeof( double ) ); if( initialize ) { int count = 0; for( j=0; j-1; k++ ) match[j] += scarr[cpmxpdn[k][j]] * cpmxpd[k][j]; } + free( scarr ); #endif } -static void Atracking_localhom( float *impwmpt, float *lasthorizontalw, float *lastverticalw, +static void Atracking_localhom( double *impwmpt, double *lasthorizontalw, double *lastverticalw, char **seq1, char **seq2, char **mseq1, char **mseq2, - float **cpmx1, float **cpmx2, - int **ijp, int icyc, int jcyc ) + int **ijp, int icyc, int jcyc, + int *warpis, int *warpjs, int warpbase, + int *ngap1, int *ngap2, int reuseprofiles ) { - int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k; - float wm; + int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k, limk; + double wm; char *gaptable1, *gt1bk; char *gaptable2, *gt2bk; lgth1 = strlen( seq1[0] ); @@ -605,12 +453,19 @@ static void Atracking_localhom( float *impwmpt, float *lasthorizontalw, float *l *gaptable1 = 0; gaptable2 = gt2bk + lgth1+lgth2; *gaptable2 = 0; + *ngap1 = *ngap2 = 0; iin = lgth1; jin = lgth2; + limk = lgth1+lgth2 + 1; *impwmpt = 0.0; - for( k=0; k<=lgth1+lgth2; k++ ) + for( k=0; k= warpbase ) + { + ifi = warpis[ijp[iin][jin]-warpbase]; + jfi = warpjs[ijp[iin][jin]-warpbase]; + } + else if( ijp[iin][jin] < 0 ) { ifi = iin-1; jfi = jin+ijp[iin][jin]; } @@ -622,25 +477,50 @@ static void Atracking_localhom( float *impwmpt, float *lasthorizontalw, float *l { ifi = iin-1; jfi = jin-1; } - l = iin - ifi; - while( --l ) + if( ifi == -warpbase && jfi == -warpbase ) { - *--gaptable1 = 'o'; - *--gaptable2 = '-'; - k++; + l = iin; + while( --l >= 0 ) + { + *--gaptable1 = 'o'; + *--gaptable2 = '-'; + k++; + *ngap2 = 1; + } + l= jin; + while( --l >= 0 ) + { + *--gaptable1 = '-'; + *--gaptable2 = 'o'; + k++; + *ngap1 = 1; + } + break; } - l= jin - jfi; - while( --l ) + else { - *--gaptable1 = '-'; - *--gaptable2 = 'o'; - k++; + l = iin - ifi; + while( --l ) + { + *--gaptable1 = 'o'; + *--gaptable2 = '-'; + k++; + *ngap2 = 1; + } + l= jin - jfi; + while( --l ) + { + *--gaptable1 = '-'; + *--gaptable2 = 'o'; + k++; + *ngap1 = 1; + } } if( iin == lgth1 || jin == lgth2 ) ; else { - *impwmpt += imp_match_out_sc( iin, jin ); + *impwmpt += (double)imp_match_out_sc( iin, jin ); // fprintf( stderr, "impwm = %f (iin=%d, jin=%d) seq1=%c, seq2=%c\n", *impwmpt, iin, jin, seq1[0][iin], seq2[0][jin] ); } @@ -651,25 +531,31 @@ static void Atracking_localhom( float *impwmpt, float *lasthorizontalw, float *l iin = ifi; jin = jfi; } - for( i=0; i= warpbase ) + { + ifi = warpis[ijp[iin][jin]-warpbase]; + jfi = warpjs[ijp[iin][jin]-warpbase]; + } + else if( ijp[iin][jin] < 0 ) { ifi = iin-1; jfi = jin+ijp[iin][jin]; } @@ -735,196 +627,149 @@ static void Atracking_localhom_gapmap( float *impwmpt, float *lasthorizontalw, f { ifi = iin-1; jfi = jin-1; } - l = iin - ifi; - while( --l ) - { - *--gaptable1 = 'o'; - *--gaptable2 = '-'; - k++; - } - l= jin - jfi; - while( --l ) + + if( ifi == -warpbase && jfi == -warpbase ) { - *--gaptable1 = '-'; - *--gaptable2 = 'o'; - k++; + l = iin; + while( --l >= 0 ) + { + *--gaptable1 = 'o'; + *--gaptable2 = '-'; + k++; + *ngap2=1; + } + l= jin; + while( --l >= 0 ) + { + *--gaptable1 = '-'; + *--gaptable2 = 'o'; + k++; + *ngap1=1; + } + break; } - if( iin == lgth1 || jin == lgth2 ) - ; else { - *impwmpt += imp_match_out_sc( gapmap1[iin], gapmap2[jin] ); - -// fprintf( stderr, "impwm = %f (iin=%d, jin=%d) seq1=%c, seq2=%c\n", *impwmpt, iin, jin, seq1[0][iin], seq2[0][jin] ); + l = iin - ifi; + while( --l ) + { + *--gaptable1 = 'o'; + *--gaptable2 = '-'; + k++; + *ngap2=1; + } + l= jin - jfi; + while( --l ) + { + *--gaptable1 = '-'; + *--gaptable2 = 'o'; + k++; + *ngap1=1; + } } if( iin <= 0 || jin <= 0 ) break; - *--gaptable1 = '-'; - *--gaptable2 = '-'; + *--gaptable1 = 'o'; + *--gaptable2 = 'o'; k++; iin = ifi; jin = jfi; } - for( i=0; i lgth1, outgap == 1 -> lgth1+1 */ + int lgth1, lgth2; + int resultlen; + double wm = 0.0; /* int ?????? */ + double g; + double *currentw, *previousw; +// double fpenalty = (double)penalty; +#if USE_PENALTY_EX + double fpenalty_ex = (double)penalty_ex; +#endif +#if 1 + double *wtmp; + int *ijppt; + double *mjpt, *prept, *curpt; + int *mpjpt; +#endif + static TLS double mi, *m; + static TLS int **ijp; + static TLS int mpi, *mp; + static TLS double *w1, *w2; + static TLS double *match; + static TLS double *initverticalw; /* kufuu sureba iranai */ + static TLS double *lastverticalw; /* kufuu sureba iranai */ + static TLS char **mseq1; + static TLS char **mseq2; + static TLS char **mseq; + static TLS double *ogcp1, *ogcp1o; + static TLS double *ogcp2; + static TLS double *fgcp1, *fgcp1o; + static TLS double *fgcp2; + static TLS double **cpmx1; + static TLS double **cpmx2; + static TLS int **intwork; + static TLS double **doublework; + static TLS int orlgth1 = 0, orlgth2 = 0; + static TLS double *gapfreq1; + static TLS double *gapfreq2; + double fpenalty = (double)penalty; + double fpenalty_shift = (double)penalty_shift; + double *fgcp2pt; + double *ogcp2pt; + double fgcp1va; + double ogcp1va; + double *gf2pt; + double *gf2ptpre; + double gf1va; + double gf1vapre; + double headgapfreq1; + double headgapfreq2; + + int *warpis = NULL; + int *warpjs = NULL; + int *warpi = NULL; + int *warpj = NULL; + int *prevwarpi = NULL; + int *prevwarpj = NULL; + double *wmrecords = NULL; + double *prevwmrecords = NULL; + int warpn = 0; + int warpbase; + double curm = 0.0; + double *wmrecordspt, *wmrecords1pt, *prevwmrecordspt; + int *warpipt, *warpjpt; + +// for( i=0; i= wm ) - { - wm = lastverticalw[i]; - iin = i; jin = lgth2-1; - ijp[lgth1][lgth2] = +( lgth1 - i ); - } - } - for( j=0; j= wm ) - { - wm = lasthorizontalw[j]; - iin = lgth1-1; jin = j; - ijp[lgth1][lgth2] = -( lgth2 - j ); - } - } - } - - for( i=0; i 0 ) - { - ifi = iin-ijp[iin][jin]; jfi = jin-1; - } - else - { - ifi = iin-1; jfi = jin-1; - } - l = iin - ifi; - while( --l ) - { - *--gaptable1 = 'o'; - *--gaptable2 = '-'; - k++; - } - l= jin - jfi; - while( --l ) - { - *--gaptable1 = '-'; - *--gaptable2 = 'o'; - k++; - } - if( iin <= 0 || jin <= 0 ) break; - *--gaptable1 = 'o'; - *--gaptable2 = 'o'; - k++; - iin = ifi; jin = jfi; - } - - for( i=0; i lgth1, outgap == 1 -> lgth1+1 */ - int lgth1, lgth2; - int resultlen; - float wm = 0.0; /* int ?????? */ - float g; - float *currentw, *previousw; -// float fpenalty = (float)penalty; -#if USE_PENALTY_EX - float fpenalty_ex = (float)penalty_ex; -#endif -#if 1 - float *wtmp; - int *ijppt; - float *mjpt, *prept, *curpt; - int *mpjpt; -#endif - static TLS float mi, *m; - static TLS int **ijp; - static TLS int mpi, *mp; - static TLS float *w1, *w2; - static TLS float *match; - static TLS float *initverticalw; /* kufuu sureba iranai */ - static TLS float *lastverticalw; /* kufuu sureba iranai */ - static TLS char **mseq1; - static TLS char **mseq2; - static TLS char **mseq; - static TLS float *ogcp1; - static TLS float *ogcp2; - static TLS float *fgcp1; - static TLS float *fgcp2; - static TLS float **cpmx1; - static TLS float **cpmx2; - static TLS int **intwork; - static TLS float **floatwork; - static TLS int orlgth1 = 0, orlgth2 = 0; - float fpenalty = (float)penalty; - float *fgcp2pt; - float *ogcp2pt; - float fgcp1va; - float ogcp1va; - - - if( seq1 == NULL ) + if( seq1 == NULL ) { if( orlgth1 ) { @@ -932,7 +777,7 @@ float A__align( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, orlgth1 = 0; orlgth2 = 0; - imp_match_init_strict( NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0 ); + imp_match_init_strict( NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL ); free( mseq1 ); free( mseq2 ); @@ -948,15 +793,20 @@ float A__align( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, FreeCharMtx( mseq ); FreeFloatVec( ogcp1 ); + FreeFloatVec( ogcp1o ); FreeFloatVec( ogcp2 ); FreeFloatVec( fgcp1 ); + FreeFloatVec( fgcp1o ); FreeFloatVec( fgcp2 ); FreeFloatMtx( cpmx1 ); FreeFloatMtx( cpmx2 ); - FreeFloatMtx( floatwork ); + FreeFloatVec( gapfreq1 ); + FreeFloatVec( gapfreq2 ); + + FreeFloatMtx( doublework ); FreeIntMtx( intwork ); } @@ -967,13 +817,15 @@ float A__align( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, return( 0.0 ); } + lgth1 = strlen( seq1[0] ); lgth2 = strlen( seq2[0] ); -#if 1 +#if 0 if( lgth1 == 0 || lgth2 == 0 ) { fprintf( stderr, "WARNING (Aalignmm): lgth1=%d, lgth2=%d\n", lgth1, lgth2 ); } +#endif if( lgth1 == 0 && lgth2 == 0 ) return( 0.0 ); @@ -983,7 +835,7 @@ float A__align( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, { j = lgth2; seq1[i][j] = 0; - while( j ) seq1[i][--j] = '-'; + while( j ) seq1[i][--j] = *newgapstr; // fprintf( stderr, "seq1[i] = %s\n", seq1[i] ); } return( 0.0 ); @@ -995,12 +847,40 @@ float A__align( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, { j = lgth1; seq2[i][j] = 0; - while( j ) seq2[i][--j] = '-'; + while( j ) seq2[i][--j] = *newgapstr; // fprintf( stderr, "seq2[i] = %s\n", seq2[i] ); } return( 0.0 ); } -#endif + + warpbase = lgth1 + lgth2; + warpis = NULL; + warpjs = NULL; + warpn = 0; + + + + if( trywarp ) + { +// fprintf( stderr, "IN A__align, penalty_shift = %d\n", penalty_shift ); + if( headgp == 0 || tailgp == 0 ) + { + fprintf( stderr, "At present, headgp and tailgp must be 1 to allow shift.\n" ); + exit( 1 ); + } + wmrecords = AllocateFloatVec( lgth2+1 ); + warpi = AllocateIntVec( lgth2+1 ); + warpj = AllocateIntVec( lgth2+1 ); + prevwmrecords = AllocateFloatVec( lgth2+1 ); + prevwarpi = AllocateIntVec( lgth2+1 ); + prevwarpj = AllocateIntVec( lgth2+1 ); + for( i=0; i 0 && orlgth2 > 0 ) { FreeFloatVec( w1 ); @@ -1038,15 +919,20 @@ float A__align( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, FreeCharMtx( mseq ); FreeFloatVec( ogcp1 ); + FreeFloatVec( ogcp1o ); FreeFloatVec( ogcp2 ); FreeFloatVec( fgcp1 ); + FreeFloatVec( fgcp1o ); FreeFloatVec( fgcp2 ); FreeFloatMtx( cpmx1 ); FreeFloatMtx( cpmx2 ); - FreeFloatMtx( floatwork ); + FreeFloatVec( gapfreq1 ); + FreeFloatVec( gapfreq2 ); + + FreeFloatMtx( doublework ); FreeIntMtx( intwork ); } @@ -1070,19 +956,26 @@ float A__align( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, mseq = AllocateCharMtx( njob, ll1+ll2 ); ogcp1 = AllocateFloatVec( ll1+2 ); + ogcp1o = AllocateFloatVec( ll1+2 ); ogcp2 = AllocateFloatVec( ll2+2 ); fgcp1 = AllocateFloatVec( ll1+2 ); + fgcp1o = AllocateFloatVec( ll1+2 ); fgcp2 = AllocateFloatVec( ll2+2 ); - cpmx1 = AllocateFloatMtx( 26, ll1+2 ); - cpmx2 = AllocateFloatMtx( 26, ll2+2 ); + cpmx1 = AllocateFloatMtx( nalphabets, ll1+2 ); + cpmx2 = AllocateFloatMtx( nalphabets, ll2+2 ); + previousfirstlen = -1; + previousicyc = -1; + + gapfreq1 = AllocateFloatVec( ll1+2 ); + gapfreq2 = AllocateFloatVec( ll2+2 ); #if FASTMATCHCALC - floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 ); - intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 27 ); + doublework = AllocateFloatMtx( MAX( ll1, ll2 )+2, nalphabets ); + intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, nalphabets+1 ); #else - floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 ); - intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 ); + doublework = AllocateFloatMtx( nalphabets, MAX( ll1, ll2 )+2 ); + intwork = AllocateIntMtx( nalphabets, MAX( ll1, ll2 )+2 ); #endif #if DEBUG @@ -1135,40 +1028,109 @@ float A__align( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, #if 0 { - float t = 0.0; + double t = 0.0; for( i=0; i= 0 && firstmem == previousfirstmem && lgth1 == previousfirstlen && nthread == 0 && icyc == previousicyc+1 ) // mouhitotsu jouken ga iru. firstmem >= 0 && firstmem == previousfirstmem && calledbytreebase && prevcalledbytreebase + reuseprofiles = 1; + else + reuseprofiles = 0; + + + if( reuseprofiles ) + { +// reporterr( "r" ); + cpmx_calc_add( seq1, cpmx1, eff1, lgth1, icyc ); + } + else + { +// reporterr( "n" ); + cpmx_calc_new( seq1, cpmx1, eff1, lgth1, icyc ); + } cpmx_calc_new( seq2, cpmx2, eff2, lgth2, jcyc ); if( sgap1 ) { - new_OpeningGapCount( ogcp1, icyc, seq1, eff1, lgth1, sgap1 ); + new_OpeningGapCount( ogcp1o, icyc, seq1, eff1, lgth1, sgap1 ); + new_FinalGapCount( fgcp1o, icyc, seq1, eff1, lgth1, egap1 ); + new_OpeningGapCount( ogcp2, jcyc, seq2, eff2, lgth2, sgap2 ); - new_FinalGapCount( fgcp1, icyc, seq1, eff1, lgth1, egap1 ); new_FinalGapCount( fgcp2, jcyc, seq2, eff2, lgth2, egap2 ); + + outgapcount( &headgapfreq1, icyc, sgap1, eff1 ); + outgapcount( &headgapfreq2, jcyc, sgap2, eff2 ); + outgapcount( gapfreq1+lgth1, icyc, egap1, eff1 ); + outgapcount( gapfreq2+lgth2, jcyc, egap2, eff2 ); } else { - st_OpeningGapCount( ogcp1, icyc, seq1, eff1, lgth1 ); + if( reuseprofiles ) + { + st_OpeningGapAdd( ogcp1o, icyc, seq1, eff1, lgth1 ); + st_FinalGapAdd( fgcp1o, icyc, seq1, eff1, lgth1 ); + } + else + { + st_OpeningGapCount( ogcp1o, icyc, seq1, eff1, lgth1 ); + st_FinalGapCount( fgcp1o, icyc, seq1, eff1, lgth1 ); + } + st_OpeningGapCount( ogcp2, jcyc, seq2, eff2, lgth2 ); - st_FinalGapCount( fgcp1, icyc, seq1, eff1, lgth1 ); st_FinalGapCount( fgcp2, jcyc, seq2, eff2, lgth2 ); + + headgapfreq1 = 0.0; + headgapfreq2 = 0.0; + gapfreq1[lgth1] = 0.0; + gapfreq2[lgth2] = 0.0; } + if( legacygapcost == 0 ) + { + if( reuseprofiles ) + gapcountadd( gapfreq1, seq1, icyc, eff1, lgth1 ); + else + gapcountf( gapfreq1, seq1, icyc, eff1, lgth1 ); + + gapcountf( gapfreq2, seq2, jcyc, eff2, lgth2 ); + + for( i=0; i tbfast.c if( localhom ) - imp_match_calc( currentw, icyc, jcyc, lgth1, lgth2, seq1, seq2, eff1, eff2, localhom, 1, 0 ); + imp_match_calc( n_dynamicmtx, currentw, icyc, jcyc, lgth1, lgth2, seq1, seq2, eff1, eff2, localhom, 1, 0 ); #endif @@ -1195,26 +1157,41 @@ float A__align( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, { for( i=1; i", wm ); + fprintf( stderr, "%5.0f? (penal=%5.2f)", g=mi+*fgcp2pt*(1.0-gapfreq1[i]), *fgcp2pt*(1.0-gapfreq1[i]) ); #endif -#if 0 - fprintf( stderr, "%5.0f?", g ); -#endif - if( (g=mi+*fgcp2pt) > wm ) + if( (g=mi+*fgcp2pt*gf1va) > wm ) { wm = g; *ijppt = -( j - mpi ); +// fprintf( stderr, "Jump to %d (%c)!", mpi, seq2[0][mpi] ); } - if( (g=*prept+*ogcp2pt) >= mi ) + if( (g=*prept+*ogcp2pt*gf1vapre) >= mi ) { mi = g; mpi = j-1; @@ -1340,14 +1341,16 @@ fprintf( stderr, "\n" ); #endif #if 0 - fprintf( stderr, "%5.0f?", g ); + fprintf( stderr, "%5.0f->", wm ); + fprintf( stderr, "%5.0f? (penal=%5.2f)", g=*mjpt+fgcp1va*(1.0-gapfreq2[j]), fgcp1va*(1.0-gapfreq2[j]) ); #endif - if( (g=*mjpt+fgcp1va) > wm ) + if( (g=*mjpt+ fgcp1va* *gf2pt) > wm ) { wm = g; *ijppt = +( i - *mpjpt ); +// fprintf( stderr, "Jump to %d (%c)!", *mpjpt, seq1[0][*mpjpt] ); } - if( (g=*prept+ogcp1va) >= *mjpt ) + if( (g=*prept+ ogcp1va* *gf2ptpre) >= *mjpt ) { *mjpt = g; *mpjpt = i-1; @@ -1356,9 +1359,55 @@ fprintf( stderr, "\n" ); m[j] += fpenalty_ex; #endif + + if( trywarp ) + { +#if USE_PENALTY_EX + if( ( g=*prevwmrecordspt++ + fpenalty_shift + fpenalty_ex * ( i - prevwarpi[j-1] + j - prevwarpj[j-1] ) ) > wm ) // naka ha osokute kamawanai +#else + if( ( g=*prevwmrecordspt++ + fpenalty_shift ) > wm ) // naka ha osokute kamawanai +#endif + { +// fprintf( stderr, "WARP!!\n" ); + if( warpn && prevwarpi[j-1] == warpis[warpn-1] && prevwarpj[j-1] == warpjs[warpn-1] ) + { + *ijppt = warpbase + warpn - 1; + } + else + { + *ijppt = warpbase + warpn; + warpis = realloc( warpis, sizeof(int) * ( warpn+1 ) ); + warpjs = realloc( warpjs, sizeof(int) * ( warpn+1 ) ); + warpis[warpn] = prevwarpi[j-1]; + warpjs[warpn] = prevwarpj[j-1]; + warpn++; + } + wm = g; + } + #if 0 - fprintf( stderr, "%5.0f ", wm ); + fprintf( stderr, "%5.0f ", wm ); #endif + curm = *curpt + wm; + + if( *wmrecords1pt > *wmrecordspt ) + { + *wmrecordspt = *wmrecords1pt; + *warpipt = *(warpipt-1); + *warpjpt = *(warpjpt-1); + } + if( curm > *wmrecordspt ) + { + *wmrecordspt = curm; + *warpipt = i; + *warpjpt = j; + } + wmrecordspt++; + wmrecords1pt++; + warpipt++; + warpjpt++; + } + *curpt++ += wm; ijppt++; mjpt++; @@ -1366,11 +1415,30 @@ fprintf( stderr, "\n" ); mpjpt++; fgcp2pt++; ogcp2pt++; + gf2ptpre++; + gf2pt++; } lastverticalw[i] = currentw[lgth2-1]; + + if( trywarp ) + { + fltncpy( prevwmrecords, wmrecords, lastj ); + intncpy( prevwarpi, warpi, lastj ); + intncpy( prevwarpj, warpj, lastj ); + } } -// fprintf( stderr, "wm = %f\n", wm ); + if( trywarp ) + { +// fprintf( stderr, "wm = %f\n", wm ); +// fprintf( stderr, "warpn = %d\n", warpn ); + free( wmrecords ); + free( prevwmrecords ); + free( warpi ); + free( warpj ); + free( prevwarpi ); + free( prevwarpj ); + } #if OUTGAP0TRY if( !outgap ) @@ -1393,10 +1461,15 @@ fprintf( stderr, "\n" ); */ if( localhom ) { - Atracking_localhom( impmatch, currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc ); + Atracking_localhom( impmatch, currentw, lastverticalw, seq1, seq2, mseq1, mseq2, ijp, icyc, jcyc, warpis, warpjs, warpbase, &ngap1, &ngap2, reuseprofiles ); } else - Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc, tailgp ); + Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, ijp, icyc, jcyc, tailgp, warpis, warpjs, warpbase, &ngap1, &ngap2, reuseprofiles ); + +// reporterr( "reuseprofiles after Atracking = %d\n", reuseprofiles ); + + if( warpis ) free( warpis ); + if( warpjs ) free( warpjs ); // fprintf( stderr, "### impmatch = %f\n", *impmatch ); @@ -1408,8 +1481,11 @@ fprintf( stderr, "\n" ); } - for( i=0; i %d\n", strlen( seq1[0] ) ); + previousfirstlen = lgth1; + previousfirstmem = firstmem; + previousicyc = icyc; + previouscall = calledbyfulltreebase; return( wm ); } -float A__align_gapmap( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, int *gapmap1, int *gapmap2 ) +double A__align_gapmap( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, double *impmatch, int *gapmap1, int *gapmap2 ) /* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */ { + fprintf( stderr, "Unexpected error. Please contact kazutaka.katoh@aist.go.jp\n" ); + exit( 1 ); +} + + +double A__align_variousdist( int **which, double ***matrices, double **n_dynamicmtx, char **seq1, char **seq2, double *eff1, double *eff2, double **eff1s, double **eff2s, int icyc, int jcyc, int alloclen, LocalHom ***localhom, double *impmatch, char *sgap1, char *sgap2, char *egap1, char *egap2, int *chudanpt, int chudanref, int *chudanres, int headgp, int tailgp ) +/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */ +{ + + // int k; - register int i, j; - int lasti, lastj; /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */ + register int i, j, c; + int ngap1, ngap2; + int lasti, lastj; /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */ int lgth1, lgth2; int resultlen; - float wm = 0.0; /* int ?????? */ - float g; - float *currentw, *previousw; -// float fpenalty = (float)penalty; + double wm = 0.0; /* int ?????? */ + double g; + double *currentw, *previousw; +// double fpenalty = (double)penalty; #if USE_PENALTY_EX - float fpenalty_ex = (float)penalty_ex; + double fpenalty_ex = (double)penalty_ex; #endif #if 1 - float *wtmp; + double *wtmp; int *ijppt; - float *mjpt, *prept, *curpt; + double *mjpt, *prept, *curpt; int *mpjpt; #endif - static TLS float mi, *m; + static TLS double mi, *m; static TLS int **ijp; static TLS int mpi, *mp; - static TLS float *w1, *w2; - static TLS float *match; - static TLS float *initverticalw; /* kufuu sureba iranai */ - static TLS float *lastverticalw; /* kufuu sureba iranai */ + static TLS double *w1, *w2; + static TLS double *match; + static TLS double *initverticalw; /* kufuu sureba iranai */ + static TLS double *lastverticalw; /* kufuu sureba iranai */ static TLS char **mseq1; static TLS char **mseq2; static TLS char **mseq; - static TLS float *ogcp1; - static TLS float *ogcp2; - static TLS float *fgcp1; - static TLS float *fgcp2; - static TLS float **cpmx1; - static TLS float **cpmx2; - static TLS int **intwork; - static TLS float **floatwork; + static TLS double *ogcp1; + static TLS double *ogcp2; + static TLS double *fgcp1; + static TLS double *fgcp2; + static TLS double ***cpmx1s; + static TLS double ***cpmx2s; + static TLS int ***intwork; + static TLS double ***doublework; static TLS int orlgth1 = 0, orlgth2 = 0; - float *fgcp2pt; - float *ogcp2pt; - float fgcp1va; - float ogcp1va; + static TLS double *gapfreq1; + static TLS double *gapfreq2; + double fpenalty = (double)penalty; + double fpenalty_shift = (double)penalty_shift; + double *fgcp2pt; + double *ogcp2pt; + double fgcp1va; + double ogcp1va; + double *gf2pt; + double *gf2ptpre; + double gf1va; + double gf1vapre; + double headgapfreq1; + double headgapfreq2; + + int *warpis = NULL; + int *warpjs = NULL; + int *warpi = NULL; + int *warpj = NULL; + int *prevwarpi = NULL; + int *prevwarpj = NULL; + double *wmrecords = NULL; + double *prevwmrecords = NULL; + int warpn = 0; + int warpbase; + double curm = 0.0; + double *wmrecordspt, *wmrecords1pt, *prevwmrecordspt; + int *warpipt, *warpjpt; + int *nmask, **masklist1, **masklist2; -#if 0 - fprintf( stderr, "eff in SA+++align\n" ); - for( i=0; i orlgth1 || lgth2 > orlgth2 ) { int ll1, ll2; + if( orlgth1 > 0 && orlgth2 > 0 ) { FreeFloatVec( w1 ); @@ -1511,11 +1767,14 @@ float A__align_gapmap( char **seq1, char **seq2, double *eff1, double *eff2, int FreeFloatVec( fgcp2 ); - FreeFloatMtx( cpmx1 ); - FreeFloatMtx( cpmx2 ); + FreeFloatCub( cpmx1s ); + FreeFloatCub( cpmx2s ); - FreeFloatMtx( floatwork ); - FreeIntMtx( intwork ); + FreeFloatVec( gapfreq1 ); + FreeFloatVec( gapfreq2 ); + + FreeFloatCub( doublework ); + FreeIntCub( intwork ); } ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100; @@ -1542,16 +1801,14 @@ float A__align_gapmap( char **seq1, char **seq2, double *eff1, double *eff2, int fgcp1 = AllocateFloatVec( ll1+2 ); fgcp2 = AllocateFloatVec( ll2+2 ); - cpmx1 = AllocateFloatMtx( 26, ll1+2 ); - cpmx2 = AllocateFloatMtx( 26, ll2+2 ); + cpmx1s = AllocateFloatCub( maxdistclass, nalphabets, ll1+2 ); + cpmx2s = AllocateFloatCub( maxdistclass, nalphabets, ll2+2 ); -#if FASTMATCHCALC - floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 ); - intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 26 ); -#else - floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 ); - intwork = AllocateIntMtx( 27, MAX( ll1, ll2 )+2 ); -#endif + gapfreq1 = AllocateFloatVec( ll1+2 ); + gapfreq2 = AllocateFloatVec( ll2+2 ); + + doublework = AllocateFloatCub( maxdistclass, MAX( ll1, ll2 )+2, nalphabets ); + intwork = AllocateIntCub( maxdistclass, MAX( ll1, ll2 )+2, nalphabets+1 ); #if DEBUG fprintf( stderr, "succeeded\n" ); @@ -1601,23 +1858,87 @@ float A__align_gapmap( char **seq1, char **seq2, double *eff1, double *eff2, int } ijp = commonIP; - cpmx_calc_new( seq1, cpmx1, eff1, strlen( seq1[0] ), icyc ); - cpmx_calc_new( seq2, cpmx2, eff2, strlen( seq2[0] ), jcyc ); +#if 0 + { + double t = 0.0; + for( i=0; i tbfast.c if( localhom ) - imp_match_calc( currentw, icyc, jcyc, lgth1, lgth2, seq1, seq2, eff1, eff2, localhom, 1, 0 ); + imp_match_calc( n_dynamicmtx, currentw, icyc, jcyc, lgth1, lgth2, seq1, seq2, eff1, eff2, localhom, 1, 0 ); #endif - if( 1 ) // tsuneni outgap=1 + if( headgp == 1 ) { for( i=1; i", wm ); + fprintf( stderr, "%5.0f? (penal=%5.2f)", g=mi+*fgcp2pt*(1.0-gapfreq1[i]), *fgcp2pt*(1.0-gapfreq1[i]) ); #endif - g = mi + *fgcp2pt; -#if 0 - fprintf( stderr, "%5.0f?", g ); -#endif - if( g > wm ) + if( (g=mi+*fgcp2pt*gf1va) > wm ) { wm = g; *ijppt = -( j - mpi ); +// fprintf( stderr, "Jump to %d (%c)!", mpi, seq2[0][mpi] ); } - g = *prept + *ogcp2pt; - if( g >= mi ) + if( (g=*prept+*ogcp2pt*gf1vapre) >= mi ) { mi = g; mpi = j-1; @@ -1775,17 +2205,17 @@ fprintf( stderr, "\n" ); mi += fpenalty_ex; #endif - g = *mjpt + fgcp1va; #if 0 - fprintf( stderr, "%5.0f?", g ); + fprintf( stderr, "%5.0f->", wm ); + fprintf( stderr, "%5.0f? (penal=%5.2f)", g=*mjpt+fgcp1va*(1.0-gapfreq2[j]), fgcp1va*(1.0-gapfreq2[j]) ); #endif - if( g > wm ) + if( (g=*mjpt+ fgcp1va* *gf2pt) > wm ) { wm = g; *ijppt = +( i - *mpjpt ); +// fprintf( stderr, "Jump to %d (%c)!", *mpjpt, seq1[0][*mpjpt] ); } - g = *prept + ogcp1va; - if( g >= *mjpt ) + if( (g=*prept+ ogcp1va* *gf2ptpre) >= *mjpt ) { *mjpt = g; *mpjpt = i-1; @@ -1793,6 +2223,48 @@ fprintf( stderr, "\n" ); #if USE_PENALTY_EX m[j] += fpenalty_ex; #endif + if( trywarp ) + { +#if USE_PENALTY_EX + if( ( g=*prevwmrecordspt++ + fpenalty_shift + fpenalty_ex * ( i - prevwarpi[j-1] + j - prevwarpj[j-1] ) ) > wm ) // naka ha osokute kamawanai +#else + if( ( g=*prevwmrecordspt++ + fpenalty_shift ) > wm ) // naka ha osokute kamawanai +#endif + { + if( warpn && prevwarpi[j-1] == warpis[warpn-1] && prevwarpj[j-1] == warpjs[warpn-1] ) + { + *ijppt = warpbase + warpn - 1; + } + else + { + *ijppt = warpbase + warpn; + warpis = realloc( warpis, sizeof(int) * ( warpn+1 ) ); + warpjs = realloc( warpjs, sizeof(int) * ( warpn+1 ) ); + warpis[warpn] = prevwarpi[j-1]; + warpjs[warpn] = prevwarpj[j-1]; + warpn++; + } + wm = g; + } + curm = *curpt + wm; + + if( *wmrecords1pt > *wmrecordspt ) + { + *wmrecordspt = *wmrecords1pt; + *warpipt = *(warpipt-1); + *warpjpt = *(warpjpt-1); + } + if( curm > *wmrecordspt ) + { + *wmrecordspt = curm; + *warpipt = i; + *warpjpt = j; + } + wmrecordspt++; + wmrecords1pt++; + warpipt++; + warpjpt++; + } #if 0 fprintf( stderr, "%5.0f ", wm ); @@ -1804,9 +2276,31 @@ fprintf( stderr, "\n" ); mpjpt++; fgcp2pt++; ogcp2pt++; + gf2ptpre++; + gf2pt++; + } lastverticalw[i] = currentw[lgth2-1]; + + if( trywarp ) + { + fltncpy( prevwmrecords, wmrecords, lastj ); + intncpy( prevwarpi, warpi, lastj ); + intncpy( prevwarpj, warpj, lastj ); + } } + if( trywarp ) + { +// fprintf( stderr, "wm = %f\n", wm ); +// fprintf( stderr, "warpn = %d\n", warpn ); + free( wmrecords ); + free( prevwmrecords ); + free( warpi ); + free( warpj ); + free( prevwarpi ); + free( prevwarpj ); + } + #if OUTGAP0TRY if( !outgap ) @@ -1829,10 +2323,13 @@ fprintf( stderr, "\n" ); */ if( localhom ) { - Atracking_localhom_gapmap( impmatch, currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc, gapmap1, gapmap2 ); + Atracking_localhom( impmatch, currentw, lastverticalw, seq1, seq2, mseq1, mseq2, ijp, icyc, jcyc, warpis, warpjs, warpbase, &ngap1, &ngap2, 0 ); } else - Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc, 1 ); + Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, ijp, icyc, jcyc, tailgp, warpis, warpjs, warpbase, &ngap1, &ngap2, 0 ); + + if( warpis ) free( warpis ); + if( warpjs ) free( warpjs ); // fprintf( stderr, "### impmatch = %f\n", *impmatch ); @@ -1846,15 +2343,19 @@ fprintf( stderr, "\n" ); for( i=0; ialn0[%d] = \n%s\n", i, aln0[i] ); + for( i=0; ialn1[%d] = \n%s\n", i, aln1[i] ); + for( i=0; ialn2[%d] = \n%s\n", i, aln2[i] ); +#endif + + free( effarr0 ); + free( effarr2 ); + free( allgap0 ); + free( allgap2 ); +} + +static void profilealignment( int n0, int n1, int n2, char **aln0, char **aln1, char **aln2, int alloclen, char alg ) // n1 ha allgap +{ + int i, j, newlen; + double *effarr0 = NULL, *effarr2 = NULL; + int *allgap0 = NULL, *allgap2 = NULL; + double dumdb; + int alcount0, alcount2; + char *cptr; + +// effarr0 = AllocateDoubleVec( n0 ); +// effarr2 = AllocateDoubleVec( n2 ); +// allgap0 = AllocateIntVec( n0 ); +// allgap2 = AllocateIntVec( n2 ); +// + if( aln0[0][1] == 0 && aln2[0][1] == 0 ) return; // --allowshift no tokiha... + +// reporterr( "In profilealignment(), strlen( aln0[0] ) %d\n", strlen( aln0[0] ) ); +// reporterr( "In profilealignment(), strlen( aln2[0] ) %d\n", strlen( aln2[0] ) ); commongappick( n0, aln0 ); commongappick( n2, aln2 ); +// reporterr( "after commongappick, strlen( aln0[0] ) %d\n", strlen( aln0[0] ) ); +// reporterr( "after commongappick, strlen( aln2[0] ) %d\n", strlen( aln2[0] ) ); + +// reporterr( "\n\n\n" ); + + if( aln2[0][0] == 0 ) + { + newlen = j = strlen( aln0[0] ); + cptr = aln2[0]; + while( j-- ) *cptr++ = '-'; + *cptr = 0; + + cptr = aln2[0]; + for( i=1; ialn0[%d] = %s\n", i, aln0[i] ); + for( i=0; ialn1[%d] = %s\n", i, aln1[i] ); + for( i=0; ialn2[%d] = %s\n", i, aln2[i] ); +#endif + +#if 0 + fprintf( stderr, "in profilealignment, after commongappick\n" ); + for( i=0; ialn0[%d] = %s\n", i, aln0[i] ); + for( i=0; ialn1[%d] = %s\n", i, aln1[i] ); + for( i=0; ialn2[%d] = %s\n", i, aln2[i] ); +#endif + free( effarr0 ); free( effarr2 ); + free( allgap0 ); + free( allgap2 ); +} + +void eq2dashmatomete( char **s, int n ) +{ + int i, j; + char sj; + + for( j=0; (sj=s[0][j]); j++ ) + { + if( sj == '=' ) + { + for( i=0; i %d\n", j, j+blocklen-1 ); + j += (blocklen-1); + + + posin12 += (blocklen-1); + posin12++; } +#if 0 + fprintf( stderr, "\n" ); + for( i=0; i\n" ); + for( i=0; i-1; i++ ) { mar[k] = 1; @@ -293,145 +711,1141 @@ void restorecommongaps( int njob, char **seq, int *ex1, int *ex2, int *gaplen, i } for( i=0; (k=ex2[i])>-1; i++ ) { - mar[k] = 1; + mar[k] = 2; // fprintf( stderr, "excluding %d\n", ex2[i] ); } + ngroup2 = ngroup1 = ngroup0 = 0; for( i=0; i= len0 ) break; // iru? + + + for( i=0; i %d\n", j, j+blocklen-1 ); + + j += (blocklen-1); +// j += gaplen[j]; + + + posin12 += (blocklen-1); // sono aida ni gapmap wo miotosu? + + + posin12++; + +#if 0 + if( disp ) + { + gappick0equalminustmptmptmp( nogapseq1, aseq[list1[0]] ); + gappick0equalminustmptmptmp( nogapseq2, seq[list1[0]] ); + + reporterr( "aseq[list1[0].nogap = %s\n", nogapseq1 ); + reporterr( " seq[list1[0].nogap = %s\n", nogapseq2 ); + reporterr( "" ); +// reporterr( "seq[list1[0]] = %s\n", seq[list1[0]] ); +// reporterr( "seq[list2[0]] = %s\n", seq[list2[0]] ); + } +#endif + } +#if 0 + fprintf( stderr, "\n" ); + for( i=0; i\n" ); + for( i=0; iaseq1[%d], len = %d\n%s\n", list1[0], strlen( aseq[list1[0]] ), aseq[list0[0]] ); + reporterr( ">seq1[%d], len = %d\n%s\n", list1[0], strlen( seq[list1[0]] ), seq[list0[i]] ); + exit( 1 ); + + + for( i=0; iaseq0[%d], len = %d\n%s\n", list0[i], strlen( aseq[list0[i]] ), aseq[list0[i]] ); + for( i=0; iaseq1[%d], len = %d\n%s\n", list1[i], strlen( aseq[list1[i]] ), aseq[list1[i]] ); + for( i=0; iaseq2[%d], len = %d\n%s\n", list2[i], strlen( aseq[list2[i]] ), aseq[list2[i]] ); + + for( i=0; iseq0[%d], len = %d\n%s\n", list0[i], strlen( seq[list0[i]] ), seq[list0[i]] ); + for( i=0; iseq1[%d], len = %d\n%s\n", list1[i], strlen( seq[list1[i]] ), seq[list1[i]] ); + for( i=0; iseq2[%d], len = %d\n%s\n", list2[i], strlen( seq[list2[i]] ), seq[list2[i]] ); + exit( 1 ); + } + +#endif + +// for( i=0; i0; i-- ) // break ari no baai, migihajiha saigo + { + if( ref[i-1] == '+' && ( ref[i] != '+' && ref[i] != '=' ) && ref[i+1] == '=' ) + { +// reporterr( "hit! i=%d, len=%d\n", i, len ); + hit = realloc( hit, (nhit+1) * sizeof( int ) ); + hit[nhit] = i; + nhit += 1; +// break; + } + } + if( nhit == 0 ) return( 0 ); + + + for( k=0; k 1 ) exit( 1 ); + return( val ); +} + +static int smoothing1leftmulti( int len, char *ref ) // osoi! +{ + int i, j, k; + int shiftfrom = -1; + int shiftto = -1; + int *hit; + int val = 0, nhit = 0; + + hit = NULL; + +// reporterr( "ref (1leftmulti) = %s\n", ref ); + + for( i=1, nhit=0; i0; i-- ) // break ari no baai, migihajiha saigo + { + if( ref[i-1] == '=' && ( ref[i] != '+' && ref[i] != '=' ) && ref[i+1] == '+' ) + { +// reporterr( "hit! i=%d, len=%d\n", i, len ); + hit = realloc( hit, (nhit+1) * sizeof( int ) ); + hit[nhit] = i; + nhit += 1; +// break; + } + } + if( nhit == 0 ) return( 0 ); + + for( k=0; k-1; j-- ) + { + if( ref[j] != '=' ) + { + shiftto = j+1; + break; + } + } + if( j == -1 && ref[0] == '=' ) + { + reporterr( "hit[i].end = %d, j = -1, skip!\n" ); + continue; + } + + if( shiftto > 0 && ref[shiftto-1] == '+' ) continue; // muda dakara + + val += 1; + shiftfrom = hit[k]; + if( ref[shiftto] != '=' ) // atode sakujo + { + reporterr( "Error in smoothing1left!\n" ); + exit( 1 ); + } + ref[shiftto] = ref[shiftfrom]; + ref[shiftfrom] = '='; + + } + free( hit ); + +// reporterr( "ref (1leftmulti) = %s\n", ref ); + reporterr( " %d out of %d have been smoothed (left).\n", val, nhit ); + + +// if( nhit > 1 ) exit( 1 ); + return( val ); +} + +void restorecommongapssmoothly( int njob, int n0, char **seq, int *ex1, int *ex2, int *gapmap, int alloclen, char gapchar ) +{ + int *mem; + char *tmpseq; + char *cptr; + int *iptr; + int *tmpgapmap; + int i, j, k, len, rep1, rep2, len1, klim, leninserted; + int totalres; + + if( n0 == 0 ) return; + + + mem = calloc( njob+1, sizeof( int ) ); // +1 ha iranai. + intcpy( mem, ex1 ); + intcat( mem, ex2 ); +// tmpseq = calloc( alloclen+2, sizeof( char ) ); +// tmpgapmap = calloc( alloclen+2, sizeof( int ) ); + +#if 0 // iranai + for( i=0; (k=mem[i])!=-1; i++ ) // iranai + reporterr( "mem[%d] = %d\n", i, k ); // iranai + if( i == njob ) // iranai + { + fprintf( stderr, "Error in restorecommongaps()\n" ); + free( mem ); + exit( 1 ); + } +#endif + rep1 = ex1[0]; + rep2 = ex2[0]; + len = strlen( seq[rep1] ); + len1 = len+1; + + tmpseq = calloc( alloclen, sizeof( char ) ); + tmpgapmap = calloc( alloclen, sizeof( int ) ); #if 0 - fprintf( stderr, "mem = " ); - for( i=0; mem[i]>-1; i++ ) fprintf( stderr, "%d ", mem[i] ); - fprintf( stderr, "\n" ); + reporterr( "\n" ); + reporterr( "seq[rep1] = %s\n", seq[rep1] ); + reporterr( "seq[rep2] = %s\n", seq[rep2] ); +#endif - fprintf( stderr, "cand = " ); - for( i=0; cand[i]>-1; i++ ) fprintf( stderr, "%d ", cand[i] ); - fprintf( stderr, "\n" ); + for( k=0; (i=mem[k])!=-1; k++ ) + { + cptr = tmpseq; + for( j=0; j\n" ); + reporterr( "seq[rep1] = \n%s\n", seq[rep1] ); + reporterr( "seq[rep2] = \n%s\n", seq[rep2] ); #endif - for( i=0, j=0; mem[i]>-1; ) + leninserted = strlen( seq[rep1] ); +#if 0 + reporterr( "gapmap =\n" ); + for(j=0; j0; i-- ) reporterr( "-" ); } + reporterr( "\n" ); +#endif - if( cand[j] == -1 ) +#if 0 + resprev = 10000; // tekitou + while( 1 ) { - return( 1 ); + res = 0; +// reporterr( "\nsmoothing1right..\n" ); + res = (0= resprev ) break; +// if( res == 0 ) break; + resprev = res; } - else +#else + totalres = 0; + totalres += smoothing1rightmulti( leninserted, seq[rep1] ); + totalres += smoothing1leftmulti( leninserted, seq[rep1] ); + if( totalres ) reflectsmoothing( seq[rep1], ex1, seq, leninserted ); + + totalres = 0; + totalres += smoothing1rightmulti( leninserted, seq[rep2] ); + totalres += smoothing1leftmulti( leninserted, seq[rep2] ); + if( totalres ) reflectsmoothing( seq[rep2], ex2, seq, leninserted ); +#endif + + for( k=0; (i=mem[k])!=-1; k++ ) plus2gapchar( seq[i], gapchar ); + +#if 0 + reporterr( "->\n" ); + reporterr( "seq[rep1] = \n%s\n", seq[rep1] ); + reporterr( "seq[rep2] = \n%s\n", seq[rep2] ); + reporterr( "gapmap =\n" ); + for(j=0; j0; i-- ) reporterr( "-" ); + } + reporterr( "\n" ); +#endif + + iptr = tmpgapmap; + for( j=0; j-1; i++ ) nm++; - nc = 0; for( i=0; cand[i]>-1; i++ ) nc++; - if( nm != nc ) return( 0 ); - for( i=0; mem[i]>-1; i++ ) + for( k=0; (i=mem[k])!=-1; k++ ) { - for( j=0; cand[j]>-1; j++ ) - if( mem[i] == cand[j] ) break; - if( cand[j] == -1 ) return( 0 ); + cptr = tmpseq; + for( j=0; j-1; i++ ) +void reconstructdeletemap( int nadd, char **addbk, int **deletelist, char **realn, FILE *fp, char **name ) +{ + int i, j, p, len; + char *gapped, *nameptr, *tmpptr; + + for( i=0; i-1; j++ ) - if( mem[i] == cand[j] ) break; - if( cand[j] == -1 ) return( 0 ); + len = strlen( addbk[i] ); + gapped = calloc( len+1, sizeof( char ) ); +// for( j=0; j _ no tame + + fprintf( fp, ">%s\n", nameptr ); + fprintf( fp, "# letter, position in the original sequence, position in the reference alignment\n" ); + +// reporterr( "addbk[%d] = %s\n", i, addbk[i] ); + for( j=0; (p=deletelist[i][j])!=-1; j++ ) + { +// reporterr( "deleting %d, %c\n", p, addbk[i][p] ); + gapped[p] = '-'; + } + +// reporterr( "addbk = %s\n", addbk[i] ); +// reporterr( "gapped = %s\n", gapped ); + + for( j=0,p=0; j 2bai +static int allowlongadds; +static int keeplength; +static int ndeleted; +static int mapout; +static int smoothing; +static double hitout; + +static int tuplesize; + +#define PLENFACA 0.01 +#define PLENFACB 10000 +#define PLENFACC 10000 +#define PLENFACD 0.1 +#define D6LENFACA 0.01 +#define D6LENFACB 2500 +#define D6LENFACC 2500 +#define D6LENFACD 0.1 +#define D10LENFACA 0.01 +#define D10LENFACB 1000000 +#define D10LENFACC 1000000 +#define D10LENFACD 0.0 + +typedef struct _thread_arg +{ + int njob; + int nadd; + int *nlen; + int *follows; + char **name; + char **seq; + LocalHom **localhomtable; + double **iscore; + double **nscore; + int *istherenewgap; + int **newgaplist; + RNApair ***singlerna; + double *eff_kozo_mapped; + int alloclen; + Treedep *dep; + int ***topol; + double **len; + Addtree *addtree; + int **deletelist; +#ifdef enablemultithread + int *iaddshare; + int thread_no; + pthread_mutex_t *mutex_counter; +#endif +} thread_arg_t; + + +#ifdef enablemultithread +typedef struct _gaplist2alnxthread_arg +{ +// int thread_no; + int ncycle; + int *jobpospt; + int tmpseqlen; + int lenfull; + char **seq; + int *newgaplist; + int *posmap; + pthread_mutex_t *mutex; +} gaplist2alnxthread_arg_t; + +typedef struct _distancematrixthread_arg +{ + int thread_no; + int njob; + int norg; + int *jobpospt; + int **pointt; + int *nogaplen; + double **imtx; + double **nmtx; + double *selfscore; + pthread_mutex_t *mutex; +} distancematrixthread_arg_t; + +typedef struct _jobtable2d +{ + int i; + int j; +} Jobtable2d; + +typedef struct _dndprethread_arg +{ + int njob; + int thread_no; + double *selfscore; + double **mtx; + char **seq; + Jobtable2d *jobpospt; + pthread_mutex_t *mutex; +} dndprethread_arg_t; + +#endif + +typedef struct _blocktorealign +{ + int start; + int end; + int nnewres; +} Blocktorealign; + +static void cnctintvec( int *res, int *o1, int *o2 ) +{ + while( *o1 != -1 ) *res++ = *o1++; + while( *o2 != -1 ) *res++ = *o2++; + *res = -1; +} + +static void countnewres( int len, Blocktorealign *realign, int *posmap, int *gaplist ) +{ + int i, regstart, regend, len1; + regstart = 0; + len1 = len+1; + for( i=0; i lenb ) return -1; + else if( lena < lenb ) return 1; + else return( 0 ); +} + +static int dorealignment_tree( Blocktorealign *block, char **fullseq, int *fullseqlenpt, int norg, int ***topol, int *follows ) +{ + int i, j, k, posinold, newlen, *nmem; + int n0, n1, localloclen, nhit, hit1, hit2; + int *pickhistory; + int nprof1, nprof2, pos, zure; + char **prof1, **prof2; + int *iinf0, *iinf1; + int *group, *nearest, *g2n, ngroup; + char ***mem; + static char **tmpaln0 = NULL; + static char **tmpaln1 = NULL; + static char **tmpseq; + int ***topolpick; + int *tmpint; + int *intptr, *intptrx; + char *tmpseq0, *cptr, **cptrptr; + + + localloclen = 4 * ( block->end - block->start + 1 ); // ookisugi? + tmpaln0 = AllocateCharMtx( njob, localloclen ); + tmpaln1 = AllocateCharMtx( njob, localloclen ); + tmpseq = AllocateCharMtx( 1, *fullseqlenpt * 4 ); + iinf0 = AllocateIntVec( njob ); + iinf1 = AllocateIntVec( njob ); + nearest = AllocateIntVec( njob ); // oosugi + + posinold = block->start; + + n0 = 0; + n1 = 0; + for( i=0; istart, block->end - block->start + 1 ); + tmpseq[0][block->end - block->start + 1] = 0; + commongappick( 1, tmpseq ); + if( tmpseq[0][0] != 0 ) + { + if( i < norg ) + { + fprintf( stderr, "BUG!!!!\n" ); + exit( 1 ); + } + strcpy( tmpaln0[n0], tmpseq[0] ); + iinf0[n0] = i; + nearest[n0] = follows[i-norg]; + n0++; + } + else + { + strcpy( tmpaln1[n0], "" ); + iinf1[n1] = i; + n1++; + } + } + mem = AllocateCharCub( n0, n0+1, 0 ); // oosugi + nmem = AllocateIntVec( n0 ); // oosugi + g2n = AllocateIntVec( n0 ); // oosugi + group = AllocateIntVec( n0 ); // oosugi + for( i=0; i %d -> group%d\n", i, nearest[i], group[i] ); +// fprintf( stderr, "mem[%d][%d] = %s\n", group[i], j, mem[group[i]][j] ); + } + + for( i=0; i newlen ) newlen = j; + for( j=0; j<=i; j++ ) + { + for( k=0; mem[j][k]; k++ ) + fillgap( mem[j][k], newlen ); + } +#endif + + } +#if 0 + fprintf( stderr, "After ingroupalignment (original order):\n" ); + for( i=0; i-1; intptr++ ) + { + for( intptrx=g2n,k=0; k %d\n", k, topol[i][0][j] ); + + for( intptr=topol[i][1]; *intptr>-1; intptr++ ) + { + for( intptrx=g2n,k=0; k %d\n", k, topol[i][1][j] ); + +#if 0 + fprintf( stderr, "\nHIT!!! \n" ); + fprintf( stderr, "\nSTEP %d\n", i ); + for( j=0; topol[i][0][j]>-1; j++ ) fprintf( stderr, "%3d ", topol[i][0][j] ); + fprintf( stderr, "\n" ); + for( j=0; topol[i][1][j]>-1; j++ ) fprintf( stderr, "%3d ", topol[i][1][j] ); + fprintf( stderr, "\n" ); +#endif + } + + for( i=0; i-1; j++ ) fprintf( stderr, "%3d ", topolpick[i][0][j] ); + fprintf( stderr, "\n" ); + for( j=0; topolpick[i][1][j]>-1; j++ ) fprintf( stderr, "%3d ", topolpick[i][1][j] ); + fprintf( stderr, "\n" ); +#endif + + pos = 0; +// for( j=0; topolpick[i][0][j]>-1; j++ ) for( k=0; (cptr=mem[topolpick[i][0][j]][k]); k++ ) prof1[pos++] = cptr; + for( intptr=topolpick[i][0]; *intptr>-1; intptr++ ) + for( cptrptr=mem[*intptr]; (cptr=*cptrptr); cptrptr++ ) + prof1[pos++] = cptr; + nprof1 = pos; + pos = 0; +// for( j=0; topolpick[i][1][j]>-1; j++ ) for( k=0; (cptr=mem[topolpick[i][1][j]][k]); k++ ) prof2[pos++] = cptr; + for( intptr=topolpick[i][1]; *intptr>-1; intptr++ ) + for( cptrptr=mem[*intptr]; (cptr=*cptrptr); cptrptr++ ) + prof2[pos++] = cptr; + nprof2 = pos; + + + profilealignment2( nprof1, nprof2, prof1, prof2, localloclen, alg ); +#if 0 + for( j=0; jend - block->start + 1 - newlen ); +// fprintf( stderr, "zure = %d, localloclen=%d, newlen=%d\n", zure, localloclen, newlen ); + + + if( *fullseqlenpt < strlen( fullseq[0] ) - (block->end-block->start+1) + newlen + 1 ) + { + *fullseqlenpt = strlen( fullseq[0] ) * 2; + fprintf( stderr, "reallocating..." ); + for( i=0; iend+1; + for( i=0; istart, tmpseq0 ); + } + for( i=0; istart, tmpseq0 ); + } + FreeCharMtx( tmpaln0 ); + FreeCharMtx( tmpaln1 ); + FreeCharMtx( tmpseq ); + for( i=0; istart; + + + n0 = 0; + n1 = 0; + for( i=0; istart, block->end - block->start + 1 ); + tmpseq[0][block->end - block->start + 1] = 0; + commongappick( 1, tmpseq ); +// if( strlen( tmpseq[0] ) > 0 ) + if( tmpseq[0][0] != 0 ) + { + if( i < norg ) + { + fprintf( stderr, "BUG!!!!\n" ); + exit( 1 ); + } + strcpy( tmpaln0[n0], tmpseq[0] ); + iinf0[n0] = i; + n0++; + } + else + { + strcpy( tmpaln1[n0], "" ); + iinf1[n1] = i; + n1++; + } + } + + + for( i=1; istart, tmpaln0[i], newlen ); + for( i=0; istart, tmpaln1[i], newlen ); + } + + posinold = block->end+1; + posinnew = block->start + newlen; + + + zure = ( block->end - block->start + 1 - strlen( tmpaln0[0] ) ); + + for( i=0; i 0 && l[i] > 0 ) + { + if( pg < l[i] ) + { + c[i] = l[i] - pg; + } + else + { + c[i] = 0; + } + } + else + { + c[i] = l[i]; + } + prep = p[i]; + } +} + + +void gaplist2alnx( int len, char *a, char *s, int *l, int *p, int lenlimit ) +{ + int gaplen; + int pos, pi, posl; + int prevp = -1; + int reslen = 0; + char *sp; +// char *abk = a; + +#if 0 + int i; + char *abk = a; + fprintf( stderr, "s = %s\n", s ); + fprintf( stderr, "posmap = " ); + for( i=0; i lenlimit ) + { + fprintf( stderr, "Length over. Please recompile!\n" ); + exit( 1 ); + } + while( gaplen-- ) *a++ = '-'; + + pos = prevp + 1; + sp = s + pos; + if( ( posl = pi - pos ) ) + { + if( ( reslen += posl ) > lenlimit ) + { + fprintf( stderr, "Length over. Please recompile\n" ); + exit( 1 ); + } + while( posl-- ) *a++ = *sp++; + } + + if( reslen++ > lenlimit ) + { + fprintf( stderr, "Length over. Please recompile\n" ); + exit( 1 ); + } + *a++ = *sp; + prevp = pi; + } + + gaplen = *l; + pi = *p; + if( (reslen+=gaplen) > lenlimit ) + { + fprintf( stderr, "Length over. Please recompile\n" ); + exit( 1 ); + } + while( gaplen-- ) *a++ = '-'; + + pos = prevp + 1; + sp = s + pos; + if( ( posl = pi - pos ) ) + { + if( ( reslen += posl ) > lenlimit ) + { + fprintf( stderr, "Length over. Please recompile\n" ); + exit( 1 ); + } + while( posl-- ) *a++ = *sp++; + } + *a = 0; +// fprintf( stderr, "reslen = %d, strlen(a) = %d\n", reslen, strlen( abk ) ); +// fprintf( stderr, "a = %s\n", abk ); +} + +static void makenewgaplist( int *l, char *a ) +{ + while( 1 ) + { + while( *a == '=' ) + { + a++; + (*l)++; +// fprintf( stderr, "a[] (i) = %s, *l=%d\n", a, *(l) ); + } + *++l = 0; + if( *a == 0 ) break; + a++; + } + *l = -1; +} + + +void arguments( int argc, char *argv[] ) +{ + int c; + + nthread = 1; + outnumber = 0; + scoreout = 0; + treein = 0; + topin = 0; + rnaprediction = 'm'; + rnakozo = 0; + nevermemsave = 0; + inputfile = NULL; + addfile = NULL; + addprofile = 1; + fftkeika = 0; + constraint = 0; + nblosum = 62; + fmodel = 0; + calledByXced = 0; + devide = 0; + use_fft = 0; // chuui + force_fft = 0; + fftscore = 1; + fftRepeatStop = 0; + fftNoAnchStop = 0; + weight = 3; + utree = 1; + tbutree = 1; + refine = 0; + check = 1; + cut = 0.0; + disp = 0; + outgap = 1; + alg = 'A'; + mix = 0; + tbitr = 0; + scmtd = 5; + tbweight = 0; + tbrweight = 3; + checkC = 0; + treemethod = 'X'; + sueff_global = 0.1; + contin = 0; + scoremtx = 1; + kobetsubunkatsu = 0; + dorp = NOTSPECIFIED; + ppenalty = NOTSPECIFIED; + penalty_shift_factor = 1000.0; + ppenalty_ex = NOTSPECIFIED; + poffset = NOTSPECIFIED; + kimuraR = NOTSPECIFIED; + pamN = NOTSPECIFIED; + geta2 = GETA2; + fftWinSize = NOTSPECIFIED; + fftThreshold = NOTSPECIFIED; + RNAppenalty = NOTSPECIFIED; + RNAppenalty_ex = NOTSPECIFIED; + RNApthr = NOTSPECIFIED; + TMorJTT = JTT; + consweight_multi = 1.0; + consweight_rna = 0.0; + nadd = 0; + multidist = 0; + tuplesize = -1; + legacygapcost = 0; + allowlongadds = 0; + keeplength = 0; + mapout = 0; + smoothing = 0; + distout = 0; + hitout = 0.0; + nwildcard = 0; + + while( --argc > 0 && (*++argv)[0] == '-' ) + { + while ( ( c = *++argv[0] ) ) + { + switch( c ) + { + case 'i': + inputfile = *++argv; + fprintf( stderr, "inputfile = %s\n", inputfile ); + --argc; + goto nextoption; + case 'I': + nadd = myatoi( *++argv ); + fprintf( stderr, "nadd = %d\n", nadd ); + --argc; + goto nextoption; + case 'e': + RNApthr = (int)( atof( *++argv ) * 1000 - 0.5 ); + --argc; + goto nextoption; + case 'o': + RNAppenalty = (int)( atof( *++argv ) * 1000 - 0.5 ); + --argc; + goto nextoption; + case 'f': + ppenalty = (int)( atof( *++argv ) * 1000 - 0.5 ); +// fprintf( stderr, "ppenalty = %d\n", ppenalty ); + --argc; + goto nextoption; + case 'Q': + penalty_shift_factor = atof( *++argv ); + --argc; + goto nextoption; + case 'g': + ppenalty_ex = (int)( atof( *++argv ) * 1000 - 0.5 ); + fprintf( stderr, "ppenalty_ex = %d\n", ppenalty_ex ); + --argc; + goto nextoption; + case 'h': + poffset = (int)( atof( *++argv ) * 1000 - 0.5 ); +// fprintf( stderr, "poffset = %d\n", poffset ); + --argc; + goto nextoption; + case 'k': + kimuraR = myatoi( *++argv ); + fprintf( stderr, "kappa = %d\n", kimuraR ); + --argc; + goto nextoption; + case 'b': + nblosum = myatoi( *++argv ); + scoremtx = 1; + fprintf( stderr, "blosum %d / kimura 200\n", nblosum ); + --argc; + goto nextoption; + case 'j': + pamN = myatoi( *++argv ); + scoremtx = 0; + TMorJTT = JTT; + fprintf( stderr, "jtt/kimura %d\n", pamN ); + --argc; + goto nextoption; + case 'm': + pamN = myatoi( *++argv ); + scoremtx = 0; + TMorJTT = TM; + fprintf( stderr, "tm %d\n", pamN ); + --argc; + goto nextoption; + case 'l': + fastathreshold = atof( *++argv ); + constraint = 2; + --argc; + goto nextoption; + case 'r': + consweight_rna = atof( *++argv ); + rnakozo = 1; + --argc; + goto nextoption; + case 'c': + consweight_multi = atof( *++argv ); + --argc; + goto nextoption; + case 'C': + nthread = myatoi( *++argv ); + fprintf( stderr, "nthread = %d\n", nthread ); + --argc; + goto nextoption; +#if 0 + case 'R': + rnaprediction = 'r'; + break; + case 's': + RNAscoremtx = 'r'; + break; +#endif +#if 1 + case 'a': + fmodel = 1; + break; +#endif + case 'K': + addprofile = 0; + break; + case 'y': + distout = 1; + break; + case '^': + hitout = atof( *++argv ); + --argc; + goto nextoption; + case 't': + treeout = 1; + break; + case 'T': + noalign = 1; + break; + case 'D': + dorp = 'd'; + break; + case 'P': + dorp = 'p'; + break; +#if 1 + case 'O': + outgap = 0; + break; +#else + case 'O': + fftNoAnchStop = 1; + break; +#endif + case 'S': + scoreout = 1; + break; +#if 0 + case 'e': + fftscore = 0; + break; + case 'r': + fmodel = -1; + break; + case 'R': + fftRepeatStop = 1; + break; + case 's': + treemethod = 's'; + break; +#endif + case 'X': + treemethod = 'X'; + sueff_global = atof( *++argv ); + fprintf( stderr, "sueff_global = %f\n", sueff_global ); + --argc; + goto nextoption; + case 'E': + treemethod = 'E'; + break; + case 'q': + treemethod = 'q'; + break; + case 'n' : + outnumber = 1; + break; +#if 0 + case 'a': + alg = 'a'; + break; + case 'Q': + alg = 'Q'; + break; +#endif + case 'H': + alg = 'H'; + break; + case 'A': + alg = 'A'; + break; + case 'M': + alg = 'M'; + break; + case 'N': + nevermemsave = 1; + break; + case 'B': // hitsuyou! memopt -M -B no tame + break; + case 'F': + use_fft = 1; + break; + case 'G': + force_fft = 1; + use_fft = 1; + break; + case 'U': + treein = 1; + break; + case 'V': + allowlongadds = 1; + break; + case 'p': + smoothing = 1; + break; +#if 0 + case 'V': + topin = 1; + break; +#endif + case 'u': + tbrweight = 0; + weight = 0; + break; + case 'v': + tbrweight = 3; + break; + case 'd': + multidist = 1; + break; + case 'W': + tuplesize = myatoi( *++argv ); + --argc; + goto nextoption; +#if 0 + case 'd': + disp = 1; + break; +#endif +/* Modified 01/08/27, default: user tree */ + case 'J': + tbutree = 0; + break; +/* modification end. */ + case 'z': + fftThreshold = myatoi( *++argv ); + --argc; + goto nextoption; + case 'w': + fftWinSize = myatoi( *++argv ); + --argc; + goto nextoption; +#if 0 + case 'Z': + checkC = 1; + break; +#endif + case 'L': + legacygapcost = 1; + break; + case 'Y': + keeplength = 1; + break; + case 'Z': + mapout = 1; + break; + case ':': + nwildcard = 1; + break; + default: + fprintf( stderr, "illegal option %c\n", c ); + argc = 0; + break; + } + } + nextoption: + ; + } + if( argc == 1 ) + { + cut = atof( (*argv) ); + argc--; + } + if( argc != 0 ) + { + fprintf( stderr, "options: Check source file !\n" ); + exit( 1 ); + } + if( tbitr == 1 && outgap == 0 ) + { + fprintf( stderr, "conflicting options : o, m or u\n" ); + exit( 1 ); + } + if( alg == 'C' && outgap == 0 ) + { + fprintf( stderr, "conflicting options : C, o\n" ); + exit( 1 ); + } +} + + +static double treebase( int nseq, int *nlen, char **aseq, int nadd, char *mergeoralign, char **mseq1, char **mseq2, int ***topol, double *effarr, int *alloclen, LocalHom **localhomtable, RNApair ***singlerna, double *effarr_kozo ) +{ + + int i, l, m; + int len1nocommongap, len2nocommongap; + int len1, len2; + int clus1, clus2; + double pscore, tscore; + char *indication1, *indication2; + double *effarr1 = NULL; + double *effarr2 = NULL; + double *effarr1_kozo = NULL; + double *effarr2_kozo = NULL; + LocalHom ***localhomshrink = NULL; + int *fftlog; + int m1, m2; + int *gaplen; + int *gapmap; + int *alreadyaligned; +// double dumfl = 0.0; + double dumdb = 0.0; + int ffttry; + RNApair ***grouprna1, ***grouprna2; + + if( rnakozo && rnaprediction == 'm' ) + { + grouprna1 = (RNApair ***)calloc( nseq, sizeof( RNApair ** ) ); + grouprna2 = (RNApair ***)calloc( nseq, sizeof( RNApair ** ) ); + } + else + { + grouprna1 = grouprna2 = NULL; + } + + fftlog = AllocateIntVec( nseq ); + effarr1 = AllocateDoubleVec( nseq ); + effarr2 = AllocateDoubleVec( nseq ); + indication1 = AllocateCharVec( 150 ); + indication2 = AllocateCharVec( 150 ); + alreadyaligned = AllocateIntVec( nseq ); + if( constraint ) + { + localhomshrink = (LocalHom ***)calloc( nseq, sizeof( LocalHom ** ) ); +#if SMALLMEMORY + if( multidist ) + { + for( i=0; i 66 ) fprintf( stderr, "..." ); + fprintf( stderr, "\n" ); + fprintf( stderr, "group2 = %.66s", indication2 ); + if( strlen( indication2 ) > 66 ) fprintf( stderr, "..." ); + fprintf( stderr, "\n" ); +#endif + + + +// for( i=0; i 30000 || len2 > 30000 ) ) ) + { + fprintf( stderr, "\nlen1=%d, len2=%d, Switching to the memsave mode.\n", len1, len2 ); + alg = 'M'; + if( commonIP ) FreeIntMtx( commonIP ); + commonIP = NULL; // 2013/Jul17 + commonAlloc1 = 0; + commonAlloc2 = 0; + } + + +// if( fftlog[m1] && fftlog[m2] ) ffttry = ( nlen[m1] > clus1 && nlen[m2] > clus2 ); + if( fftlog[m1] && fftlog[m2] ) ffttry = ( nlen[m1] > clus1 && nlen[m2] > clus2 && clus1 < 1000 && clus2 < 1000 ); + else ffttry = 0; +// ffttry = ( nlen[m1] > clus1 && nlen[m2] > clus2 && clus1 < 5000 && clus2 < 5000 ); // v6.708 +// fprintf( stderr, "f=%d, len1/fftlog[m1]=%f, clus1=%d, len2/fftlog[m2]=%f, clus2=%d\n", ffttry, (double)len1/fftlog[m1], clus1, (double)len2/fftlog[m2], clus2 ); +// fprintf( stderr, "f=%d, clus1=%d, fftlog[m1]=%d, clus2=%d, fftlog[m2]=%d\n", ffttry, clus1, fftlog[m1], clus2, fftlog[m2] ); + if( constraint == 2 ) + { + if( alg == 'M' ) + { + fprintf( stderr, "\n\nMemory saving mode is not supported.\n\n" ); + exit( 1 ); + } + fprintf( stderr, "c" ); + if( alg == 'A' ) + { + imp_match_init_strict( NULL, clus1, clus2, strlen( mseq1[0] ), strlen( mseq2[0] ), mseq1, mseq2, effarr1, effarr2, effarr1_kozo, effarr2_kozo, localhomshrink, NULL, 1, topol[l][0], topol[l][1] ); + if( rnakozo ) imp_rna( clus1, clus2, mseq1, mseq2, effarr1, effarr2, grouprna1, grouprna2, NULL, NULL, NULL ); + pscore = A__align( n_dis_consweight_multi, mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, localhomshrink, &dumdb, NULL, NULL, NULL, NULL, NULL, 0, NULL, outgap, outgap, -1, -1 ); + } + else if( alg == 'Q' ) + { + fprintf( stderr, "Q has been disabled.\n" ); + exit( 1 ); + } + } + else if( force_fft || ( use_fft && ffttry ) ) + { + fprintf( stderr, "f" ); + if( alg == 'M' ) + { + fprintf( stderr, "m" ); + pscore = Falign_udpari_long( NULL, NULL, n_dis_consweight_multi, mseq1, mseq2, effarr1, effarr2, NULL, NULL, clus1, clus2, *alloclen, fftlog+m1 ); + } + else + pscore = Falign( NULL, NULL, n_dis_consweight_multi, mseq1, mseq2, effarr1, effarr2, NULL, NULL, clus1, clus2, *alloclen, fftlog+m1, NULL, 0, NULL ); + } + else + { + fprintf( stderr, "d" ); + fftlog[m1] = 0; + switch( alg ) + { + case( 'a' ): + pscore = Aalign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen ); + break; + case( 'M' ): + fprintf( stderr, "m" ); + pscore = MSalignmm( n_dis_consweight_multi, mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, NULL, NULL, NULL, NULL, 0, NULL, outgap, outgap ); + break; + case( 'A' ): + pscore = A__align( n_dis_consweight_multi, mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, &dumdb, NULL, NULL, NULL, NULL, NULL, 0, NULL, outgap, outgap, -1, -1 ); + break; + default: + ErrorExit( "ERROR IN SOURCE FILE" ); + } + } + + + nlen[m1] = 0.5 * ( nlen[m1] + nlen[m2] ); + +// fprintf( stderr, "aseq[last] = %s\n", aseq[nseq-1] ); + +#if SCOREOUT + fprintf( stderr, "score = %10.2f\n", pscore ); +#endif + tscore += pscore; +#if 0 // New gaps = '=' + fprintf( stderr, "Original msa\n" ); + for( i=0; i-1; i++ ) alreadyaligned[m] = 1; + } + if( mergeoralign[l] == '2' ) + { +// if( deleteadditionalinsertions ) ndeleted += deletenewinsertions( clus1, clus2, mseq1, mseq2, deleterecord ); + adjustgapmap( strlen( mseq1[0] )-len1nocommongap+len1, gapmap, mseq1[0] ); + restorecommongaps( nseq, nseq-(clus1+clus2), aseq, topol[l][0], topol[l][1], gapmap, *alloclen, '-' ); + findnewgaps( clus1, 0, mseq1, gaplen ); + insertnewgaps( nseq, alreadyaligned, aseq, topol[l][0], topol[l][1], gaplen, gapmap, *alloclen, alg, '-' ); +// for( i=0; i-1; i++ ) alreadyaligned[m] = 1; + } + +#if 0 + free( topol[l][0] ); + free( topol[l][1] ); + free( topol[l] ); +#endif + } + +//for( i=0; ithread_no; + int *iaddshare = targ->iaddshare; +#endif + int njob = targ->njob; + int *follows = targ->follows; + int nadd = targ->nadd; + int *nlen = targ->nlen; + char **name = targ->name; + char **seq = targ->seq; + LocalHom **localhomtable = targ->localhomtable; + double **iscore = targ->iscore; + double **nscore = targ->nscore; + int *istherenewgap = targ->istherenewgap; + int **newgaplist = targ->newgaplist; + RNApair ***singlerna = targ->singlerna; + double *eff_kozo_mapped = targ->eff_kozo_mapped; + int alloclen = targ->alloclen; + Treedep *dep = targ->dep; + int ***topol = targ->topol; + double **len = targ->len; + Addtree *addtree = targ->addtree; + int **deletelist = targ->deletelist; + double pscore; + int *alnleninnode = NULL; + char *targetseq; + + + +// fprintf( stderr, "\nPreparing thread %d\n", thread_no ); + norg = njob - nadd; + njobc = norg+1; + + alnleninnode = AllocateIntVec( norg ); + addmem = AllocateIntVec( nadd+1 ); + depc = (Treedep *)calloc( njobc, sizeof( Treedep ) ); + mseq1 = AllocateCharMtx( njob, 0 ); + mseq2 = AllocateCharMtx( njob, 0 ); + bseq = AllocateCharMtx( njobc, alloclen ); + namec = AllocateCharMtx( njob, 0 ); + nlenc = AllocateIntVec( njob ); + mergeoralign = AllocateCharVec( njob ); + nogaplenjusttodecideaddhereornot = AllocateIntVec( njobc ); + tmpseq = calloc( alloclen, sizeof( char ) ); + + if( allowlongadds ) // hontou ha iranai. + { + for( i=0; i=0; i-- ) +// for( i=norg-2; i; i-- ) // BUG!!!! + { +// reporterr( "\nstep %d\n", i ); + k = 0; + for( j=0; (m=topol[i][0][j])!=-1; j++ ) + { + mseq1[k++] = bseq[m]; +// reporterr( "%d ", m ); + } + for( j=0; (m=topol[i][1][j])!=-1; j++ ) + { + mseq1[k++] = bseq[m]; +// reporterr( "%d ", m ); + } +// reporterr( "\n" ); + commongappick( k, mseq1 ); + alnleninnode[i] = strlen( mseq1[0] ); +// fprintf( stderr, "alnleninnode[%d] = %d\n", i, alnleninnode[i] ); + } + } +// for( i=0; imutex_counter ); + iadd = *iaddshare; + if( iadd == nadd ) + { + pthread_mutex_unlock( targ->mutex_counter ); + break; + } + fprintf( stderr, "\r%d / %d (thread %d) \r", iadd, nadd, thread_no ); + ++(*iaddshare); + targetseq = seq[norg+iadd]; + pthread_mutex_unlock( targ->mutex_counter ); + } + else +#endif + { + iadd++; + if( iadd == nadd ) break; + targetseq = seq[norg+iadd]; + fprintf( stderr, "\r%d / %d \r", iadd, nadd ); + } + + for( i=0; i 0 ) + { + for( i=0; imutex_counter ); + fprintf( stdout, "\nmergeoralign (iadd=%d) = ", iadd ); + for( i=0; imutex_counter ); +#endif + + singlerna = NULL; + pscore = treebase( njobc, nlenc, bseq, 1, mergeoralign, mseq1, mseq2, topolc, effc, &alloclen, localhomtablec, singlerna, eff_kozo_mapped ); +#if 0 + pthread_mutex_lock( targ->mutex_counter ); +// fprintf( stdout, "res (iadd=%d) = %s, pscore=%f\n", iadd, bseq[norg], pscore ); +// fprintf( stdout, "effc (iadd=%d) = ", iadd ); +// for( i=0; imutex_counter ); +#endif + + +#if 0 + fprintf( trap_g, "done.\n" ); + fclose( trap_g ); +#endif +// fprintf( stdout, "\n>seq[%d, iadd=%d] = \n%s\n", norg+iadd, iadd, seq[norg+iadd] ); +// fprintf( stdout, "\n>bseq[%d, iadd=%d] = \n%s\n", norg, iadd, bseq[norg] ); + +// strcpy( seq[norg+iadd], bseq[norg] ); + + + if( keeplength ) + { +// reporterr( "deletelist = %p\n", deletelist ); +// reporterr( "deletelist+iadd = %p\n", deletelist+iadd ); + ndeleted += deletenewinsertions_whole_eq( norg, 1, bseq, bseq+norg, deletelist+iadd ); +// for( i=0; i\n%s\n", bseq[i] ); + strcpy( targetseq, bseq[norg] ); + i = norg; // no new gap!! + } + else + { + strcpy( targetseq, bseq[norg] ); + rep = -1; + for( i=0; i maxl ) maxl = nogaplen[i]; + if( dorp == 'd' ) /* nuc */ + { + seq_grp_nuc( grpseq, tmpseq ); +// makepointtable_nuc( pointt[i], grpseq ); +// makepointtable_nuc_octet( pointt[i], grpseq ); + if( tuplesize == 10 ) + makepointtable_nuc_dectet( pointt[i], grpseq ); + else if( tuplesize == 6 ) + makepointtable_nuc( pointt[i], grpseq ); + else + { + fprintf( stderr, "tuplesize=%d: not supported\n", tuplesize ); + exit( 1 ); + } + } + else /* amino */ + { + seq_grp( grpseq, tmpseq ); + makepointtable( pointt[i], grpseq ); + } + + } + if( nunknown ) fprintf( stderr, "\nThere are %d ambiguous characters\n", nunknown ); + + for( i=0; i 0 ) + { + distancematrixthread_arg_t *targ; + int jobpos; + pthread_t *handle; + pthread_mutex_t mutex; + + jobpos = 0; + targ = calloc( nthread, sizeof( distancematrixthread_arg_t ) ); + handle = calloc( nthread, sizeof( pthread_t ) ); + pthread_mutex_init( &mutex, NULL ); + + for( i=0; i nogaplen[j] ) + { + longer=(double)nogaplen[i]; + shorter=(double)nogaplen[j]; + } + else + { + longer=(double)nogaplen[j]; + shorter=(double)nogaplen[i]; + } + lenfac = 1.0 / ( shorter / longer * lenfacd + lenfacb / ( longer + lenfacc ) + lenfaca ); + bunbo = MIN( selfscore[i], selfscore[j] ); + + if( j < norg ) + { + if( bunbo == 0.0 ) + imtx[i][j-i] = maxdist; + else + imtx[i][j-i] = maxdist * ( 1.0 - mtxv / bunbo ) * lenfac; + } + else + { + if( bunbo == 0.0 ) + nmtx[i][j-norg] = maxdist; + else + nmtx[i][j-norg] = maxdist * ( 1.0 - mtxv / bunbo ) * lenfac; + } + } + free( table1 ); + } + } + + fprintf( stderr, "\ndone.\n\n" ); + fflush( stderr ); + + free( grpseq ); + free( tmpseq ); + FreeIntMtx( pointt ); + free( nogaplen ); + free( selfscore ); + + + if( hitout<0.0 ) + { + fprintf( stdout, "Threshold=%f\n\n", -hitout ); + for( i=0; i0.0 ) + { + fprintf( stdout, "Threshold=%f\n\n", hitout ); + for( i=norg; i 0 ) + { + dndprethread_arg_t *targ; + Jobtable2d jobpos; + pthread_t *handle; + pthread_mutex_t mutex; + + jobpos.i = 0; + jobpos.j = 0; + + targ = calloc( nthread, sizeof( dndprethread_arg_t ) ); + handle = calloc( nthread, sizeof( pthread_t ) ); + pthread_mutex_init( &mutex, NULL ); + + for( i=0; i 9.9 ) + { + fprintf( stderr, "WARNING: distance %d-%d is strange, %f.\n", i, j, mtxv ); + mtxv = 9.9; +// exit( 1 ); // 2016/Aug/3 + } +#else // CHUUI!!! 2012/05/16 + if( mtxv > 2.0 ) + { + mtxv = 2.0; + } + if( mtxv < 0.0 ) + { + fprintf( stderr, "Distance %d-%d is strange, %f.\n", i, j, mtxv ); + exit( 1 ); + } +#endif + mtx[i][j-i] = mtxv; + } + } + } + +#if TEST + for( i=0; i %d\n", postoshiftfrom, postoshiftto ); + for( j=0; j %d\n", postoshiftfrom, postoshiftto ); + for( j=0; j 1000 || nadd > 1000 ) use_fft = 0; + + fullseqlen = alloclen = nlenmax*4+1; //chuui! + seq = AllocateCharMtx( njob, alloclen ); + + name = AllocateCharMtx( njob, B+1 ); + nlen = AllocateIntVec( njob ); + + ndeleted = 0; + + + if( multidist || tuplesize > 0 ) + { + iscore = AllocateFloatHalfMtx( norg ); + nscore = AllocateFloatMtx( norg, nadd ); + } + else + { + iscore = AllocateFloatHalfMtx( njob ); + nscore = NULL; + } + + kozoarivec = AllocateCharVec( njob ); + + + ordertable = AllocateIntVec( norg+1 ); + + + if( constraint ) + { +#if SMALLMEMORY + if( multidist ) + { + localhomtable = (LocalHom **)calloc( norg, sizeof( LocalHom *) ); + for( i=0; i 0 ) // if mtx is internally computed + { + if( multidist == 1 ) + { + ktupledistancematrix( njob, norg, nlenmax, seq, name, iscore, nscore ); // iscore ha muda. + +// hat2p = fopen( "hat2-1", "w" ); +// WriteFloatHat2_pointer_halfmtx( hat2p, njob, name, iscore ); +// fclose( hat2p ); + + dndpre( norg, seq, iscore ); +// fprintf( stderr, "Loading 'hat2i' (aligned sequences) ... " ); +// prep = fopen( "hat2i", "r" ); +// if( prep == NULL ) ErrorExit( "Make hat2i." ); +// readhat2_doublehalf_pointer( prep, njob-nadd, name, iscore ); +// fclose( prep ); +// fprintf( stderr, "done.\n" ); + +// hat2p = fopen( "hat2-2", "w" ); +// WriteFloatHat2_pointer_halfmtx( hat2p, norg, name, iscore ); +// fclose( hat2p ); + } + else + { + ktupledistancematrix( njob, norg, nlenmax, seq, name, iscore, nscore ); + } + } + else + { + if( multidist == 1 ) + { + fprintf( stderr, "Loading 'hat2n' (aligned sequences - new sequences) ... " ); + prep = fopen( "hat2n", "r" ); + if( prep == NULL ) ErrorExit( "Make hat2n." ); + readhat2_doublehalf_part_pointer( prep, njob, nadd, name, nscore ); + fclose( prep ); + fprintf( stderr, "done.\n" ); + + fprintf( stderr, "Loading 'hat2i' (aligned sequences) ... " ); + prep = fopen( "hat2i", "r" ); + if( prep == NULL ) ErrorExit( "Make hat2i." ); + readhat2_doublehalf_pointer( prep, njob-nadd, name, iscore ); + fclose( prep ); + fprintf( stderr, "done.\n" ); + } + else + { + fprintf( stderr, "Loading 'hat2' ... " ); + prep = fopen( "hat2", "r" ); + if( prep == NULL ) ErrorExit( "Make hat2." ); + readhat2_doublehalf_pointer( prep, njob, name, iscore ); + fclose( prep ); + fprintf( stderr, "done.\n" ); + } + } + +#if 1 + if( distout ) + { + fprintf( stderr, "Writing distances between new sequences and existing msa.\n" ); + hat2p = fopen( "hat2", "w" ); + if( multidist || tuplesize > 0 ) + { + for( iadd=0; iadd 1 ) + cnctintvec( ordertable, topol[norg-2][0], topol[norg-2][1] ); + else + { + ordertable[0] = 0; ordertable[1] = -1; + } + FreeFloatHalfMtx( iscoreo, norg ); + +#ifdef enablemultithread + if( nthread ) + { + pthread_t *handle; + pthread_mutex_t mutex_counter; + thread_arg_t *targ; + int *iaddsharept; + + targ = calloc( nthread, sizeof( thread_arg_t ) ); + handle = calloc( nthread, sizeof( pthread_t ) ); + pthread_mutex_init( &mutex_counter, NULL ); + iaddsharept = calloc( 1, sizeof(int) ); + *iaddsharept = 0; + + for( i=0; i 0 ) FreeFloatMtx( nscore ); + + +// for( i=0; i%s (%d) \n%s\n", name[norg+i], norg+i, seq[norg+i] ); + + if( treeout ) + { + fp = fopen( "infile.tree", "a" ); + if( fp == 0 ) + { + fprintf( stderr, "File error!\n" ); + exit( 1 ); + } + for( i=0; i %d\n", follower[i][j]+norg, i ); + } + fclose( orderfp ); + + posmap = AllocateIntVec( lenfull+2 ); + realign = calloc( lenfull+2, sizeof( Blocktorealign ) ); + for( i=0; i= fullseqlen ) + { + fullseqlen = tmplen * 2+1; +// fprintf( stderr, "Length over!\n" ); +// fprintf( stderr, "strlen(tmpseq1)=%d\n", (int)strlen( tmpseq1 ) ); + fprintf( stderr, "reallocating..." ); +// fprintf( stderr, "alloclen=%d\n", alloclen ); +// fprintf( stderr, "Please recompile!\n" ); +// exit( 1 ); + for( i=0; i 0 && ien > 500 ) + { + gaplist2alnxthread_arg_t *targ; + int jobpos; + pthread_t *handle; + pthread_mutex_t mutex; + fprintf( stderr, "%d / %d (threads %d-%d)\r", iadd, nadd, 0, nthread ); + + targ = calloc( nthread, sizeof( gaplist2alnxthread_arg_t ) ); + handle = calloc( nthread, sizeof( pthread_t ) ); + pthread_mutex_init( &mutex, NULL ); + jobpos = 1; + for( i=0; i%s (iadd=%d)\n%s\n", name[i], iadd, tmpseq1 ); + strcpy( seq[i], tmpseq1 ); + } + } + } + tmpseq1 = tmpseq[0]; +// insertgapsbyotherfragments_simple( lenfull, tmpseq1, seq[norg+iadd], newgaplist_o[iadd], posmap ); + insertgapsbyotherfragments_compact( lenfull, tmpseq1, seq[norg+iadd], newgaplist_o[iadd], posmap ); +// fprintf( stderr, "%d = %s\n", iadd, tmpseq1 ); + eq2dash( tmpseq1 ); + strcpy( seq[norg+iadd], tmpseq1 ); + +// adjustposmap( lenfull, posmap, newgaplist_o[iadd] ); + adjustposmap( lenfull, posmap, newgaplist_compact ); + countnewres( lenfull, realign, posmap, newgaplist_o[iadd] ); // muda? +// countnewres( lenfull, realign, posmap, newgaplist_compact ); // muda? + + } + fprintf( stderr, "\r done. \n\n" ); + +#if 0 + for( i=0; i%s\n", name[i] ); + fprintf( stderr, "%s\n", seq[i] ); + } +#endif + +#if 0 + fprintf( stderr, "realign[].nnewres = " ); + for( i=0; i 1 ) + { +// fprintf( stderr, "i=%d: %d-%d\n", i, realign[i].start, realign[i].end ); + fprintf( stderr, "\rRealigning %d/%d \r", i, lenfull ); +// zure = dorealignment_compact( realign+i, seq, &fullseqlen, norg ); +// zure = dorealignment_order( realign+i, seq, &fullseqlen, norg, ordertable, follows ); + zure = dorealignment_tree( realign+i, seq, &fullseqlen, norg, topol, follows ); +#if 0 + gappick0( check1, seq[0] ); + fprintf( stderr, "check1 = %s\n", check1 ); + if( strcmp( check1, check2 ) ) + { + fprintf( stderr, "CHANGED!!!!!\n" ); + exit( 1 ); + } +#endif + for( j=i+1; j 0 ) + { + reporterr( "\nTo keep the alignment length, %d letters were DELETED.\n", ndeleted ); + if( mapout ) + reporterr( "The deleted letters are shown in the (filename).map file.\n" ); + else + reporterr( "To know the positions of deleted letters, rerun the same command with the --mapout option.\n" ); + } + return( 0 ); +} diff --git a/binaries/src/mafft/core/addsingle.o b/binaries/src/mafft/core/addsingle.o new file mode 100644 index 0000000..d6a7650 Binary files /dev/null and b/binaries/src/mafft/core/addsingle.o differ diff --git a/binaries/src/mafft/core/blosum.c b/binaries/src/mafft/core/blosum.c index 62652e5..45a7d9b 100644 --- a/binaries/src/mafft/core/blosum.c +++ b/binaries/src/mafft/core/blosum.c @@ -2,7 +2,8 @@ #define DEFAULTGEP_B -00 #define DEFAULTOFS_B -123 /* +10 -- -50 teido ka ? */ -void BLOSUMmtx( int n, double **matrix, double *freq, char *amino, char *amino_grp ) + +void BLOSUMmtx( int n, double **matrix, double *freq, unsigned char *amino, char *amino_grp ) { /* char locaminod[26] = "GASTPLIMVDNEQFYWKRHCXXX.-U"; @@ -157,6 +158,52 @@ void BLOSUMmtx( int n, double **matrix, double *freq, char *amino, char *amino_g -4, -4, -4, -6, -5, -3, -5, -6, 3, -3, -2, -4, -3, 4, -6, -3, -3, 3, 11, -1, -4, -5, -6, -2, -4, -4, -6, -5, 4, 1, -4, 1, -2, -4, -3, 0, -5, -3, 7, }; + double tmpmtx90[] = + { + 5, +-2, 6, +-2, -1, 7, +-3, -3, 1, 7, +-1, -5, -4, -5, 9, +-1, 1, 0, -1, -4, 7, +-1, -1, -1, 1, -6, 2, 6, + 0, -3, -1, -2, -4, -3, -3, 6, +-2, 0, 0, -2, -5, 1, -1, -3, 8, +-2, -4, -4, -5, -2, -4, -4, -5, -4, 5, +-2, -3, -4, -5, -2, -3, -4, -5, -4, 1, 5, +-1, 2, 0, -1, -4, 1, 0, -2, -1, -4, -3, 6, +-2, -2, -3, -4, -2, 0, -3, -4, -3, 1, 2, -2, 7, +-3, -4, -4, -5, -3, -4, -5, -5, -2, -1, 0, -4, -1, 7, +-1, -3, -3, -3, -4, -2, -2, -3, -3, -4, -4, -2, -3, -4, 8, + 1, -1, 0, -1, -2, -1, -1, -1, -2, -3, -3, -1, -2, -3, -2, 5, + 0, -2, 0, -2, -2, -1, -1, -3, -2, -1, -2, -1, -1, -3, -2, 1, 6, +-4, -4, -5, -6, -4, -3, -5, -4, -3, -4, -3, -5, -2, 0, -5, -4, -4, 11, +-3, -3, -3, -4, -4, -3, -4, -5, 1, -2, -2, -3, -2, 3, -4, -3, -2, 2, 8, +-1, -3, -4, -5, -2, -3, -3, -5, -4, 3, 0, -3, 0, -2, -3, -2, -1, -3, -3, 5, + }; + double tmpmtx100[] = + { + 8, +-3,10, +-4,-2,11, +-5,-5, 1,10, +-2,-8,-5,-8,14, +-2, 0,-1,-2,-7,11, +-3,-2,-2, 2,-9, 2,10, +-1,-6,-2,-4,-7,-5,-6, 9, +-4,-1, 0,-3,-8, 1,-2,-6,13, +-4,-7,-7,-8,-3,-6,-7,-9,-7, 8, +-4,-6,-7,-8,-5,-5,-7,-8,-6, 2, 8, +-2, 3,-1,-3,-8, 2, 0,-5,-3,-6,-6,10, +-3,-4,-5,-8,-4,-2,-5,-7,-5, 1, 3,-4,12, +-5,-6,-7,-8,-4,-6,-8,-8,-4,-2, 0,-6,-1,11, +-2,-5,-5,-5,-8,-4,-4,-6,-5,-7,-7,-3,-5,-7,12, + 1,-3, 0,-2,-3,-2,-2,-2,-3,-5,-6,-2,-4,-5,-3, 9, +-1,-3,-1,-4,-3,-3,-3,-5,-4,-3,-4,-3,-2,-5,-4, 2, 9, +-6,-7,-8,-10,-7,-5,-8,-7,-5,-6,-5,-8,-4, 0,-8,-7,-7,17, +-5,-5,-5,-7,-6,-4,-7,-8, 1,-4,-4,-5,-5, 4,-7,-5,-5, 2,12, +-2,-6,-7,-8,-3,-5,-5,-8,-7, 4, 0,-5, 0,-3,-6,-4,-1,-5,-5, 8, + }; double tmpmtx0[] = { 2.4, @@ -190,6 +237,8 @@ void BLOSUMmtx( int n, double **matrix, double *freq, char *amino, char *amino_g else if( n == 50 ) tmpmtx = tmpmtx50; else if( n == 62 ) tmpmtx = tmpmtx62; else if( n == 80 ) tmpmtx = tmpmtx80; + else if( n == 90 ) tmpmtx = tmpmtx90; + else if( n == 100 ) tmpmtx = tmpmtx100; else if( n == 0 ) tmpmtx = tmpmtx0; else if( n == -1 ) tmpmtx = loadaamtx(); else @@ -264,3 +313,44 @@ void BLOSUMmtx( int n, double **matrix, double *freq, char *amino, char *amino_g for( i=0; i<26; i++ ) amino[i] = locaminod[i]; for( i=0; i<26; i++ ) amino_grp[(int)amino[i]] = locgrpd[i]; } + +void extendedmtx( double **matrix, double *freq, unsigned char *amino, char *amino_grp ) +{ + int i; + int j; + + for( i=0; i i=%d, n_dis[%d][%d] = %d\n", i, i, amino_n['n'], n_dis[i][amino_n['n']] ); + n_dis[amino_n['n']][i] = n_dis[i][amino_n['n']]; + } +// n_dis[amino_n['n']][amino_n['n']] = shishagonyuu( (double)0.25 * 0.25 * ( n_dis[0][0] + n_dis[1][1] + n_dis[2][2] + n_dis[3][3] ) ); + n_dis[amino_n['n']][amino_n['n']] = shishagonyuu( (double)0.25 * ( n_dis[0][0] + n_dis[1][1] + n_dis[2][2] + n_dis[3][3] ) ); // 2017/Jan/2 + +#if 0 // Ato de kakunin + for( i=0; i<26; i++ ) + { + n_dis[i][amino_n['-']] = shishagonyuu( (double)0.25 * n_dis[i][i] ); + n_dis[amino_n['-']][i] = n_dis[i][amino_n['-']]; + } +// n_dis[amino_n['-']][amino_n['-']] = shishagonyuu( (double)0.25 * 0.25 * ( n_dis[0][0] + n_dis[1][1] + n_dis[2][2] + n_dis[3][3] ) ); // DAME! +#endif +} + + +static void ambiguousscore( int *amino_n, int **n_dis ) +{ + int i; + for( i=0; i<26; i++ ) + { + n_dis[i][amino_n['r']] = shishagonyuu( (double)1/2 * ( n_dis[amino_n['a']][i] + n_dis[amino_n['g']][i] ) ); + n_dis[i][amino_n['y']] = shishagonyuu( (double)1/2 * ( n_dis[amino_n['c']][i] + n_dis[amino_n['t']][i] ) ); + n_dis[i][amino_n['k']] = shishagonyuu( (double)1/2 * ( n_dis[amino_n['g']][i] + n_dis[amino_n['t']][i] ) ); + n_dis[i][amino_n['m']] = shishagonyuu( (double)1/2 * ( n_dis[amino_n['a']][i] + n_dis[amino_n['c']][i] ) ); + n_dis[i][amino_n['s']] = shishagonyuu( (double)1/2 * ( n_dis[amino_n['g']][i] + n_dis[amino_n['c']][i] ) ); + n_dis[i][amino_n['w']] = shishagonyuu( (double)1/2 * ( n_dis[amino_n['a']][i] + n_dis[amino_n['t']][i] ) ); + n_dis[i][amino_n['b']] = shishagonyuu( (double)1/3 * ( n_dis[amino_n['c']][i] + n_dis[amino_n['g']][i] + n_dis[amino_n['t']][i] ) ); + n_dis[i][amino_n['d']] = shishagonyuu( (double)1/3 * ( n_dis[amino_n['a']][i] + n_dis[amino_n['g']][i] + n_dis[amino_n['t']][i] ) ); + n_dis[i][amino_n['h']] = shishagonyuu( (double)1/3 * ( n_dis[amino_n['a']][i] + n_dis[amino_n['c']][i] + n_dis[amino_n['t']][i] ) ); + n_dis[i][amino_n['v']] = shishagonyuu( (double)1/3 * ( n_dis[amino_n['a']][i] + n_dis[amino_n['c']][i] + n_dis[amino_n['g']][i] ) ); + + n_dis[amino_n['r']][i] = n_dis[i][amino_n['r']]; + n_dis[amino_n['y']][i] = n_dis[i][amino_n['y']]; + n_dis[amino_n['k']][i] = n_dis[i][amino_n['k']]; + n_dis[amino_n['m']][i] = n_dis[i][amino_n['m']]; + n_dis[amino_n['s']][i] = n_dis[i][amino_n['s']]; + n_dis[amino_n['w']][i] = n_dis[i][amino_n['w']]; + n_dis[amino_n['b']][i] = n_dis[i][amino_n['b']]; + n_dis[amino_n['d']][i] = n_dis[i][amino_n['d']]; + n_dis[amino_n['h']][i] = n_dis[i][amino_n['h']]; + n_dis[amino_n['v']][i] = n_dis[i][amino_n['v']]; + } + + i = amino_n['r']; n_dis[i][i] = shishagonyuu( (double)1/2 * ( n_dis[amino_n['a']][amino_n['a']] + n_dis[amino_n['g']][amino_n['g']] ) ); + i = amino_n['y']; n_dis[i][i] = shishagonyuu( (double)1/2 * ( n_dis[amino_n['c']][amino_n['c']] + n_dis[amino_n['t']][amino_n['t']] ) ); + i = amino_n['k']; n_dis[i][i] = shishagonyuu( (double)1/2 * ( n_dis[amino_n['g']][amino_n['g']] + n_dis[amino_n['t']][amino_n['t']] ) ); + i = amino_n['m']; n_dis[i][i] = shishagonyuu( (double)1/2 * ( n_dis[amino_n['a']][amino_n['a']] + n_dis[amino_n['c']][amino_n['c']] ) ); + i = amino_n['s']; n_dis[i][i] = shishagonyuu( (double)1/2 * ( n_dis[amino_n['g']][amino_n['g']] + n_dis[amino_n['c']][amino_n['c']] ) ); + i = amino_n['w']; n_dis[i][i] = shishagonyuu( (double)1/2 * ( n_dis[amino_n['a']][amino_n['a']] + n_dis[amino_n['t']][amino_n['t']] ) ); + i = amino_n['b']; n_dis[i][i] = shishagonyuu( (double)1/3 * ( n_dis[amino_n['c']][amino_n['c']] + n_dis[amino_n['g']][amino_n['g']] + n_dis[amino_n['t']][amino_n['t']] ) ); + i = amino_n['d']; n_dis[i][i] = shishagonyuu( (double)1/3 * ( n_dis[amino_n['a']][amino_n['a']] + n_dis[amino_n['g']][amino_n['g']] + n_dis[amino_n['t']][amino_n['t']] ) ); + i = amino_n['h']; n_dis[i][i] = shishagonyuu( (double)1/3 * ( n_dis[amino_n['a']][amino_n['a']] + n_dis[amino_n['c']][amino_n['c']] + n_dis[amino_n['t']][amino_n['t']] ) ); + i = amino_n['v']; n_dis[i][i] = shishagonyuu( (double)1/3 * ( n_dis[amino_n['a']][amino_n['a']] + n_dis[amino_n['c']][amino_n['c']] + n_dis[amino_n['g']][amino_n['g']] ) ); +} + + static void calcfreq_nuc( int nseq, char **seq, double *datafreq ) { int i, j, l; @@ -43,19 +109,20 @@ static void calcfreq_nuc( int nseq, char **seq, double *datafreq ) } } } - for( i=0; i<4; i++ ) - if( datafreq[i] < 0.0001 ) datafreq[i] = 0.0001; + total = 0.0; for( i=0; i<4; i++ ) total += datafreq[i]; + for( i=0; i<4; i++ ) datafreq[i] /= (double)total; + for( i=0; i<4; i++ ) if( datafreq[i] < 0.0001 ) datafreq[i] = 0.0001; total = 0.0; for( i=0; i<4; i++ ) total += datafreq[i]; -// fprintf( stderr, "total = %f\n", total ); +// reporterr( "total = %f\n", total ); for( i=0; i<4; i++ ) datafreq[i] /= (double)total; #if 0 - fprintf( stderr, "\ndatafreq = " ); + reporterr( "\ndatafreq = " ); for( i=0; i<4; i++ ) - fprintf( stderr, "%10.5f ", datafreq[i] ); - fprintf( stderr, "\n" ); + reporterr( "%10.5f ", datafreq[i] ); + reporterr( "\n" ); exit( 1 ); #endif } @@ -65,7 +132,7 @@ static void calcfreq( int nseq, char **seq, double *datafreq ) int i, j, l; int aan; double total; - for( i=0; i<20; i++ ) + for( i=0; i= 0 && aan < 20 ) + if( aan >= 0 && aan < nscoredalphabets && seq[i][j] != '-' ) { datafreq[aan] += 1.0; total += 1.0; } } } - for( i=0; i<20; i++ ) - if( datafreq[i] < 0.0001 ) datafreq[i] = 0.0001; + total = 0.0; for( i=0; i= 0 && aan < nscoredalphabets && seq[i][j] != '-' ) + { + datafreq[aan] += 1.0; + total += 1.0; + } + } + } + total = 0.0; for( i=0; i= 10 ) trywarp = 0; + else trywarp = 1; if( dorp == 'd' ) /* DNA */ { @@ -106,11 +244,18 @@ void constants( int nseq, char **seq ) double **pam1 = AllocateDoubleMtx( 4, 4 ); double *freq = AllocateDoubleVec( 4 ); + nalphabets = 26; + nscoredalphabets = 10; + charsize = 0x80; + + n_dis = AllocateIntMtx( nalphabets, nalphabets ); + n_disLN = AllocateDoubleMtx( nalphabets, nalphabets ); scoremtx = -1; if( RNAppenalty == NOTSPECIFIED ) RNAppenalty = DEFAULTRNAGOP_N; if( RNAppenalty_ex == NOTSPECIFIED ) RNAppenalty_ex = DEFAULTRNAGEP_N; if( ppenalty == NOTSPECIFIED ) ppenalty = DEFAULTGOP_N; + if( ppenalty_dist == NOTSPECIFIED ) ppenalty_dist = ppenalty; if( ppenalty_OP == NOTSPECIFIED ) ppenalty_OP = DEFAULTGOP_N; if( ppenalty_ex == NOTSPECIFIED ) ppenalty_ex = DEFAULTGEP_N; if( ppenalty_EX == NOTSPECIFIED ) ppenalty_EX = DEFAULTGEP_N; @@ -121,23 +266,48 @@ void constants( int nseq, char **seq ) RNApenalty = (int)( 3 * 600.0 / 1000.0 * RNAppenalty + 0.5 ); RNApenalty_ex = (int)( 3 * 600.0 / 1000.0 * RNAppenalty_ex + 0.5 ); -// fprintf( stderr, "DEFAULTRNAGOP_N = %d\n", DEFAULTRNAGOP_N ); -// fprintf( stderr, "RNAppenalty = %d\n", RNAppenalty ); -// fprintf( stderr, "RNApenalty = %d\n", RNApenalty ); +// reporterr( "DEFAULTRNAGOP_N = %d\n", DEFAULTRNAGOP_N ); +// reporterr( "RNAppenalty = %d\n", RNAppenalty ); +// reporterr( "RNApenalty = %d\n", RNApenalty ); RNAthr = (int)( 3 * 600.0 / 1000.0 * RNApthr + 0.5 ); penalty = (int)( 3 * 600.0 / 1000.0 * ppenalty + 0.5); + penalty_dist = (int)( 3 * 600.0 / 1000.0 * ppenalty_dist + 0.5); + penalty_shift = (int)( penalty_shift_factor * penalty ); penalty_OP = (int)( 3 * 600.0 / 1000.0 * ppenalty_OP + 0.5); penalty_ex = (int)( 3 * 600.0 / 1000.0 * ppenalty_ex + 0.5); penalty_EX = (int)( 3 * 600.0 / 1000.0 * ppenalty_EX + 0.5); - offset = (int)( 3 * 600.0 / 1000.0 * poffset + 0.5); - offsetFFT = (int)( 3 * 600.0 / 1000.0 * (-0) + 0.5); - offsetLN = (int)( 3 * 600.0 / 1000.0 * 100 + 0.5); + offset = (int)( 1 * 600.0 / 1000.0 * poffset + 0.5); + offsetFFT = (int)( 1 * 600.0 / 1000.0 * (-0) + 0.5); + offsetLN = (int)( 1 * 600.0 / 1000.0 * 100 + 0.5); penaltyLN = (int)( 3 * 600.0 / 1000.0 * -2000 + 0.5); penalty_exLN = (int)( 3 * 600.0 / 1000.0 * -100 + 0.5); - sprintf( modelname, "%s%d (%d), %6.3f (%6.3f), %6.3f (%6.3f)", rnakozo?"RNA":"DNA", pamN, kimuraR, - -(double)ppenalty*0.001, -(double)ppenalty*0.003, -(double)poffset*0.001, -(double)poffset*0.003 ); + + if( trywarp ) sprintf( shiftmodel, "%4.2f (%4.2f)", -(double)penalty_shift/1800, -(double)penalty_shift/600 ); + else sprintf( shiftmodel, "noshift" ); + + sprintf( modelname, "%s%d (%d), %4.2f (%4.2f), %4.2f (%4.2f), %s", rnakozo?"RNA":"DNA", pamN, kimuraR, -(double)ppenalty*0.001, -(double)ppenalty*0.003, -(double)poffset*0.001, -(double)poffset*0.003, shiftmodel ); + + for( i=0; i<26; i++ ) amino[i] = locaminon[i]; + for( i=0; i<0x80; i++ ) amino_n[i] = -1; + for( i=0; i<26; i++ ) amino_n[(int)amino[i]] = i; + if( fmodel == 1 ) + { + calcfreq_nuc( nseq, seq, freq ); + reporterr( "a, freq[0] = %f\n", freq[0] ); + reporterr( "g, freq[1] = %f\n", freq[1] ); + reporterr( "c, freq[2] = %f\n", freq[2] ); + reporterr( "t, freq[3] = %f\n", freq[3] ); + } + else + { + freq[0] = 0.25; + freq[1] = 0.25; + freq[2] = 0.25; + freq[3] = 0.25; + } + if( kimuraR == 9999 ) { @@ -150,7 +320,7 @@ void constants( int nseq, char **seq ) average /= 16.0; if( disp ) - fprintf( stderr, "average = %f\n", average ); + reporterr( "average = %f\n", average ); for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) pamx[i][j] -= average; @@ -164,6 +334,7 @@ void constants( int nseq, char **seq ) } else { +#if 0 double f = 0.99; double s = (double)kimuraR / ( 2 + kimuraR ) * 0.01; double v = (double)1 / ( 2 + kimuraR ) * 0.01; @@ -171,32 +342,49 @@ void constants( int nseq, char **seq ) pam1[1][0] = s; pam1[1][1] = f; pam1[1][2] = v; pam1[1][3] = v; pam1[2][0] = v; pam1[2][1] = v; pam1[2][2] = f; pam1[2][3] = s; pam1[3][0] = v; pam1[3][1] = v; pam1[3][2] = s; pam1[3][3] = f; +#else + generatenuc1pam( pam1, kimuraR, freq ); +#endif - fprintf( stderr, "generating %dPAM scoring matrix for nucleotides ... ", pamN ); + reporterr( "generating a scoring matrix for nucleotide (dist=%d) ... ", pamN ); if( disp ) { - fprintf( stderr, " TPM \n" ); + reporterr( " TPM \n" ); for( i=0; i<4; i++ ) { for( j=0; j<4; j++ ) - fprintf( stderr, "%+#6.10f", pam1[i][j] ); - fprintf( stderr, "\n" ); + reporterr( "%+#6.10f", pam1[i][j] ); + reporterr( "\n" ); } - fprintf( stderr, "\n" ); + reporterr( "\n" ); } MtxuntDouble( pamx, 4 ); for( x=0; x < pamN; x++ ) MtxmltDouble( pamx, pam1, 4 ); + + if( disp ) + { + reporterr( " TPM \n" ); + for( i=0; i<4; i++ ) + { + for( j=0; j<4; j++ ) + reporterr( "%+#6.10f", pamx[i][j] ); + reporterr( "\n" ); + } + reporterr( "\n" ); + } + for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) - pamx[i][j] /= 1.0 / 4.0; + pamx[i][j] /= freq[j]; +// pamx[i][j] /= 0.25; for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) { if( pamx[i][j] == 0.0 ) { - fprintf( stderr, "WARNING: pamx[i][j] = 0.0 ?\n" ); + reporterr( "WARNING: pamx[i][j] = 0.0 ?\n" ); pamx[i][j] = 0.00001; /* by J. Thompson */ } pamx[i][j] = log10( pamx[i][j] ) * 1000.0; @@ -204,35 +392,18 @@ void constants( int nseq, char **seq ) if( disp ) { - fprintf( stderr, " after log\n" ); + reporterr( " after log\n" ); for( i=0; i<4; i++ ) { for( j=0; j<4; j++ ) - fprintf( stderr, "%+#6.10f", pamx[i][j] ); - fprintf( stderr, "\n" ); + reporterr( "%+10.6f ", pamx[i][j] ); + reporterr( "\n" ); } - fprintf( stderr, "\n" ); + reporterr( "\n" ); } // ????? - for( i=0; i<26; i++ ) amino[i] = locaminon[i]; - for( i=0; i<0x80; i++ ) amino_n[i] = -1; - for( i=0; i<26; i++ ) amino_n[(int)amino[i]] = i; - if( fmodel == 1 ) - calcfreq_nuc( nseq, seq, freq ); - else - { - freq[0] = 0.25; - freq[1] = 0.25; - freq[2] = 0.25; - freq[3] = 0.25; - } -// fprintf( stderr, "a, freq[0] = %f\n", freq[0] ); -// fprintf( stderr, "g, freq[1] = %f\n", freq[1] ); -// fprintf( stderr, "c, freq[2] = %f\n", freq[2] ); -// fprintf( stderr, "t, freq[3] = %f\n", freq[3] ); - average = 0.0; for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) @@ -249,23 +420,23 @@ void constants( int nseq, char **seq ) for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) - pamx[i][j] -= offset; /* extending gap cost */ + pamx[i][j] -= offset; for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) pamx[i][j] = shishagonyuu( pamx[i][j] ); if( disp ) { - fprintf( stderr, " after shishagonyuu\n" ); + reporterr( " after shishagonyuu\n" ); for( i=0; i<4; i++ ) { for( j=0; j<4; j++ ) - fprintf( stderr, "%+#6.10f", pamx[i][j] ); - fprintf( stderr, "\n" ); + reporterr( "%+#6.10f", pamx[i][j] ); + reporterr( "\n" ); } - fprintf( stderr, "\n" ); + reporterr( "\n" ); } - fprintf( stderr, "done\n" ); + reporterr( "done\n" ); } for( i=0; i<5; i++ ) @@ -281,42 +452,49 @@ void constants( int nseq, char **seq ) if( disp ) { - fprintf( stderr, " before dis\n" ); + reporterr( " before dis\n" ); for( i=0; i<4; i++ ) { for( j=0; j<4; j++ ) - fprintf( stderr, "%+#6.10f", pamx[i][j] ); - fprintf( stderr, "\n" ); + reporterr( "%+#6.10f", pamx[i][j] ); + reporterr( "\n" ); } - fprintf( stderr, "\n" ); + reporterr( "\n" ); } if( disp ) { - fprintf( stderr, " score matrix \n" ); + reporterr( " score matrix \n" ); for( i=0; i<4; i++ ) { for( j=0; j<4; j++ ) - fprintf( stderr, "%+#6.10f", pamx[i][j] ); - fprintf( stderr, "\n" ); + reporterr( "%+#6.10f", pamx[i][j] ); + reporterr( "\n" ); } - fprintf( stderr, "\n" ); + reporterr( "\n" ); + exit( 1 ); } for( i=0; i<26; i++ ) amino[i] = locaminon[i]; for( i=0; i<26; i++ ) amino_grp[(int)amino[i]] = locgrpn[i]; for( i=0; i<26; i++ ) for( j=0; j<26; j++ ) n_dis[i][j] = 0; for( i=0; i<10; i++ ) for( j=0; j<10; j++ ) n_dis[i][j] = shishagonyuu( pamx[i][j] ); + + ambiguousscore( amino_n, n_dis ); + if( nwildcard ) nscore( amino_n, n_dis ); + if( disp ) { - fprintf( stderr, " score matrix \n" ); + reporterr( " score matrix \n" ); for( i=0; i<26; i++ ) { for( j=0; j<26; j++ ) - fprintf( stderr, "%+6d", n_dis[i][j] ); - fprintf( stderr, "\n" ); + reporterr( "%+6d", n_dis[i][j] ); + reporterr( "\n" ); } - fprintf( stderr, "\n" ); + reporterr( "\n" ); + reporterr( "penalty = %d, penalty_ex = %d\n", penalty, penalty_ex ); +//exit( 1 ); } // RIBOSUM @@ -368,24 +546,24 @@ void constants( int nseq, char **seq ) if( disp ) { - fprintf( stderr, "ribosum after shishagonyuu\n" ); + reporterr( "ribosum after shishagonyuu\n" ); for( i=0; i<4; i++ ) { for( j=0; j<4; j++ ) - fprintf( stderr, "%+#6.10f", ribosum4[i][j] ); - fprintf( stderr, "\n" ); + reporterr( "%+#6.10f", ribosum4[i][j] ); + reporterr( "\n" ); } - fprintf( stderr, "\n" ); - fprintf( stderr, "ribosum16 after shishagonyuu\n" ); + reporterr( "\n" ); + reporterr( "ribosum16 after shishagonyuu\n" ); for( i=0; i<16; i++ ) { for( j=0; j<16; j++ ) - fprintf( stderr, "%+#7.0f", ribosum16[i][j] ); - fprintf( stderr, "\n" ); + reporterr( "%+#7.0f", ribosum16[i][j] ); + reporterr( "\n" ); } - fprintf( stderr, "\n" ); + reporterr( "\n" ); } - fprintf( stderr, "done\n" ); +// reporterr( "done\n" ); #if 1 for( i=0; i<37; i++ ) for( j=0; j<37; j++ ) ribosumdis[i][j] = 0.0; //iru @@ -403,16 +581,16 @@ void constants( int nseq, char **seq ) if( disp ) { - fprintf( stderr, "ribosumdis\n" ); + reporterr( "ribosumdis\n" ); for( i=0; i<37; i++ ) { for( j=0; j<37; j++ ) - fprintf( stderr, "%+5d", ribosumdis[i][j] ); - fprintf( stderr, "\n" ); + reporterr( "%+5d", ribosumdis[i][j] ); + reporterr( "\n" ); } - fprintf( stderr, "\n" ); + reporterr( "\n" ); } - fprintf( stderr, "done\n" ); +// reporterr( "done\n" ); #endif FreeDoubleMtx( pam1 ); @@ -420,7 +598,7 @@ void constants( int nseq, char **seq ) free( freq ); } - else if( dorp == 'p' && scoremtx == 1 ) /* Blosum */ + else if( dorp == 'p' && scoremtx == 1 && nblosum == -2 ) /* extended */ { double *freq; double *freq1; @@ -429,11 +607,230 @@ void constants( int nseq, char **seq ) // double tmp; double **n_distmp; + nalphabets = 0x100; + nscoredalphabets = 0x100; + charsize = 0x100; + + reporterr( "nalphabets = %d\n", nalphabets ); + + n_dis = AllocateIntMtx( nalphabets, nalphabets ); + n_disLN = AllocateDoubleMtx( nalphabets, nalphabets ); + n_distmp = AllocateDoubleMtx( nalphabets, nalphabets ); + datafreq = AllocateDoubleVec( nalphabets ); + freq = AllocateDoubleVec( nalphabets ); + + if( ppenalty == NOTSPECIFIED ) ppenalty = DEFAULTGOP_B; + if( ppenalty_dist == NOTSPECIFIED ) ppenalty_dist = ppenalty; + if( ppenalty_OP == NOTSPECIFIED ) ppenalty_OP = DEFAULTGOP_B; + if( ppenalty_ex == NOTSPECIFIED ) ppenalty_ex = DEFAULTGEP_B; + if( ppenalty_EX == NOTSPECIFIED ) ppenalty_EX = DEFAULTGEP_B; + if( poffset == NOTSPECIFIED ) poffset = DEFAULTOFS_B; + if( pamN == NOTSPECIFIED ) pamN = 0; + if( kimuraR == NOTSPECIFIED ) kimuraR = 1; + penalty = (int)( 600.0 / 1000.0 * ppenalty + 0.5 ); + penalty_dist = (int)( 600.0 / 1000.0 * ppenalty_dist + 0.5 ); + penalty_shift = (int)( penalty_shift_factor * penalty ); + penalty_OP = (int)( 600.0 / 1000.0 * ppenalty_OP + 0.5 ); + penalty_ex = (int)( 600.0 / 1000.0 * ppenalty_ex + 0.5 ); + penalty_EX = (int)( 600.0 / 1000.0 * ppenalty_EX + 0.5 ); + offset = (int)( 600.0 / 1000.0 * poffset + 0.5 ); + offsetFFT = (int)( 600.0 / 1000.0 * (-0) + 0.5); + offsetLN = (int)( 600.0 / 1000.0 * 100 + 0.5); + penaltyLN = (int)( 600.0 / 1000.0 * -2000 + 0.5); + penalty_exLN = (int)( 600.0 / 1000.0 * -100 + 0.5); + + extendedmtx( n_distmp, freq, amino, amino_grp ); + + if( trywarp ) sprintf( shiftmodel, "%4.2f", -(double)penalty_shift/600 ); + else sprintf( shiftmodel, "noshift" ); + + sprintf( modelname, "Extended, %4.2f, %+4.2f, %+4.2f, %s", -(double)ppenalty/1000, -(double)poffset/1000, -(double)ppenalty_ex/1000, shiftmodel ); +#if 0 + for( i=0; i<26; i++ ) amino[i] = locaminod[i]; + for( i=0; i<26; i++ ) amino_grp[(int)amino[i]] = locgrpd[i]; + for( i=0; i<0x80; i++ ) amino_n[i] = 0; + for( i=0; i<26; i++ ) amino_n[(int)amino[i]] = i; +#endif + for( i=0; i<0x100; i++ )amino_n[i] = -1; + for( i=0; ibestpos!=-1; pairprobpt++ ) { - pairprobpt->bestscore /= (float)njob; + pairprobpt->bestscore /= (double)njob; left = i; right = pairprobpt->bestpos; prob = pairprobpt->bestscore; diff --git a/binaries/src/mafft/core/contrafoldwrap.o b/binaries/src/mafft/core/contrafoldwrap.o new file mode 100644 index 0000000..cb6ad64 Binary files /dev/null and b/binaries/src/mafft/core/contrafoldwrap.o differ diff --git a/binaries/src/mafft/core/countlen b/binaries/src/mafft/core/countlen new file mode 100644 index 0000000..2e9bf04 Binary files /dev/null and b/binaries/src/mafft/core/countlen differ diff --git a/binaries/src/mafft/core/countlen.c b/binaries/src/mafft/core/countlen.c index 3cb7030..fd52686 100644 --- a/binaries/src/mafft/core/countlen.c +++ b/binaries/src/mafft/core/countlen.c @@ -14,7 +14,7 @@ void arguments( int argc, char *argv[] ) { case 'i': inputfile = *++argv; - fprintf( stderr, "inputfile = %s\n", inputfile ); +// fprintf( stderr, "inputfile = %s\n", inputfile ); --argc; goto nextoption; default: @@ -38,6 +38,7 @@ int main( int argc, char *argv[] ) { FILE *infp; int nlenmin; + double nfreq; arguments( argc, argv ); @@ -54,8 +55,10 @@ int main( int argc, char *argv[] ) infp = stdin; dorp = NOTSPECIFIED; - getnumlen_nogap( infp, &nlenmin ); + getnumlen_nogap_countn( infp, &nlenmin, &nfreq ); - fprintf( stdout, "%d x %d - %d %c\n", njob, nlenmax, nlenmin, dorp ); + fprintf( stdout, "%d x %d - %d %c nfreq=%f\n", njob, nlenmax, nlenmin, dorp, nfreq ); + + fclose( infp ); return( 0 ); } diff --git a/binaries/src/mafft/core/countlen.o b/binaries/src/mafft/core/countlen.o new file mode 100644 index 0000000..90ae728 Binary files /dev/null and b/binaries/src/mafft/core/countlen.o differ diff --git a/binaries/src/mafft/core/defs.c b/binaries/src/mafft/core/defs.c index 4136bc3..7a50555 100644 --- a/binaries/src/mafft/core/defs.c +++ b/binaries/src/mafft/core/defs.c @@ -11,19 +11,21 @@ int randomseed = 0; int parallelizationstrategy = BAATARI1; -char modelname[100]; +char modelname[500]; int njob, nlenmax; -int amino_n[0x80]; -char amino_grp[0x80]; -int amino_dis[0x80][0x80]; -int amino_disLN[0x80][0x80]; -double amino_dis_consweight_multi[0x80][0x80]; -int n_dis[26][26]; -int n_disFFT[26][26]; -float n_dis_consweight_multi[26][26]; -char amino[26]; -double polarity[20]; -double volume[20]; +int amino_n[0x100]; +char amino_grp[0x100]; +//int amino_dis[0x100][0x100]; +int **amino_dis = NULL; +double **n_disLN = NULL; +//double amino_dis_consweight_multi[0x100][0x100]; +double **amino_dis_consweight_multi = NULL; +int **n_dis = NULL; +int **n_disFFT = NULL; +double **n_dis_consweight_multi = NULL; +unsigned char amino[0x100]; +double polarity[0x100]; +double volume[0x100]; int ribosumdis[37][37]; int ppid; @@ -36,7 +38,7 @@ int fmodel; // 1-> fmodel 0->default -1->raw int nblosum; // 45, 50, 62, 80 int kobetsubunkatsu; int bunkatsu; -int dorp; +int dorp = NOTSPECIFIED; // arguments de shitei suruto, tbfast -> pairlocalalign no yobidashi de futsugou int niter; int contin; int calledByXced; @@ -49,12 +51,16 @@ int refine; int check; double cut; int cooling; +int trywarp = 0; int penalty, ppenalty, penaltyLN; +int penalty_dist, ppenalty_dist; int RNApenalty, RNAppenalty; int RNApenalty_ex, RNAppenalty_ex; int penalty_ex, ppenalty_ex, penalty_exLN; int penalty_EX, ppenalty_EX; int penalty_OP, ppenalty_OP; +int penalty_shift, ppenalty_shift; +double penalty_shift_factor = 100.0; int RNAthr, RNApthr; int offset, poffset, offsetLN, offsetFFT; int scoremtx; @@ -80,7 +86,7 @@ int tbrweight; int disopt; int pamN; int checkC; -float geta2; +double geta2; int treemethod; int kimuraR; char *swopt; @@ -93,7 +99,11 @@ int addprofile = 1; int rnakozo; char rnaprediction; int scoreout = 0; +int spscoreout = 0; int outnumber = 0; +int legacygapcost = 0; +double minimumweight = 0.0005; +int nwildcard = 0; char *signalSM; FILE *prep_g; @@ -101,8 +111,55 @@ FILE *trap_g; char **seq_g; char **res_g; -float consweight_multi = 1.0; -float consweight_rna = 0.0; +double consweight_multi = 1.0; +double consweight_rna = 0.0; char RNAscoremtx = 'n'; -char *newgapstr = "-"; +char TLS *newgapstr = "-"; + +int nalphabets = 26; +int nscoredalphabets = 20; + +double specificityconsideration = 0.0; +int ndistclass = 10; +int maxdistclass = -1; + +int gmsg = 0; + +double sueff_global = SUEFF; + +double lenfaca, lenfacb, lenfacc, lenfacd; +int maxl, tsize; + +void initglobalvariables() +{ + commonAlloc1 = 0; + commonAlloc2 = 0; + commonIP = NULL; + commonJP = NULL; + nthread = 1; + randomseed = 0; + parallelizationstrategy = BAATARI1; + + trywarp = 0; + penalty_shift_factor = 100.0; + outgap = 1; + addprofile = 1; + scoreout = 0; + outnumber = 0; + legacygapcost = 0; + consweight_multi = 1.0; + consweight_rna = 0.0; + RNAscoremtx = 'n'; + + newgapstr = "-"; + + nalphabets = 26; + nscoredalphabets = 20; + + specificityconsideration = 0.0; + ndistclass = 10; + maxdistclass = -1; + + gmsg = 0; +} diff --git a/binaries/src/mafft/core/defs.o b/binaries/src/mafft/core/defs.o new file mode 100644 index 0000000..de4e919 Binary files /dev/null and b/binaries/src/mafft/core/defs.o differ diff --git a/binaries/src/mafft/core/disttbfast b/binaries/src/mafft/core/disttbfast new file mode 100644 index 0000000..29b4343 Binary files /dev/null and b/binaries/src/mafft/core/disttbfast differ diff --git a/binaries/src/mafft/core/disttbfast.c b/binaries/src/mafft/core/disttbfast.c index c7c50fc..8efa68d 100644 --- a/binaries/src/mafft/core/disttbfast.c +++ b/binaries/src/mafft/core/disttbfast.c @@ -1,8 +1,11 @@ #include "mltaln.h" + + #define DEBUG 0 #define IODEBUG 0 #define SCOREOUT 0 +#define SKIP 1 #define END_OF_VEC -1 @@ -12,7 +15,18 @@ static int topin; static int treeout; static int noalign; static int distout; -static float lenfaca, lenfacb, lenfacc, lenfacd; +static int tuplesize; +static int subalignment; +static int subalignmentoffset; +static int nguidetree; +static int sparsepickup; +static int keeplength; +static int ndeleted; +static int mapout; +static int smoothing; +static int compacttree = 0; +static double maxdistmtxsize; + #if 0 #define PLENFACA 0.0123 #define PLENFACB 10252 @@ -27,13 +41,71 @@ static float lenfaca, lenfacb, lenfacc, lenfacd; #define PLENFACB 10000 #define PLENFACC 10000 #define PLENFACD 0.1 -#define DLENFACA 0.01 -#define DLENFACB 2500 -#define DLENFACC 2500 -#define DLENFACD 0.1 +#define D6LENFACA 0.01 +#define D6LENFACB 2500 +#define D6LENFACC 2500 +#define D6LENFACD 0.1 +#define D10LENFACA 0.01 +#define D10LENFACB 1000000 +#define D10LENFACC 1000000 +#define D10LENFACD 0.0 +#endif + +typedef struct _jobtable +{ + int i; + int j; +} Jobtable; + +typedef struct _msacompactdistmtxthread_arg +{ + int njob; + int thread_no; + int *selfscore; + double **partmtx; + char **seq; + int **skiptable; + double *mindist; + int *mindistfrom; + int *jobpospt; +#ifdef enablemultithread + pthread_mutex_t *mutex; +#endif +} msacompactdistmtxthread_arg_t; + +typedef struct _compactdistmtxthread_arg +{ + int njob; + int thread_no; + int *nogaplen; + int **pointt; + int *selfscore; + double **partmtx; + int *jobpospt; + double *mindist; + int *mindistfrom; +#ifdef enablemultithread + pthread_mutex_t *mutex; +#endif +} compactdistmtxthread_arg_t; + +typedef struct _msadistmtxthread_arg +{ + int njob; + int thread_no; + int *selfscore; + double **iscore; + double **partmtx; + char **seq; + int **skiptable; + Jobtable *jobpospt; +#ifdef enablemultithread + pthread_mutex_t *mutex; #endif +} msadistmtxthread_arg_t; #ifdef enablemultithread +// ue futatsu ha singlethread demo tsukau typedef struct _treebasethread_arg { int thread_no; @@ -47,6 +119,9 @@ typedef struct _treebasethread_arg double *effarr; int *alloclenpt; int *fftlog; + char *mergeoralign; + double **newdistmtx; + int *selfscore; pthread_mutex_t *mutex; pthread_cond_t *treecond; } treebasethread_arg_t; @@ -57,7 +132,7 @@ typedef struct _distancematrixthread_arg int njob; int *jobpospt; int **pointt; - float **mtx; + double **mtx; pthread_mutex_t *mutex; } distancematrixthread_arg_t; #endif @@ -105,12 +180,15 @@ void arguments( int argc, char *argv[] ) tbrweight = 3; checkC = 0; treemethod = 'X'; + sueff_global = 0.1; contin = 0; scoremtx = 1; kobetsubunkatsu = 0; dorp = NOTSPECIFIED; + ppenalty_dist = NOTSPECIFIED; ppenalty = -1530; ppenalty_ex = NOTSPECIFIED; + penalty_shift_factor = 1000.0; poffset = -123; kimuraR = NOTSPECIFIED; pamN = NOTSPECIFIED; @@ -119,6 +197,18 @@ void arguments( int argc, char *argv[] ) fftThreshold = NOTSPECIFIED; TMorJTT = JTT; scoreout = 0; + spscoreout = 0; + tuplesize = 6; + subalignment = 0; + subalignmentoffset = 0; + legacygapcost = 0; + specificityconsideration = 0.0; + nguidetree = 1; + sparsepickup = 0; + keeplength = 0; + mapout = 0; + smoothing = 0; + nwildcard = 0; while( --argc > 0 && (*++argv)[0] == '-' ) { @@ -128,57 +218,71 @@ void arguments( int argc, char *argv[] ) { case 'i': inputfile = *++argv; - fprintf( stderr, "inputfile = %s\n", inputfile ); + reporterr( "inputfile = %s\n", inputfile ); --argc; goto nextoption; case 'I': - nadd = atoi( *++argv ); - fprintf( stderr, "nadd = %d\n", nadd ); + nadd = myatoi( *++argv ); + reporterr( "nadd = %d\n", nadd ); + --argc; + goto nextoption; + case 'V': + ppenalty_dist = (int)( atof( *++argv ) * 1000 - 0.5 ); +// fprintf( stderr, "ppenalty = %d\n", ppenalty ); --argc; goto nextoption; case 'f': ppenalty = (int)( atof( *++argv ) * 1000 - 0.5 ); -// fprintf( stderr, "ppenalty = %d\n", ppenalty ); +// reporterr( "ppenalty = %d\n", ppenalty ); + --argc; + goto nextoption; + case 'Q': + penalty_shift_factor = atof( *++argv ); --argc; goto nextoption; case 'g': ppenalty_ex = (int)( atof( *++argv ) * 1000 - 0.5 ); - fprintf( stderr, "ppenalty_ex = %d\n", ppenalty_ex ); + reporterr( "ppenalty_ex = %d\n", ppenalty_ex ); --argc; goto nextoption; case 'h': poffset = (int)( atof( *++argv ) * 1000 - 0.5 ); -// fprintf( stderr, "poffset = %d\n", poffset ); +// reporterr( "poffset = %d\n", poffset ); --argc; goto nextoption; case 'k': - kimuraR = atoi( *++argv ); - fprintf( stderr, "kappa = %d\n", kimuraR ); + kimuraR = myatoi( *++argv ); + reporterr( "kappa = %d\n", kimuraR ); --argc; goto nextoption; case 'b': - nblosum = atoi( *++argv ); + nblosum = myatoi( *++argv ); scoremtx = 1; -// fprintf( stderr, "blosum %d / kimura 200 \n", nblosum ); +// reporterr( "blosum %d / kimura 200 \n", nblosum ); --argc; goto nextoption; case 'j': - pamN = atoi( *++argv ); + pamN = myatoi( *++argv ); scoremtx = 0; TMorJTT = JTT; - fprintf( stderr, "jtt/kimura %d\n", pamN ); + reporterr( "jtt/kimura %d\n", pamN ); --argc; goto nextoption; case 'm': - pamN = atoi( *++argv ); + pamN = myatoi( *++argv ); scoremtx = 0; TMorJTT = TM; - fprintf( stderr, "tm %d\n", pamN ); + reporterr( "tm %d\n", pamN ); --argc; goto nextoption; case 'C': - nthread = atoi( *++argv ); - fprintf( stderr, "nthread = %d\n", nthread ); + nthread = myatoi( *++argv ); + reporterr( "nthread = %d\n", nthread ); + --argc; + goto nextoption; + case 's': + specificityconsideration = (double)myatof( *++argv ); +// reporterr( "specificityconsideration = %f\n", specificityconsideration ); --argc; goto nextoption; #if 1 @@ -198,18 +302,28 @@ void arguments( int argc, char *argv[] ) case 'T': noalign = 1; break; +#if 0 case 'r': fmodel = -1; break; +#endif case 'D': dorp = 'd'; break; case 'P': dorp = 'p'; break; + case 'L': + legacygapcost = 1; + break; case 'e': fftscore = 0; break; + case 'H': + subalignment = 1; + subalignmentoffset = myatoi( *++argv ); + --argc; + goto nextoption; #if 0 case 'R': fftRepeatStop = 1; @@ -218,45 +332,66 @@ void arguments( int argc, char *argv[] ) case 'n' : outnumber = 1; break; +#if 0 case 's': treemethod = 's'; break; - case 'X': - treemethod = 'X'; // mix - break; - case 'E': - treemethod = 'E'; // upg (average) - break; case 'q': treemethod = 'q'; // minimum break; +#endif + case 'q': + sparsepickup = myatoi( *++argv ); +// reporterr( "sparsepickup = %d\n", sparsepickup ); + --argc; + goto nextoption; + case 'X': + treemethod = 'X'; + sueff_global = atof( *++argv ); +// fprintf( stderr, "sueff_global = %f\n", sueff_global ); + --argc; + goto nextoption; + case 'E': + nguidetree = myatoi( *++argv ); +// reporterr( "nguidetree = %d\n", nguidetree ); + --argc; + goto nextoption; #if 0 case 'a': alg = 'a'; break; -#endif - case 'R': - alg = 'R'; - break; - case 'Q': - alg = 'Q'; - break; case 'H': alg = 'H'; break; + case 'R': + alg = 'R'; + break; +#endif case 'A': alg = 'A'; break; + case '&': + alg = 'a'; + break; + case '@': + alg = 'd'; + break; case 'N': nevermemsave = 1; break; case 'M': alg = 'M'; break; - case 'S': - scoreout = 1; +#if 0 + case 'S' : + scoreout = 1; // for checking parallel calculation + break; +#else + case 'S' : + spscoreout = 1; // 2014/Dec/30, sp score break; - case 'B': +#endif + case 'B': // hitsuyou! memopt -M -B no tame break; case 'F': use_fft = 1; @@ -265,9 +400,11 @@ void arguments( int argc, char *argv[] ) use_fft = 1; force_fft = 1; break; +#if 0 case 'V': topin = 1; break; +#endif case 'U': treein = 1; break; @@ -278,9 +415,11 @@ void arguments( int argc, char *argv[] ) case 'v': tbrweight = 3; break; +#if 1 case 'd': disp = 1; break; +#endif #if 1 case 'O': outgap = 0; @@ -294,18 +433,36 @@ void arguments( int argc, char *argv[] ) tbutree = 0; break; case 'z': - fftThreshold = atoi( *++argv ); + fftThreshold = myatoi( *++argv ); --argc; goto nextoption; case 'w': - fftWinSize = atoi( *++argv ); + fftWinSize = myatoi( *++argv ); --argc; goto nextoption; + case 'W': + tuplesize = myatoi( *++argv ); + --argc; + goto nextoption; +#if 0 case 'Z': checkC = 1; break; +#endif + case 'Y': + keeplength = 1; + break; + case 'Z': + mapout = 1; + break; + case 'p': + smoothing = 1; + break; + case ':': + nwildcard = 1; + break; default: - fprintf( stderr, "illegal option %c\n", c ); + reporterr( "illegal option %c\n", c ); argc = 0; break; } @@ -320,21 +477,168 @@ void arguments( int argc, char *argv[] ) } if( argc != 0 ) { - fprintf( stderr, "options: Check source file !\n" ); + reporterr( "options: Check source file !\n" ); exit( 1 ); } if( tbitr == 1 && outgap == 0 ) { - fprintf( stderr, "conflicting options : o, m or u\n" ); + reporterr( "conflicting options : o, m or u\n" ); exit( 1 ); } } +static int varpairscore( int nseq, int npick, int nlenmax, char **seq, int seed ) +{ + int i, j, npair; + int *slist; + char **pickseq; + double score; + double scoreav; + double scoreav2; + double scorestd; + double scorevar; + slist = calloc( nseq, sizeof( int ) ); + pickseq = AllocateCharMtx( npick, nlenmax ); + reporterr( "nseq = %d, nlenmax=%d, seed=%d\n", nseq, nlenmax, seed ); + + srand( seed ); + + for( i=0; i longestlen[i][0] ) + { + longestlen[i][0] = seqlen[m]; + longestseq[i][0] = m; + } +// reporterr( "%d ", topol[i][0][j] ); + } +// reporterr( "longest = %d (%d)\n", longestlen[i][0], longestseq[i][0] ); + + + longestlen[i][1] = -1; + longestseq[i][1] = -1; + for( j=0; (m=topol[i][1][j])!=-1; j++ ) // sukoshi muda + { + if( seqlen[m] > longestlen[i][1] ) + { + longestlen[i][1] = seqlen[m]; + longestseq[i][1] = m; + } +// reporterr( "%d ", topol[i][1][j] ); + } +// reporterr( "longest = %d (%d)\n", longestlen[i][1], longestseq[i][1] ); + } + m = 1; + for( i=n-2; i>-1; i-- ) + { +// reporterr( "longest[%d][0] = %d (%d)\n", i, longestlen[i][0], longestseq[i][0] ); +// reporterr( "longest[%d][1] = %d (%d)\n", i, longestlen[i][1], longestseq[i][1] ); + select[longestseq[i][0]] = 1; + select[longestseq[i][1]] = 1; + m += 1; + if( m >= sparsepickup ) break; + } + for( i=0, k=0, j=0; ithread_no; + pos -= ori; + if( pos < 0 ) pos += max; + return( 0.00000000000001 * pos ); +} + +static void *compactdisthalfmtxthread( void *arg ) // enablemultithread == 0 demo tsukau +{ + compactdistmtxthread_arg_t *targ = (compactdistmtxthread_arg_t *)arg; int njob = targ->njob; - int *jobpospt = targ->jobpospt; + int thread_no = targ->thread_no; + int *selfscore = targ->selfscore; + double **partmtx = targ->partmtx; + int *nogaplen = targ->nogaplen; int **pointt = targ->pointt; - float **mtx = targ->mtx; - - short *table1; + int *jobpospt = targ->jobpospt; + double *mindist = targ->mindist; + int *mindistfrom = targ->mindistfrom; int i, j; + double tmpdist, preference, tmpdistx, tmpdisty; + int *table1; while( 1 ) { - pthread_mutex_lock( targ->mutex ); - i = *jobpospt; - if( i == njob ) +#ifdef enablemultithread + if( nthread ) { + pthread_mutex_lock( targ->mutex ); + i = *jobpospt; + if( i == njob-1 ) + { + pthread_mutex_unlock( targ->mutex ); + commonsextet_p( NULL, NULL ); + return( NULL ); + } + *jobpospt = i+1; pthread_mutex_unlock( targ->mutex ); - commonsextet_p( NULL, NULL ); - return( NULL ); } - *jobpospt = i+1; - pthread_mutex_unlock( targ->mutex ); + else +#endif + { + i = *jobpospt; + if( i == njob-1 ) + { + commonsextet_p( NULL, NULL ); + return( NULL ); + } + *jobpospt = i+1; + } - table1 = (short *)calloc( tsize, sizeof( short ) ); + table1 = (int *)calloc( tsize, sizeof( int ) ); if( !table1 ) ErrorExit( "Cannot allocate table1\n" ); - if( i % 10 == 0 ) + if( i % 100 == 0 ) { - fprintf( stderr, "\r% 5d / %d (thread %4d)", i+1, njob, thread_no ); + if( nthread ) + reporterr( "\r% 5d / %d (thread %4d)", i+1, njob, thread_no ); + else + reporterr( "\r% 5d / %d", i+1, njob ); } makecompositiontable_p( table1, pointt[i] ); - for( j=i; jthread_no; - int *nrunpt = targ->nrunpt; + msacompactdistmtxthread_arg_t *targ = (msacompactdistmtxthread_arg_t *)arg; int njob = targ->njob; - int *nlen = targ->nlen; - int *jobpospt = targ->jobpospt; - int ***topol = targ->topol; - Treedep *dep = targ->dep; - char **aseq = targ->aseq; - double *effarr = targ->effarr; - int *alloclen = targ->alloclenpt; - int *fftlog = targ->fftlog; - - char **mseq1, **mseq2; - char **localcopy; - int i, j, l; - int len1, len2; - int clus1, clus2; - float pscore, tscore; - char *indication1, *indication2; - double *effarr1 = NULL; - double *effarr2 = NULL; - float dumfl = 0.0; - int ffttry; - int m1, m2; -#if 0 + int thread_no = targ->thread_no; + int *selfscore = targ->selfscore; + double **partmtx = targ->partmtx; + char **seq = targ->seq; + int **skiptable = targ->skiptable; + double *mindist = targ->mindist; + int *mindistfrom = targ->mindistfrom; + int *jobpospt = targ->jobpospt; + double tmpdist, preference, tmpdistx, tmpdisty; int i, j; -#endif - - mseq1 = AllocateCharMtx( njob, 0 ); - mseq2 = AllocateCharMtx( njob, 0 ); - localcopy = calloc( njob, sizeof( char * ) ); - effarr1 = AllocateDoubleVec( njob ); - effarr2 = AllocateDoubleVec( njob ); - indication1 = AllocateCharVec( 150 ); - indication2 = AllocateCharVec( 150 ); - - -#if 0 - fprintf( stderr, "##### fftwinsize = %d, fftthreshold = %d\n", fftWinSize, fftThreshold ); -#endif - -#if 0 - for( i=0; imutex ); - l = *jobpospt; - if( l == njob-1 ) +#ifdef enablemultithread + if( nthread ) { - pthread_mutex_unlock( targ->mutex ); + pthread_mutex_lock( targ->mutex ); + i = *jobpospt; + if( i == njob-1 ) + { + pthread_mutex_unlock( targ->mutex ); + return( NULL ); + } + *jobpospt = i+1; + pthread_mutex_unlock( targ->mutex ); + } + else +#endif + { + i = *jobpospt; + if( i == njob-1 ) + { + return( NULL ); + } + *jobpospt = i+1; + } + + if( i % 100 == 0 ) + { + if( nthread ) + fprintf( stderr, "\r% 5d / %d (thread %4d)", i, njob, thread_no ); + else + fprintf( stderr, "\r% 5d / %d", i, njob ); + } + + for( j=i+1; jnjob; + int thread_no = targ->thread_no; + int *selfscore = targ->selfscore; + double **iscore = targ->iscore; + char **seq = targ->seq; + int **skiptable = targ->skiptable; + Jobtable *jobpospt = targ->jobpospt; + + + double ssi, ssj, bunbo, iscoretmp; + int i, j; + int nlim = njob-1; + + while( 1 ) + { +#ifdef enablemultithread + if( nthread ) + { + pthread_mutex_lock( targ->mutex ); + i = jobpospt->i; // (jobpospt-i)++ dato, shuuryou hantei no mae ni ++ surunode, tomaranakunaru. + + if( i == nlim ) + { + pthread_mutex_unlock( targ->mutex ); + return( NULL ); + } + jobpospt->i += 1; + pthread_mutex_unlock( targ->mutex ); + if( i % 100 == 0 ) fprintf( stderr, "\r% 5d / %d (thread %4d)", i, njob, thread_no ); + } + else +#endif + { + i = (jobpospt->i)++; + if( i == nlim ) return( NULL ); + if( i % 100 == 0 ) fprintf( stderr, "\r% 5d / %d", i, njob ); + } + + ssi = selfscore[i]; + for( j=i+1; j 10 ) iscoretmp = 10.0; // 2015/Mar/17 + + } + if( iscoretmp < 0.0 ) + { + reporterr( "WARNING: negative distance, iscoretmp = %f\n", iscoretmp ); + iscoretmp = 0.0; + } + iscore[i][j-i] = iscoretmp; +// printf( "i,j=%d,%d, iscoretmp=%f\n", i, j, iscoretmp ); + + } + } +} +#else +static void *msadistmtxthread( void *arg ) // enablemultithread == 0 demo tsukau +{ + msadistmtxthread_arg_t *targ = (msadistmtxthread_arg_t *)arg; + int njob = targ->njob; + int thread_no = targ->thread_no; + int *selfscore = targ->selfscore; + double **iscore = targ->iscore; + char **seq = targ->seq; + int **skiptable = targ->skiptable; + Jobtable *jobpospt = targ->jobpospt; + + + double ssi, ssj, bunbo, iscoretmp; + int i, j; + + while( 1 ) + { +#ifdef enablemultithread + if( nthread ) pthread_mutex_lock( targ->mutex ); +#endif + j = jobpospt->j; + i = jobpospt->i; + j++; + if( j == njob ) + { + i++; + j = i + 1; + if( i == njob-1 ) + { +#ifdef enablemultithread + if( nthread ) pthread_mutex_unlock( targ->mutex ); +#endif + return( NULL ); + } + } + jobpospt->j = j; + jobpospt->i = i; +#ifdef enablemultithread + if( nthread ) pthread_mutex_unlock( targ->mutex ); +#endif + + + if( nthread ) + { + if( j==i+1 && i % 10 == 0 ) fprintf( stderr, "\r% 5d / %d (thread %4d)", i, njob, thread_no ); + } + else + { + if( j==i+1 && i % 10 == 0 ) fprintf( stderr, "\r% 5d / %d", i, njob ); + } + ssi = selfscore[i]; + ssj = selfscore[j]; + bunbo = MIN( ssi, ssj ); +//fprintf( stderr, "bunbo = %f\n", bunbo ); +//fprintf( stderr, "naivepairscorefast() = %f\n", naivepairscorefast( seq[i], seq[j], skiptable[i], skiptable[j], penalty_dist ) ); + if( bunbo == 0.0 ) + iscoretmp = 2.0; // 2013/Oct/17 + else + { + iscoretmp = ( 1.0 - naivepairscorefast( seq[i], seq[j], skiptable[i], skiptable[j], penalty_dist ) / bunbo ) * 2.0; // 2014/Aug/15 fast + if( iscoretmp > 10 ) iscoretmp = 10.0; // 2015/Mar/17 + + } + iscore[i][j-i] = iscoretmp; + + + } +} +#endif + +#ifdef enablemultithread +static void *distancematrixthread( void *arg ) +{ + distancematrixthread_arg_t *targ = (distancematrixthread_arg_t *)arg; + int thread_no = targ->thread_no; + int njob = targ->njob; + int *jobpospt = targ->jobpospt; + int **pointt = targ->pointt; + double **mtx = targ->mtx; + + int *table1; + int i, j; + + while( 1 ) + { + pthread_mutex_lock( targ->mutex ); + i = *jobpospt; + if( i == njob ) + { + pthread_mutex_unlock( targ->mutex ); + commonsextet_p( NULL, NULL ); + return( NULL ); + } + *jobpospt = i+1; + pthread_mutex_unlock( targ->mutex ); + + table1 = (int *)calloc( tsize, sizeof( int ) ); + if( !table1 ) ErrorExit( "Cannot allocate table1\n" ); + if( i % 100 == 0 ) + { + reporterr( "\r% 5d / %d (thread %4d)", i+1, njob, thread_no ); + } + makecompositiontable_p( table1, pointt[i] ); + + for( j=i; jthread_no; + int *nrunpt = targ->nrunpt; + int njob = targ->njob; + int *nlen = targ->nlen; + int *jobpospt = targ->jobpospt; + int ***topol = targ->topol; + Treedep *dep = targ->dep; + char **aseq = targ->aseq; + double *effarr = targ->effarr; + int *alloclen = targ->alloclenpt; + int *fftlog = targ->fftlog; + char *mergeoralign = targ->mergeoralign; + double **newdistmtx = targ->newdistmtx; + int *selfscore = targ->selfscore; + + char **mseq1, **mseq2; + char **localcopy; + int i, m, j, l; + int immin, immax; + int len1, len2; + int clus1, clus2; + double pscore, tscore; + char *indication1, *indication2; + double *effarr1 = NULL; + double *effarr2 = NULL; +// double dumfl = 0.0; + double dumdb = 0.0; + int ffttry; + int m1, m2; + double **dynamicmtx; + int ssi, ssm, bunbo; + int tm, ti; + int **localmem = NULL; + int posinmem; +#if SKIP + int **skiptable1 = NULL, **skiptable2 = NULL; +#endif +#if 0 + int i, j; +#endif + + mseq1 = AllocateCharMtx( njob, 0 ); + mseq2 = AllocateCharMtx( njob, 0 ); + localcopy = calloc( njob, sizeof( char * ) ); + for( i=0; imutex ); + l = *jobpospt; + if( l == njob-1 ) + { + pthread_mutex_unlock( targ->mutex ); if( commonIP ) FreeIntMtx( commonIP ); commonIP = NULL; - Falign( NULL, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, 0, NULL ); + Falign( NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, 0, NULL ); + Falign_udpari_long( NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, NULL ); + A__align( NULL, NULL, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0, -1, -1 ); + D__align( NULL, NULL, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0 ); + G__align11( NULL, NULL, NULL, 0, 0, 0 ); // iru? free( mseq1 ); free( mseq2 ); free( localcopy ); @@ -604,6 +1255,8 @@ static void *treebasethread( void *arg ) free( effarr2 ); free( indication1 ); free( indication2 ); + FreeDoubleMtx( dynamicmtx ); + FreeIntMtx( localmem ); return( NULL ); } *jobpospt = l+1; @@ -622,34 +1275,76 @@ static void *treebasethread( void *arg ) pthread_cond_wait( targ->treecond, targ->mutex ); (*nrunpt)++; + + if( mergeoralign[l] == 'n' ) + { +// reporterr( "SKIP!\n" ); + dep[l].done = 1; + (*nrunpt)--; + pthread_cond_broadcast( targ->treecond ); +// free( topol[l][0] ); topol[l][0] = NULL; +// free( topol[l][1] ); topol[l][1] = NULL; +// free( topol[l] ); topol[l] = NULL; + pthread_mutex_unlock( targ->mutex ); + continue; + } + + + m1 = topol[l][0][0]; m2 = topol[l][1][0]; +// reporterr( "\ndistfromtip = %f\n", dep[l].distfromtip ); +// makedynamicmtx( dynamicmtx, n_dis_consweight_multi, dep[l].distfromtip - 0.5 ); + makedynamicmtx( dynamicmtx, n_dis_consweight_multi, dep[l].distfromtip ); + len1 = strlen( aseq[m1] ); len2 = strlen( aseq[m2] ); if( *alloclen <= len1 + len2 ) { - fprintf( stderr, "\nReallocating.." ); + reporterr( "\nReallocating.." ); *alloclen = ( len1 + len2 ) + 1000; ReallocateCharMtx( aseq, njob, *alloclen + 10 ); - fprintf( stderr, "done. *alloclen = %d\n", *alloclen ); + reporterr( "done. *alloclen = %d\n", *alloclen ); } - for( i=0; (j=topol[l][0][i])!=-1; i++ ) + localmem[0][0] = -1; + posinmem=0; + topolorder( njob, localmem[0], &posinmem, topol, dep, l, 0 ); + localmem[1][0] = -1; + posinmem=0; + topolorder( njob, localmem[1], &posinmem, topol, dep, l, 1 ); + for( i=0; (j=localmem[0][i])!=-1; i++ ) { localcopy[j] = calloc( *alloclen, sizeof( char ) ); strcpy( localcopy[j], aseq[j] ); } - for( i=0; (j=topol[l][1][i])!=-1; i++ ) + for( i=0; (j=localmem[1][i])!=-1; i++ ) { localcopy[j] = calloc( *alloclen, sizeof( char ) ); strcpy( localcopy[j], aseq[j] ); } + + if( !nevermemsave && ( alg != 'M' && ( len1 > 30000 || len2 > 30000 ) ) ) + { + reporterr( "\nlen1=%d, len2=%d, Switching to the memsave mode\n", len1, len2 ); + alg = 'M'; + } + + if( alg == 'M' ) // hoka no thread ga M ni shitakamo shirenainode + { +// reporterr( "Freeing commonIP (thread %d)\n", thread_no ); + if( commonIP ) FreeIntMtx( commonIP ); + commonIP = NULL; + commonAlloc1 = 0; + commonAlloc2 = 0; + } + pthread_mutex_unlock( targ->mutex ); #if 1 // CHUUI@@@@ - clus1 = fastconjuction_noname( topol[l][0], localcopy, mseq1, effarr1, effarr, indication1 ); - clus2 = fastconjuction_noname( topol[l][1], localcopy, mseq2, effarr2, effarr, indication2 ); + clus1 = fastconjuction_noname( localmem[0], localcopy, mseq1, effarr1, effarr, indication1, 0.0 ); + clus2 = fastconjuction_noname( localmem[1], localcopy, mseq2, effarr2, effarr, indication2, 0.0 ); #else clus1 = fastconjuction_noweight( topol[l][0], localcopy, mseq1, effarr1, indication1 ); clus2 = fastconjuction_noweight( topol[l][1], localcopy, mseq2, effarr2, indication2 ); @@ -661,8 +1356,8 @@ static void *treebasethread( void *arg ) { if( strlen( mseq1[i] ) != len1 ) { - fprintf( stderr, "i = %d / %d\n", i, clus1 ); - fprintf( stderr, "hairetsu ga kowareta (in treebase, after conjuction) !\n" ); + reporterr( "i = %d / %d\n", i, clus1 ); + reporterr( "hairetsu ga kowareta (in treebase, after conjuction) !\n" ); exit( 1 ); } } @@ -670,8 +1365,8 @@ static void *treebasethread( void *arg ) { if( strlen( mseq2[j] ) != len2 ) { - fprintf( stderr, "j = %d / %d\n", j, clus2 ); - fprintf( stderr, "hairetsu ga kowareta (in treebase, after conjuction) !\n" ); + reporterr( "j = %d / %d\n", j, clus2 ); + reporterr( "hairetsu ga kowareta (in treebase, after conjuction) !\n" ); exit( 1 ); } } @@ -682,8 +1377,8 @@ static void *treebasethread( void *arg ) { if( strlen( mseq1[i] ) != len1 ) { - fprintf( stderr, "i = %d / %d\n", i, clus1 ); - fprintf( stderr, "hairetsu ga kowareta (in treebase, after free topol) !\n" ); + reporterr( "i = %d / %d\n", i, clus1 ); + reporterr( "hairetsu ga kowareta (in treebase, after free topol) !\n" ); exit( 1 ); } } @@ -691,8 +1386,8 @@ static void *treebasethread( void *arg ) { if( strlen( mseq2[j] ) != len2 ) { - fprintf( stderr, "j = %d / %d\n", j, clus2 ); - fprintf( stderr, "hairetsu ga kowareta (in treebase, after free topol) !\n" ); + reporterr( "j = %d / %d\n", j, clus2 ); + reporterr( "hairetsu ga kowareta (in treebase, after free topol) !\n" ); exit( 1 ); } } @@ -703,63 +1398,55 @@ static void *treebasethread( void *arg ) // fprintf( trap_g, "group1 = %s\n", indication1 ); // fprintf( trap_g, "group2 = %s\n", indication2 ); -// fprintf( stderr, "\rSTEP % 5d / %d %d-%d", l+1, njob-1, clus1, clus2 ); - fprintf( stderr, "\rSTEP % 5d / %d (thread %4d)", l+1, njob-1, thread_no ); +// reporterr( "\rSTEP % 5d / %d %d-%d", l+1, njob-1, clus1, clus2 ); + reporterr( "\rSTEP % 5d / %d (thread %4d)", l+1, njob-1, thread_no ); #if 0 - fprintf( stderr, "STEP %d /%d\n", l+1, njob-1 ); - fprintf( stderr, "group1 = %.66s", indication1 ); - if( strlen( indication1 ) > 66 ) fprintf( stderr, "..." ); - fprintf( stderr, "\n" ); - fprintf( stderr, "group2 = %.66s", indication2 ); - if( strlen( indication2 ) > 66 ) fprintf( stderr, "..." ); - fprintf( stderr, "\n" ); + reporterr( "STEP %d /%d\n", l+1, njob-1 ); + reporterr( "group1 = %.66s", indication1 ); + if( strlen( indication1 ) > 66 ) reporterr( "..." ); + reporterr( "\n" ); + reporterr( "group2 = %.66s", indication2 ); + if( strlen( indication2 ) > 66 ) reporterr( "..." ); + reporterr( "\n" ); #endif /* - fprintf( stderr, "before align all\n" ); + reporterr( "before align all\n" ); display( aseq, njob ); - fprintf( stderr, "\n" ); - fprintf( stderr, "before align 1 %s \n", indication1 ); + reporterr( "\n" ); + reporterr( "before align 1 %s \n", indication1 ); display( mseq1, clus1 ); - fprintf( stderr, "\n" ); - fprintf( stderr, "before align 2 %s \n", indication2 ); + reporterr( "\n" ); + reporterr( "before align 2 %s \n", indication2 ); display( mseq2, clus2 ); - fprintf( stderr, "\n" ); + reporterr( "\n" ); */ - if( !nevermemsave && ( alg != 'M' && ( len1 > 30000 || len2 > 30000 ) ) ) - { - fprintf( stderr, "\nlen1=%d, len2=%d, Switching to the memsave mode\n", len1, len2 ); - alg = 'M'; - if( commonIP ) FreeIntMtx( commonIP ); - commonAlloc1 = 0; - commonAlloc2 = 0; - } // if( fftlog[m1] && fftlog[m2] ) ffttry = ( nlen[m1] > clus1 && nlen[m2] > clus2 ); if( fftlog[m1] && fftlog[m2] ) ffttry = ( nlen[m1] > clus1 && nlen[m2] > clus2 && clus1 < 1000 && clus2 < 1000); else ffttry = 0; // ffttry = ( nlen[m1] > clus1 && nlen[m2] > clus2 && clus1 < 5000 && clus2 < 5000); // v6.708 -// fprintf( stderr, "f=%d, len1/fftlog[m1]=%f, clus1=%d, len2/fftlog[m2]=%f, clus2=%d\n", ffttry, (float)len1/fftlog[m1], clus1, (float)len2/fftlog[m2], clus2 ); +// reporterr( "f=%d, len1/fftlog[m1]=%f, clus1=%d, len2/fftlog[m2]=%f, clus2=%d\n", ffttry, (double)len1/fftlog[m1], clus1, (double)len2/fftlog[m2], clus2 ); if( force_fft || ( use_fft && ffttry ) ) { - fprintf( stderr, "f" ); + reporterr( "f" ); if( alg == 'M' ) { - fprintf( stderr, "m" ); - pscore = Falign_udpari_long( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, fftlog+m1 ); + reporterr( "m" ); + pscore = Falign_udpari_long( NULL, NULL, dynamicmtx, mseq1, mseq2, effarr1, effarr2, NULL, NULL, clus1, clus2, *alloclen, fftlog+m1 ); } else { - pscore = Falign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, fftlog+m1, NULL, 0, NULL ); + pscore = Falign( NULL, NULL, dynamicmtx, mseq1, mseq2, effarr1, effarr2, NULL, NULL, clus1, clus2, *alloclen, fftlog+m1, NULL, 0, NULL ); } } else { - fprintf( stderr, "d" ); + reporterr( "d" ); fftlog[m1] = 0; switch( alg ) { @@ -767,37 +1454,32 @@ static void *treebasethread( void *arg ) pscore = Aalign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen ); break; case( 'M' ): - fprintf( stderr, "m" ); -// fprintf( stderr, "%d-%d", clus1, clus2 ); - pscore = MSalignmm( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, NULL, NULL, NULL, NULL, 0, NULL, outgap, outgap ); + reporterr( "m" ); +// reporterr( "%d-%d", clus1, clus2 ); + pscore = MSalignmm( dynamicmtx, mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, NULL, NULL, NULL, NULL, 0, NULL, outgap, outgap ); break; - case( 'Q' ): - if( clus1 == 1 && clus2 == 1 && 0 ) + case( 'd' ): + if( 1 && clus1 == 1 && clus2 == 1 ) { -// fprintf( stderr, "%d-%d", clus1, clus2 ); - pscore = G__align11( mseq1, mseq2, *alloclen, outgap, outgap ); +// reporterr( "%d-%d", clus1, clus2 ); + pscore = G__align11( dynamicmtx, mseq1, mseq2, *alloclen, outgap, outgap ); } else { - pscore = Q__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL ); +// reporterr( "%d-%d", clus1, clus2 ); + pscore = D__align_ls( dynamicmtx, mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, &dumdb, NULL, NULL, NULL, NULL, NULL, 0, NULL, outgap, outgap ); } break; - case( 'R' ): - pscore = R__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL ); - break; - case( 'H' ): - pscore = H__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL ); - break; case( 'A' ): if( clus1 == 1 && clus2 == 1 ) { -// fprintf( stderr, "%d-%d", clus1, clus2 ); - pscore = G__align11( mseq1, mseq2, *alloclen, outgap, outgap ); +// reporterr( "%d-%d", clus1, clus2 ); + pscore = G__align11( dynamicmtx, mseq1, mseq2, *alloclen, outgap, outgap ); } else { -// fprintf( stderr, "%d-%d", clus1, clus2 ); - pscore = A__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL, NULL, 0, NULL, outgap, outgap ); +// reporterr( "%d-%d", clus1, clus2 ); + pscore = A__align( dynamicmtx, mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, &dumdb, NULL, NULL, NULL, NULL, NULL, 0, NULL, outgap, outgap, -1, -1 ); } break; default: @@ -805,62 +1487,146 @@ static void *treebasethread( void *arg ) } } #if SCOREOUT - fprintf( stderr, "score = %10.2f\n", pscore ); + reporterr( "score = %10.2f\n", pscore ); #endif tscore += pscore; nlen[m1] = 0.5 * ( nlen[m1] + nlen[m2] ); - if( disp ) display( localcopy, njob ); + if( newdistmtx ) // tsukawanai + { +#if 0 + reporterr( "group1 = " ); + for( i=0; imutex ); dep[l].done = 1; (*nrunpt)--; pthread_cond_broadcast( targ->treecond ); - for( i=0; (j=topol[l][0][i])!=-1; i++ ) + for( i=0; (j=localmem[0][i])!=-1; i++ ) strcpy( aseq[j], localcopy[j] ); - for( i=0; (j=topol[l][1][i])!=-1; i++ ) + for( i=0; (j=localmem[1][i])!=-1; i++ ) strcpy( aseq[j], localcopy[j] ); - pthread_mutex_unlock( targ->mutex ); - for( i=0; (j=topol[l][0][i])!=-1; i++ ) - free( localcopy[j] ); - for( i=0; (j=topol[l][1][i])!=-1; i++ ) - free( localcopy[j] ); - free( topol[l][0] ); - free( topol[l][1] ); - free( topol[l] ); +// reporterr( "at step %d\n", l ); +// use_getrusage(); + pthread_mutex_unlock( targ->mutex ); -// fprintf( stderr, "\n" ); - } -#if SCOREOUT - fprintf( stderr, "totalscore = %10.2f\n\n", tscore ); -#endif -} -#endif -static void treebase( int *nlen, char **aseq, int nadd, char *mergeoralign, char **mseq1, char **mseq2, int ***topol, double *effarr, int *alloclen ) -{ - int l, len1, len2, i, m; - int len1nocommongap, len2nocommongap; + + for( i=0; (j=localmem[0][i])!=-1; i++ ) + { + if(localcopy[j] ) free( localcopy[j] ); + localcopy[j] = NULL; + } + for( i=0; (j=localmem[1][i])!=-1; i++ ) + { + if( localcopy[j] ) free( localcopy[j] ); + localcopy[j] = NULL; + } + + +// if( topol[l][0] ) free( topol[l][0] ); +// topol[l][0] = NULL; +// if( topol[l][1] ) free( topol[l][1] ); +// topol[l][1] = NULL; +// if( topol[l] ) free( topol[l] ); +// topol[l] = NULL; + + +// reporterr( "\n" ); + } +#if SCOREOUT + reporterr( "totalscore = %10.2f\n\n", tscore ); +#endif +} +#endif + +static int treebase( int *nlen, char **aseq, int nadd, char *mergeoralign, char **mseq1, char **mseq2, int ***topol, Treedep *dep, double *effarr, double **newdistmtx, int *selfscore, int *alloclen, int (*callback)(int, int, char*) ) +{ + int l, len1, len2, i, m, immin, immax; + int len1nocommongap, len2nocommongap; int clus1, clus2; - float pscore, tscore; - static char *indication1, *indication2; - static double *effarr1 = NULL; - static double *effarr2 = NULL; - static int *fftlog; // fixed at 2006/07/26 - float dumfl = 0.0; + double pscore, tscore; + char *indication1 = NULL, *indication2 = NULL; + double *effarr1 = NULL; + double *effarr2 = NULL; + int *fftlog = NULL; // fixed at 2006/07/26 +// double dumfl = 0.0; + double dumdb = 0.0; int ffttry; int m1, m2; - static int *gaplen; - static int *gapmap; - static int *alreadyaligned; + int *gaplen = NULL; + int *gapmap = NULL; + int *alreadyaligned = NULL; + double **dynamicmtx = NULL; + double ssi, ssm, bunbo; + int tm, ti; + int gapmaplen; + int **localmem = NULL; + int posinmem; +#if SKIP + int **skiptable1 = NULL, **skiptable2 = NULL; +#endif #if 0 int i, j; #endif +// reporterr( "treebase newdistmtx=%p\n", newdistmtx ); + if( effarr1 == NULL ) { effarr1 = AllocateDoubleVec( njob ); @@ -871,19 +1637,26 @@ static void treebase( int *nlen, char **aseq, int nadd, char *mergeoralign, char gaplen = AllocateIntVec( *alloclen+10 ); gapmap = AllocateIntVec( *alloclen+10 ); alreadyaligned = AllocateIntVec( njob ); + dynamicmtx = AllocateDoubleMtx( nalphabets, nalphabets ); + localmem = AllocateIntMtx( 2, njob+1 ); } for( i=0; i 0 && dep[l].child0 == l-1 && dep[l].child1 == -1 && dep[dep[l].child0].child1 == -1 ) + { + localmem[0][clus1] = topol[l-1][1][0]; + localmem[0][clus1+1] = -1; + + localmem[1][0] = topol[l][1][0]; + localmem[1][1] = -1; + } + else + { + localmem[0][0] = -1; + posinmem = 0; + topolorder( njob, localmem[0], &posinmem, topol, dep, l, 0 ); + localmem[1][0] = -1; + posinmem = 0; + topolorder( njob, localmem[1], &posinmem, topol, dep, l, 1 ); + } + if( mergeoralign[l] == 'n' ) { -// fprintf( stderr, "SKIP!\n" ); - free( topol[l][0] ); - free( topol[l][1] ); - free( topol[l] ); +// reporterr( "SKIP!\n" ); +// free( topol[l][0] ); topol[l][0] = NULL; +// free( topol[l][1] ); topol[l][1] = NULL; +// free( topol[l] ); topol[l] = NULL; continue; } +// reporterr( "\ndistfromtip = %f\n", dep[l].distfromtip ); + makedynamicmtx( dynamicmtx, n_dis_consweight_multi, dep[l].distfromtip ); +// makedynamicmtx( dynamicmtx, n_dis_consweight_multi, ( dep[l].distfromtip - 0.2 ) * 3 ); + + m1 = topol[l][0][0]; m2 = topol[l][1][0]; len1 = strlen( aseq[m1] ); len2 = strlen( aseq[m2] ); if( *alloclen < len1 + len2 ) { - fprintf( stderr, "\nReallocating.." ); + reporterr( "\nReallocating.." ); *alloclen = ( len1 + len2 ) + 1000; ReallocateCharMtx( aseq, njob, *alloclen + 10 ); gaplen = realloc( gaplen, ( *alloclen + 10 ) * sizeof( int ) ); if( gaplen == NULL ) { - fprintf( stderr, "Cannot realloc gaplen\n" ); + reporterr( "Cannot realloc gaplen\n" ); exit( 1 ); } gapmap = realloc( gapmap, ( *alloclen + 10 ) * sizeof( int ) ); if( gapmap == NULL ) { - fprintf( stderr, "Cannot realloc gapmap\n" ); + reporterr( "Cannot realloc gapmap\n" ); exit( 1 ); } - fprintf( stderr, "done. *alloclen = %d\n", *alloclen ); + reporterr( "done. *alloclen = %d\n", *alloclen ); } #if 1 // CHUUI@@@@ - clus1 = fastconjuction_noname( topol[l][0], aseq, mseq1, effarr1, effarr, indication1 ); - clus2 = fastconjuction_noname( topol[l][1], aseq, mseq2, effarr2, effarr, indication2 ); + clus1 = fastconjuction_noname( localmem[0], aseq, mseq1, effarr1, effarr, indication1, 0.0 ); + clus2 = fastconjuction_noname( localmem[1], aseq, mseq2, effarr2, effarr, indication2, 0.0 ); #else - clus1 = fastconjuction_noweight( topol[l][0], aseq, mseq1, effarr1, indication1 ); - clus2 = fastconjuction_noweight( topol[l][1], aseq, mseq2, effarr2, indication2 ); + clus1 = fastconjuction_noname( topol[l][0], aseq, mseq1, effarr1, effarr, indication1, 0.0 ); + clus2 = fastconjuction_noname( topol[l][1], aseq, mseq2, effarr2, effarr, indication2, 0.0 ); +// clus1 = fastconjuction_noweight( topol[l][0], aseq, mseq1, effarr1, indication1 ); +// clus2 = fastconjuction_noweight( topol[l][1], aseq, mseq2, effarr2, indication2 ); #endif + + + + + + + + + + + if( mergeoralign[l] == '1' || mergeoralign[l] == '2' ) { newgapstr = "="; @@ -961,8 +1772,8 @@ static void treebase( int *nlen, char **aseq, int nadd, char *mergeoralign, char { if( strlen( mseq1[i] ) != len1 ) { - fprintf( stderr, "i = %d / %d\n", i, clus1 ); - fprintf( stderr, "hairetsu ga kowareta (in treebase, after conjuction) !\n" ); + reporterr( "i = %d / %d\n", i, clus1 ); + reporterr( "hairetsu ga kowareta (in treebase, after conjuction) !\n" ); exit( 1 ); } } @@ -970,8 +1781,8 @@ static void treebase( int *nlen, char **aseq, int nadd, char *mergeoralign, char { if( strlen( mseq2[j] ) != len2 ) { - fprintf( stderr, "j = %d / %d\n", j, clus2 ); - fprintf( stderr, "hairetsu ga kowareta (in treebase, after conjuction) !\n" ); + reporterr( "j = %d / %d\n", j, clus2 ); + reporterr( "hairetsu ga kowareta (in treebase, after conjuction) !\n" ); exit( 1 ); } } @@ -983,8 +1794,8 @@ static void treebase( int *nlen, char **aseq, int nadd, char *mergeoralign, char { if( strlen( mseq1[i] ) != len1 ) { - fprintf( stderr, "i = %d / %d\n", i, clus1 ); - fprintf( stderr, "hairetsu ga kowareta (in treebase, after free topol) !\n" ); + reporterr( "i = %d / %d\n", i, clus1 ); + reporterr( "hairetsu ga kowareta (in treebase, after free topol) !\n" ); exit( 1 ); } } @@ -992,8 +1803,8 @@ static void treebase( int *nlen, char **aseq, int nadd, char *mergeoralign, char { if( strlen( mseq2[j] ) != len2 ) { - fprintf( stderr, "j = %d / %d\n", j, clus2 ); - fprintf( stderr, "hairetsu ga kowareta (in treebase, after free topol) !\n" ); + reporterr( "j = %d / %d\n", j, clus2 ); + reporterr( "hairetsu ga kowareta (in treebase, after free topol) !\n" ); exit( 1 ); } } @@ -1004,38 +1815,39 @@ static void treebase( int *nlen, char **aseq, int nadd, char *mergeoralign, char // fprintf( trap_g, "group1 = %s\n", indication1 ); // fprintf( trap_g, "group2 = %s\n", indication2 ); -// fprintf( stderr, "\rSTEP % 5d / %d %d-%d", l+1, njob-1, clus1, clus2 ); - fprintf( stderr, "\rSTEP % 5d / %d ", l+1, njob-1 ); - fflush( stderr ); +// reporterr( "\rSTEP % 5d / %d %d-%d", l+1, njob-1, clus1, clus2 ); + reporterr( "\rSTEP % 5d / %d ", l+1, njob-1 ); + if( callback && callback( 0, 50+50*l/(njob-1), "Progressive alignment" ) ) goto chudan_tbfast; #if 0 - fprintf( stderr, "STEP %d /%d\n", l+1, njob-1 ); - fprintf( stderr, "group1 = %.66s", indication1 ); - if( strlen( indication1 ) > 66 ) fprintf( stderr, "..." ); - fprintf( stderr, "\n" ); - fprintf( stderr, "group2 = %.66s", indication2 ); - if( strlen( indication2 ) > 66 ) fprintf( stderr, "..." ); - fprintf( stderr, "\n" ); + reporterr( "STEP %d /%d\n", l+1, njob-1 ); + reporterr( "group1 = %.66s", indication1 ); + if( strlen( indication1 ) > 66 ) reporterr( "..." ); + reporterr( "\n" ); + reporterr( "group2 = %.66s", indication2 ); + if( strlen( indication2 ) > 66 ) reporterr( "..." ); + reporterr( "\n" ); #endif /* - fprintf( stderr, "before align all\n" ); + reporterr( "before align all\n" ); display( aseq, njob ); - fprintf( stderr, "\n" ); - fprintf( stderr, "before align 1 %s \n", indication1 ); + reporterr( "\n" ); + reporterr( "before align 1 %s \n", indication1 ); display( mseq1, clus1 ); - fprintf( stderr, "\n" ); - fprintf( stderr, "before align 2 %s \n", indication2 ); + reporterr( "\n" ); + reporterr( "before align 2 %s \n", indication2 ); display( mseq2, clus2 ); - fprintf( stderr, "\n" ); + reporterr( "\n" ); */ if( !nevermemsave && ( alg != 'M' && ( len1 > 30000 || len2 > 30000 ) ) ) { - fprintf( stderr, "\nlen1=%d, len2=%d, Switching to the memsave mode\n", len1, len2 ); + reporterr( "\nlen1=%d, len2=%d, Switching to the memsave mode\n", len1, len2 ); alg = 'M'; if( commonIP ) FreeIntMtx( commonIP ); + commonIP = NULL; commonAlloc1 = 0; commonAlloc2 = 0; } @@ -1044,24 +1856,25 @@ static void treebase( int *nlen, char **aseq, int nadd, char *mergeoralign, char if( fftlog[m1] && fftlog[m2] ) ffttry = ( nlen[m1] > clus1 && nlen[m2] > clus2 && clus1 < 1000 && clus2 < 1000); else ffttry = 0; // ffttry = ( nlen[m1] > clus1 && nlen[m2] > clus2 && clus1 < 5000 && clus2 < 5000); // v6.708 -// fprintf( stderr, "f=%d, len1/fftlog[m1]=%f, clus1=%d, len2/fftlog[m2]=%f, clus2=%d\n", ffttry, (float)len1/fftlog[m1], clus1, (float)len2/fftlog[m2], clus2 ); +// reporterr( "f=%d, len1/fftlog[m1]=%f, clus1=%d, len2/fftlog[m2]=%f, clus2=%d\n", ffttry, (double)len1/fftlog[m1], clus1, (double)len2/fftlog[m2], clus2 ); if( force_fft || ( use_fft && ffttry ) ) { - fprintf( stderr, "f" ); + reporterr( "f" ); if( alg == 'M' ) { - fprintf( stderr, "m" ); - pscore = Falign_udpari_long( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, fftlog+m1 ); + reporterr( "m" ); + pscore = Falign_udpari_long( NULL, NULL, dynamicmtx, mseq1, mseq2, effarr1, effarr2, NULL, NULL, clus1, clus2, *alloclen, fftlog+m1 ); } else { - pscore = Falign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, fftlog+m1, NULL, 0, NULL ); + pscore = Falign( NULL, NULL, dynamicmtx, mseq1, mseq2, effarr1, effarr2, NULL, NULL, clus1, clus2, *alloclen, fftlog+m1, NULL, 0, NULL ); +// reporterr( "######### mseq1[0] = %s\n", mseq1[0] ); } } else { - fprintf( stderr, "d" ); + reporterr( "d" ); fftlog[m1] = 0; switch( alg ) { @@ -1069,37 +1882,32 @@ static void treebase( int *nlen, char **aseq, int nadd, char *mergeoralign, char pscore = Aalign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen ); break; case( 'M' ): - fprintf( stderr, "m" ); -// fprintf( stderr, "%d-%d", clus1, clus2 ); - pscore = MSalignmm( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, NULL, NULL, NULL, NULL, 0, NULL, outgap, outgap ); + reporterr( "m" ); +// reporterr( "%d-%d", clus1, clus2 ); + pscore = MSalignmm( dynamicmtx, mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, NULL, NULL, NULL, NULL, 0, NULL, outgap, outgap ); break; - case( 'Q' ): - if( clus1 == 1 && clus2 == 1 && 0 ) + case( 'd' ): + if( 1 && clus1 == 1 && clus2 == 1 ) { -// fprintf( stderr, "%d-%d", clus1, clus2 ); - pscore = G__align11( mseq1, mseq2, *alloclen, outgap, outgap ); +// reporterr( "%d-%d", clus1, clus2 ); + pscore = G__align11( dynamicmtx, mseq1, mseq2, *alloclen, outgap, outgap ); } else { - pscore = Q__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL ); +// reporterr( "%d-%d", clus1, clus2 ); + pscore = D__align_ls( dynamicmtx, mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, &dumdb, NULL, NULL, NULL, NULL, NULL, 0, NULL, outgap, outgap ); } break; - case( 'R' ): - pscore = R__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL ); - break; - case( 'H' ): - pscore = H__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL ); - break; case( 'A' ): if( clus1 == 1 && clus2 == 1 ) { -// fprintf( stderr, "%d-%d", clus1, clus2 ); - pscore = G__align11( mseq1, mseq2, *alloclen, outgap, outgap ); +// reporterr( "%d-%d", clus1, clus2 ); + pscore = G__align11( dynamicmtx, mseq1, mseq2, *alloclen, outgap, outgap ); } else { -// fprintf( stderr, "%d-%d", clus1, clus2 ); - pscore = A__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL, NULL, 0, NULL, outgap, outgap ); +// reporterr( "\n\n %d - %d (%d-%d) : ", topol[l][0][0], topol[l][1][0], clus1, clus2 ); + pscore = A__align( dynamicmtx, mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, &dumdb, NULL, NULL, NULL, NULL, NULL, 0, NULL, outgap, outgap, localmem[0][0], 1 ); } break; default: @@ -1107,7 +1915,7 @@ static void treebase( int *nlen, char **aseq, int nadd, char *mergeoralign, char } } #if SCOREOUT - fprintf( stderr, "score = %10.2f\n", pscore ); + reporterr( "score = %10.2f\n", pscore ); #endif tscore += pscore; nlen[m1] = 0.5 * ( nlen[m1] + nlen[m2] ); @@ -1115,40 +1923,175 @@ static void treebase( int *nlen, char **aseq, int nadd, char *mergeoralign, char // writePre( njob, name, nlen, aseq, 0 ); if( disp ) display( aseq, njob ); -// fprintf( stderr, "\n" ); +// reporterr( "\n" ); if( mergeoralign[l] == '1' ) // jissainiha nai. atarashii hairetsu ha saigo dakara. { - adjustgapmap( strlen( mseq2[0] )-len2nocommongap+len2, gapmap, mseq2[0] ); - restorecommongaps( njob, aseq, topol[l][0], topol[l][1], gapmap, *alloclen ); - findnewgaps( clus2, mseq2, gaplen ); - insertnewgaps( njob, alreadyaligned, aseq, topol[l][1], topol[l][0], gaplen, gapmap, *alloclen, alg ); - for( i=0; i-1; i++ ) alreadyaligned[m] = 1; + reporterr( "Check source!!!\n" ); + exit( 1 ); } if( mergeoralign[l] == '2' ) { - adjustgapmap( strlen( mseq1[0] )-len1nocommongap+len1, gapmap, mseq1[0] ); -// fprintf( stderr, ">STEP1 mseq1[0] = \n%s\n", mseq1[0] ); -// fprintf( stderr, ">STEP1 mseq2[0] = \n%s\n", mseq2[0] ); - restorecommongaps( njob, aseq, topol[l][0], topol[l][1], gapmap, *alloclen ); -// fprintf( stderr, "STEP2 mseq1[0] = %s\n", mseq1[0] ); -// fprintf( stderr, "STEP2 mseq2[0] = %s\n", mseq2[0] ); - findnewgaps( clus1, mseq1, gaplen ); - insertnewgaps( njob, alreadyaligned, aseq, topol[l][0], topol[l][1], gaplen, gapmap, *alloclen, alg ); -// fprintf( stderr, "STEP3 mseq1[0] = %s\n", mseq1[0] ); -// fprintf( stderr, "STEP3 mseq2[0] = %s\n", mseq2[0] ); +// if( localkeeplength ) ndeleted += deletenewinsertions( clus1, clus2, mseq1, mseq2, NULL ); +// for( i=0; iSTEP0 mseq1[%d] = \n%s\n", i, mseq1[i] ); +// for( i=0; iSTEP0 mseq2[%d] = \n%s\n", i, mseq2[i] ); + gapmaplen = strlen( mseq1[0] )-len1nocommongap+len1; + adjustgapmap( gapmaplen, gapmap, mseq1[0] ); +#if 0 + reporterr( "\n" ); + for( i=0; iSTEP1 mseq1[%d] = \n%s\n", i, mseq1[i] ); + for( i=0; iSTEP1 mseq2[%d] = \n%s\n", i, mseq2[i] ); +#endif +// if( clus1 + clus2 < njob ) restorecommongaps( njob, aseq, topol[l][0], topol[l][1], gapmap, *alloclen, '-' ); + if( smoothing ) + { + restorecommongapssmoothly( njob, njob-(clus1+clus2), aseq, localmem[0], localmem[1], gapmap, *alloclen, '-' ); + findnewgaps( clus1, 0, mseq1, gaplen ); + insertnewgaps_bothorders( njob, alreadyaligned, aseq, localmem[0], localmem[1], gaplen, gapmap, gapmaplen, *alloclen, alg, '-' ); + } + else + { + restorecommongaps( njob, njob-(clus1+clus2), aseq, localmem[0], localmem[1], gapmap, *alloclen, '-' ); + findnewgaps( clus1, 0, mseq1, gaplen ); + insertnewgaps( njob, alreadyaligned, aseq, localmem[0], localmem[1], gaplen, gapmap, *alloclen, alg, '-' ); + } + +#if 0 + reporterr( "\n" ); + for( i=0; iSTEP3 mseq1[%d] = \n%s\n", i, mseq1[i] ); + for( i=0; iSTEP3 mseq2[%d] = \n%s\n", i, mseq2[i] ); +#endif + +#if 0 for( i=0; i-1; i++ ) alreadyaligned[m] = 1; + for( i=0; i-1; i++ ) alreadyaligned[m] = 1; + } + + if( newdistmtx ) // tsukawanai + { +#if 0 + reporterr( "group1 = " ); + for( i=0; i514\n%s\n", aseq[514] ); } #if SCOREOUT - fprintf( stderr, "totalscore = %10.2f\n\n", tscore ); + reporterr( "totalscore = %10.2f\n\n", tscore ); +#endif + Falign( NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, 0, NULL ); + Falign_udpari_long( NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, NULL ); + A__align( NULL, NULL, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0, -1, -1 ); + D__align( NULL, NULL, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0 ); + G__align11( NULL, NULL, NULL, 0, 0, 0 ); // iru? + free( effarr1 ); + free( effarr2 ); + free( indication1 ); + free( indication2 ); + free( fftlog ); + free( gaplen ); + free( gapmap ); + FreeDoubleMtx( dynamicmtx ); + free( alreadyaligned ); + FreeIntMtx( localmem ); + effarr1 = NULL; + return( 0 ); + + chudan_tbfast: + + Falign( NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, 0, NULL ); + Falign_udpari_long( NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, NULL ); + A__align( NULL, NULL, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0, -1, -1 ); + D__align( NULL, NULL, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0 ); + G__align11( NULL, NULL, NULL, 0, 0, 0 ); // iru? + if( effarr1 ) free( effarr1 ); effarr1 = NULL; + if( effarr2 ) free( effarr2 ); effarr2 = NULL; + if( indication1 ) free( indication1 ); indication1 = NULL; + if( indication2 ) free( indication2 ); indication2 = NULL; + if( fftlog ) free( fftlog ); fftlog = NULL; + if( gaplen ) free( gaplen ); gaplen = NULL; + if( gapmap ) free( gapmap ); gapmap = NULL; + if( alreadyaligned ) free( alreadyaligned ); alreadyaligned = NULL; + if( dynamicmtx ) FreeDoubleMtx( dynamicmtx ); dynamicmtx = NULL; + if( localmem ) FreeIntMtx( localmem ); localmem = NULL; +#if SKIP + if( skiptable1 ) FreeIntMtx( skiptable1 ); skiptable1 = NULL; + if( skiptable2 ) FreeIntMtx( skiptable2 ); skiptable2 = NULL; #endif + + return( 1 ); } static void WriteOptions( FILE *fp ) @@ -1161,7 +2104,7 @@ static void WriteOptions( FILE *fp ) else if( scoremtx == 1 ) fprintf( fp, "BLOSUM %d\n", nblosum ); else if( scoremtx == 2 ) fprintf( fp, "M-Y\n" ); } - fprintf( stderr, "Gap Penalty = %+5.2f, %+5.2f, %+5.2f\n", (double)ppenalty/1000, (double)ppenalty_ex/1000, (double)poffset/1000 ); + reporterr( "Gap Penalty = %+5.2f, %+5.2f, %+5.2f\n", (double)ppenalty/1000, (double)ppenalty_ex/1000, (double)poffset/1000 ); if( use_fft ) fprintf( fp, "FFT on\n" ); fprintf( fp, "tree-base method\n" ); @@ -1213,82 +2156,215 @@ static void WriteOptions( FILE *fp ) fprintf( fp, "FFT off\n" ); fflush( fp ); } - -int main( int argc, char *argv[] ) +static double **preparepartmtx( int nseq ) +{ + int i; + double **val; + double size; + + val = (double **)calloc( nseq, sizeof( double *) );; + size = 0; + + if( compacttree == 1 ) + { + for( i=0; i maxdistmtxsize ) + { + reporterr( "\n\nThe size of full distance matrix is estimated to exceed %.2fGB.\n", maxdistmtxsize / 1000 / 1000 /1000 ); + reporterr( "Will try the calculation using a %d x %d matrix.\n", nseq, i ); + reporterr( "This calculation will be slow due to the limited RAM space.\n", i, nseq ); + reporterr( "To avoid the slowdown, please try '--initialramusage xGB' (x>>%.2f),\n", maxdistmtxsize / 1000 / 1000 /1000 ); + reporterr( "if larger RAM space is available.\n" ); + reporterr( "Note that xGB is NOT the upper limit of RAM usage.\n" ); + reporterr( "Two to three times larger space may be used for building a guide tree.\n" ); + reporterr( "Memory usage of the MSA stage depends on similarity of input sequences.\n\n" ); +// reporterr( "If the RAM is small, try '--initialramusage xGB' with a smaller x value.\n" ); + reporterr( "The '--memsavetree' option uses smaller RAM space.\n" ); + reporterr( "If tree-like relationship can be ignored, try '--pileup' or '--randomchain'.\n\n" ); + reporterr( "The result of --initialramusage xGB is almost identical to the default, except for rounding differences.\n" ); + + reporterr( "In the cases of --memsavetree, --pileup and --randomchain, the result differs from the default.\n\n" ); + break; + } + val[i] = (double *)calloc( nseq, sizeof( double ) ); + } + if( i == nseq ) reporterr( "The full matrix will be used.\n" ); + + for( ;i nlenmax ) nlenmax = ien; + } + infp = NULL; +// stderr = fopen( "/dev/null", "a" ); // Windows???? + tmpargv = AllocateCharMtx( argc, 0 ); + for( i=0; i 20000 ) { - fprintf( stderr, "The number of sequences must be < %d\n", 20000 ); - fprintf( stderr, "Please try the --parttree option for such large data.\n" ); + if( inputfile ) + { + infp = fopen( inputfile, "r" ); + if( !infp ) + { + reporterr( "Cannot open %s\n", inputfile ); + exit( 1 ); + } + } + else + infp = stdin; + + getnumlen( infp ); + rewind( infp ); + } + + if( njob > 1000000 ) + { + reporterr( "The number of sequences must be < %d\n", 1000000 ); + reporterr( "Please try the --parttree option for such large data.\n" ); exit( 1 ); } if( njob < 2 ) { - fprintf( stderr, "At least 2 sequences should be input!\n" + reporterr( "At least 2 sequences should be input!\n" "Only %d sequence found.\n", njob ); exit( 1 ); } + if( specificityconsideration != 0.0 && nlenmax) + { + if( nlenmax > 100000 ) + { + reporterr( "\n" ); + reporterr( "Too long to apply --allowshift or --unalignlevel>0\n" ); + reporterr( "Please use the normal mode.\n" ); + reporterr( "Please also note that MAFFT does not assume genomic rearrangements.\n" ); + reporterr( "\n" ); + exit( 1 ); + } + } + +#ifndef mingw + setstacksize( 200 * njob ); // topolorder() de ookime no stack wo shiyou. +#endif + + if( subalignment ) + { + readsubalignmentstable( njob, NULL, NULL, &nsubalignments, &maxmem ); + reporterr( "nsubalignments = %d\n", nsubalignments ); + reporterr( "maxmem = %d\n", maxmem ); + subtable = AllocateIntMtx( nsubalignments, maxmem+1 ); + insubtable = AllocateIntVec( njob ); + preservegaps = AllocateIntVec( njob ); + for( i=0; i 200000 ) + { + reporterr( "Chain?\n" ); + treein = 's'; + nguidetree = 1; + } + else if( njob < 100 || 't' == varpairscore( njob, npickx, nlenmax, seq, randomseed ) ) + { + if( treein == 'c' ) exit( 1 ); + reporterr( "Tree!\n" ); + treein = 0; + nguidetree = 2; + } + else + { + reporterr( "Chain!\n" ); + treein = 's'; + nguidetree = 1; + } + } + else if ( treein != 0 ) // auto no toki arieru + nguidetree = 1; + } + + if( compacttree == 1 ) + { + if( maxdistmtxsize > (double)njob * (njob-1) * sizeof( double ) / 2 ) + { + reporterr( "Use conventional tree.\n" ); + compacttree = 0; + } + } if( !treein ) { - fprintf( stderr, "\n\nMaking a distance matrix ..\n" ); - fflush( stderr ); + reporterr( "\n\nMaking a distance matrix ..\n" ); + if( callback && callback( 0, 0, "Distance matrix" ) ) goto chudan; - tmpseq = AllocateCharVec( nlenmax+1 ); + tmpseq = AllocateCharVec( nlenmax+1 ); grpseq = AllocateIntVec( nlenmax+1 ); pointt = AllocateIntMtx( njob, nlenmax+1 ); - mtx = AllocateFloatHalfMtx( njob ); - if( dorp == 'd' ) tsize = (int)pow( 4, 6 ); + if( !compacttree ) mtx = AllocateFloatHalfMtx( njob ); + if( dorp == 'd' ) tsize = (int)pow( 4, tuplesize ); else tsize = (int)pow( 6, 6 ); - if( dorp == 'd' ) + if( dorp == 'd' && tuplesize == 6 ) + { + lenfaca = D6LENFACA; + lenfacb = D6LENFACB; + lenfacc = D6LENFACC; + lenfacd = D6LENFACD; + } + else if( dorp == 'd' && tuplesize == 10 ) { - lenfaca = DLENFACA; - lenfacb = DLENFACB; - lenfacc = DLENFACC; - lenfacd = DLENFACD; + lenfaca = D10LENFACA; + lenfacb = D10LENFACB; + lenfacc = D10LENFACC; + lenfacd = D10LENFACD; } else { @@ -1363,15 +2528,25 @@ int main( int argc, char *argv[] ) nogaplen[i] = strlen( tmpseq ); if( nogaplen[i] < 6 ) { -// fprintf( stderr, "Seq %d, too short, %d characters\n", i+1, nogaplen[i] ); -// fprintf( stderr, "Please use mafft-ginsi, mafft-linsi or mafft-ginsi\n\n\n" ); +// reporterr( "Seq %d, too short, %d characters\n", i+1, nogaplen[i] ); +// reporterr( "Please use mafft-ginsi, mafft-linsi or mafft-ginsi\n\n\n" ); // exit( 1 ); } if( nogaplen[i] > maxl ) maxl = nogaplen[i]; if( dorp == 'd' ) /* nuc */ { seq_grp_nuc( grpseq, tmpseq ); - makepointtable_nuc( pointt[i], grpseq ); +// makepointtable_nuc( pointt[i], grpseq ); +// makepointtable_nuc_octet( pointt[i], grpseq ); + if( tuplesize == 10 ) + makepointtable_nuc_dectet( pointt[i], grpseq ); + else if( tuplesize == 6 ) + makepointtable_nuc( pointt[i], grpseq ); + else + { + reporterr( "tuplesize=%d: not supported\n", tuplesize ); + exit( 1 ); + } } else /* amino */ { @@ -1379,421 +2554,1332 @@ int main( int argc, char *argv[] ) makepointtable( pointt[i], grpseq ); } } -#ifdef enablemultithread - if( nthread > 0 ) + if( nunknown ) reporterr( "\nThere are %d ambiguous characters.\n", nunknown ); + + + if( compacttree ) { - distancematrixthread_arg_t *targ; - int jobpos; - pthread_t *handle; - pthread_mutex_t mutex; - jobpos = 0; - targ = calloc( nthread, sizeof( distancematrixthread_arg_t ) ); - handle = calloc( nthread, sizeof( pthread_t ) ); - pthread_mutex_init( &mutex, NULL ); + reporterr( "Compact tree, step 1\n" ); + mindistfrom = (int *)calloc( njob, sizeof( int ) ); + mindist = (double *)calloc( njob, sizeof( double ) ); + selfscore = (int *)calloc( njob, sizeof( int ) ); + partmtx = preparepartmtx( njob ); - for( i=0; i 0 ) { - if( nogaplen[i] > nogaplen[j] ) + compactdistmtxthread_arg_t *targ; + int jobpos; + pthread_t *handle; + pthread_mutex_t mutex; + double **mindistthread; + int **mindistfromthread; + jobpos = 0; + targ = calloc( nthread, sizeof( compactdistmtxthread_arg_t ) ); + handle = calloc( nthread, sizeof( pthread_t ) ); + mindistthread = AllocateDoubleMtx( nthread, njob ); + mindistfromthread = AllocateIntMtx( nthread, njob ); + pthread_mutex_init( &mutex, NULL ); + + + for( j=0; j 0 ) + { + distancematrixthread_arg_t *targ; + int jobpos; + pthread_t *handle; + pthread_mutex_t mutex; + + jobpos = 0; + targ = calloc( nthread, sizeof( distancematrixthread_arg_t ) ); + handle = calloc( nthread, sizeof( pthread_t ) ); + pthread_mutex_init( &mutex, NULL ); + + for( i=0; i nogaplen[j] ) + { + longer=(double)nogaplen[i]; + shorter=(double)nogaplen[j]; + } + else + { + longer=(double)nogaplen[j]; + shorter=(double)nogaplen[i]; + } +// if( tuplesize == 6 ) + lenfac = 1.0 / ( shorter / longer * lenfacd + lenfacb / ( longer + lenfacc ) + lenfaca ); +// else +// lenfac = 1.0; +// reporterr( "lenfac = %f (%.0f,%.0f)\n", lenfac, longer, shorter ); + bunbo = MIN( mtx[i][0], mtx[j][0] ); + if( bunbo == 0.0 ) + mtx[i][j-i] = 2.0; // 2013/Oct/17 -> 2bai + else + mtx[i][j-i] = ( 1.0 - mtx[i][j-i] / bunbo ) * lenfac * 2.0; // 2013/Oct/17 -> 2bai +// reporterr( "##### mtx = %f, mtx[i][0]=%f, mtx[j][0]=%f, bunbo=%f\n", mtx[i][j-i], mtx[i][0], mtx[j][0], bunbo ); + } + } + if( disopt ) + { + for( i=0; i iguidetree loop nai ni idou + if( distout ) + { + hat2p = fopen( "hat2", "w" ); + WriteFloatHat2_pointer_halfmtx( hat2p, njob, name, mtx ); + fclose( hat2p ); + } +#endif - FreeFloatHalfMtx( mtx, njob ); } - else +#if 0 + else { - fprintf( stderr, "Constructing a UPGMA tree ... " ); - fixed_musclesupg_float_realloc_nobk_halfmtx( njob, mtx, topol, len, dep ); - FreeFloatHalfMtx( mtx, njob ); + reporterr( "Loading 'hat2' ... " ); + prep = fopen( "hat2", "r" ); + if( prep == NULL ) ErrorExit( "Make hat2." ); + readhat2_double( prep, njob, name, mtx ); // name chuui + fclose( prep ); + reporterr( "done.\n" ); } -// else -// ErrorExit( "Incorrect tree\n" ); - fprintf( stderr, "\ndone.\n\n" ); - fflush( stderr ); +#endif - orderfp = fopen( "order", "w" ); - if( !orderfp ) - { - fprintf( stderr, "Cannot open 'order'\n" ); - exit( 1 ); - } - for( i=0; (j=topol[njob-2][0][i])!=-1; i++ ) - { - fprintf( orderfp, "%d\n", j ); - } - for( i=0; (j=topol[njob-2][1][i])!=-1; i++ ) - { - fprintf( orderfp, "%d\n", j ); - } - fclose( orderfp ); +// reporterr( "after computing distance matrix," ); +// use_getrusage(); - if( ( treeout || distout ) && noalign ) + if( nadd && keeplength ) { - writeData_pointer( stdout, njob, name, nlen, seq ); - fprintf( stderr, "\n" ); - SHOWVERSION; - return( 0 ); - } - + originalgaps = (char *)calloc( nlenmax+1, sizeof( char) ); + recordoriginalgaps( originalgaps, njob-nadd, seq ); - if( tbrweight ) - { - weight = 3; -#if 0 - utree = 0; counteff( njob, topol, len, eff ); utree = 1; -#else - counteff_simple_float( njob, topol, len, eff ); -#endif + if( mapout ) + { + addbk = (char **)calloc( nadd+1, sizeof( char * ) ); + for( i=0; i= njob ) // check sumi + { + reporterr( "No such sequence, %d.\n", subtable[i][j]+1 ); + exit( 1 ); + } + if( alignmentlength != strlen( seq[subtable[i][j]] ) ) + { + reporterr( "\n" ); + reporterr( "###############################################################################\n" ); + reporterr( "# ERROR!\n" ); + reporterr( "# Subalignment %d must be aligned.\n", i+1 ); + reporterr( "# Please check the alignment lengths of following sequences.\n" ); + reporterr( "#\n" ); + reporterr( "# %d. %-10.10s -> %d letters (including gaps)\n", subtable[i][0]+1, name[subtable[i][0]]+1, alignmentlength ); + reporterr( "# %d. %-10.10s -> %d letters (including gaps)\n", subtable[i][j]+1, name[subtable[i][j]]+1, (int)strlen( seq[subtable[i][j]] ) ); + reporterr( "#\n" ); + reporterr( "# See http://mafft.cbrc.jp/alignment/software/merge.html for details.\n" ); + if( subalignmentoffset ) + { + reporterr( "#\n" ); + reporterr( "# You specified seed alignment(s) consisting of %d sequences.\n", subalignmentoffset ); + reporterr( "# In this case, the rule of numbering is:\n" ); + reporterr( "# The aligned seed sequences are numbered as 1 .. %d\n", subalignmentoffset ); + reporterr( "# The input sequences to be aligned are numbered as %d .. %d\n", subalignmentoffset+1, subalignmentoffset+njob ); + } + reporterr( "###############################################################################\n" ); + reporterr( "\n" ); + goto chudan; // TEST!! + //exit( 1 ); + } + insubtable[subtable[i][j]] = 1; } - else if( includemember( topol[i][0], addmem ) ) + for( j=0; j OK\n" ); + break; + } } + if( !foundthebranch ) + { + system( "cp infile.tree GuideTree" ); // tekitou + reporterr( "\n" ); + reporterr( "###############################################################################\n" ); + reporterr( "# ERROR!\n" ); + reporterr( "# Subalignment %d does not seem to form a monophyletic cluster\n", i+1 ); + reporterr( "# in the guide tree ('GuideTree' in this directory) internally computed.\n" ); + reporterr( "# If you really want to use this subalignment, pelase give a tree with --treein \n" ); + reporterr( "# http://mafft.cbrc.jp/alignment/software/treein.html\n" ); + reporterr( "# http://mafft.cbrc.jp/alignment/software/merge.html\n" ); + if( subalignmentoffset ) + { + reporterr( "#\n" ); + reporterr( "# You specified seed alignment(s) consisting of %d sequences.\n", subalignmentoffset ); + reporterr( "# In this case, the rule of numbering is:\n" ); + reporterr( "# The aligned seed sequences are numbered as 1 .. %d\n", subalignmentoffset ); + reporterr( "# The input sequences to be aligned are numbered as %d .. %d\n", subalignmentoffset+1, subalignmentoffset+njob ); + } + reporterr( "############################################################################### \n" ); + reporterr( "\n" ); + goto chudan; // TEST!! + //exit( 1 ); + } +// commongappick( seq[subtable[i]], subalignment[i] ); // irukamo } #if 0 for( i=0; i %c\n\n", i, mergeoralign[i] ); } #endif - for( i=njob-nadd; i iguidetree loop no soto he + FreeIntMtx( subtable ); + free( insubtable ); + for( i=0; i 0 && nadd == 0 ) + { + treebasethread_arg_t *targ; + int jobpos; + pthread_t *handle; + pthread_mutex_t mutex; + pthread_cond_t treecond; + int *fftlog; + int nrun; + int nthread_yoyu; + + nthread_yoyu = nthread * 1; + nrun = 0; + jobpos = 0; + targ = calloc( nthread_yoyu, sizeof( treebasethread_arg_t ) ); + fftlog = AllocateIntVec( njob ); + handle = calloc( nthread_yoyu, sizeof( pthread_t ) ); + pthread_mutex_init( &mutex, NULL ); + pthread_cond_init( &treecond, NULL ); + + for( i=0; i 0 && nadd == 0 ) - { - treebasethread_arg_t *targ; - int jobpos; - pthread_t *handle; - pthread_mutex_t mutex; - pthread_cond_t treecond; - int *fftlog; - int nrun; - int nthread_yoyu; - - nthread_yoyu = nthread * 1; - nrun = 0; - jobpos = 0; - targ = calloc( nthread_yoyu, sizeof( treebasethread_arg_t ) ); - fftlog = AllocateIntVec( njob ); - handle = calloc( nthread_yoyu, sizeof( pthread_t ) ); - pthread_mutex_init( &mutex, NULL ); - pthread_cond_init( &treecond, NULL ); - - for( i=0; i0 && nadd==0 ) if( calcpairdists ) + if( calcpairdists && !compacttree ) +#else +// if( 0 && nadd==0 ) if( calcpairdists ) // zettai nai + if( calcpairdists && !compacttree ) +#endif + { + reporterr( "Making a distance matrix from msa.. \n" ); + skiptable = AllocateIntMtx( njob, 0 ); + makeskiptable( njob, skiptable, bseq ); // allocate suru. +#ifdef enablemultithread + if( nthread > 0 ) + { + msadistmtxthread_arg_t *targ; + Jobtable jobpos; + pthread_t *handle; + pthread_mutex_t mutex; + + jobpos.i = 0; + jobpos.j = 0; + + targ = calloc( nthread, sizeof( msadistmtxthread_arg_t ) ); + handle = calloc( nthread, sizeof( pthread_t ) ); + pthread_mutex_init( &mutex, NULL ); + + for( i=0; i 0 ) + { + msacompactdistmtxthread_arg_t *targ; + int jobpos; + pthread_t *handle; + pthread_mutex_t mutex; + double **mindistthread; + int **mindistfromthread; + + mindistthread = AllocateDoubleMtx( nthread, njob ); + mindistfromthread = AllocateIntMtx( nthread, njob ); + targ = calloc( nthread, sizeof( msacompactdistmtxthread_arg_t ) ); + handle = calloc( nthread, sizeof( pthread_t ) ); + pthread_mutex_init( &mutex, NULL ); + jobpos = 0; + + for( i=0; i lgui ) + { + reporterr( "alignmentlength = %d, gui allocated %d", ien, lgui ); + val = GUI_LENGTHOVER; + } + else + { + for( i=0; i 0 ) + { + reporterr( "\nTo keep the alignment length, %d letters were DELETED.\n", ndeleted ); + if( mapout ) + reporterr( "The deleted letters are shown in the (filename).map file.\n" ); + else + reporterr( "To know the positions of deleted letters, rerun the same command with the --mapout option.\n" ); + } + + + + if( subalignment ) + { + FreeIntMtx( subtable ); + free( insubtable ); + for( i=0; injob; int thread_no = targ->thread_no; - float *selfscore = targ->selfscore; + double *selfscore = targ->selfscore; double **mtx = targ->mtx; char **seq = targ->seq; + int **skiptable = targ->skiptable; Jobtable *jobpospt = targ->jobpospt; int i, j; - float ssi, ssj, bunbo; + double ssi, ssj, bunbo; + double mtxv; + + if( njob == 1 ) return( NULL ); while( 1 ) { @@ -41,17 +50,21 @@ void *athread( void *arg ) j = jobpospt->j; i = jobpospt->i; j++; +// fprintf( stderr, "\n i=%d, j=%d before check\n", i, j ); if( j == njob ) { +// fprintf( stderr, "\n j = %d, i = %d, njob = %d\n", j, i, njob ); fprintf( stderr, "%4d/%4d (thread %4d), dndpre\r", i+1, njob, thread_no ); i++; j = i + 1; if( i == njob-1 ) { +// fprintf( stderr, "\n i=%d, njob-1=%d\n", i, njob-1 ); pthread_mutex_unlock( targ->mutex ); return( NULL ); } } +// fprintf( stderr, "\n i=%d, j=%d after check\n", i, j ); jobpospt->j = j; jobpospt->i = i; pthread_mutex_unlock( targ->mutex ); @@ -61,11 +74,119 @@ void *athread( void *arg ) bunbo = MIN( ssi, ssj ); if( bunbo == 0.0 ) - mtx[i][j] = 1.0; + mtxv = maxdist; else - mtx[i][j] = 1.0 - (double)naivepairscore11( seq[i], seq[j], penalty ) / bunbo; + { +// mtxv = maxdist * ( 1.0 - (double)naivepairscore11( seq[i], seq[j], penalty ) / bunbo ); + if( usenaivescoreinsteadofalignmentscore ) + mtxv = maxdist * ( 1.0 - (double)naivepairscorefast( seq[i], seq[j], skiptable[i], skiptable[j], 0.0 ) / bunbo ); + else + mtxv = maxdist * ( 1.0 - (double)naivepairscorefast( seq[i], seq[j], skiptable[i], skiptable[j], penalty ) / bunbo ); + } +#if 1 + if( mtxv < 0.0 ) + { + reporterr( "WARNING: negative distance, mtxv = %f\n", mtxv ); + mtxv = 0.0; + } + + if( mtxv > 9.0 ) + { + fprintf( stderr, "Distance %d-%d is strange, %f.\n", i, j, mtxv ); + exit( 1 ); + } +#else // CHUUI!!! 2012/05/16 + if( mtxv > 2.0 ) + { + mtxv = 2.0; + } + if( mtxv < 0.0 ) + { + fprintf( stderr, "Distance %d-%d is strange, %f.\n", i, j, mtxv ); + exit( 1 ); + } +#endif + mtx[i][j] = mtxv; + } +} +#else +void *athread( void *arg ) +{ + thread_arg_t *targ = (thread_arg_t *)arg; + int njob = targ->njob; + int thread_no = targ->thread_no; + double *selfscore = targ->selfscore; + double **mtx = targ->mtx; + char **seq = targ->seq; + int **skiptable = targ->skiptable; + Jobtable *jobpospt = targ->jobpospt; + + int i, j; + double ssi, ssj, bunbo; + double mtxv; + + if( njob == 1 ) return( NULL ); + + while( 1 ) + { + pthread_mutex_lock( targ->mutex ); + i = jobpospt->i; + if( i == njob-1 ) + { + pthread_mutex_unlock( targ->mutex ); + return( NULL ); + } + jobpospt->i += 1; + pthread_mutex_unlock( targ->mutex ); + if( i % 100 == 0 ) fprintf( stderr, "\r% 5d / %d (thread %4d)", i, njob, thread_no ); + + + ssi = selfscore[i]; + for( j=i+1; j 9.9 ) + { + fprintf( stderr, "WARNING: distance %d-%d is strange, %f.\n", i, j, mtxv ); + mtxv = 9.9; +// exit( 1 ); // 2016/Aug/3 + } +#else // CHUUI!!! 2012/05/16 + if( mtxv > 2.0 ) + { + mtxv = 2.0; + } + if( mtxv < 0.0 ) + { + fprintf( stderr, "Distance %d-%d is strange, %f.\n", i, j, mtxv ); + exit( 1 ); + } +#endif + mtx[i][j] = mtxv; + } } } +#endif #endif @@ -73,6 +194,7 @@ void arguments( int argc, char *argv[] ) { int c; + nadd = 0; nthread = 1; alg = 'X'; fmodel = 0; @@ -86,6 +208,8 @@ void arguments( int argc, char *argv[] ) poffset = NOTSPECIFIED; //? kimuraR = NOTSPECIFIED; pamN = NOTSPECIFIED; + usenaivescoreinsteadofalignmentscore = 0; + nwildcard = 0; while( --argc > 0 && (*++argv)[0] == '-' ) { @@ -93,6 +217,9 @@ void arguments( int argc, char *argv[] ) { switch( c ) { + case 'Z': + usenaivescoreinsteadofalignmentscore = 1; + break; case 't': treeout = '1'; break; @@ -105,16 +232,69 @@ void arguments( int argc, char *argv[] ) case 'P': dorp = 'p'; break; + case ':': + nwildcard = 1; + break; + case 'K': // Hontou ha iranai. disttbfast.c, tbfast.c to awaserutame. + break; + case 'I': + nadd = myatoi( *++argv ); + fprintf( stderr, "nadd = %d\n", nadd ); + --argc; + goto nextoption; + case 'f': + ppenalty = (int)( atof( *++argv ) * 1000 - 0.5 ); + --argc; + goto nextoption; + case 'g': + ppenalty_ex = (int)( atof( *++argv ) * 1000 - 0.5 ); + --argc; + goto nextoption; + case 'h': + poffset = (int)( atof( *++argv ) * 1000 - 0.5 ); + --argc; + goto nextoption; + case 'k': + kimuraR = myatoi( *++argv ); +// fprintf( stderr, "kimuraR = %d\n", kimuraR ); + --argc; + goto nextoption; + case 'b': + nblosum = myatoi( *++argv ); + scoremtx = 1; +// fprintf( stderr, "blosum %d\n", nblosum ); + --argc; + goto nextoption; + case 'j': + pamN = myatoi( *++argv ); + scoremtx = 0; + TMorJTT = JTT; +// fprintf( stderr, "jtt %d\n", pamN ); + --argc; + goto nextoption; + case 'm': + pamN = myatoi( *++argv ); + scoremtx = 0; + TMorJTT = TM; +// fprintf( stderr, "TM %d\n", pamN ); + --argc; + goto nextoption; case 'i': inputfile = *++argv; - fprintf( stderr, "inputfile = %s\n", inputfile ); +// fprintf( stderr, "inputfile = %s\n", inputfile ); --argc; goto nextoption; + case 'M': + maxdist = myatoi( *++argv ); +// fprintf( stderr, "maxdist = %d\n", maxdist ); + --argc; + goto nextoption; case 'C': - nthread = atoi( *++argv ); - fprintf( stderr, "nthread = %d\n", nthread ); + nthread = myatoi( *++argv ); +// fprintf( stderr, "nthread = %d\n", nthread ); --argc; goto nextoption; + break; } } nextoption: @@ -129,15 +309,18 @@ void arguments( int argc, char *argv[] ) int main( int argc, char **argv ) { - int i, j; + int i, j, ilim; char **seq; static char **name; - static int nlen[M]; - float *selfscore; + int *nlen; + double *selfscore; double **mtx; + double mtxv; FILE *fp; FILE *infp; - float ssi, ssj, bunbo; + double ssi, ssj, bunbo; + int **skiptable = NULL; + char c; arguments( argc, argv ); @@ -164,10 +347,14 @@ int main( int argc, char **argv ) #endif rewind( infp ); + njob -= nadd; // atarashii hairetsu ha mushi + seq = AllocateCharMtx( njob, nlenmax+1 ); name = AllocateCharMtx( njob, B+1 ); mtx = AllocateDoubleMtx( njob, njob ); selfscore = AllocateFloatVec( njob ); + nlen = AllocateIntVec( njob ); + #if 0 FRead( stdin, name, nlen, seq ); @@ -176,8 +363,25 @@ int main( int argc, char **argv ) #endif fclose( infp ); + + for( i=1; i 0 ) { @@ -214,6 +421,7 @@ int main( int argc, char **argv ) targ[i].selfscore = selfscore; targ[i].mtx = mtx; targ[i].seq = seq; + targ[i].skiptable = skiptable; targ[i].jobpospt = &jobpos; targ[i].mutex = &mutex; @@ -229,7 +437,8 @@ int main( int argc, char **argv ) else #endif { - for( i=0; i 9.0 ) + { + fprintf( stderr, "WARNING: Distance %d-%d is strange, %f.\n", i, j, mtxv ); + mtxv = 9.9; +// exit( 1 ); // 2016/Aug/3 + } +#else // CHUUI!!! 2012/05/16 + if( mtxv > 2.0 ) + { + mtxv = 2.0; + } + if( mtxv < 0.0 ) + { + fprintf( stderr, "Distance %d-%d is strange, %f.\n", i, j, mtxv ); + exit( 1 ); + } +#endif + mtx[i][j] = mtxv; } } } @@ -267,6 +508,7 @@ int main( int argc, char **argv ) veryfastsupg_double_outtree( njob, mtx, topol, len ); } #endif + if( skiptable ) FreeIntMtx( skiptable ); skiptable = NULL; SHOWVERSION; exit( 0 ); /* diff --git a/binaries/src/mafft/core/dndpre.o b/binaries/src/mafft/core/dndpre.o new file mode 100644 index 0000000..6838899 Binary files /dev/null and b/binaries/src/mafft/core/dndpre.o differ diff --git a/binaries/src/mafft/core/dvtditr b/binaries/src/mafft/core/dvtditr new file mode 100644 index 0000000..20c3c2f Binary files /dev/null and b/binaries/src/mafft/core/dvtditr differ diff --git a/binaries/src/mafft/core/dvtditr.c b/binaries/src/mafft/core/dvtditr.c index 54b44c6..a258902 100644 --- a/binaries/src/mafft/core/dvtditr.c +++ b/binaries/src/mafft/core/dvtditr.c @@ -5,9 +5,31 @@ extern char **seq_g; extern char **res_g; +static int subalignment; +static int subalignmentoffset; +static int specifictarget; static int intop; static int intree; +static double autosubalignment; + + +static void calcmaxdistclass( void ) +{ + int c; + double rep; + for( c=0; c 0 && (*++argv)[0] == '-' ) { @@ -85,7 +117,7 @@ void arguments( int argc, char *argv[] ) --argc; goto nextoption; case 'I': - niter = atoi( *++argv ); + niter = myatoi( *++argv ); fprintf( stderr, "niter = %d\n", niter ); --argc; goto nextoption; @@ -102,6 +134,15 @@ void arguments( int argc, char *argv[] ) // fprintf( stderr, "ppenalty = %d\n", ppenalty ); --argc; goto nextoption; + case 'Q': + penalty_shift_factor = atof( *++argv ); + if( penalty_shift_factor < 100.0 && penalty_shift_factor != 2.0 ) + { + fprintf( stderr, "%f, penalty_shift is fixed to penalty x 2 in the iterative refinement phase.\n", penalty_shift_factor ); + penalty_shift_factor = 2.0; + } + --argc; + goto nextoption; case 'g': ppenalty_ex = (int)( atof( *++argv ) * 1000 - 0.5 ); // fprintf( stderr, "ppenalty_ex = %d\n", ppenalty_ex ); @@ -113,25 +154,25 @@ void arguments( int argc, char *argv[] ) --argc; goto nextoption; case 'k': - kimuraR = atoi( *++argv ); + kimuraR = myatoi( *++argv ); fprintf( stderr, "kappa = %d\n", kimuraR ); --argc; goto nextoption; case 'b': - nblosum = atoi( *++argv ); + nblosum = myatoi( *++argv ); scoremtx = 1; fprintf( stderr, "blosum %d / kimura 200\n", nblosum ); --argc; goto nextoption; case 'j': - pamN = atoi( *++argv ); + pamN = myatoi( *++argv ); scoremtx = 0; TMorJTT = JTT; fprintf( stderr, "jtt/kimura %d\n", pamN ); --argc; goto nextoption; case 'm': - pamN = atoi( *++argv ); + pamN = myatoi( *++argv ); scoremtx = 0; TMorJTT = TM; fprintf( stderr, "tm %d\n", pamN ); @@ -152,12 +193,17 @@ void arguments( int argc, char *argv[] ) --argc; goto nextoption; case 'C': - nthread = atoi( *++argv ); + nthread = myatoi( *++argv ); fprintf( stderr, "nthread = %d\n", nthread ); --argc; goto nextoption; + case 'H': + subalignment = 1; + subalignmentoffset = myatoi( *++argv ); + --argc; + goto nextoption; case 't': - randomseed = atoi( *++argv ); + randomseed = myatoi( *++argv ); fprintf( stderr, "randomseed = %d\n", randomseed ); --argc; goto nextoption; @@ -175,12 +221,25 @@ void arguments( int argc, char *argv[] ) // exit( 1 ); --argc; goto nextoption; + case 's': + specificityconsideration = (double)myatof( *++argv ); +// fprintf( stderr, "specificityconsideration = %f\n", specificityconsideration ); + --argc; + goto nextoption; +#if 0 + case 'S' : + scoreout = 1; // for checking parallel calculation + break; +#else case 'S' : - scoreout = 1; + spscoreout = 1; // 2014/Dec/30, sp score break; +#endif +#if 0 case 's' : RNAscoremtx = 'r'; break; +#endif #if 1 case 'a': fmodel = 1; @@ -195,9 +254,11 @@ void arguments( int argc, char *argv[] ) case 'P': dorp = 'p'; break; +#if 0 case 'Q': alg = 'Q'; break; +#endif case 'R': rnaprediction = 'r'; break; @@ -231,16 +292,19 @@ void arguments( int argc, char *argv[] ) case 's' : treemethod = 's'; break; -#endif case 'H': alg = 'H'; break; +#endif case 'A': alg = 'A'; break; case 'M': alg = 'M'; break; + case '@': + alg = 'd'; + break; case 'F': use_fft = 1; break; @@ -261,15 +325,20 @@ void arguments( int argc, char *argv[] ) case 'J': utree = 0; break; +#if 0 case 'd': disp = 1; break; +#endif case 'Z': score_check = 0; break; case 'Y': score_check = 2; break; + case 'L': + legacygapcost = 1; + break; #if 0 case 'n' : treemethod = 'n'; @@ -278,23 +347,44 @@ void arguments( int argc, char *argv[] ) case 'n' : outnumber = 1; break; - case 'X' : + case 'X': treemethod = 'X'; - break; + sueff_global = atof( *++argv ); + fprintf( stderr, "sueff_global = %f\n", sueff_global ); + --argc; + goto nextoption; +#if 0 case 'E' : treemethod = 'E'; break; case 'q' : treemethod = 'q'; break; +#endif + case 'E': + autosubalignment = atof( *++argv ); + fprintf( stderr, "autosubalignment = %f\n", autosubalignment ); + --argc; + goto nextoption; + case 'W': + minimumweight = atof( *++argv ); + fprintf( stderr, "minimumweight = %f\n", minimumweight ); + --argc; + goto nextoption; case 'z': - fftThreshold = atoi( *++argv ); + fftThreshold = myatoi( *++argv ); --argc; goto nextoption; case 'w': - fftWinSize = atoi( *++argv ); + fftWinSize = myatoi( *++argv ); --argc; goto nextoption; + case '=': + specifictarget = 1; + break; + case ':': + nwildcard = 1; + break; default: fprintf( stderr, "illegal option %c\n", c ); argc = 0; @@ -335,6 +425,7 @@ int main( int argc, char *argv[] ) double **eff; FILE *prep; FILE *infp; + FILE *orderfp; int alloclen; int returnvalue; char c; @@ -346,11 +437,22 @@ int main( int argc, char *argv[] ) static char **nogap1seq; static char *kozoarivec; int nkozo; + int alignmentlength; + int **skipthisbranch; + int foundthebranch; + int nsubalignments, maxmem; + int **subtable; + int *insubtable; + int *preservegaps; + char ***subalnpt; + int ntarget, *targetmap, *targetmapr; + int ilim; arguments( argc, argv ); #ifndef enablemultithread nthread = 0; #endif + if( fastathreshold < 0.0001 ) constraint = 0; if( inputfile ) { @@ -380,6 +482,29 @@ int main( int argc, char *argv[] ) exit( 1 ); } + + if( subalignment ) + { + readsubalignmentstable( njob, NULL, NULL, &nsubalignments, &maxmem ); + fprintf( stderr, "nsubalignments = %d\n", nsubalignments ); + fprintf( stderr, "maxmem = %d\n", maxmem ); + subtable = AllocateIntMtx( nsubalignments, maxmem+1 ); + insubtable = AllocateIntVec( njob ); + preservegaps = AllocateIntVec( njob ); + for( i=0; i 0.0 && subalignment == 0 ) + { +// reporterr( "Computing skipthisbranch..\n" ); + insubtable = AllocateIntVec( njob ); + preservegaps = AllocateIntVec( njob ); + subtable = calloc( 1, sizeof( char * ) ); + subtable[0] = NULL; // for FreeIntMtx + for( i=0; i= njob ) + { + fprintf( stderr, "No such sequence, %d.\n", subtable[i][j]+1 ); + exit( 1 ); + } + if( alignmentlength != strlen( seq[subtable[i][j]] ) ) + { + fprintf( stderr, "\n" ); + fprintf( stderr, "###############################################################################\n" ); + fprintf( stderr, "# ERROR!\n" ); + fprintf( stderr, "# Subalignment %d must be aligned.\n", i+1 ); + fprintf( stderr, "# Please check the alignment lengths of following sequences.\n" ); + fprintf( stderr, "#\n" ); + fprintf( stderr, "# %d. %-10.10s -> %d letters (including gaps)\n", subtable[i][0]+1, name[subtable[i][0]]+1, alignmentlength ); + fprintf( stderr, "# %d. %-10.10s -> %d letters (including gaps)\n", subtable[i][j]+1, name[subtable[i][j]]+1, (int)strlen( seq[subtable[i][j]] ) ); + fprintf( stderr, "#\n" ); + fprintf( stderr, "# See http://mafft.cbrc.jp/alignment/software/merge.html for details.\n" ); + if( subalignmentoffset ) + { + fprintf( stderr, "#\n" ); + fprintf( stderr, "# You specified seed alignment(s) consisting of %d sequences.\n", subalignmentoffset ); + fprintf( stderr, "# In this case, the rule of numbering is:\n" ); + fprintf( stderr, "# The aligned seed sequences are numbered as 1 .. %d\n", subalignmentoffset ); + fprintf( stderr, "# The input sequences to be aligned are numbered as %d .. %d\n", subalignmentoffset+1, subalignmentoffset+njob ); + } + fprintf( stderr, "###############################################################################\n" ); + fprintf( stderr, "\n" ); + exit( 1 ); + } + insubtable[subtable[i][j]] = 1; + } + for( j=0; j OK\n" ); + break; + } + } + if( !foundthebranch ) + { + system( "cp infile.tree GuideTree" ); // tekitou + fprintf( stderr, "\n" ); + fprintf( stderr, "###############################################################################\n" ); + fprintf( stderr, "# ERROR!\n" ); + fprintf( stderr, "# Subalignment %d does not seem to form a monophyletic cluster\n", i+1 ); + fprintf( stderr, "# in the guide tree ('GuideTree' in this directory) internally computed.\n" ); + fprintf( stderr, "# If you really want to use this subalignment, pelase give a tree with --treein \n" ); + fprintf( stderr, "# http://mafft.cbrc.jp/alignment/software/treein.html\n" ); + fprintf( stderr, "# http://mafft.cbrc.jp/alignment/software/merge.html\n" ); + if( subalignmentoffset ) + { + fprintf( stderr, "#\n" ); + fprintf( stderr, "# You specified seed alignment(s) consisting of %d sequences.\n", subalignmentoffset ); + fprintf( stderr, "# In this case, the rule of numbering is:\n" ); + fprintf( stderr, "# The aligned seed sequences are numbered as 1 .. %d\n", subalignmentoffset ); + fprintf( stderr, "# The input sequences to be aligned are numbered as %d .. %d\n", subalignmentoffset+1, subalignmentoffset+njob ); + } + fprintf( stderr, "############################################################################### \n" ); + fprintf( stderr, "\n" ); + exit( 1 ); + } +// commongappick( seq[subtable[i]], subalignment[i] ); // irukamo + } +#if 0 + for( i=0; i %d\n\n", skipthisbranch[i][0] ); + fprintf( stderr, "group2 = " ); + for( j=0; topol[i][1][j] != -1; j++ ) + fprintf( stderr, "%d ", topol[i][1][j]+1 ); + fprintf( stderr, "\n" ); + fprintf( stderr, "SKIP -> %d\n\n", skipthisbranch[i][1] ); + } +#endif + + for( i=0; i= nalpha || amino_n[(unsigned char)firstletter] < 0 ) continue; + for( j=0; j 0 && (*++argv)[0] == '-' ) { @@ -161,7 +200,7 @@ void arguments( int argc, char *argv[] ) --argc; goto nextoption; case 'n': - namelen = atoi( *++argv ); + namelen = myatoi( *++argv ); fprintf( stderr, "namelen = %d\n", namelen ); --argc; goto nextoption; @@ -171,6 +210,13 @@ void arguments( int argc, char *argv[] ) case 'y': format = 'y'; break; + case 'E': + extendedalphabet = 1; + nblosum = -2; + break; + case 'N': + extendedalphabet = 0; + break; default: fprintf( stderr, "illegal option %c\n", c ); argc = 0; @@ -227,7 +273,7 @@ int main( int argc, char *argv[] ) if( orderfile ) { orderfp = fopen( orderfile, "r" ); - if( !orderfile ) + if( !orderfp ) { fprintf( stderr, "Cannot open %s\n", orderfile ); exit( 1 ); @@ -264,7 +310,7 @@ int main( int argc, char *argv[] ) else if( format == 'c' ) clustalout_pointer( stdout, njob, nlenmax, seq, name, mark, comment, order, namelen ); else if( format == 'y' ) - phylipout_pointer( stdout, njob, nlenmax, seq, name, order ); + phylipout_pointer( stdout, njob, nlenmax, seq, name, order, namelen ); else fprintf( stderr, "Unknown format\n" ); diff --git a/binaries/src/mafft/core/f2cl.o b/binaries/src/mafft/core/f2cl.o new file mode 100644 index 0000000..ed97204 Binary files /dev/null and b/binaries/src/mafft/core/f2cl.o differ diff --git a/binaries/src/mafft/core/fft.c b/binaries/src/mafft/core/fft.c index c217cb7..5cec495 100644 --- a/binaries/src/mafft/core/fft.c +++ b/binaries/src/mafft/core/fft.c @@ -4,7 +4,7 @@ /* from "C gengo niyoru saishin algorithm jiten" ISBN4-87408-414-1 Haruhiko Okumura */ -static void make_sintbl(int n, float sintbl[]) +static void make_sintbl(int n, double sintbl[]) { int i, n2, n4, n8; double c, s, dc, ds, t; @@ -46,14 +46,15 @@ int fft(int n, Fukusosuu *x, int freeflag) { static TLS int last_n = 0; /* {\tt n} */ static TLS int *bitrev = NULL; /* */ - static TLS float *sintbl = NULL; /* */ + static TLS double *sintbl = NULL; /* */ int i, j, k, ik, h, d, k2, n4, inverse; - float t, s, c, dR, dI; + double t, s, c, dR, dI; if (freeflag) { - if (bitrev) free(bitrev); - if (sintbl) free(sintbl); + if (bitrev) free(bitrev); bitrev = NULL; + if (sintbl) free(sintbl); sintbl = NULL; + last_n = 0; return( 0 ); } @@ -74,10 +75,10 @@ int fft(int n, Fukusosuu *x, int freeflag) bitrev = NULL; } if (n == 0) return 0; /* */ - sintbl = (float *)malloc((n + n4) * sizeof(float)); + sintbl = (double *)malloc((n + n4) * sizeof(double)); bitrev = (int *)malloc(n * sizeof(int)); #else /* by T. Nishiyama */ - sintbl = realloc(sintbl, (n + n4) * sizeof(float)); + sintbl = realloc(sintbl, (n + n4) * sizeof(double)); bitrev = realloc(bitrev, n * sizeof(int)); #endif if (sintbl == NULL || bitrev == NULL) { diff --git a/binaries/src/mafft/core/fft.o b/binaries/src/mafft/core/fft.o new file mode 100644 index 0000000..b70432d Binary files /dev/null and b/binaries/src/mafft/core/fft.o differ diff --git a/binaries/src/mafft/core/fftFunctions.c b/binaries/src/mafft/core/fftFunctions.c index 927dc3f..8c6d186 100644 --- a/binaries/src/mafft/core/fftFunctions.c +++ b/binaries/src/mafft/core/fftFunctions.c @@ -206,20 +206,21 @@ int alignableReagion( int clus1, int clus2, if( clus1 == 0 ) { - FreeDoubleVec( stra ); stra = NULL; - FreeDoubleVec( prf1 ); prf1 = NULL; - FreeDoubleVec( prf2 ); prf2 = NULL; - FreeIntVec( hat1 ); hat1 = NULL; - FreeIntVec( hat2 ); hat2 = NULL; + if( stra ) FreeDoubleVec( stra ); stra = NULL; + if( prf1 ) FreeDoubleVec( prf1 ); prf1 = NULL; + if( prf2 ) FreeDoubleVec( prf2 ); prf2 = NULL; + if( hat1 ) FreeIntVec( hat1 ); hat1 = NULL; + if( hat2 ) FreeIntVec( hat2 ); hat2 = NULL; + alloclen = 0; return( 0 ); } if( prf1 == NULL ) { - prf1 = AllocateDoubleVec( 26 ); - prf2 = AllocateDoubleVec( 26 ); - hat1 = AllocateIntVec( 27 ); - hat2 = AllocateIntVec( 27 ); + prf1 = AllocateDoubleVec( nalphabets ); + prf2 = AllocateDoubleVec( nalphabets ); + hat1 = AllocateIntVec( nalphabets+1 ); + hat2 = AllocateIntVec( nalphabets+1 ); } len = MIN( strlen( seq1[0] ), strlen( seq2[0] ) ); @@ -244,7 +245,7 @@ int alignableReagion( int clus1, int clus2, for( i=0; i=0; j-- ) { if( prf1[j] ) @@ -279,8 +280,8 @@ int alignableReagion( int clus1, int clus2, /* make site score */ stra[i] = 0.0; - for( k=hat1[26]; k!=-1; k=hat1[k] ) - for( j=hat2[26]; j!=-1; j=hat2[j] ) + for( k=hat1[nalphabets]; k!=-1; k=hat1[k] ) + for( j=hat2[nalphabets]; j!=-1; j=hat2[j] ) // stra[i] += n_dis[k][j] * prf1[k] * prf2[j]; stra[i] += n_disFFT[k][j] * prf1[k] * prf2[j]; stra[i] /= totaleff; @@ -400,13 +401,14 @@ void blockAlign2( int *cut1, int *cut2, Segment **seg1, Segment **seg2, double * { if( result1 ) { - free( result1 ); - free( result2 ); - free( ocut1 ); - free( ocut2 ); - FreeIntMtx( track ); - FreeDoubleMtx( crossscore ); + if( result1 ) free( result1 ); result1 = NULL; + if( result2 ) free( result2 ); result2 = NULL; + if( ocut1 ) free( ocut1 ); ocut1 = NULL; + if( ocut2 ) free( ocut2 ); ocut2 = NULL; + if( track ) FreeIntMtx( track ); track = NULL; + if( crossscore ) FreeDoubleMtx( crossscore ); crossscore = NULL; } + crossscoresize = 0; return; } diff --git a/binaries/src/mafft/core/fftFunctions.o b/binaries/src/mafft/core/fftFunctions.o new file mode 100644 index 0000000..ffa6a2e Binary files /dev/null and b/binaries/src/mafft/core/fftFunctions.o differ diff --git a/binaries/src/mafft/core/float2double b/binaries/src/mafft/core/float2double new file mode 100644 index 0000000..5301d56 --- /dev/null +++ b/binaries/src/mafft/core/float2double @@ -0,0 +1,5 @@ +foreach i ( *.c *.h ) + sed 's/float/double/g' $i > $i.double + echo $i + mv $i.double $i +end diff --git a/binaries/src/mafft/core/functions.h b/binaries/src/mafft/core/functions.h index 44d8688..6d2d195 100644 --- a/binaries/src/mafft/core/functions.h +++ b/binaries/src/mafft/core/functions.h @@ -1,21 +1,23 @@ extern int intlen( int *num ); extern char seqcheck( char **seq ); -extern void scmx_calc( int icyc, char **aseq, double *effarr, float **scmx ); +extern void scmx_calc( int icyc, char **aseq, double *effarr, double **scmx ); extern void exitall( char arr[] ); extern void display( char **seq, int nseq ); extern void intergroup_score( char **seq1, char **seq2, double *eff1, double *eff2, int clus1, int clus2, int len, double *value ); +//extern void intergroup_score_dynmtx( double **pairoffset, int mtx[0x80][0x80], char **seq1, char **seq2, double *eff1, double *eff2, int clus1, int clus2, int len, double *value ); +extern void intergroup_score_multimtx( int **whichmtx, double ***matrices, char **seq1, char **seq2, double *eff1, double *eff2, int clus1, int clus2, int len, double *value ); extern void intergroup_score_gapnomi( char **seq1, char **seq2, double *eff1, double *eff2, int clus1, int clus2, int len, double *value ); extern void intergroup_score_new( char **seq1, char **seq2, double *eff1, double *eff2, int clus1, int clus2, int len, double *value ); extern double score_calc5( char **seq, int s, double **eff, int ex ); extern double score_calc4( char **seq, int s, double **eff, int ex ); extern void upg2( int nseq, double **eff, int ***topol, double **len ); -//extern void veryfastsupg_float_realloc_nobk_halfmtx( int njob, float **mtx, int ***topol, float **len ); -//extern void veryfastsupg_float_realloc_nobk( int njob, float **mtx, int ***topol, float **len ); +//extern void veryfastsupg_double_realloc_nobk_halfmtx( int njob, double **mtx, int ***topol, double **len ); +//extern void veryfastsupg_double_realloc_nobk( int njob, double **mtx, int ***topol, double **len ); extern void veryfastsupg_int_realloc_nobk( int njob, int **mtx, int ***topol, double **len ); extern void veryfastsupg( int nseq, double **oeff, int ***topol, double **len ); extern void veryfastsupg_double( int nseq, double **oeff, int ***topol, double **len ); -extern void veryfastsupg_double_loadtree( int nseq, double **oeff, int ***topol, double **len ); -extern void veryfastsupg_double_loadtop( int nseq, double **oeff, int ***topol, double **len ); +extern void veryfastsupg_double_loadtree( int nseq, double **oeff, int ***topol, double **len, char **name ); +//extern void veryfastsupg_double_loadtop( int nseq, double **oeff, int ***topol, double **len ); extern void veryfastsupg_int( int nseq, int **oeff, int ***topol, double **len ); extern void fastsupg( int nseq, double **oeff, int ***topol, double **len ); extern void supg( int nseq, double **oeff, int ***topol, double **len ); @@ -24,16 +26,18 @@ extern double ipower( double x, int n ); extern void countnode( int nseq, int ***topol, double **node ); extern void countnode_int( int nseq, int ***topol, int **node ); extern void counteff_simple( int nseq, int ***topol, double **len, double *node ); -extern void counteff_simple_float( int nseq, int ***topol, float **len, double *node ); +extern void counteff_simple_double( int nseq, int ***topol, double **len, double *node ); +extern void counteff_simple_double_nostatic( int nseq, int ***topol, double **len, double *node ); +extern void counteff_simple_double_nostatic_memsave( int nseq, int ***topol, double **len, Treedep *dep, double *node ); extern void counteff( int nseq, int ***topol, double **len, double **node ); -extern float score_calc1( char *seq1, char *seq2 ); -extern float score_calcp( char *seq1, char *seq2, int len ); -extern float substitution_nid( char *seq1, char *seq2 ); -extern float substitution_score( char *seq1, char *seq2 ); -extern float substitution_hosei( char *seq1, char *seq2 ); -extern float substitution( char *seq1, char *seq2 ); +extern double score_calc1( char *seq1, char *seq2 ); +extern double score_calcp( char *seq1, char *seq2, int len ); +extern double substitution_nid( char *seq1, char *seq2 ); +extern double substitution_score( char *seq1, char *seq2 ); +extern double substitution_hosei( char *seq1, char *seq2 ); +extern double substitution( char *seq1, char *seq2 ); extern void treeconstruction( char **seq, int nseq, int ***topol, double **len, double **eff ); -extern float bscore_calc( char **seq, int s, double **eff ); +extern double bscore_calc( char **seq, int s, double **eff ); extern void AllocateTmpSeqs( char ***mseq2pt, char **mseq1pt, int locnlenmax ); extern void FreeTmpSeqs( char **mseq2, char *mseq1 ); extern void gappick_samestring( char *aseq ); @@ -42,54 +46,68 @@ extern void gappick( int nseq, int s, char **aseq, char **mseq2, double **eff, double *effarr ); extern void commongappick_record( int nseq, char **seq, int *map ); extern void commongappick( int nseq, char **seq ); +extern int commongapcount( int , int, char **, char ** ); +//extern void commongaprecord( int nseq, char **seq, char *originallygapped ); extern double score_calc0( char **seq, int s, double **eff, int ex ); extern void strins( char *str1, char *str2 ); extern int isaligned( int nseq, char **seq ); extern double score_calc_for_score( int nseq, char **seq ); -extern void floatncpy( float *vec1, float *vec2, int len ); -extern float score_calc_a( char **seq, int s, double **eff ); -extern float score_calc_s( char **seq, int s, double **eff ); +extern void doublencpy( double *vec1, double *vec2, int len ); +extern double score_calc_a( char **seq, int s, double **eff ); +extern double score_calc_s( char **seq, int s, double **eff ); extern double score_calc_for_score_s( int s, char **seq ); extern double SSPscore( int s, char **seq ); extern double DSPscore( int s, char **seq ); extern int searchAnchors( int nseq, char **seq, Segment *seg ); extern char *progName( char *str ); extern void dontcalcimportance( int nseq, double *eff, char **seq, LocalHom **localhom ); +extern void dontcalcimportance_target( int nseq, double *eff, char **seq, LocalHom **localhom, int ntarget ); +extern void calcimportance_target( int nseq, int ntarget, double *eff, char **seq, LocalHom **localhom, int *targetmap, int *targetmapr ); +extern void dontcalcimportance_lastone( int nseq, double *eff, char **seq, LocalHom **localhom ); +extern void dontcalcimportance_firstone( int nseq, double *eff, char **seq, LocalHom **localhom ); extern void calcimportance( int nseq, double *eff, char **seq, LocalHom **localhom ); +extern void calcimportance_half( int nseq, double *eff, char **seq, LocalHom **localhom ); extern void weightimportance2( int nseq, double *eff, LocalHom **localhom ); extern void weightimportance4( int clus1, int clus2, double *eff1, double *eff2, LocalHom ***localhom ); extern void extendlocalhom( int nseq, LocalHom **localhom ); extern void extendlocalhom2( int nseq, LocalHom **localhom, double **mtx ); extern int makelocal( char *s1, char *s2, int thr ); extern void mdfymtx( char **pair, int s1, double **partialmtx, double **mtx ); -extern float score_calc( char **seq, int s ); -extern void cpmx_calc( char **seq, float **cpmx, double *eff, int lgth, int clus ); -extern void cpmx_calc_new( char **seq, float **cpmx, double *eff, int lgth, int clus ); -extern void MScpmx_calc_new( char **seq, float **cpmx, double *eff, int lgth, int clus ); +extern double score_calc( char **seq, int s ); +extern void cpmx_calc( char **seq, double **cpmx, double *eff, int lgth, int clus ); +extern void cpmx_calc_new( char **seq, double **cpmx, double *eff, int lgth, int clus ); +extern void cpmx_calc_add( char **seq, double **cpmx, double *eff, int lgth, int clus ); +extern void MScpmx_calc_new( char **seq, double **cpmx, double *eff, int lgth, int clus ); extern void mseqcat( char **seq1, char **seq2, double **eff, double *effarr1, double *effarr2, char name1[M][B], char name2[M][B], int clus1, int clus2 ); extern void strnbcat( char *s1, char *s2, int m ); extern int conjuctionforgaln( int s0, int s1, char **seq, char **aseq, double *peff, double *eff, char **name, char **aname, char *d ); extern int fastconjuction( int *memlist, char **seq, char **aseq, double *peff, double *eff, char name[M][B], char aname[M][B], char *d ); extern int fastconjuction_noname_kozo( int *memlist, char **seq, char **aseq, double *peff, double *eff, double *peff_kozo, double *eff_kozo, char *d ); -extern int fastconjuction_noname( int *memlist, char **seq, char **aseq, double *peff, double *eff, char *d ); +extern int fastconjuction_noname( int *memlist, char **seq, char **aseq, double *peff, double *eff, char *d, double mineff ); +extern int fastconjuction_target( int *memlist, char **seq, char **aseq, double *peff, double *eff, char *d, double mineff, int *targetmap ); extern int fastconjuction_noweight( int *memlist, char **seq, char **aseq, double *peff, char *d ); -extern int conjuctionfortbfast( char **pair, int s, char **seq, char **aseq, double *peff, double *eff, char *d ); -extern int conjuctionfortbfast_kozo( double *tmptmp, char **pair, int s, char **seq, char **aseq, double *peff, double *eff, double *peff_kozo, double *eff_kozo, char *d ); +extern int conjuctionfortbfast_old( char **pair, int s, char **seq, char **aseq, double *peff, double *eff, char *d ); extern int conjuction( char **pair, int s, char **seq, char **aseq, double *peff, double *eff, char **name, char **aname, char *d ); -extern void floatdelete( float **cpmx, int d, int len ); +extern void doubledelete( double **cpmx, int d, int len ); extern void chardelete( char *seq, int d ); extern int RootBranchNode( int nseq, int ***topol, int step, int branch ); extern void BranchLeafNode( int nseq, int ***topol, int *node, int step, int branch ); extern void RootLeafNode( int nseq, int ***topol, int *node ); extern void nodeFromABranch( int nseq, int *result, int **pairwisenode, int ***topol, double **len, int step, int num ); -extern void OneClusterAndTheOther( int locnjob, char **pair, int *s1, int *s2, int ***topol, int step, int branch ); +//extern void OneClusterAndTheOther( int locnjob, char **pair, int *s1, int *s2, int ***topol, int step, int branch ); +extern void OneClusterAndTheOther_fast( int locnjob, int *memlist1, int *memlist2, int *s1, int *s2, char *pairbuf, int ***topol, int step, int branch, double **smalldistmtx, double **distmtx, double *distontree ); extern void makeEffMtx( int nseq, double **mtx, double *vec ); extern void node_eff( int nseq, double *eff, int *node ); extern int shrinklocalhom( char **pair, int s1, int s2, LocalHom **localhom, LocalHom ***localhomshrink ); -extern int msshrinklocalhom( char **pair, int s1, int s2, LocalHom **localhom, LocalHom ***localhomshrink ); +extern int msshrinklocalhom_fast( int *memlist1, int *memlist2, LocalHom **localhom, LocalHom ***localhomshrink ); +extern int msshrinklocalhom_fast_half( int *memlist1, int *memlist2, LocalHom **localhom, LocalHom ***localhomshrink ); +extern int msshrinklocalhom_fast_target( int *memlist1, int *memlist2, LocalHom **localhom, LocalHom ***localhomshrink, char *swaplist, int *targetmap ); extern int fastshrinklocalhom( int *mem1, int *mem2, LocalHom **localhom, LocalHom ***localhomshrink ); +extern int fastshrinklocalhom_half( int *mem1, int *mem2, LocalHom **localhom, LocalHom ***localhomshrink ); +extern int fastshrinklocalhom_target( int *mem1, int *mem2, LocalHom **localhom, LocalHom ***localhomshrink, char *swaplist, int *targetmap ); +extern int fastshrinklocalhom_one( int *mem1, int *mem2, int norg, LocalHom **localhom, LocalHom ***localhomshrink ); extern int msfastshrinklocalhom( int *mem1, int *mem2, LocalHom **localhom, LocalHom ***localhomshrink ); -extern int TreeDependentIteration( int locnjob, char **name, int nlen[M], char **aseq, char **bseq, int ***topol, double **len, int alloclen, LocalHom **localhomtable, RNApair ***single, int nkozo, char *kozoarivec ); +extern int TreeDependentIteration( int locnjob, char **name, int nlen[M], char **aseq, char **bseq, int ***topol, double **len, double **eff, int **skipthisbranch, int alloclen, LocalHom **localhomtable, RNApair ***single, int nkozo, char *kozoarivec, int ntarget, int *targetmap, int *targetmapr ); extern void checkMinusLength( int nseq, double **len ); extern void negativeMember2( int *mem, int *query, int locnseq ); extern int *negativeMember( int *query, int locnseq ); @@ -102,8 +120,8 @@ extern double syntheticLength( Node *ob, Node *oppositeNode ); extern double calcW( Node *ob, Node *op ); extern void calcBranchWeight( double **bw, int locnseq, Node *stopol, int ***topol, double **len ); extern void branchWeightToPairWeight( int locnseq, int ***topol, double **pw, double **bw ); -extern void weightFromABranch_rec( double *result, Node *ob, Node *op ); extern void weightFromABranch( int nseq, double *result, Node *stopol, int ***topol, int step, int LorR ); +extern void distFromABranch( int nseq, double *result, Node *stopol, int ***topol, double **len, int step, int LorR ); extern void keika( char *str, int current, int all ); extern double maxItch( double *soukan, int size ); extern void calcNaiseki( Fukusosuu *value, Fukusosuu *x, Fukusosuu *y ); @@ -119,46 +137,38 @@ extern int alignableReagion( int clus1, int clus2, char **seq1, char **s extern void blockAlign( int *cut1, int *cut2, double **ocrossscore, int *ncut ); extern void blockAlign2( int *cut1, int *cut2, Segment **seg1, Segment **seg2, double **ocrossscore, int *ncut ); extern void blockAlign3( int *cut1, int *cut2, Segment **seg1, Segment **seg2, double **ocrossscore, int *ncut ); -extern float A__align11( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch ); -extern float imp_match_out_scH( int i1, int j1 ); -extern void imp_match_init_strictH( float *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, LocalHom ***localhom, int forscore ); -extern float imp_match_out_scQ( int i1, int j1 ); -extern float imp_match_out_scR( int i1, int j1 ); -extern void imp_match_init_strictQ( float *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, LocalHom ***localhom, int forscore ); -extern void imp_match_init_strictR( float *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, LocalHom ***localhom, int forscore ); -extern void imp_match_init( float *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, LocalHom ***localhom ); -extern float MSalignmm( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, char *, char *, char *, char *, int *, int, int *, int headgp, int tailgp ); -extern float Lalignmm_hmout( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, char *, char *, char *, char *, float **map ); -extern float Lalign2m2m_hmout( char **seq1, char **seq2, char **seq1r, char **seq2r, char *dir1, char *dir2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, char *, char *, char *, char *, float **map ); -extern float MSalign11( char **seq1, char **seq2, int alloclen ); -//extern float rnalocal( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, RNApair **pair ); -extern float A__align( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, char *gs1, char *gs2, char *ge1, char *ge2, int *, int, int *, int headgp, int tailgp ); -extern float H__align( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, char *gs1, char *gs2, char *ge1, char *ge2 ); -extern float Q__align( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, char *gs1, char *gs2, char *ge1, char *ge2 ); -extern float Q__align_gapmap( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, char *gs1, char *gs2, char *ge1, char *ge2, int *gapmap1, int *gapmap2 ); -extern float R__align( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, char *gs1, char *gs2, char *ge1, char *ge2 ); -extern float R__align( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, char *gs1, char *gs2, char *ge1, char *ge2 ); -extern float A__align_gapmap( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, int *gapmap1, int *gapmap2 ); -extern float D__align_gapmap( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, int *gapmap1, int *gapmap2 ); -extern float translate_and_Calign( char **mseq1, char **mseq2, double *effarr1, double *effarr2, int clus1, int clus2, int alloclen ); -extern double Fgetlag( char **seq1, char **seq2, double *eff1, double *eff2, int clus1, int clus2, int alloclen ); -extern float Falign( char **seq1, char **seq2, double *eff1, double *eff2, int clus1, int clus2, int alloclen, int *fftlog, int *, int, int * ); -extern float Falign_udpari_long( char **seq1, char **seq2, double *eff1, double *eff2, int clus1, int clus2, int alloclen, int *fftlog ); -float Falign_localhom( char **seq1, char **seq2, double *eff1, double *eff2, int clus1, int clus2, int alloclen, LocalHom ***localhom, float *totalimpmatch, int *gapmap1, int *gapmap2, int *chudanpt, int chudanref, int *chudanres ); -extern float part_imp_match_out_sc( int i1, int j1 ); -extern float part_imp_match_out_scQ( int i1, int j1 ); -extern void part_imp_match_init_strict( float *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, double *eff1_kozo, double *eff2_kozo, LocalHom ***localhom, int forscore ); -extern void part_imp_match_init_strictQ( float *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, LocalHom ***localhom, int forscore ); -extern void part_imp_match_init( float *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, LocalHom ***localhom ); -extern float partA__align( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, int start1, int end1, int start2, int end2, int *gapmap1, int *gapmap2, char *, char *, char *, char *, int *, int, int * ); -extern float partQ__align( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, int start1, int end1, int start2, int end2, int *gapmap1, int *gapmap2, char *, char *, char *, char *); -extern float G__align11( char **seq1, char **seq2, int alloclen, int headgp, int tailgp ); -extern float G__align11_noalign( int mtx[0x80][0x80], int penal, int penal_ex, char **seq1, char **seq2, int alloclen ); -extern float L__align11( char **seq1, char **seq2, int alloclen, int *off1pt, int *off2pt ); -extern float genL__align11( char **seq1, char **seq2, int alloclen, int *off1pt, int *off2pt ); -extern float genG__align11( char **seq1, char **seq2, int alloclen ); -extern float VAalign11( char **seq1, char **seq2, int alloclen, int *off1pt, int *off2pt, LocalHom *lhmpt ); -extern float suboptalign11( char **seq1, char **seq2, int alloclen, int *off1pt, int *off2pt, LocalHom *lhmpt ) +extern double A__align11( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, double *impmatch ); +extern double imp_match_out_scD( int i1, int j1 ); +extern void imp_match_init_strictD( double *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, double *eff1kozo, double*eff2kozo, LocalHom ***localhom, char *swaplist, int forscore, int *memlist1, int *memlist2 ); +extern void imp_match_init( double *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, LocalHom ***localhom ); +extern double MSalignmm( double **n_dynamicmtx, char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, char *, char *, char *, char *, int *, int, int *, int headgp, int tailgp ); +extern double MSalignmm_variousdist( double **pairoffset, double ***matrices, double **dummtx, char **seq1, char **seq2, double *eff1, double *eff2, double **eff1s, double **eff2s, int icyc, int jcyc, int alloclen, char *, char *, char *, char *, int *, int, int *, int headgp, int tailgp ); +extern double Lalignmm_hmout( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, char *, char *, char *, char *, double **map ); +extern double Lalign2m2m_hmout( char **seq1, char **seq2, char **seq1r, char **seq2r, char *dir1, char *dir2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, char *, char *, char *, char *, double **map ); +extern double MSalign11( char **seq1, char **seq2, int alloclen ); +//extern double rnalocal( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, RNApair **pair ); +extern double A__align( double **scoringmtx, char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, double *impmatch, char *gs1, char *gs2, char *ge1, char *ge2, int *, int, int *, int headgp, int tailgp, int firstmem, int calledby ); +extern double A__align_variousdist( int **which, double ***scoringmatrices, double **dummtx, char **seq1, char **seq2, double *eff1, double *eff2, double **eff1s, double **eff2s, int icyc, int jcyc, int alloclen, LocalHom ***localhom, double *impmatch, char *gs1, char *gs2, char *ge1, char *ge2, int *, int, int *, int headgp, int tailgp ); +extern double A__align_gapmap( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, double *impmatch, int *gapmap1, int *gapmap2 ); +//extern double D__align_gapmap( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, double *impmatch, int *gapmap1, int *gapmap2 ); +extern double translate_and_Calign( char **mseq1, char **mseq2, double *effarr1, double *effarr2, int clus1, int clus2, int alloclen ); +extern double Fgetlag( double **scoringmtx, char **seq1, char **seq2, double *eff1, double *eff2, int clus1, int clus2, int alloclen ); +extern double Falign( int **whichmtx, double ***scoringmatrices, double **scoreingmtx, char **seq1, char **seq2, double *eff1, double *eff2, double **eff1s, double **eff2s, int clus1, int clus2, int alloclen, int *fftlog, int *, int, int * ); +extern double Falign_udpari_long( int **whichmtx, double ***scoringmatrices, double **scoringmtx, char **seq1, char **seq2, double *eff1, double *eff2, double **eff1s, double **eff2s, int clus1, int clus2, int alloclen, int *fftlog ); +double Falign_localhom( int **which, double ***scoringmatrices, double **scoreingmtx, char **seq1, char **seq2, double *eff1, double *eff2, double **eff1s, double **eff2s, int clus1, int clus2, int alloclen, LocalHom ***localhom, double *totalimpmatch, int *gapmap1, int *gapmap2, int *chudanpt, int chudanref, int *chudanres ); +extern double part_imp_match_out_sc( int i1, int j1 ); +extern void part_imp_match_init_strict( double *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, double *eff1_kozo, double *eff2_kozo, LocalHom ***localhom, char *swaplist, int forscore, int *memlist1, int *memlist2 ); +extern void part_imp_match_init( double *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, LocalHom ***localhom ); +extern double partA__align( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, double *impmatch, int start1, int end1, int start2, int end2, int *gapmap1, int *gapmap2, char *, char *, char *, char *, int *, int, int * ); +extern double partA__align_variousdist( int **which, double ***scoringmatrices, double **dummtx, char **seq1, char **seq2, double *eff1, double *eff2, double **eff1s, double **eff2s, int icyc, int jcyc, int alloclen, LocalHom ***localhom, double *impmatch, int start1, int end1, int start2, int end2, int *gapmap1, int *gapmap2, char *, char *, char *, char *, int *, int, int * ); +extern double G__align11( double **scoringmtx, char **seq1, char **seq2, int alloclen, int headgp, int tailgp ); +extern double G__align11_noalign( double **scoringmtx, int penal, int penal_ex, char **seq1, char **seq2, int alloclen ); +extern double L__align11( double **scoringmtx, double scoreoffset, char **seq1, char **seq2, int alloclen, int *off1pt, int *off2pt ); +extern double L__align11_noalign( double **scoringmtx, char **seq1, char **seq2 ); +extern double genL__align11( double **scoringmtx, char **seq1, char **seq2, int alloclen, int *off1pt, int *off2pt ); +extern double genG__align11( char **seq1, char **seq2, int alloclen ); +extern double VAalign11( char **seq1, char **seq2, int alloclen, int *off1pt, int *off2pt, LocalHom *lhmpt ); +extern double suboptalign11( char **seq1, char **seq2, int alloclen, int *off1pt, int *off2pt, LocalHom *lhmpt ) ; extern int fft(int n, Fukusosuu *x, int dum); extern void topolcpy( int s1[], int s2[], int *mpt1, int *mpt2 ); @@ -167,13 +177,14 @@ extern void topolsort( int m, int s[] ); extern void topolswap( int s1[], int s2[], int *mpt1, int *mpt2 ); extern void reduc( double **mtx, int nseq, int im, int jm ); extern void nj( int nseq, double **omtx, int ***topol, double **dis ); -extern void JTTmtx( double **rsr, double *freq, char locamino[26], char locgrp[26], int isTM ); -extern void BLOSUMmtx( int n, double **matrix, double *freq, char *amino, char *amino_grp ); -extern void putlocalhom2( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa ); -extern void putlocalhom_str( char *al1, char *al2, double *equiv, double scale, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa ); -extern void putlocalhom_ext( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa ); -extern void putlocalhom3( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa ); -extern void putlocalhom( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa ); +extern void JTTmtx( double **rsr, double *freq, unsigned char locamino[0x80], char locgrp[0x80], int isTM ); +extern void BLOSUMmtx( int n, double **matrix, double *freq, unsigned char *amino, char *amino_grp ); +extern void extendedmtx( double **matrix, double *freq, unsigned char *amino, char *amino_grp ); +extern void putlocalhom2( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa, char korh ); +extern void putlocalhom_str( char *al1, char *al2, double *equiv, double scale, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa, char korh ); +extern void putlocalhom_ext( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa, char korh ); +extern void putlocalhom3( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa, char korh ); +extern void putlocalhom( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa, char korh ); extern char *cutal( char *al, int al_display_start, int start, int end ); extern void ErrorExit( char *message ); extern void strncpy_caseC( char *str1, char *str2, int len ); @@ -182,12 +193,13 @@ extern void seqLower( int nseq, char **seq ); extern int getaline_fp_eof( char *s, int l, FILE *fp ); extern int getaline_fp_eof_new(char s[], int l, FILE *fp); extern int myfgets(char s[], int l, FILE *fp); -extern float input_new( FILE *fp, int d ); +extern double input_new( FILE *fp, int d ); extern void PreRead( FILE *fp, int *locnjob, int *locnlenmax ); extern int allSpace( char *str ); extern void Read( char name[M][B], int nlen[M], char **seq ); extern void FRead( FILE *fp, char name[][B], int nlen[], char **seq ); extern void kake2hiku( char *str ); +extern int copydatafromgui( char **namegui, char **seqgui, char **name, int *nlen, char **seq ); extern void readDataforgaln( FILE *fp, char **name, int *nlen, char **seq ); extern void readData( FILE *fp, char name[][B], int nlen[], char **seq ); extern void readData_pointer_casepreserve( FILE *fp, char **name, int *nlen, char **seq ); @@ -198,29 +210,32 @@ extern int countATGC( char *s, int *total ); extern void getnumlen( FILE *fp ); extern void getnumlen_casepreserve( FILE *fp, int *nlenmin ); extern void getnumlen_nogap( FILE *fp, int *nlenmin ); +extern void getnumlen_nogap_countn( FILE *fp, int *nlenmin, double *nfreq ); extern void WriteGapFill( FILE *fp, int locnjob, char name[][B], int nlen[M], char **aseq ); extern void writeDataforgaln( FILE *fp, int locnjob, char **name, int *nlen, char **aseq ); extern void writeData( FILE *fp, int locnjob, char name[][B], int nlen[], char **aseq ); extern void writeData_pointer( FILE *fp, int locnjob, char **name, int *nlen, char **aseq ); -extern void readhat2_floathalf( FILE *fp, int nseq, char name[M][B], float **mtx ); -extern void readhat2_floathalf_pointer( FILE *fp, int nseq, char **name, float **mtx ); -extern void readhat2_float( FILE *fp, int nseq, char name[M][B], float **mtx ); +extern void readhat2_doublehalf( FILE *fp, int nseq, char name[M][B], double **mtx ); +extern void readhat2_doublehalf_pointer( FILE *fp, int nseq, char **name, double **mtx ); +extern void readhat2_doublehalf_part_pointer( FILE *fp, int nseq, int nadd, char **name, double **mtx ); +extern void readhat2_double( FILE *fp, int nseq, char name[M][B], double **mtx ); extern void readhat2_int( FILE *fp, int nseq, char name[M][B], int **mtx ); extern void readhat2_pointer( FILE *fp, int nseq, char **name, double **mtx ); extern void readhat2( FILE *fp, int nseq, char name[M][B], double **mtx ); -extern void WriteFloatHat2_pointer_halfmtx( FILE *hat2p, int locnjob, char **name, float **mtx ); -extern void WriteFloatHat2( FILE *hat2p, int locnjob, char name[M][B], float **mtx ); +extern void WriteFloatHat2_pointer_halfmtx( FILE *hat2p, int locnjob, char **name, double **mtx ); +extern void WriteFloatHat2( FILE *hat2p, int locnjob, char name[M][B], double **mtx ); extern void WriteHat2_int( FILE *hat2p, int locnjob, char name[M][B], int **mtx ); extern void WriteHat2( FILE *hat2p, int locnjob, char name[M][B], double **mtx ); extern void WriteHat2_pointer( FILE *hat2p, int locnjob, char **name, double **mtx ); +extern void WriteHat2_part_pointer( FILE *hat2p, int locnjob, int nadd, char **name, double **mtx ); extern int ReadFasta_sub( FILE *fp, double *dis, int nseq, char name[M][B] ); extern int ReadSsearch( FILE *fp, double *dis, int nseq, char name[M][B] ); -extern int ReadBlastm7( FILE *fp, double *dis, int qmem, char name[M][B], LocalHom *localhomlist ); +extern int ReadBlastm7( FILE *fp, double *dis, int qmem, char **name, LocalHom *localhomlist ); extern int ReadBlastm7_scoreonly( FILE *fp, double *dis, int nin ); extern int ReadBlastm7_avscore( FILE *fp, double *dis, int nin ); -extern int ReadFasta34noalign( FILE *fp, double *dis, int qmem, char name[M][B], LocalHom *localhomlist ); -extern int ReadFasta34m10_nuc( FILE *fp, double *dis, int qmem, char name[M][B], LocalHom *localhomlist ); -extern int ReadFasta34m10( FILE *fp, double *dis, int qmem, char name[M][B], LocalHom *localhomlist ); +extern int ReadFasta34noalign( FILE *fp, double *dis, int qmem, char **name, LocalHom *localhomlist ); +extern int ReadFasta34m10_nuc( FILE *fp, double *dis, int qmem, char **name, LocalHom *localhomlist ); +extern int ReadFasta34m10( FILE *fp, double *dis, int qmem, char **name, LocalHom *localhomlist ); extern int ReadFasta34m10_scoreonly_nuc( FILE *fp, double *dis, int nin ); extern int ReadFasta34m10_scoreonly( FILE *fp, double *dis, int nin ); extern int ReadFasta34( FILE *fp, double *dis, int nseq, char name[M][B], LocalHom *localhomlist ); @@ -232,15 +247,27 @@ extern int writePre( int nseq, char **name, int nlen[M], char **aseq, int force extern void readOtherOptions( int *ppidptr, int *fftThresholdptr, int *fftWinSizeptr ); extern void initSignalSM( void ); extern void initFiles( void ); -extern void WriteForFasta( FILE *fp, int locnjob, char name[][B], int nlen[M], char **aseq ); +extern void WriteForFasta( FILE *fp, int locnjob, char **name, int nlen[M], char **aseq ); extern void readlocalhomtable( FILE*fp, int njob, LocalHom **localhomtable, char *kozoarivec ); +extern void readlocalhomtable_half( FILE*fp, int njob, LocalHom **localhomtable, char *kozoarivec ); +extern void readlocalhomtable_target( FILE*fp, int nt, int njob, LocalHom **localhomtable, char *kozoarivec, int *targetmap ); extern void readlocalhomtable2( FILE*fp, int njob, LocalHom **localhomtable, char *kozoarivec ); +extern void readlocalhomtable2_half( FILE*fp, int njob, LocalHom **localhomtable, char *kozoarivec ); +extern void readlocalhomtable2_target( FILE*fp, int njob, LocalHom **localhomtable, char *kozoarivec, int *targetmap ); +extern void readlocalhomtable_part( FILE*fp, int njob, int nadd, LocalHom **localhomtable, char *kozoarivec ); +extern void readlocalhomtable_two( FILE*fp, int njob, int nadd, LocalHom **localhomtable, LocalHom **localhomtablex, char *kozoarivec ); +extern void readlocalhomtable_one( FILE*fp, int njob, int nadd, LocalHom **localhomtable, char *kozoarivec ); extern void outlocalhom( LocalHom **localhom, int nseq ); +extern void outlocalhom_part( LocalHom **localhom, int norg, int nadd ); extern void outlocalhompt( LocalHom ***localhom, int n1, int n2 ); +extern void FreeLocalHomTable_half( LocalHom **localhomtable, int n ) ; extern void FreeLocalHomTable( LocalHom **localhomtable, int n ) ; +extern void FreeLocalHomTable_part( LocalHom **localhomtable, int n, int m ) ; +extern void FreeLocalHomTable_two( LocalHom **localhomtable, int n, int m ) ; +extern void FreeLocalHomTable_one( LocalHom **localhomtable, int n, int m ) ; extern void constants( int nseq, char **seq ); extern void clustalout_pointer( FILE *fp, int nseq, int maxlen, char **seq, char **name, char *mark, char *comment, int *order, int namelen ); -extern void phylipout_pointer( FILE *fp, int nseq, int maxlen, char **seq, char **name, int *order ); +extern void phylipout_pointer( FILE *fp, int nseq, int maxlen, char **seq, char **name, int *order, int namelen ); extern void writeData_reorder( FILE *fp, int locnjob, char name[][B], int nlen[], char **aseq, int *order ); extern void writeData_reorder_pointer( FILE *fp, int locnjob, char **name, int *nlen, char **aseq, int *order ); @@ -248,56 +275,63 @@ extern void resetlocalhom( int, LocalHom ** ); extern int load1SeqWithoutName_new( FILE *fpp, char *cbuf ); extern char *load1SeqWithoutName_realloc( FILE *fpp ); extern char *load1SeqWithoutName_realloc_casepreserve( FILE *fpp ); -extern int disttbfast( char **in, int nlen[M], char name[M][B] ); extern void searchKUorWA( FILE *fp ); extern void gapireru( char *res, char *ori, char *gt ); extern int seqlen( char *seq ); -extern void st_FinalGapCount( float *fgcp, int clus, char **seq, double *eff, int len ); -extern void st_OpeningGapCount( float *ogcp, int clus, char **seq, double *eff, int len ); -extern void st_OpeningGapCount( float *ogcp, int clus, char **seq, double *eff, int len ); -extern void st_FinalGapCount_zure( float *fgcp, int clus, char **seq, double *eff, int len ); -extern void getdiaminofreq_x( float *freq, int clus, char **seq, double *eff, int len ); -extern void new_FinalGapCount_zure( float *fgcp, int clus, char **seq, double *eff, int len, char *s, char *e ); -extern void new_FinalGapCount( float *fgcp, int clus, char **seq, double *eff, int len, char *g ); -extern void new_OpeningGapCount( float *ogcp, int clus, char **seq, double *eff, int len, char *g ); -extern void new_OpeningGapCount_zure( float *ogcp, int clus, char **seq, double *eff, int len, char *s, char *e ); -extern void getGapPattern( float *fgcp, int clus, char **seq, double *eff, int len, char *g ); -extern void getgapfreq( float *freq, int clus, char **seq, double *eff, int len ); -extern void getgapfreq_zure( float *freq, int clus, char **seq, double *eff, int len ); -//extern void getgapfreq_zure_part( float *freq, int clus, char **seq, double *eff, int len, char *s ); -extern void getgapfreq_zure_part( float *freq, int clus, char **seq, double *eff, int len, char *s ); -extern void getdiaminofreq_part( float *freq, int clus, char **seq, double *eff, int len, char *s, char *e ); -extern void getdigapfreq_part( float *freq, int clus, char **seq, double *eff, int len, char *s, char *e ); -extern void getdiaminofreq_st( float *freq, int clus, char **seq, double *eff, int len ); -extern void getdigapfreq_st( float *freq, int clus, char **seq, double *eff, int len ); +extern void st_FinalGapCount( double *fgcp, int clus, char **seq, double *eff, int len ); +extern void st_FinalGapAdd( double *fgcp, int clus, char **seq, double *eff, int len ); +extern void st_OpeningGapCount( double *ogcp, int clus, char **seq, double *eff, int len ); +extern void st_OpeningGapAdd( double *ogcp, int clus, char **seq, double *eff, int len ); +extern void st_FinalGapCount_zure( double *fgcp, int clus, char **seq, double *eff, int len ); +extern void getdiaminofreq_x( double *freq, int clus, char **seq, double *eff, int len ); +extern void new_FinalGapCount_zure( double *fgcp, int clus, char **seq, double *eff, int len, char *s, char *e ); +extern void new_FinalGapCount( double *fgcp, int clus, char **seq, double *eff, int len, char *g ); +extern void new_OpeningGapCount( double *ogcp, int clus, char **seq, double *eff, int len, char *g ); +extern void new_OpeningGapCount_zure( double *ogcp, int clus, char **seq, double *eff, int len, char *s, char *e ); +extern void getGapPattern( double *fgcp, int clus, char **seq, double *eff, int len, char *g ); +extern void getgapfreq( double *freq, int clus, char **seq, double *eff, int len ); +extern void getgapfreq_zure( double *freq, int clus, char **seq, double *eff, int len ); +//extern void getgapfreq_zure_part( double *freq, int clus, char **seq, double *eff, int len, char *s ); +extern void getgapfreq_zure_part( double *freq, int clus, char **seq, double *eff, int len, char *s ); +extern void getdiaminofreq_part( double *freq, int clus, char **seq, double *eff, int len, char *s, char *e ); +extern void getdigapfreq_part( double *freq, int clus, char **seq, double *eff, int len, char *s, char *e ); +extern void getdiaminofreq_st( double *freq, int clus, char **seq, double *eff, int len ); +extern void getdigapfreq_st( double *freq, int clus, char **seq, double *eff, int len ); extern void st_getGapPattern( Gappat **gpat, int clus, char **seq, double *eff, int len ); extern void getkyokaigap( char *g, char **s, int pos, int n ); extern double *loadaamtx( void ); -extern float naivepairscore( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, int penal ); -extern float naivepairscore11( char *seq1, char *seq2, int penal ); -extern float naiveQpairscore( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, int penal ); -extern float naiveRpairscore( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, int penal ); -extern float naiveHpairscore( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, int penal ); -extern void foldrna( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, RNApair ***gr1, RNApair ***gr2, float **impmtx, int *gapmap1, int *gapmap2, RNApair *pair ); -extern void foldrna_gappick( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, RNApair ***gr1, RNApair ***gr2, float **impmtx, int *gapmap1, int *gapmap2, RNApair *pair ); +extern double naivepairscore( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, int penal ); +extern double naivepairscore11( char *seq1, char *seq2, int penal ); +extern double naivepairscore11_dynmtx( double **, char *seq1, char *seq2, int penal ); +extern double naivepairscorefast( char *seq1, char *seq2, int *skip1, int *skip2, int penal ); +extern double naiveQpairscore( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, int penal ); +extern double naiveRpairscore( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, int penal ); +extern double naiveHpairscore( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, int penal ); +extern void foldrna( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, RNApair ***gr1, RNApair ***gr2, double **impmtx, int *gapmap1, int *gapmap2, RNApair *pair ); +extern void foldrna_gappick( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, RNApair ***gr1, RNApair ***gr2, double **impmtx, int *gapmap1, int *gapmap2, RNApair *pair ); extern void imp_rna( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, RNApair ***gr1, RNApair ***gr2, int *gapmap1, int *gapmap2, RNApair *pair ); -extern void imp_rnaQ( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, RNApair ***gr1, RNApair ***gr2, int *gapmap1, int *gapmap2, RNApair *pair ); -extern void part_imp_rnaQ( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, RNApair ***gr1, RNApair ***gr2, int *gapmap1, int *gapmap2, RNApair *pair ); +extern void imp_rnaD( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, RNApair ***gr1, RNApair ***gr2, int *gapmap1, int *gapmap2, RNApair *pair ); extern void part_imp_rna( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, RNApair ***gr1, RNApair ***gr2, int *gapmap1, int *gapmap2, RNApair *pair ); -extern void imp_rnaQ_gappick( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, RNApair ***gr1, RNApair ***gr2, int *gapmap1, int *gapmap2, RNApair *pair ); extern void foldalignedrna( int clus1, int clus2, char **mseq1, char **mseq2, double *effarr1, double *effarr2, RNApair *rnapairboth ); void readmccaskill( FILE *fp, RNApair **pairprob, int length ); void makegrouprna( RNApair ***group, RNApair ***all, int *memlist ); -void makegrouprnait( RNApair ***group, RNApair ***all, char **pair, int s ); -extern void fixed_musclesupg_float_realloc_nobk_halfmtx( int nseq, float **eff, int ***topol, float **len, Treedep * ); -extern void loadtree( int nseq, int ***topol, float **len, char **name, int *nlen, Treedep * ); -extern void loadtop( int nseq, float **eff, int ***topol, float **len ); -extern void fixed_musclesupg_float_realloc_nobk_halfmtx_treeout( int nseq, float **eff, int ***topol, float **len, char **name, int *nlen, Treedep * ); +void makegrouprnait( RNApair ***group, RNApair ***all, char *pair, int s ); +extern void fixed_musclesupg_double_realloc_nobk_halfmtx( int nseq, double **eff, int ***topol, double **len, Treedep *, int progressout, int efffree ); +extern void fixed_musclesupg_double_realloc_nobk_halfmtx_memsave( int nseq, double **eff, int ***topol, double **len, Treedep *, int progressout, int efffree ); +extern void loadtop( int nseq, double **mtx, int ***topol, double **len, char **name, int *nlen, Treedep * ); +extern void loadtree( int nseq, int ***topol, double **len, char **name, int *nlen, Treedep *, int treeout ); +extern int check_guidetreefile( int *seed, int *npick, double *limitram ); +extern void createchain( int nseq, int ***topol, double **len, char **name, int *nlen, Treedep *dep, int treeout, int shuffle, int seed ); +//extern void loadtop( int nseq, double **eff, int ***topol, double **len ); +extern void fixed_musclesupg_double_realloc_nobk_halfmtx_treeout( int nseq, double **eff, int ***topol, double **len, char **name, int *nlen, Treedep *, int efffree ); // KESU +extern void fixed_musclesupg_double_realloc_nobk_halfmtx_treeout_memsave( int nseq, double **eff, int ***topol, double **len, char **name, int *nlen, Treedep *, int efffree ); +extern void fixed_supg_double_realloc_nobk_halfmtx_treeout_constrained( int nseq, double **eff, int ***topol, double **len, char **name, int *nlen, Treedep *, int ncons, int **constraints, int efffree ); extern void fixed_musclesupg_double_treeout( int nseq, double **eff, int ***topol, double **len, char **name ); -extern void imp_match_init_strict( float *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, double *eff1kozo, double*eff2kozo, LocalHom ***localhom, int forscore ); +extern void fixed_supg_double_treeout_constrained( int nseq, double **eff, int ***topol, double **len, char **name, int ncons, int **constraints ); +extern void imp_match_init_strict( double *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, double *eff1kozo, double*eff2kozo, LocalHom ***localhom, char *swaplist, int forscore, int *memlist1, int *memlist2 ); extern void miyataout_reorder_pointer( FILE *fp, int locnjob, int nlenmax, char **name, int *nlen, char **aseq, int *order ); extern void veryfastsupg_double_outtree( int nseq, double **eff, int ***topol, double **len, char **name ); -extern void cpmx_ribosum( char **seq, char **seqr, char *dir, float **cpmx, double *eff, int lgth, int clus ); +extern void cpmx_ribosum( char **seq, char **seqr, char *dir, double **cpmx, double *eff, int lgth, int clus ); extern void rnaalifoldcall( char **seq, int nseq, RNApair **pairprob ); extern void readpairfoldalign( FILE *fp, char *seq1, char *seq2, char *aln1, char *aln2, int q1, int q2, int *of1, int *of2, int sumlen ); extern void write1seq( FILE *fp, char *aseq ); @@ -309,11 +343,65 @@ extern void getnumlen_nogap_outallreg_web( FILE *fp, FILE *ofp, int *nlenminpt, extern void getnumlen_nogap_outallreg( FILE *fp, int *nlenminpt ); extern double plainscore( int nseq, char **seq ); extern void eq2dash( char *s ); -extern void findnewgaps( int n, char **seq, int *gaplen ); +extern void eq2dashmatometehayaku( char **s, int n ); +extern void findnewgaps( int n, int rep, char **seq, int *gaplen ); extern void findcommongaps( int, char **, int * ); extern void adjustgapmap( int, int *, char * ); -extern void insertnewgaps( int njob, int *alreadyaligned, char **seq, int *ex1, int *ex2, int *gaplen, int *gapmap, int alloclen, char alg ); -extern void restorecommongaps( int n, char **seq, int *top0, int *top1, int *gaplen, int alloclen ); +extern void insertnewgaps_bothorders( int njob, int *alreadyaligned, char **seq, int *ex1, int *ex2, int *gaplen, int *gapmap, int gapmaplen, int alloclen, char alg, char gapchar ); +extern void insertnewgaps( int njob, int *alreadyaligned, char **seq, int *ex1, int *ex2, int *gaplen, int *gapmap, int alloclen, char alg, char gapchar ); +extern void restorecommongaps( int n, int n0, char **seq, int *top0, int *top1, int *gaplen, int alloclen, char gapchar ); +extern void restorecommongapssmoothly( int n, int n0, char **seq, int *top0, int *top1, int *gaplen, int alloclen, char gapchar ); extern int samemember( int *mem, int *cand ); +extern int samemembern( int *mem, int *cand, int candn ); extern int includemember( int *mem, int *cand ); -extern void profilealignment( int n0, int n1, int n2, char **aln0, char **aln1, char **aln2, int alloclen, char alg ); +extern int overlapmember( int *mem1, int *mem2 ); +//extern void profilealignment( int n0, int n1, int n2, char **aln0, char **aln1, char **aln2, int alloclen, char alg ); +extern void profilealignment2( int n0, int n2, char **aln0, char **aln2, int alloclen, char alg ); +extern void sreverse( char *r, char *s ); +extern int addonetip( int njobc, int ***topolc, double **lenc, double **iscorec, int ***topol, double **len, Treedep *dep, int treeout, Addtree *addtree, int iadd, char **name, int *alnleninnode, int *nogaplen, int noalign ); +extern void intcpy( int *s1, int *s2 ); +extern void intncpy( int *s1, int *s2, int n ); +extern void fltncpy( double *s1, double *s2, int n ); +extern void intcat( int *s1, int *s2 ); +extern void readsubalignmentstable( int n, int **table, int *preservegaps, int *nsubpt, int *maxmempt ); +extern int myatoi( char * ); +extern double myatof( char * ); +extern void gapcount( double *freq, char **seq, int nseq, double *eff, int lgth ); +extern void gapcountf( double *freq, char **seq, int nseq, double *eff, int lgth ); +extern void gapcountadd( double *freq, char **seq, int nseq, double *eff, int lgth ); +extern void outgapcount( double *freq, int nseq, char *gappat, double *eff ); +extern void makedynamicmtx( double **out, double **in, double offset ); +extern double dist2offset( double dist ); +extern void reporterr( const char *str, ... ); +extern void freeconstants(); +extern void closeFiles(); +extern void FreeCommonIP(); +extern void initglobalvariables(); +extern void makeskiptable( int n, int **skip, char **seq ); +extern int generatesubalignmentstable( int nseq, int ***tablept, int *nsubpt, int *maxmempt, int ***topol, double **len, double threshold ); +extern double sumofpairsscore( int nseq, char **seq ); +//extern int maskoriginalgaps( char *repseq, char *originallygapped ); + +//extern void restoregaponlysites( char *originallygapped, int n1, int n2, char **s1, char **s2, int rep ); +extern int isallgap( char * ); +extern int deletenewinsertions_whole( int on, int an, char **oseq, char **aseq, int **deletelist ); +extern int deletenewinsertions_whole_eq( int on, int an, char **oseq, char **aseq, int **deletelist ); +extern int recordoriginalgaps( char *originallygapped, int n, char **s ); +extern void restoreoriginalgaps( int n, char **seq, char *originalgaps ); +extern void reconstructdeletemap( int nadd, char ** addbk, int **deletelist, char **realn, FILE *fp, char **name ); +extern double D__align( double **n_dynamicmtx, char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, double *impmatch, char *sgap1, char *sgap2, char *egap1, char *egap2, int *chudanpt, int chudanref, int *chudanres, int headgp, int tailgp ); +extern double D__align_ls( double **n_dynamicmtx, char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, double *impmatch, char *sgap1, char *sgap2, char *egap1, char *egap2, int *chudanpt, int chudanref, int *chudanres, int headgp, int tailgp ); +extern double D__align_variousdist( int **whichmtx, double ***matrices, double **n_dynamicmtx, char **seq1, char **seq2, double *eff1, double *eff2, double **eff1s, double **eff2s, int icyc, int jcyc, int alloclen, LocalHom ***localhom, double *impmatch, char *sgap1, char *sgap2, char *egap1, char *egap2, int *chudanpt, int chudanref, int *chudanres, int headgp, int tailgp ); +extern double D__align_gapmap( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, double *impmatch, int *gapmap1, int *gapmap2 ); +extern void stringshuffle( int *ary, int size ); +extern void topolorder( int n, int *order, int *posinorder, int ***topol, Treedep *dep, int pos, int child ); +extern int commonsextet_p( int *table, int *pointt ); +extern void compacttree_memsaveselectable( int nseq, double **partmtx, int *nearest, double *mindist, int **pointt, int *selfscore, char **seq, int **skiptable, int ***topol, double **len, char **name, int *nlen, Treedep *dep, int treeout, int howcompact, int memsave ); +extern double distcompact( int len1, int len2, int *table1, int *point2, int ss1, int ss2 ); +extern double distcompact_msa( char *seq1, char *seq2, int *skiptable1, int *skiptable2, int ss1, int ss2 ); +extern void fillimp( double **impmtx, double *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, double *eff1_kozo, double *eff2_kozo, LocalHom ***localhom, char *swaplist, int forscore, int *orinum1, int *orinum2 ); +extern int pairlocalalign( int ngui, int lgui, char **namegui, char **seqgui, double **distancemtx, LocalHom **localhomtable, int argc, char **argv ); +extern char creverse( char f ); +#ifndef mingw +extern void setstacksize( rlim_t ); +#endif diff --git a/binaries/src/mafft/core/genalign11.c b/binaries/src/mafft/core/genalign11.c index 29cb6fd..832eb98 100644 --- a/binaries/src/mafft/core/genalign11.c +++ b/binaries/src/mafft/core/genalign11.c @@ -9,16 +9,16 @@ static TLS int localstop; #if 1 -static void match_calc( float *match, char **s1, char **s2, int i1, int lgth2 ) +static void match_calc_mtx( double **mtx, double *match, char **s1, char **s2, int i1, int lgth2 ) { - char tmpc = s1[0][i1]; char *seq2 = s2[0]; + double *doubleptr = mtx[(unsigned char)s1[0][i1]]; while( lgth2-- ) - *match++ = amino_dis[(int)tmpc][(int)*seq2++]; + *match++ = doubleptr[(unsigned char)*seq2++]; } #else -static void match_calc( float *match, char **s1, char **s2, int i1, int lgth2 ) +static void match_calc( double *match, char **s1, char **s2, int i1, int lgth2 ) { int j; @@ -27,70 +27,10 @@ static void match_calc( float *match, char **s1, char **s2, int i1, int lgth2 ) } #endif -#if 0 -static void match_calc_bk( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize ) -{ - int j, k, l; - float scarr[26]; - float **cpmxpd = floatwork; - int **cpmxpdn = intwork; - int count = 0; - - if( initialize ) - { - for( j=0; j -1 ) - *fpt2 += scarr[*ipt++] * *fpt++; - fpt2++,iptpt++,fptpt++; - } - } -#else - for( j=0; j-1; k++ ) - match[j] += scarr[cpmxpdn[k][j]] * cpmxpd[k][j]; - } -#endif -} -#endif - -static float gentracking( float *lasthorizontalw, float *lastverticalw, +static double gentracking( double *lasthorizontalw, double *lastverticalw, char **seq1, char **seq2, char **mseq1, char **mseq2, - float **cpmx1, float **cpmx2, + double **cpmx1, double **cpmx2, int **ijpi, int **ijpj, int *off1pt, int *off2pt, int endi, int endj ) { int i, j, l, iin, jin, lgth1, lgth2, k, limk; @@ -170,7 +110,7 @@ static float gentracking( float *lasthorizontalw, float *lastverticalw, } -float genL__align11( char **seq1, char **seq2, int alloclen, int *off1pt, int *off2pt ) +double genL__align11( double **n_dynamicmtx, char **seq1, char **seq2, int alloclen, int *off1pt, int *off2pt ) /* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */ { // int k; @@ -178,47 +118,48 @@ float genL__align11( char **seq1, char **seq2, int alloclen, int *off1pt, int *o int lasti, lastj; int lgth1, lgth2; int resultlen; - float wm = 0.0; /* int ?????? */ - float g; - float *currentw, *previousw; + double wm = 0.0; /* int ?????? */ + double g; + double *currentw, *previousw; #if 1 - float *wtmp; + double *wtmp; int *ijpipt; int *ijpjpt; - float *mjpt, *Mjpt, *prept, *curpt; + double *mjpt, *Mjpt, *prept, *curpt; int *mpjpt, *Mpjpt; #endif - static TLS float mi, *m; - static TLS float Mi, *largeM; + static TLS double mi, *m; + static TLS double Mi, *largeM; static TLS int **ijpi; static TLS int **ijpj; static TLS int mpi, *mp; static TLS int Mpi, *Mp; - static TLS float *w1, *w2; - static TLS float *match; - static TLS float *initverticalw; /* kufuu sureba iranai */ - static TLS float *lastverticalw; /* kufuu sureba iranai */ + static TLS double *w1, *w2; + static TLS double *match; + static TLS double *initverticalw; /* kufuu sureba iranai */ + static TLS double *lastverticalw; /* kufuu sureba iranai */ static TLS char **mseq1; static TLS char **mseq2; static TLS char **mseq; - static TLS float **cpmx1; - static TLS float **cpmx2; + static TLS double **cpmx1; + static TLS double **cpmx2; static TLS int **intwork; - static TLS float **floatwork; + static TLS double **doublework; static TLS int orlgth1 = 0, orlgth2 = 0; - float maxwm; - float tbk; + static TLS double **amino_dynamicmtx = NULL; // ?? + double maxwm; + double tbk; int tbki, tbkj; int endali, endalj; -// float localthr = 0.0; -// float localthr2 = 0.0; - float fpenalty = (float)penalty; - float fpenalty_OP = (float)penalty_OP; - float fpenalty_ex = (float)penalty_ex; -// float fpenalty_EX = (float)penalty_EX; - float foffset = (float)offset; - float localthr = -foffset; - float localthr2 = -foffset; +// double localthr = 0.0; +// double localthr2 = 0.0; + double fpenalty = (double)penalty; + double fpenalty_OP = (double)penalty_OP; + double fpenalty_ex = (double)penalty_ex; +// double fpenalty_EX = (double)penalty_EX; + double foffset = (double)offset; + double localthr = -foffset; + double localthr2 = -foffset; if( seq1 == NULL ) { @@ -244,8 +185,9 @@ float genL__align11( char **seq1, char **seq2, int alloclen, int *off1pt, int *o FreeFloatMtx( cpmx1 ); FreeFloatMtx( cpmx2 ); - FreeFloatMtx( floatwork ); + FreeFloatMtx( doublework ); FreeIntMtx( intwork ); + if( amino_dynamicmtx ) FreeDoubleMtx( amino_dynamicmtx ); amino_dynamicmtx = NULL; } return( 0.0 ); @@ -287,8 +229,9 @@ float genL__align11( char **seq1, char **seq2, int alloclen, int *off1pt, int *o FreeFloatMtx( cpmx1 ); FreeFloatMtx( cpmx2 ); - FreeFloatMtx( floatwork ); + FreeFloatMtx( doublework ); FreeIntMtx( intwork ); + if( amino_dynamicmtx ) FreeDoubleMtx( amino_dynamicmtx ); amino_dynamicmtx = NULL; } ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100; @@ -312,11 +255,13 @@ float genL__align11( char **seq1, char **seq2, int alloclen, int *off1pt, int *o mseq = AllocateCharMtx( njob, ll1+ll2 ); - cpmx1 = AllocateFloatMtx( 26, ll1+2 ); - cpmx2 = AllocateFloatMtx( 26, ll2+2 ); + cpmx1 = AllocateFloatMtx( nalphabets, ll1+2 ); + cpmx2 = AllocateFloatMtx( nalphabets, ll2+2 ); + + doublework = AllocateFloatMtx( nalphabets, MAX( ll1, ll2 )+2 ); + intwork = AllocateIntMtx( nalphabets, MAX( ll1, ll2 )+2 ); - floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 ); - intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 ); + amino_dynamicmtx = AllocateDoubleMtx( 0x100, 0x100 ); #if DEBUG fprintf( stderr, "succeeded\n" ); @@ -326,6 +271,8 @@ float genL__align11( char **seq1, char **seq2, int alloclen, int *off1pt, int *o orlgth2 = ll2 - 100; } + for( i=0; i-1; i++ ) { diff --git a/binaries/src/mafft/core/getlag.o b/binaries/src/mafft/core/getlag.o new file mode 100644 index 0000000..2be6c45 Binary files /dev/null and b/binaries/src/mafft/core/getlag.o differ diff --git a/binaries/src/mafft/core/interface.c b/binaries/src/mafft/core/interface.c new file mode 100644 index 0000000..4e8aafb --- /dev/null +++ b/binaries/src/mafft/core/interface.c @@ -0,0 +1,144 @@ +#include +#include +#include +#include "mafft.h" + +int report( int status, int progress, char *message ) +{ + fprintf( stderr, "status = %d\n", status ); + fprintf( stderr, "progress = %d / 100\n", progress ); + fprintf( stderr, "message = %s\n", message ); + return( 0 ); +} + +int chudan( int status, int progress, char *message ) +{ + fprintf( stderr, "status = %d\n", status ); + fprintf( stderr, "progress = %d / 100\n", progress ); + fprintf( stderr, "message = %s\n", message ); + return( 2 ); +} +int main( void ) +{ + int i; + int argc; + char **argv; + char **seq; + char **name; + char *message; + int res; + int n, l, mlen; + +// printf( "This is interface.\n" ); + + + l = 10000; + n = 130; + seq = (char **)calloc( n, sizeof( char * ) ); + name = (char **)calloc( n, sizeof( char * ) ); + for( i=0; i -D; Protein -> -P + strcpy( argv[18], "-I" ); // --add + strcpy( argv[19], "2" ); // --add + +#if 0 + mlen = 5000; + message = (char *)calloc( mlen+1, sizeof( char ) ); + + fprintf( stderr, "first run\n" ); + res = disttbfast( n, l, mlen, name, seq, &message, argc, argv, report ); + fprintf( stderr, "second run\n" ); + res = disttbfast( n, l, mlen, name, seq, &message, argc, argv, report ); + fprintf( stderr, "third run\n" ); + res = disttbfast( n, l, mlen, name, seq, &message, argc, argv, report ); + + fprintf( stderr, "\n\n\nmessage in interface = :%s:\n", message ); + free( message ); +#else + fprintf( stderr, "first run\n" ); + res = disttbfast( n, l, name, seq, argc, argv, report ); + fprintf( stderr, "second run\n" ); + res = disttbfast( n, l, name, seq, argc, argv, chudan ); +// fprintf( stderr, "third run\n" ); +// res = disttbfast( n, l, name, seq, argc, argv, report ); +#endif + + if( res == GUI_LENGTHOVER ) + { + fprintf( stderr, "length over!" ); + } + else + { + fprintf( stderr, "res = %d\n", res ); + fprintf( stdout, "Output:\n" ); + for( i=0; istart2 = start2; tmppt->end1 = end1 ; tmppt->end2 = end2 ; + tmppt->korh = korh ; #if 1 sumscore += score; @@ -273,7 +300,7 @@ static int addlocalhom_r( char *al1, char *al2, LocalHom *localhompt, int off1, start1 = pos1; start2 = pos2; st = 1; } - score += (double)n_dis[(int)amino_n[(int)*pt1]][(int)amino_n[(int)*pt2]]; + score += (double)n_dis[(int)amino_n[(unsigned char)*pt1]][(int)amino_n[(unsigned char)*pt2]]; // fprintf( stderr, "%c-%c, score(0) = %f\n", *pt1, *pt2, score ); } if( *pt1++ != '-' ) pos1++; @@ -293,6 +320,7 @@ static int addlocalhom_r( char *al1, char *al2, LocalHom *localhompt, int off1, tmppt->start2 = start2; tmppt->end1 = end1 ; tmppt->end2 = end2 ; + tmppt->korh = korh ; #if 1 sumscore += score; @@ -315,7 +343,7 @@ static int addlocalhom_r( char *al1, char *al2, LocalHom *localhompt, int off1, } return( nlocalhom ); } -void putlocalhom3( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa ) +void putlocalhom3( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa, char korh ) { int pos1, pos2, start1, start2, end1, end2; char *pt1, *pt2; @@ -367,6 +395,7 @@ void putlocalhom3( char *al1, char *al2, LocalHom *localhompt, int off1, int off tmppt->start2 = start2; tmppt->end1 = end1 ; tmppt->end2 = end2 ; + tmppt->korh = korh ; #if 1 if( divpairscore ) @@ -399,7 +428,7 @@ void putlocalhom3( char *al1, char *al2, LocalHom *localhompt, int off1, int off start1 = pos1; start2 = pos2; st = 1; } - score += (double)n_dis[(int)amino_n[(int)*pt1]][(int)amino_n[(int)*pt2]]; // - offset ¤Ï¤¤¤é¤Ê¤¤¤«¤â + score += (double)n_dis[(int)amino_n[(unsigned char)*pt1]][(int)amino_n[(unsigned char)*pt2]]; // - offset ¤Ï¤¤¤é¤Ê¤¤¤«¤â // fprintf( stderr, "%c-%c, score(0) = %f\n", *pt1, *pt2, score ); } if( *pt1++ != '-' ) pos1++; @@ -422,6 +451,7 @@ void putlocalhom3( char *al1, char *al2, LocalHom *localhompt, int off1, int off tmppt->start2 = start2; tmppt->end1 = end1 ; tmppt->end2 = end2 ; + tmppt->korh = korh ; #if 1 @@ -460,7 +490,7 @@ void putlocalhom3( char *al1, char *al2, LocalHom *localhompt, int off1, int off } } } -void putlocalhom_ext( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa ) +void putlocalhom_ext( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa, char korh ) { int pos1, pos2, start1, start2, end1, end2; char *pt1, *pt2; @@ -501,6 +531,7 @@ void putlocalhom_ext( char *al1, char *al2, LocalHom *localhompt, int off1, int tmppt->start2 = start2; tmppt->end1 = end1 ; tmppt->end2 = end2 ; + tmppt->korh = korh ; #if 1 if( divpairscore ) @@ -533,7 +564,7 @@ void putlocalhom_ext( char *al1, char *al2, LocalHom *localhompt, int off1, int start1 = pos1; start2 = pos2; st = 1; } - iscore += n_dis[(int)amino_n[(int)*pt1]][(int)amino_n[(int)*pt2]]; // - offset ¤Ï¤¤¤é¤Ê¤¤¤«¤â + iscore += n_dis[(int)amino_n[(unsigned char)*pt1]][(int)amino_n[(unsigned char)*pt2]]; // - offset ¤Ï¤¤¤é¤Ê¤¤¤«¤â // fprintf( stderr, "%c-%c, iscore(0) = %d\n", *pt1, *pt2, iscore ); } if( *pt1++ != '-' ) pos1++; @@ -555,6 +586,7 @@ void putlocalhom_ext( char *al1, char *al2, LocalHom *localhompt, int off1, int tmppt->start2 = start2; tmppt->end1 = end1 ; tmppt->end2 = end2 ; + tmppt->korh = korh ; #if 1 if( divpairscore ) @@ -591,7 +623,7 @@ void putlocalhom_ext( char *al1, char *al2, LocalHom *localhompt, int off1, int } } -void putlocalhom_str( char *al1, char *al2, double *equiv, double scale, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa ) +void putlocalhom_str( char *al1, char *al2, double *equiv, double scale, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa, char korh ) { int posinaln, pos1, pos2, start1, start2, end1, end2; char *pt1, *pt2; @@ -626,6 +658,7 @@ void putlocalhom_str( char *al1, char *al2, double *equiv, double scale, LocalHo tmppt->start2 = start2; tmppt->end1 = end1 ; tmppt->end2 = end2 ; + tmppt->korh = korh ; tmppt->overlapaa = 1; // tmppt->opt = (double)iscore / tmppt->overlapaa * 5.8 / 600; @@ -639,7 +672,9 @@ void putlocalhom_str( char *al1, char *al2, double *equiv, double scale, LocalHo } } -void putlocalhom2( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa ) + + +void putlocalhom2( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa, char korh ) { int pos1, pos2, start1, start2, end1, end2; char *pt1, *pt2; @@ -680,6 +715,9 @@ void putlocalhom2( char *al1, char *al2, LocalHom *localhompt, int off1, int off tmppt->start2 = start2; tmppt->end1 = end1 ; tmppt->end2 = end2 ; + tmppt->korh = korh ; + tmppt->nokori += 1; + localhompt->last = tmppt; #if 1 if( divpairscore ) @@ -712,7 +750,7 @@ void putlocalhom2( char *al1, char *al2, LocalHom *localhompt, int off1, int off start1 = pos1; start2 = pos2; st = 1; } - iscore += n_dis[(int)amino_n[(int)*pt1]][(int)amino_n[(int)*pt2]]; // - offset ¤Ï¤¤¤é¤Ê¤¤¤«¤â + iscore += n_dis[(int)amino_n[(unsigned char)*pt1]][(int)amino_n[(unsigned char)*pt2]]; // - offset ¤Ï¤¤¤é¤Ê¤¤¤«¤â // fprintf( stderr, "%c-%c, iscore(0) = %d\n", *pt1, *pt2, iscore ); } if( *pt1++ != '-' ) pos1++; @@ -734,6 +772,9 @@ void putlocalhom2( char *al1, char *al2, LocalHom *localhompt, int off1, int off tmppt->start2 = start2; tmppt->end1 = end1 ; tmppt->end2 = end2 ; + tmppt->korh = korh ; + tmppt->nokori += 1; + localhompt->last = tmppt; #if 1 if( divpairscore ) @@ -768,7 +809,9 @@ void putlocalhom2( char *al1, char *al2, LocalHom *localhompt, int off1, int off } } } -void putlocalhom( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa ) + +#if 0 +void putlocalhom( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa, char korh ) { int pos1, pos2, start1, start2, end1, end2; char *pt1, *pt2; @@ -809,6 +852,7 @@ void putlocalhom( char *al1, char *al2, LocalHom *localhompt, int off1, int off2 tmppt->start2 = start2; tmppt->end1 = end1 ; tmppt->end2 = end2 ; + tmppt->korh = korh ; #if 1 if( divpairscore ) @@ -841,7 +885,7 @@ void putlocalhom( char *al1, char *al2, LocalHom *localhompt, int off1, int off2 start1 = pos1; start2 = pos2; st = 1; } - score += (double)n_dis[(int)amino_n[(int)*pt1]][(int)amino_n[(int)*pt2]]; // - offset ¤Ï¤¤¤é¤Ê¤¤¤«¤â + score += (double)n_dis[(int)amino_n[(unsigned char)*pt1]][(int)amino_n[(unsigned char)*pt2]]; // - offset ¤Ï¤¤¤é¤Ê¤¤¤«¤â // fprintf( stderr, "%c-%c, score(0) = %f\n", *pt1, *pt2, score ); } if( *pt1++ != '-' ) pos1++; @@ -861,6 +905,7 @@ void putlocalhom( char *al1, char *al2, LocalHom *localhompt, int off1, int off2 tmppt->start2 = start2; tmppt->end1 = end1 ; tmppt->end2 = end2 ; + tmppt->korh = korh ; #if 1 if( divpairscore ) @@ -894,6 +939,7 @@ void putlocalhom( char *al1, char *al2, LocalHom *localhompt, int off1, int off2 } } } +#endif char *cutal( char *al, int al_display_start, int start, int end ) { @@ -929,7 +975,7 @@ void strncpy_caseC( char *str1, char *str2, int len ) else strncpy( str1, str2, len ); } -void seqUpper( int nseq, char **seq ) /* not used */ +void seqUpper( int nseq, char **seq ) { int i, j, len; for( i=0; i' ) + if( tmp == '>' || tmp == '(' ) { fprintf( stderr, "========================================================\n" ); fprintf( stderr, "========================================================\n" ); fprintf( stderr, "=== \n" ); fprintf( stderr, "=== ERROR!! \n" ); - fprintf( stderr, "=== In the '--anysymbol' and '--preservecase' modes, \n" ); - fprintf( stderr, "=== '>' in sequence is unacceptable.\n" ); +// fprintf( stderr, "=== In the '--anysymbol' and '--preservecase' modes, \n" ); + fprintf( stderr, "=== '>' and '(' are acceptable only in title lines.\n" ); fprintf( stderr, "=== \n" ); fprintf( stderr, "========================================================\n" ); fprintf( stderr, "========================================================\n" ); @@ -1217,6 +1264,37 @@ static int onlyGraph( char *str ) *res = 0; return( res - bk ); } +#endif + +static int charfilter( unsigned char *str ) +{ + unsigned char tmp; + unsigned char *res = str; + unsigned char *bk = str; + + while( (tmp=*str++) ) + { +// if( tmp == '=' || tmp == '*' || tmp == '<' || tmp == '>' || tmp == '(' || tmp == ')' ) + if( tmp == '=' || tmp == '<' || tmp == '>' ) + { + fprintf( stderr, "\n" ); + fprintf( stderr, "Characters '= < >' are not accepted in the --text mode, \nalthough most printable characters are ok.\n" ); + fprintf( stderr, "\n" ); + exit( 1 ); + } +// if( 0x20 < tmp && tmp < 0x7f ) +// if( 0x0 <=tmp && tmp < 0x100 && + if( tmp != 0x0a && tmp != 0x20 && tmp != 0x0d ) +// if( tmp != '\n' && tmp != ' ' && tmp != '\t' ) // unprintable characters mo ok. + { + *res++ = tmp; +// reporterr( "tmp=%d (%c)\n", tmp, tmp ); + } + } + *res = 0; + return( res - bk ); +} + static int onlyAlpha_lower( char *str ) { @@ -1262,7 +1340,7 @@ char *load1SeqWithoutName_realloc_casepreserve( FILE *fpp ) b = '\n'; while( ( c = getc( fpp ) ) != EOF && - !( ( c == '>' || c == '(' || c == EOF ) && b == '\n' ) ) + !( ( c == '>' || c == EOF ) && b == '\n' ) ) { *cbuf++ = (char)c; /* Ť¹¤®¤Æ¤â¤·¤é¤Ê¤¤ */ if( cbuf - val == size ) @@ -1282,7 +1360,8 @@ char *load1SeqWithoutName_realloc_casepreserve( FILE *fpp ) } ungetc( c, fpp ); *cbuf = 0; - onlyGraph( val ); +// onlyGraph( val ); + charfilter( (unsigned char *) val ); // kake2hiku( val ); return( val ); } @@ -1299,7 +1378,7 @@ char *load1SeqWithoutName_realloc( FILE *fpp ) b = '\n'; while( ( c = getc( fpp ) ) != EOF && - !( ( c == '>' || c == '(' || c == EOF ) && b == '\n' ) ) + !( ( c == '>' || c == EOF ) && b == '\n' ) ) { *cbuf++ = (char)c; /* Ť¹¤®¤Æ¤â¤·¤é¤Ê¤¤ */ if( cbuf - val == size ) @@ -1319,11 +1398,19 @@ char *load1SeqWithoutName_realloc( FILE *fpp ) } ungetc( c, fpp ); *cbuf = 0; - if( dorp == 'd' ) - onlyAlpha_lower( val ); + + if( nblosum == -2 ) + { + charfilter( (unsigned char *) val ); + } else - onlyAlpha_upper( val ); - kake2hiku( val ); + { + if( dorp == 'd' ) + onlyAlpha_lower( val ); + else + onlyAlpha_upper( val ); + kake2hiku( val ); + } return( val ); } @@ -1334,7 +1421,7 @@ int load1SeqWithoutName_new( FILE *fpp, char *cbuf ) b = '\n'; while( ( c = getc( fpp ) ) != EOF && /* by T. Nishiyama */ - !( ( c == '>' || c == '(' || c == EOF ) && b == '\n' ) ) + !( ( c == '>' || c == EOF ) && b == '\n' ) ) { *cbuf++ = (char)c; /* Ť¹¤®¤Æ¤â¤·¤é¤Ê¤¤ */ b = c; @@ -1526,6 +1613,53 @@ void readData_pointer_casepreserve( FILE *fp, char **name, int *nlen, char **seq } +int copydatafromgui( char **namegui, char **seqgui, char **name, int *nlen, char **seq ) +{ + int i; + + + for( i=0; i endpos ) - { - endpos = regtable[i][j*2]; - startpos = regtable[i][j*2+1]; - } - - if( startpos < 0 ) startpos = 0; - if( endpos < 0 ) endpos = 0; - if( endpos >= seqlen ) endpos = seqlen-1; - if( startpos >= seqlen ) startpos = seqlen-1; - + startpos = 0; + endpos = seqlen-1; outlen = endpos - startpos + 1; - if( revtable[i][j] == 'f' ) - { - fprintf( stderr, "startpos = %d\n", startpos ); - fprintf( stderr, "endpos = %d\n", endpos ); - fprintf( stderr, "outlen = %d\n", outlen ); - fprintf( stdout, "%.*s\n", outlen, tmpseq+startpos ); - } - else + fprintf( stdout, "%.*s\n", outlen, tmpseq+startpos ); + } + else + { + for( j=0; j<5; j++ ) { - fs = AllocateCharVec( outlen+1 ); - rs = AllocateCharVec( outlen+1 ); - - fs[outlen] = 0; - strncpy( fs, tmpseq+startpos, outlen ); - sreverse( rs, fs ); - fprintf( stdout, "%s\n", rs ); - free( fs ); - free( rs ); + if( regtable[i][j*2] == -1 && regtable[i][j*2+1] == -1 ) continue; + + startpos = regtable[i][j*2]; + endpos = regtable[i][j*2+1]; + + if( startpos > endpos ) + { + endpos = regtable[i][j*2]; + startpos = regtable[i][j*2+1]; + } + + if( startpos < 0 ) startpos = 0; + if( endpos < 0 ) endpos = 0; + if( endpos >= seqlen ) endpos = seqlen-1; + if( startpos >= seqlen ) startpos = seqlen-1; + + outlen = endpos - startpos + 1; + if( revtable[i][j] == 'f' ) + { + fprintf( stderr, "startpos = %d\n", startpos ); + fprintf( stderr, "endpos = %d\n", endpos ); + fprintf( stderr, "outlen = %d\n", outlen ); + fprintf( stdout, "%.*s\n", outlen, tmpseq+startpos ); + } + else + { + fs = AllocateCharVec( outlen+1 ); + rs = AllocateCharVec( outlen+1 ); + + fs[outlen] = 0; + strncpy( fs, tmpseq+startpos, outlen ); + sreverse( rs, fs ); + fprintf( stdout, "%s\n", rs ); + free( fs ); + free( rs ); + } } } } @@ -1826,6 +1970,41 @@ void catData( FILE *fp ) } } +int countATGCandN( char *s, int *countN, int *total ) +{ + int nATGC; + int nChar; + int nN; + char c; + nN = nATGC = nChar = 0; + + if( *s == 0 ) + { + *total = 0; + return( 0 ); + } + + do + { + c = tolower( *s ); + if( isalpha( c ) ) + { + nChar++; + if( c == 'a' || c == 't' || c == 'g' || c == 'c' || c == 'u' || c == 'n' ) + nATGC++; + if( c == 'n' ) + nN++; + } + } + while( *++s ); + +// reporterr( "nN = %d", nN ); + + *total = nChar; + *countN = nN; + return( nATGC ); +} + int countATGC( char *s, int *total ) { int nATGC; @@ -1835,7 +2014,7 @@ int countATGC( char *s, int *total ) if( *s == 0 ) { - total = 0; + *total = 0; return( 0 ); } @@ -1885,6 +2064,14 @@ int countnogaplen( char *seq ) return( val ); } +int countnormalletters( char *seq, char *ref ) +{ + int val = 0; + while( *seq ) + if( strchr( ref, *seq++ ) ) val++; + return( val ); +} + void getnumlen_casepreserve( FILE *fp, int *nlenminpt ) { int total; @@ -1929,6 +2116,53 @@ void getnumlen_casepreserve( FILE *fp, int *nlenminpt ) } } +void getnumlen_nogap_countn( FILE *fp, int *nlenminpt, double *nfreq ) +{ + int total; + int nsite = 0; + int atgcnum, nnum, nN; + int i, tmp; + char *tmpseq, *tmpname; + double atgcfreq; + tmpname = AllocateCharVec( N ); + njob = countKUorWA( fp ); + searchKUorWA( fp ); + nlenmax = 0; + *nlenminpt = 99999999; + atgcnum = 0; + total = 0; + nnum = 0; + for( i=0; i nlenmax ) nlenmax = tmp; + if( tmp < *nlenminpt ) *nlenminpt = tmp; + atgcnum += countATGCandN( tmpseq, &nN, &nsite ); + total += nsite; + nnum += nN; + free( tmpseq ); + } + free( tmpname ); + atgcfreq = (double)atgcnum / total; + *nfreq = (double)nnum / atgcnum; +// fprintf( stderr, "##### nnum = %d\n", nnum ); +// fprintf( stderr, "##### atgcfreq = %f, *nfreq = %f\n", atgcfreq, *nfreq ); + if( dorp == NOTSPECIFIED ) + { + if( atgcfreq > 0.75 ) + { + dorp = 'd'; + upperCase = -1; + } + else + { + dorp = 'p'; + upperCase = 0; + } + } +} void getnumlen_nogap( FILE *fp, int *nlenminpt ) { int total; @@ -1957,7 +2191,7 @@ void getnumlen_nogap( FILE *fp, int *nlenminpt ) } free( tmpname ); atgcfreq = (double)atgcnum / total; - fprintf( stderr, "##### atgcfreq = %f\n", atgcfreq ); +// fprintf( stderr, "##### atgcfreq = %f\n", atgcfreq ); if( dorp == NOTSPECIFIED ) { if( atgcfreq > 0.75 ) @@ -2004,7 +2238,7 @@ void getnumlen_nogap_outallreg( FILE *fp, int *nlenminpt ) } free( tmpname ); atgcfreq = (double)atgcnum / total; - fprintf( stderr, "##### atgcfreq = %f\n", atgcfreq ); +// fprintf( stderr, "##### atgcfreq = %f\n", atgcfreq ); if( dorp == NOTSPECIFIED ) { if( atgcfreq > 0.75 ) @@ -2020,16 +2254,59 @@ void getnumlen_nogap_outallreg( FILE *fp, int *nlenminpt ) } } +static void escapehtml( char *res, char *ori, int maxlen ) +{ + char *res0 = res; + while( *ori ) + { + if( *ori == '<' ) + { + strcpy( res, "<" ); + res += 3; + } + else if( *ori == '>' ) + { + strcpy( res, ">" ); + res += 3; + } + else if( *ori == '&' ) + { + strcpy( res, "&" ); + res += 4; + } + else if( *ori == '"' ) + { + strcpy( res, """ ); + res += 5; + } + else if( *ori == ' ' ) + { + strcpy( res, " " ); + res += 5; + } + else + { + *res = *ori; + } + res++; + ori++; + + if( res - res0 -10 > N ) break; + } + *res = 0; +} + void getnumlen_nogap_outallreg_web( FILE *fp, FILE *ofp, int *nlenminpt, int *isalignedpt ) { int total; int nsite = 0; int atgcnum; int alnlen = 0, alnlen_prev; - int i, tmp; - char *tmpseq, *tmpname; + int i, tmp, lennormalchar; + char *tmpseq, *tmpname, *tmpname2; double atgcfreq; tmpname = AllocateCharVec( N ); + tmpname2 = AllocateCharVec( N ); njob = countKUorWA( fp ); searchKUorWA( fp ); nlenmax = 0; @@ -2041,7 +2318,11 @@ void getnumlen_nogap_outallreg_web( FILE *fp, FILE *ofp, int *nlenminpt, int *is for( i=0; i0 && alnlen_prev != alnlen ) *isalignedpt = 0; alnlen_prev = alnlen; - free( tmpseq ); atgcfreq = (double)atgcnum / total; // fprintf( stderr, "##### atgcfreq = %f\n", atgcfreq ); // if( dorp == NOTSPECIFIED ) // you kentou @@ -2072,34 +2352,36 @@ void getnumlen_nogap_outallreg_web( FILE *fp, FILE *ofp, int *nlenminpt, int *is } } + if( dorp == 'd' ) lennormalchar = countnormalletters( tmpseq, "atgcuATGCU" ); + else lennormalchar = countnormalletters( tmpseq, "ARNDCQEGHILKMFPSTWYVarndcqeghilkmfpstwyv" ); + free( tmpseq ); - - - fprintf( ofp, " \n", i, i, i, tmpname ); + fprintf( ofp, " \n", i, i, i, i, i, lennormalchar, tmpname2 ); fprintf( ofp, "" ); fprintf( ofp, "" ); fprintf( ofp, "" ); fprintf( ofp, "" ); fprintf( ofp, "" ); } free( tmpname ); + free( tmpname2 ); atgcfreq = (double)atgcnum / total; fprintf( stderr, "##### atgcfreq = %f\n", atgcfreq ); // if( dorp == NOTSPECIFIED ) // you kentou @@ -2115,9 +2397,9 @@ void getnumlen_nogap_outallreg_web( FILE *fp, FILE *ofp, int *nlenminpt, int *is upperCase = 0; } } + fprintf( ofp, "\n" ); if( *isalignedpt ) { - fprintf( ofp, "\n" ); fprintf( ofp, "