<commit_before>/*
 *                    BioJava development code
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  If you do not have a copy,
 * see:
 *
 *      http://www.gnu.org/copyleft/lesser.html
 *
 * Copyright for this code is held jointly by the individual
 * authors.  These should be listed in @author doc comments.
 *
 * For more information on the BioJava project and its aims,
 * or to join the biojava-l mailing list, visit the home page
 * at:
 *
 *      http://www.biojava.org/
 *
 * Created on Feb 15, 2010
 * Author: <NAME> 
 *
 */

package org.biojava.bio.structure.align.model;

import java.io.StringWriter;
import java.util.List;

import org.biojava.bio.structure.Atom;
import org.biojava.bio.structure.Chain;
import org.biojava.bio.structure.Group;
import org.biojava.bio.structure.ResidueNumber;
import org.biojava.bio.structure.StructureTools;

import org.biojava.bio.structure.align.ce.CeMain;
import org.biojava.bio.structure.align.ce.CeSideChainMain;
import org.biojava.bio.structure.align.fatcat.FatCatFlexible;
import org.biojava.bio.structure.align.seq.SmithWaterman3Daligner;
import org.biojava.bio.structure.align.util.AFPAlignmentDisplay;
import org.biojava.bio.structure.jama.Matrix;

/** A class to convert the data in an AfpChain object to various String outputs.
 *  
 * @author <NAME>
 *
 */
public class AfpChainWriter
{

	public static final String newline = System.getProperty("line.separator");

	private static int LINELENGTH = 70;

	public static String toFatCat(AFPChain afpChain, Atom[] ca1, Atom[] ca2)
	{

		boolean printLegend = true;
		boolean longHeader  = true;
		boolean showHTML = false;
		boolean showAlignmentBlock = false;
		
		return toFatCatCore(afpChain, ca1, ca2, printLegend, longHeader, showHTML, showAlignmentBlock);   
	}

	public static String toScoresList(AFPChain afpChain){

		// see sippl On distance and similarity in fold space 2008 bioinformatics

		StringWriter writer = new StringWriter();

		if ( afpChain.getAlgorithmName().startsWith("CE")) {
			writer.append("Z-score " );
			writer.append(String.format("%.2f", afpChain.getProbability()));
			writer.append(newline);
		}


		writer.append("Sab (nr. equivalent residues): " );
		writer.append(afpChain.getNrEQR()+"");
		writer.append(newline);

		writer.append("Dab (distance between folds a,b): ");
		int dab = afpChain.getCa1Length()+afpChain.getCa2Length() - 2 * afpChain.getNrEQR();
		writer.append(dab+"");
		writer.append(newline);

		writer.append("sab (relative similarity): ");
		double sab = 2 * afpChain.getNrEQR() / (double)( afpChain.getCa1Length() + afpChain.getCa2Length());
		writer.append(sab+"");
		writer.append(newline);

		writer.append("cab (coverage a): ");
		double cab = afpChain.getNrEQR() / (double) afpChain.getCa1Length();
		writer.append(cab+"");
		writer.append(newline);

		writer.append("cba (coverage b): ");
		double cba = afpChain.getNrEQR() / (double) afpChain.getCa2Length();
		writer.append(cba+"");
		writer.append(newline);

		writer.append("seq similarity: ");
		writer.append(afpChain.getSimilarity()+"");
		writer.append(newline);

		writer.append("TM-score: ");
		writer.append(afpChain.getTMScore()+"");
		writer.append(newline);

		return writer.toString();
	}

	public static String toFatCatCore(
			AFPChain afpChain, 
			Atom[] ca1, 
			Atom[] ca2, 
			boolean printLegend, boolean longHeader, boolean showHTML, boolean showAlignmentBlock){

		if(!afpChain.isSequentialAlignment()) {
			//TODO find some topology-independent output format
			return "Can't display circular permutations";
		}

		String name1 = afpChain.getName1();
		String name2 = afpChain.getName2();
		int ca1Length = afpChain.getCa1Length();
		int ca2Length = afpChain.getCa2Length();

		int blockNum = afpChain.getBlockNum();<commit_msg>Allow CECP results to display in FatCatCore format, dispite the format being unable to display CP residue numbers correctly.<commit_after>/*
 *                    BioJava development code
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  If you do not have a copy,
 * see:
 *
 *      http://www.gnu.org/copyleft/lesser.html
 *
 * Copyright for this code is held jointly by the individual
 * authors.  These should be listed in @author doc comments.
 *
 * For more information on the BioJava project and its aims,
 * or to join the biojava-l mailing list, visit the home page
 * at:
 *
 *      http://www.biojava.org/
 *
 * Created on Feb 15, 2010
 * Author: <NAME> 
 *
 */

package org.biojava.bio.structure.align.model;

import java.io.StringWriter;
import java.util.List;

import org.biojava.bio.structure.Atom;
import org.biojava.bio.structure.Chain;
import org.biojava.bio.structure.Group;
import org.biojava.bio.structure.ResidueNumber;
import org.biojava.bio.structure.StructureTools;

import org.biojava.bio.structure.align.ce.CeMain;
import org.biojava.bio.structure.align.ce.CeSideChainMain;
import org.biojava.bio.structure.align.fatcat.FatCatFlexible;
import org.biojava.bio.structure.align.seq.SmithWaterman3Daligner;
import org.biojava.bio.structure.align.util.AFPAlignmentDisplay;
import org.biojava.bio.structure.jama.Matrix;

/** A class to convert the data in an AfpChain object to various String outputs.
 *  
 * @author <NAME>
 *
 */
public class AfpChainWriter
{

	public static final String newline = System.getProperty("line.separator");

	private static int LINELENGTH = 70;

	public static String toFatCat(AFPChain afpChain, Atom[] ca1, Atom[] ca2)
	{

		boolean printLegend = true;
		boolean longHeader  = true;
		boolean showHTML = false;
		boolean showAlignmentBlock = false;
		
		return toFatCatCore(afpChain, ca1, ca2, printLegend, longHeader, showHTML, showAlignmentBlock);   
	}

	public static String toScoresList(AFPChain afpChain){

		// see sippl On distance and similarity in fold space 2008 bioinformatics

		StringWriter writer = new StringWriter();

		if ( afpChain.getAlgorithmName().startsWith("CE")) {
			writer.append("Z-score " );
			writer.append(String.format("%.2f", afpChain.getProbability()));
			writer.append(newline);
		}


		writer.append("Sab (nr. equivalent residues): " );
		writer.append(afpChain.getNrEQR()+"");
		writer.append(newline);

		writer.append("Dab (distance between folds a,b): ");
		int dab = afpChain.getCa1Length()+afpChain.getCa2Length() - 2 * afpChain.getNrEQR();
		writer.append(dab+"");
		writer.append(newline);

		writer.append("sab (relative similarity): ");
		double sab = 2 * afpChain.getNrEQR() / (double)( afpChain.getCa1Length() + afpChain.getCa2Length());
		writer.append(sab+"");
		writer.append(newline);

		writer.append("cab (coverage a): ");
		double cab = afpChain.getNrEQR() / (double) afpChain.getCa1Length();
		writer.append(cab+"");
		writer.append(newline);

		writer.append("cba (coverage b): ");
		double cba = afpChain.getNrEQR() / (double) afpChain.getCa2Length();
		writer.append(cba+"");
		writer.append(newline);

		writer.append("seq similarity: ");
		writer.append(afpChain.getSimilarity()+"");
		writer.append(newline);

		writer.append("TM-score: ");
		writer.append(afpChain.getTMScore()+"");
		writer.append(newline);

		return writer.toString();
	}

	/**
	 * Output in FatCatCore format
	 * 
	 * <p>Note that if a circular permutation has occured the residue numbers may
	 * be innaccurate.
	 * 
	 * @param afpChain
	 * @param ca1
	 * @param ca2
	 * @param printLegend
	 * @param longHeader
	 * @param showHTML
	 * @param showAlignmentBlock
	 * @return
	 */
	public static String toFatCatCore(
			AFPChain afpChain, 
			Atom[] ca1, 
			Atom[] ca2, 
			boolean printLegend, boolean longHeader, boolean showHTML, boolean showAlignmentBlock){

		//TODO The sequence numbers are inaccurate if a !afpChain.isSequential()

		String name1 = afpChain.getName1();
		String name2 = afpChain.getName2();
		int ca1Length = afpChain.getCa1Length();
		int ca2Length = afpChain.getCa2Length();

		int blockNum = afpChain.getBlockNum();
{'fraction_non_alphanumeric': 0.12352652259332024, 'fraction_numerical': 0.009086444007858546, 'mean_word_length': 4.207800511508951, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '2502233', 'n_tokens_mistral': 2867, 'n_tokens_neox': 2603, 'n_words': 655}