All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.biojava.nbio.aaproperties.xml.ModifiedAminoAcidCompoundSet Maven / Gradle / Ivy

There is a newer version: 7.1.3
Show newest version
/*
 *                    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/
 *
 */
package org.biojava.nbio.aaproperties.xml;

import org.biojava.nbio.core.sequence.compound.AminoAcidCompound;
import org.biojava.nbio.core.sequence.template.CompoundSet;
import org.biojava.nbio.core.sequence.template.Sequence;

import java.util.*;

public class ModifiedAminoAcidCompoundSet implements CompoundSet {

	private final Map aminoAcidCompoundCache = new HashMap();

	public ModifiedAminoAcidCompoundSet(List aaList, Map aaSymbol2MolecularWeight) {
		this.aminoAcidCompoundCache.put("-", new AminoAcidCompound(null, "-", "", "", 0.0f));
		for (AminoAcidComposition aa : aaList) {
			this.aminoAcidCompoundCache.put(aa.getSymbol(),
					new AminoAcidCompound(null, aa.getSymbol(), aa.getShorName(), aa.getName(),
							aaSymbol2MolecularWeight.get(aa.getSymbol().charAt(0)).floatValue()));
		}
	}

	@Override
	public int getMaxSingleCompoundStringLength() {
		return 1;
	}

	@Override
	public boolean isCompoundStringLengthEqual() {
		return true;
	}

	@Override
	public AminoAcidCompound getCompoundForString(String string) {
		if (string.length() == 0) {
			return null;
		}
		if (string.length() > this.getMaxSingleCompoundStringLength()) {
			throw new IllegalArgumentException("String supplied (" + string + ") is too long. Max is " + getMaxSingleCompoundStringLength());
		}
		return this.aminoAcidCompoundCache.get(string);
	}

	@Override
	public String getStringForCompound(AminoAcidCompound compound) {
		return compound.toString();
	}

	@Override
	public boolean compoundsEquivalent(AminoAcidCompound compoundOne, AminoAcidCompound compoundTwo) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public Set getEquivalentCompounds(AminoAcidCompound compound) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean hasCompound(AminoAcidCompound compound) {
		return aminoAcidCompoundCache.containsValue(compound);
	}

	@Override
	public List getAllCompounds() {
		return new ArrayList(aminoAcidCompoundCache.values());
	}

	@Override
	public boolean isComplementable() {
		return false;
	}

	@Override
	public boolean isValidSequence(Sequence sequence) {
		for (AminoAcidCompound c : sequence) {
			if (!hasCompound(c)) {
				return false;
			}
		}
		return true;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy