<commit_before>﻿<!DOCTYPE html>
<html lang="en">
<head>
	<title>MoDMaps3D - Three Dimensional Molecular Distance Maps</title>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
	<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
	<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
	<script type="text/javascript" src="js/numeric-1.2.6.min.js"></script>
	
	<script>
	var dbg = false, errorHasOccured = false, noMDS = false;
	var eigenval, eigenvec, eigensystem, finalEigenval, finalEigenvec, points ;
	var mapID, allSequences={}, distMatrix=[], fcgrRes=9, getTaxa = false;
	var accIDs, step1A, step1B, step2A, step2B, step3A, step3B, time;
	var callsNCBIDone, progress;
	var labelColors = ['blue', 'red', 'green', 'orange', 'magenta', 'yellow', 'brown', 'lime', 'gray', 'pink','cyan','seagreen', 'yellow'];
	
	function geturlparamvalue(name) {
		name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
		var regexS = "[\\?&]" + name + "=([^&#]*)";
		var regex = new RegExp(regexS);
		var results = regex.exec(window.location.href);
		if(results!=null){
			return results[1];
		}else{
			return -1;
		}
	}

	function computeMDS(){
		time = new Date();
		step3A = time.getTime();
		console.log("BEGIN computeMDS()");	
		
		// pre-processign MDS

		// part 1
		var numOfSeq = distMatrix.length;
		var distMatrixSqTotals = [];
		for(var i=0; i<numOfSeq; i++){
			var tmpColSum = 0;
			for(var j=0; j<numOfSeq; j++){
				tmpColSum += Math.pow(distMatrix[i][j], 2);
			}
			distMatrixSqTotals.push(tmpColSum);
		}
		if(dbg){console.log('sqtotals=',distMatrixSqTotals);}
		
		// part 2
		var sumOfSqTotals = 0;
		for(var i=0; i<numOfSeq; i++){
			sumOfSqTotals += distMatrixSqTotals[i];
		}
		if(dbg){console.log('sumofsqtotals=',sumOfSqTotals);}
		
		// part 3
		var distMatrixCentered = [];
		for(var i=0; i<numOfSeq; i++){
			distMatrixCentered.push([]);
			for(var j=0; j<numOfSeq; j++){
				var tmpVal = -(1/2)*(Math.pow(distMatrix[i][j], 2) - (1/numOfSeq)*distMatrixSqTotals[i] - (1/numOfSeq)*distMatrixSqTotals[j] + (1/(Math.pow(numOfSeq, 2)))* sumOfSqTotals);
				distMatrixCentered[i].push(tmpVal);
			}
		}
		
		//DEBUGING FOR PRINTING dMatrix
		if(noMDS){
			if(dbg){console.log(distMatrixCentered);}
			var toprint="{";
			for(var i=0; i<distMatrixCentered.length; i++){
				toprint+='{';
				for (var j=0; j<distMatrixCentered.length; j++){
					toprint+=distMatrixCentered[i][j]+',';
				}
				toprint = toprint.substring(0, toprint.length - 1);
				toprint+='},'
			}
			toprint = toprint.substring(0, toprint.length - 1);
			toprint+='}';
			console.log('COPY/PASTE MATHEMATICA');
			console.log("Eigensystem[",toprint,"]");
			$('#ncbiprogress').html('noMDS == true. Please take a look at the console..');
			return;
		}
		

		// EIGENVALUES - EIGENVECTORS
		try{
			res2 = numeric.eig(distMatrixCentered);	
		}catch(err){
			console.log(err.message);
			errorHasOccured = true;
			$('#ncbiprogress').html('<div class="alert alert-danger" role="alert"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span><span class="sr-only">Error:</span>'+' ERROR [<strong>'+err.message+'</strong>] while computing MDS. Internal errors originate from numerical errors in distance matrices. Consider changing/increasing value of length of k-mers.</div>');<commit_msg>fix nomds<commit_after>﻿<!DOCTYPE html>
<html lang="en">
<head>
	<title>MoDMaps3D - Three Dimensional Molecular Distance Maps</title>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
	<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
	<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
	<script type="text/javascript" src="js/numeric-1.2.6.min.js"></script>
	
	<script>
	var dbg = false, errorHasOccured = false, noMDS = false;
	var eigenval, eigenvec, eigensystem, finalEigenval, finalEigenvec, points ;
	var mapID, allSequences={}, distMatrix=[], fcgrRes=9, getTaxa = false;
	var accIDs, step1A, step1B, step2A, step2B, step3A, step3B, time;
	var callsNCBIDone, progress;
	var labelColors = ['blue', 'red', 'green', 'orange', 'magenta', 'yellow', 'brown', 'lime', 'gray', 'pink','cyan','seagreen', 'yellow'];
	
	function geturlparamvalue(name) {
		name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
		var regexS = "[\\?&]" + name + "=([^&#]*)";
		var regex = new RegExp(regexS);
		var results = regex.exec(window.location.href);
		if(results!=null){
			return results[1];
		}else{
			return -1;
		}
	}

	function computeMDS(){
		time = new Date();
		step3A = time.getTime();
		console.log("BEGIN computeMDS()");	
		
		// pre-processign MDS

		// part 1
		var numOfSeq = distMatrix.length;
		var distMatrixSqTotals = [];
		for(var i=0; i<numOfSeq; i++){
			var tmpColSum = 0;
			for(var j=0; j<numOfSeq; j++){
				tmpColSum += Math.pow(distMatrix[i][j], 2);
			}
			distMatrixSqTotals.push(tmpColSum);
		}
		if(dbg){console.log('sqtotals=',distMatrixSqTotals);}
		
		// part 2
		var sumOfSqTotals = 0;
		for(var i=0; i<numOfSeq; i++){
			sumOfSqTotals += distMatrixSqTotals[i];
		}
		if(dbg){console.log('sumofsqtotals=',sumOfSqTotals);}
		
		// part 3
		var distMatrixCentered = [];
		for(var i=0; i<numOfSeq; i++){
			distMatrixCentered.push([]);
			for(var j=0; j<numOfSeq; j++){
				var tmpVal = -(1/2)*(Math.pow(distMatrix[i][j], 2) - (1/numOfSeq)*distMatrixSqTotals[i] - (1/numOfSeq)*distMatrixSqTotals[j] + (1/(Math.pow(numOfSeq, 2)))* sumOfSqTotals);
				distMatrixCentered[i].push(tmpVal);
			}
		}
		
		//DEBUGING FOR PRINTING dMatrix
		if(noMDS){
			if(dbg){console.log(distMatrixCentered);}
			var toprint="{";
			for(var i=0; i<distMatrixCentered.length; i++){
				toprint+='{';
				for (var j=0; j<distMatrixCentered.length; j++){
					toprint+=distMatrixCentered[i][j]+',';
				}
				toprint = toprint.substring(0, toprint.length - 1);
				toprint+='},'
			}
			toprint = toprint.substring(0, toprint.length - 1);
			toprint+='}';
			console.log('COPY/PASTE MATHEMATICA');
			//console.log("Eigensystem[",toprint,"]");
			$('#ncbiprogress').html('noMDS == true. Please take a look at the console..');
			// 
			toprint2='accIDs={';
			for(var i=0; i<accIDsSets.length; i++){
				toprint2 += '{';
				for(var j=0; j<accIDsSets[i].length; j++){
					toprint2 += '"'+accIDsSets[i][j]+'",'
				}
				toprint2 = toprint2.substring(0, toprint2.length - 1);
				toprint2 +='},'
			}
			toprint2 = toprint2.substring(0, toprint2.length - 1);
			toprint2 +='};';
			console.log("eig=Eigensystem["+toprint+"];"+toprint2);
			//

			return;
		}
		

		// EIGENVALUES - EIGENVECTORS
		try{
			res2 = numeric.eig(distMatrixCentered);	
		}catch(err){
			console.log(err.message);
			errorHasOccured = true;
			$('#ncbiprogress').html('<div class="alert alert-danger" role="alert"><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span><span class="sr-only">Error:</span>'+' ERROR [<strong>'+err.message+'</strong>] while computing MDS. Internal errors originate from numerical errors in distance matrices. Consider changing/increasing value of length of k-mers.</div>');
{'fraction_non_alphanumeric': 0.19851551956815114, 'fraction_numerical': 0.016194331983805668, 'mean_word_length': 4.270981507823613, 'pattern_counts': {'":': 0, '<': 65, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1136045', 'n_tokens_mistral': 3223, 'n_tokens_neox': 2804, 'n_words': 511}