001/* 002 * BioJava development code 003 * 004 * This code may be freely distributed and modified under the 005 * terms of the GNU Lesser General Public Licence. This should 006 * be distributed with the code. If you do not have a copy, 007 * see: 008 * 009 * http://www.gnu.org/copyleft/lesser.html 010 * 011 * Copyright for this code is held jointly by the individual 012 * authors. These should be listed in @author doc comments. 013 * 014 * For more information on the BioJava project and its aims, 015 * or to join the biojava-l mailing list, visit the home page 016 * at: 017 * 018 * http://www.biojava.org/ 019 * 020 */ 021package org.biojava.nbio.structure; 022 023import java.io.IOException; 024import java.util.ArrayList; 025import java.util.regex.Matcher; 026import java.util.regex.Pattern; 027 028import org.biojava.nbio.structure.align.util.AtomCache; 029 030public class BioAssemblyIdentifier implements StructureIdentifier { 031 private String pdbCode; 032 private int biolNr; 033 034 public static final Pattern BIO_NAME_PATTERN = Pattern.compile("^(?:BIO:)([0-9][a-z0-9]{3})(?::([0-9]+))?$", Pattern.CASE_INSENSITIVE); 035 036 public BioAssemblyIdentifier(String name) { 037 Matcher match = BIO_NAME_PATTERN.matcher(name); 038 if(! match.matches() ) { 039 throw new IllegalArgumentException("Invalid BIO identifier"); 040 } 041 pdbCode = match.group(1); 042 if(match.group(2) != null) { 043 biolNr = Integer.parseInt(match.group(2)); 044 } else { 045 biolNr = 1; 046 } 047 } 048 049 public BioAssemblyIdentifier(String pdbCode, int biolNr) { 050 this.pdbCode = pdbCode; 051 this.biolNr = biolNr; 052 } 053 054 @Override 055 public String getIdentifier() { 056 if( biolNr < 0) { 057 return "BIO:"+pdbCode; 058 } else { 059 return String.format("BIO:%s:%d",pdbCode,biolNr); 060 } 061 } 062 @Override 063 public String toString() { 064 return getIdentifier(); 065 } 066 067 @Override 068 public Structure loadStructure(AtomCache cache) throws StructureException, 069 IOException { 070 return cache.getBiologicalAssembly(pdbCode, biolNr); 071 } 072 073 @Override 074 public SubstructureIdentifier toCanonical() throws StructureException { 075 return new SubstructureIdentifier(pdbCode, new ArrayList<ResidueRange>()); 076 } 077 078 @Override 079 public Structure reduce(Structure input) throws StructureException { 080 // Should be the full structure 081 return input; 082 } 083 084}