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

com.hfg.bio.DigestFragment Maven / Gradle / Ivy

There is a newer version: 20240423
Show newest version
package com.hfg.bio;

import java.util.ArrayList;
import java.util.List;

import com.hfg.bio.seq.Protein;
import com.hfg.bio.seq.SeqLocation;
import com.hfg.util.StringBuilderPlus;
import com.hfg.util.collection.CollectionUtil;
import com.hfg.util.StringUtil;

//------------------------------------------------------------------------------
/**
 * Product of a proteolytic digest.
 *
 * @author J. Alex Taylor, hairyfatguy.com
 */
//------------------------------------------------------------------------------
// com.hfg XML/HTML Coding Library
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
// [email protected]
//------------------------------------------------------------------------------

public class DigestFragment extends Protein
{
   private String      mSrcChainId;
   private int    mBegin;
   private int    mEnd;
   private int    mNumUncleavedSites;
   private int    mBeginFragIndex;
   private int    mEndFragIndex;
   private Character mPrecedingResidue;
   private Character mTrailingResidue;

   private List mIdenticalFrags;

   //Cached
   private SeqLocation mSeqLocation;

   //---------------------------------------------------------------------------
   public DigestFragment clone()
   {
      DigestFragment clone = (DigestFragment) super.clone();

      if (CollectionUtil.hasValues(mIdenticalFrags))
      {
         clone.mIdenticalFrags = new ArrayList<>(mIdenticalFrags.size());
         for (DigestFragment identicalFrag : mIdenticalFrags)
         {
            clone.mIdenticalFrags.add(identicalFrag.clone());
         }
      }

      return clone;
   }

   //---------------------------------------------------------------------------
   public DigestFragment setSrcChainId(String inValue)
   {
      mSrcChainId = inValue;
      return this;
   }

   //---------------------------------------------------------------------------
   public String getSrcChainId()
   {
      return mSrcChainId;
   }


   //---------------------------------------------------------------------------
   public void setBegin(int inValue)
   {
      mBegin = inValue;
      mSeqLocation =  null;
   }

   //---------------------------------------------------------------------------
   public int getBegin()
   {
      return mBegin;
   }

   //---------------------------------------------------------------------------
   public void setEnd(int inValue)
   {
      mEnd = inValue;
      mSeqLocation =  null;
   }

   //---------------------------------------------------------------------------
   public int getEnd()
   {
      return mEnd;
   }

   //---------------------------------------------------------------------------
   public SeqLocation getSeqLocation()
   {
      if (null == mSeqLocation)
      {
         mSeqLocation = new SeqLocation(getBegin(), getEnd());
      }

      return mSeqLocation;
   }


   //---------------------------------------------------------------------------
   public void setPrecedingResidue(Character inValue)
   {
      mPrecedingResidue = inValue;
   }

   //---------------------------------------------------------------------------
   public Character getPrecedingResidue()
   {
      return mPrecedingResidue;
   }


   //---------------------------------------------------------------------------
   public void setTrailingResidue(Character inValue)
   {
      mTrailingResidue = inValue;
   }

   //---------------------------------------------------------------------------
   public Character getTrailingResidue()
   {
      return mTrailingResidue;
   }


   //---------------------------------------------------------------------------
   public void setNumUncleavedSites(int inValue)
   {
      mNumUncleavedSites = inValue;
   }

   //---------------------------------------------------------------------------
   public int getNumUncleavedSites()
   {
      return mNumUncleavedSites;
   }

   //---------------------------------------------------------------------------
   public void setBeginFragIndex(int inValue)
   {
      mBeginFragIndex = inValue;
   }

   //---------------------------------------------------------------------------
   public int getBeginFragIndex()
   {
      return mBeginFragIndex;
   }

   //---------------------------------------------------------------------------
   public void setEndFragIndex(int inValue)
   {
      mEndFragIndex = inValue;
   }

   //---------------------------------------------------------------------------
   public int getEndFragIndex()
   {
      return mEndFragIndex;
   }

   //---------------------------------------------------------------------------
   public String getFragIndexString()
   {
      return mBeginFragIndex + (mEndFragIndex != mBeginFragIndex ? ".." + mEndFragIndex : "");
   }

   //---------------------------------------------------------------------------
   public void addIdenticalFragment(DigestFragment inValue)
   {
      if (null == mIdenticalFrags)
      {
         mIdenticalFrags = new ArrayList<>(3);
      }

      mIdenticalFrags.add(inValue);
   }

   //---------------------------------------------------------------------------
   public List getIdenticalFragments()
   {
      return mIdenticalFrags;
   }

   //---------------------------------------------------------------------------
   @Override
   public String toString()
   {
      StringBuilder buffer = new StringBuilder();

      if (CollectionUtil.hasValues(getChains()))
      {
         for (DigestFragment chain : (List) (Object) getChains())
         {
            if (StringUtil.isSet(chain.getSrcChainId()))
            {
               buffer.append(chain.getSrcChainId());
               buffer.append(" ");
            }
            else if (StringUtil.isSet(chain.getID()))
            {
               buffer.append(chain.getID());
               buffer.append(" ");
            }
            buffer.append("#" + chain.getFragIndexString());
            buffer.append("\t");
            buffer.append(chain.getBegin());
            buffer.append(" - ");
            buffer.append(chain.getEnd());
            buffer.append("\t");
            buffer.append(chain.getSequence());
            buffer.append("\n    ");
         }
         buffer.append(getXLinks());
      }
      else
      {
         if (StringUtil.isSet(getID()))
         {
            buffer.append(getID());
            buffer.append(" ");
         }

         buffer.append(getFragIndexString());
         if (CollectionUtil.hasValues(mIdenticalFrags))
         {
            buffer.append("[");
            StringBuilderPlus fragNumBuffer = new StringBuilderPlus().setDelimiter(",");
            for (DigestFragment identicalFrag : mIdenticalFrags)
            {
               if (identicalFrag.getID().equals(getID()))
               {
                  // Just show the fragment index
                  fragNumBuffer.delimitedAppend(identicalFrag.getFragIndexString());
               }
               else
               {
                  // Show the chain name and fragment index
                  fragNumBuffer.delimitedAppend(identicalFrag.getID() + " " + identicalFrag.getFragIndexString());
               }
            }
            buffer.append(fragNumBuffer);
            buffer.append("]");
         }

         buffer.append("\t");

         buffer.append(getBegin());
         buffer.append(" - ");
         buffer.append(getEnd());

         if (CollectionUtil.hasValues(mIdenticalFrags))
         {
            buffer.append("[");
            StringBuilderPlus fragNumBuffer = new StringBuilderPlus().setDelimiter(",");
            for (DigestFragment identicalFrag : mIdenticalFrags)
            {
               fragNumBuffer.delimitedAppend(identicalFrag.getBegin() + " - " + identicalFrag.getEnd());
            }
            buffer.append(fragNumBuffer);
            buffer.append("]");
         }

         buffer.append("\t");
         buffer.append(getSequence());
      }

      return buffer.toString();
   }
}
































































© 2015 - 2024 Weber Informatics LLC | Privacy Policy