Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
  
      ngs-feature  Features.
      Copyright (c) 2014-2015 National Marrow Donor Program (NMDP)
  
      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 3 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; with out 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.
 
     > http://www.gnu.org/licenses/lgpl.html
 
 */
 package org.nmdp.ngs.feature;
 
 
 
 
 
Allele class for extending assembly-specific genomic coordinates (Locus objects) with sequence data.
 
 public final class Allele extends Locus {
    
Name of the allele.
 
     String name;
    
Enumeration of possible lesion types.
 
     public enum Lesion {
        
Unknown or undetermined.
 
         UNKNOWN,
        
Matches the specified reference sequence at the corresponding genomic location.
 
         MATCH,
        
A single basepair mismatch with respect to the reference sequence.
 
         SUBSTITUTION,
        
One or more gaps in the sequence with respect to the reference.
 
         INSERTION,
        
One or more gaps in the reference with respect to the sequence.
 
         DELETION
     }
    
Sequence of acceptable characters (alphabet) at the corresponding genomic location.
 
     public final SymbolList sequence;
    
Lesion represented by the sequence with respect to a specified reference sequence. The reference sequence is assigned with proper Allele object instantiation using a Builder.
 
     public final Lesion lesion;
    
Construct a new allele.

Parameters:
name of the allele
contig assembly (may include information about the source reference)
start or lower genomic coordinate
end or upper genomic coordinate
sequence of the allele
lesion or named difference with respect to the reference
 
     Allele(final String namefinal String contigfinal int startfinal int endfinal SymbolList sequencefinal Lesion lesion) {
         super(contigstartend);
         this. = name;
         this. = sequence
         this. = lesion;
     }
    

Returns:
allele name
 
     public String getName() {
        return ;
    }
    

Parameters:
name assignment
    public void setName(final String name) {
        this. = name;
    }
    

Returns:
new parameterized Allele object
    public static Builder builder() {
        return new Builder();
    }
    
Builder class for Allele.
    public static final class Builder {
        private String namecontigreference;
        private int startend;
        private SymbolList sequence;
        private Lesion lesion;
        
Construct a new allele with unassigned members.
        private Builder() {
            // empty
        }
        

Parameters:
name assignment
Returns:
this builder with assigned name
        public Builder withName(final String name) {
            this. = name;
            return this;
        }
        

Parameters:
contig assignment
Returns:
this builder with assigned contig
        public Builder withContig(final String contig) {
            this. = contig;
            return this;
        }
        

Parameters:
start assignment
Returns:
this builder with assigned start
        public Builder withStart(final int start) {
            this. = start;
            return this;
        }
        

Parameters:
end assignment
Returns:
this builder with assigned end
        public Builder withEnd(final int end) {
            this. = end;
            return this;
        }
        

Parameters:
sequence assignment
Returns:
this builder with assigned sequence
        public Builder withSequence(final SymbolList sequence) {
            this. = sequence;
            return this;
        }
        

Parameters:
lesion assignment
Returns:
this builder with assigned lesion
        public Builder withLesion(final Lesion lesion) {
            this. = lesion;
            return this;
        }
        

Parameters:
reference assignment (a URI is nice, but not strictly enforced)
Returns:
this builder with assigned reference
        public Builder withReference(final String reference) {
            this. = reference;
            return this;
        }
        

Returns:
reference identifier
        public String getReference() {
            return ;
        }
        

Returns:
builder with Allele members set to default values
        public Builder reset() {
            this. = "";
            this. = "";
            this. = "";
            this. = 0;
            this. = 0;
            this. = .;
            this. = .;
            return this;
        }
        

Returns:
new Allele parameterized using with methods
Throws:
AlleleException if Allele cannot be built because the assigned sequence contains illegal symbols (eg non-nucleic acid)
        public Allele build() throws AlleleException {
            if ( == null ||  == .) {
                String gaps = Joiner.on("").join(Collections.nCopies( - "-"));
                try {
                    this. = DNATools.createDNA(gaps);
                }
                catch (IllegalSymbolException ex) {
                    throw new AlleleException("cannot build allele: " + ex.getMessage());
                }
            }
            if ( != null && !.isEmpty()) {
                if ( == . ||  == .) {
                    if ( == ) {
                         = Locus.Util.pushLeft(.seqString(), );
                         = Locus.Util.pushRight(.seqString(), );
                    }
                }
            }
            return new Allele();
        }
    }
    
Define allele equivalence as the same genomic location (contig, start, and end) as well as the same lesion and sequence.

Parameters:
right allele
Returns:
true if this is equal to right, false otherwise
    @Override
    public boolean equals(final Object right) {
        if (!super.equals(right)) {
            return false;
        }
        Allele allele = (Alleleright;
        return allele.lesion == this. && allele.sequence.equals(this.);
    }
    

Returns:
allele hash code
    @Override
    public int hashCode() {
      return super.hashCode() + Objects.hashCode() + .hashCode();
    }
    
A method to simulate double crossover between Allele objects whereby the sequence from one allele is joined to the other within a specific region of overlap.

Parameters:
right allele
Returns:
a new crossed-over allele. This implementation treats the original alleles as immutable thus favoring programmatic convenience over genetic reality.
Throws:
org.biojava.bio.symbol.IllegalSymbolException
java.lang.IndexOutOfBoundsException
org.biojava.bio.symbol.IllegalAlphabetException
        if (this.overlaps(right)) {
            //System.out.println("this range" + this.toString() + " sequence = " + this.sequence.seqString() + "sequence length = " + sequence.length());
            Locus homologue = intersection(right);
            //System.out.println("homologue = " + homologue);
            SymbolList copy = DNATools.createDNA(this..seqString());
            int length = homologue.getEnd() - homologue.getStart();
            int target = homologue.getStart() - right.getStart() + 1;
            int from = homologue.getStart() - this.getStart() + 1;
            //System.out.println("length = " + length);
            //System.out.println("target = " + target);
            //System.out.println("from = " + from);
            //System.out.println("copy = " + copy.seqString());
            try {
                SymbolList replace = right.sequence.subList(targettarget + length - 1);
                //System.out.println("replace = " + replace.seqString());
                copy.edit(new Edit(fromlengthreplace));
            }
            catch(ChangeVetoException e) {
                //System.out.println("CHANGE VETO EXCEPTON" + e.getMessage());
            }
            //System.out.println("CROSSEDOVER SEQUENCE = " + copy.seqString());
            //copy.edit(new Edit());
            //Sequence left = this.sequence.subList(0, homologue.getStart());
            //Sequence middle = right.sequence.subList(homologue.getStart() - right.getStart(), i1);
            return new Allele(this.this.this.getStart(), this.getEnd(), copy.);
        }
        return new Allele(this.this.this.getStart(), this.getEnd(), this..);
    }
    
A method to simulate merging of two alleles strictly, meaning the sequence in the overlapping regions must be equal.

Parameters:
right allele
minimumOverlap for the merge to occur
Returns:
new merged allele.
Throws:
org.biojava.bio.symbol.IllegalSymbolException
java.lang.IndexOutOfBoundsException
org.biojava.bio.symbol.IllegalAlphabetException
AlleleException
    public Allele merge(final Allele rightfinal long minimumOverlapthrows IllegalSymbolExceptionIndexOutOfBoundsExceptionIllegalAlphabetExceptionAlleleException {
      
        Allele.Builder builder = Allele.builder();
        Locus overlap = intersection(right);
        // System.out.println("overlap = " + overlap);
        // System.out.println("overlap.length() " + overlap.length() + " < " + startimumOverlap + "??");
        if (overlap.length() < minimumOverlap) {
            return builder.reset().build();
        }
        Allele bit = builder  
            .withContig(overlap.getContig())
            .withStart(overlap.getStart())
            .withEnd(overlap.getEnd())
            .withSequence(.)
            .withLesion(.)
            .build();
        // System.out.println("bit = " + bit + " " + bit.sequence.seqString());
        Allele a = bit.doubleCrossover(right);
        // System.out.println("a = " + a + " " + a.sequence.seqString());
        Allele b = bit.doubleCrossover(this);
        // System.out.println("b = " + b + " " + b.sequence.seqString());   
        if (a.sequence.seqString().equals(b.sequence.seqString())) {
            Locus union = union(right);
            return builder
                .withName(right.getName())
                .withContig(union.getContig())
                .withStart(union.getStart())
                .withEnd(union.getEnd())
                .withSequence(.)
                .withLesion(.)
                .build()
                .doubleCrossover(right)
                .doubleCrossover(this);
        }
        return builder.reset().build(); 
    }
    
A method to simulate hard clipping (removal) of leftmost sequence, for example synthesized sequence representing molecular barcodes or target capture probes (primers)

Parameters:
pattern sequence (will be strictly matched, no regular expressions)
Returns:
new Allele with clipped sequence
Throws:
org.biojava.bio.symbol.IllegalAlphabetException
AlleleException
org.biojava.bio.symbol.IllegalSymbolException
        int start = this.getStart();
        SymbolList copy = DNATools.createDNA(.seqString());
        while (copy.seqString().startsWith(pattern)) {
            copy.edit(new Edit(1, pattern.length(), .));
            start += pattern.length();
        }
        return builder()
            .withContig(this.getContig())
            .withStart(start)
            .withEnd(this.getEnd())
            .withSequence(copy)
            .withLesion(this.)
            .build();
    }
    
A method to simulate hard clipping (removal) of rightmost sequence, for example synthesized sequence representing molecular barcodes or target capture probes (primers)

Parameters:
pattern sequence (will be strictly matched, no regular expressions)
Returns:
new Allele with clipped sequence
Throws:
org.biojava.bio.symbol.IllegalAlphabetException
AlleleException
org.biojava.bio.symbol.IllegalSymbolException
        int end = this.getEnd();
        // System.out.println("end before = " + end);
        SymbolList copy = DNATools.createDNA(.seqString());
        while (copy.seqString().endsWith(pattern)) {
            copy.edit(new Edit(copy.length() - pattern.length() + 1, pattern.length(), .));
            end -= pattern.length();
            // System.out.println("end during " + end);
            // System.out.println("editing copy " + copy.seqString());
        }
        // System.out.println("end after = " + end);
        // System.out.println("edited copy = " + copy.seqString());
        return builder()
            .withContig(this.getContig())
            .withStart(this.getStart())
            .withEnd(end)
            .withSequence(copy)
            .withLesion(this.)
            .build();
    }
New to GrepCode? Check out our FAQ X