<commit_before>//		xiNET cross-link viewer
//		Copyright 2013 Rappsilber Laboratory
//
//		author: <NAME>
//		
//		Match.js

// TODO: for historical reasons the order of the parameters 
// to this function is not that logical - should reorder them.
function Match(pep1_protIDs, pep1_positions, pep2_protIDs, pep2_positions,
        id, score, xlvController, linkPos1, linkPos2, 
        //the following attributes are optional (also pep1_positions, pep2_positions and score in preceeding)
         pepSeq1, pepSeq2, autovalidated, validated, rejected, dataSetId){
	
	this.id = id.toString().trim();
  	this.residueLinks = new Array();//if the match is ambiguous it will relate to many residueLinks
    this.xlv = xlvController;//reference to controlling xiNET.Controller object 
    
    //for comparison of different data sets (for mathieu)
  	this.dataSetId = dataSetId;
  	
  	//sanitise the inputs  
    //http://stackoverflow.com/questions/5515310/is-there-a-standard-function-to-check-for-null-undefined-or-blank-variables-in
    
    //score - leaves this.score undefined if !isNaN(parseInt(score)) 
    if (typeof score != 'undefined' && score){
		score = parseFloat(score);
		if (!isNaN(score)){
			this.score = score;
			if (this.xlv.scores == null){
					this.xlv.scores = {
						'min':this.score,
						'max':this.score
					};
			}
			if (this.score > this.xlv.scores.max) {
				this.xlv.scores.max = this.score;
			}
			else if (this.score < this.xlv.scores.min) {
				this.xlv.scores.min = this.score;
			}
		}
	}
	
	//autovalidated - an attribute used internally by Rappsilber Lab, 
	// but, hey, its another attribute you can filter on if you want  
	if (typeof autovalidated != 'undefined' && autovalidated){
		autovalidated = autovalidated.trim();
		if (autovalidated !== ''){
			if (autovalidated == "t" || autovalidated == "true" || autovalidated === true){
				this.autovalidated = true;
			} else {
				this.autovalidated = false;
			}		
			this.xlv.autoValidatedFound = true;
		}
    }
    
    // used in Rappsilber Lab to record manual validation status
    if (typeof validated != 'undefined' && validated){
		validated = validated.trim();
		if (validated !== ''){
			this.validated = validated;	
			this.xlv.manualValidatedFound = true;
		}
	}
	
	//protein IDs
	pep1_protIDs = sanitiseProteinIDs(pep1_protIDs);
	pep2_protIDs = sanitiseProteinIDs(pep2_protIDs);

	//tidy up IDs, leaves protIDs null if empty, 'n/a' or '-'
	// forbidden characters are ,;'"
	var eliminateQuotes = /(['"])/g;
	var split = /[;,]/;
	function sanitiseProteinIDs(protIDs){
		if (protIDs){
			protIDs = protIDs.toString().trim();
			if (protIDs !== '' && protIDs !== '-' && protIDs !== 'n/a'){
				// eliminate all forms of quotation mark
				// - sooner or later their going to screw up javascript, prob whilst trying to generate>parse JSON
				protIDs = protIDs.replace(eliminateQuotes, '');
				protIDs = protIDs.split(split);			
				var protIDCount = protIDs.length
				for (var p2 = 0; p2 < protIDCount; p2++ ){
					protIDs[p2] = protIDs[p2].trim();
				}		
			}
			else {
				protIDs = null;
			}
		}
		else {
			protIDs = null;
		}		
		return protIDs;
	}

	if (typeof pepSeq1 != 'undefined' && pepSeq1 != null){
		pepSeq1 = pepSeq1.trim();
		if (pepSeq1){
			this.pepSeq1 = pepSeq1.replace(/[^A-Z]/g, '');	
		}
		else{
			this.pepSeq1 = null;
		}	
	}
	else {
		this.pepSeq1 = null;
	}

	if (typeof pepSeq2 !== 'undefined' && pepSeq2 != null){
		pepSeq2 = pepSeq2.trim();
		if (pepSeq2){
			this.pepSeq2 = pepSeq2.replace(/[^A-Z]/g, '');
		} else {
			this.pepSeq2 = null;
		}
	}
	else {
		this.pepSeq2 = null;
	}
	
	pep1_positions = sanitisePositions(pep1_positions);
	pep2_positions = sanitisePositions(pep2_positions);
	linkPos1 = sanitisePositions(linkPos1);
	linkPos2 = sanitisePositions(linkPos2);
	
	// tidy up postions (peptide and link positions), 
	// leaves positions null if empty, 'n/a' or '-'
	// forbidden characters are ,;'"
	function sanitisePositions(positions){
		if (positions){
			positions = positions.toString().trim();
			if (positions !== '' && positions !== '-' && positions !== 'n/a'){
				// eliminate all forms of quotation mark 
				positions = positions.toString().replace(eliminateQuotes, '');
				//; or , as seperator
				positions = positions.split(split);	
				var posCount = positions.length;
				for (var i2 = 0; i2 < posCount; i2++ ){
					var pos = parseInt(positions[i2]);
					if (isNaN(pos)) {
						console.debug('Absurd non-numerical position. Match id:' <commit_msg>bugs in Match.js re resetting Regex<commit_after>//		xiNET cross-link viewer
//		Copyright 2013 Rappsilber Laboratory
//
//		author: <NAME>
//		
//		Match.js

// TODO: for historical reasons the order of the parameters 
// to this function is not that logical - should reorder them.
function Match(pep1_protIDs, pep1_positions, pep2_protIDs, pep2_positions,
        id, score, xlvController, linkPos1, linkPos2, 
        //the following attributes are optional (also pep1_positions, pep2_positions and score in preceeding)
         pepSeq1, pepSeq2, autovalidated, validated, rejected, dataSetId){
	
	this.id = id.toString().trim();
  	this.residueLinks = new Array();//if the match is ambiguous it will relate to many residueLinks
    this.xlv = xlvController;//reference to controlling xiNET.Controller object 
    
    //for comparison of different data sets (for mathieu)
  	this.dataSetId = dataSetId;
  	
  	//sanitise the inputs  
    //http://stackoverflow.com/questions/5515310/is-there-a-standard-function-to-check-for-null-undefined-or-blank-variables-in
    
    //score - leaves this.score undefined if !isNaN(parseInt(score)) 
    if (typeof score != 'undefined' && score){
		score = parseFloat(score);
		if (!isNaN(score)){
			this.score = score;
			if (this.xlv.scores == null){
					this.xlv.scores = {
						'min':this.score,
						'max':this.score
					};
			}
			if (this.score > this.xlv.scores.max) {
				this.xlv.scores.max = this.score;
			}
			else if (this.score < this.xlv.scores.min) {
				this.xlv.scores.min = this.score;
			}
		}
	}
	
	//autovalidated - an attribute used internally by Rappsilber Lab, 
	// but, hey, its another attribute you can filter on if you want  
	if (typeof autovalidated != 'undefined' && autovalidated){
		autovalidated = autovalidated.trim();
		if (autovalidated !== ''){
			if (autovalidated == "t" || autovalidated == "true" || autovalidated === true){
				this.autovalidated = true;
			} else {
				this.autovalidated = false;
			}		
			this.xlv.autoValidatedFound = true;
		}
    }
    
    // used in Rappsilber Lab to record manual validation status
    if (typeof validated != 'undefined' && validated){
		validated = validated.trim();
		if (validated !== ''){
			this.validated = validated;	
			this.xlv.manualValidatedFound = true;
		}
	}
		
	//tidy up IDs, leaves protIDs null if empty, 'n/a' or '-'
	// forbidden characters are ,;'"
	var eliminateQuotes = /(['"])/g;
	var split = /[;,]/g;
	var capitalsOnly = /[^A-Z]/g;
	function sanitiseProteinIDs(protIDs){
		if (protIDs){
			protIDs = protIDs.toString().trim();
			if (protIDs !== '' && protIDs !== '-' && protIDs !== 'n/a'){
				// eliminate all forms of quotation mark
				// - sooner or later they're going to screw up javascript, prob whilst trying to generate>parse JSON
				eliminateQuotes.lastIndex = 0;
				protIDs = protIDs.replace(eliminateQuotes, '');
				split.lastIndex = 0;
				protIDs = protIDs.split(split);			
				var protIDCount = protIDs.length
				for (var p2 = 0; p2 < protIDCount; p2++ ){
					protIDs[p2] = protIDs[p2].trim();
				}		
			}
			else {
				protIDs = null;
			}
		}
		else {
			protIDs = null;
		}		
		return protIDs;
	}

	//protein IDs
	pep1_protIDs = sanitiseProteinIDs(pep1_protIDs);
	pep2_protIDs = sanitiseProteinIDs(pep2_protIDs);


	if (typeof pepSeq1 != 'undefined' && pepSeq1 != null){
		pepSeq1 = pepSeq1.trim();
		if (pepSeq1){
			capitalsOnly.lastindex = 0;
			this.pepSeq1 = pepSeq1.replace(capitalsOnly, '');	
		}
		else{
			this.pepSeq1 = null;
		}	
	}
	else {
		this.pepSeq1 = null;
	}

	if (typeof pepSeq2 !== 'undefined' && pepSeq2 != null){
		pepSeq2 = pepSeq2.trim();
		if (pepSeq2){
			capitalsOnly.lastindex = 0;
			this.pepSeq2 = pepSeq2.replace(capitalsOnly, '');
		} else {
			this.pepSeq2 = null;
		}
	}
	else {
		this.pepSeq2 = null;
	}
	
	pep1_positions = sanitisePositions(pep1_positions);
	pep2_positions = sanitisePositions(pep2_positions);
	linkPos1 = sanitisePositions(linkPos1);
	linkPos2 = sanitisePositions(linkPos2);
	
	// tidy up postions (peptide and link positions), 
	// leaves positions null if empty, 'n/a' or '-'
	// forbidden characters are ,;'"
	function sanitisePositions(positions){
		if (positions){
			positions = positions.toString().trim();
			if (positions !== '' && positions !== '-' && positions !== 'n/a'){
				// eliminate all forms of quotation mark 
				eliminateQuotes.lastIndex = 0;
				positions = positions.toString().replace(eliminateQuotes, '');
				//; or , as seperator
				split.lastIndex = 0;
				positions = positions.split(split);	
				var posCount = positions.length;
				for (var i2 = 0; i2 < posCount; i2++ ){
					var pos = parseInt(positions[i2]);
					if (isNaN(pos)) {
						console.debug('Absurd non-numerical position. Match id:' 
{'fraction_non_alphanumeric': 0.13904433921653034, 'fraction_numerical': 0.013990529487731381, 'mean_word_length': 3.1210643015521065, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, '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': '5065427', 'n_tokens_mistral': 3741, 'n_tokens_neox': 3200, 'n_words': 775}