package prok; import java.util.ArrayList; import java.util.HashMap; import dna.AminoAcid; import gff.GffLine; import shared.Shared; import shared.Tools; import structures.ByteBuilder; /** * ORF means Open Reading Frame. * It starts at the first base of a start codon and ends at the last base of a stop codon. * The length is divisible by 3. * @author Brian Bushnell * @date Sep 20, 2018 * */ public class Orf extends PFeature { /*--------------------------------------------------------------*/ /*---------------- Initialization ----------------*/ /*--------------------------------------------------------------*/ /** * Bases and coordinates are assumed to be the correct strand. * Minus-strand ORFs can be flipped at the end of the constructor. * @param scafName_ * @param start_ * @param stop_ * @param strand_ * @param frame_ * @param bases * @param flip */ public Orf(String scafName_, int start_, int stop_, int strand_, int frame_, byte[] bases, boolean flip, int type_) { super(scafName_, start_, stop_, strand_, bases.length); frame=frame_; startCodon=getCodon(start, bases); stopCodon=getCodon(stop-2, bases); type=type_; if(flip && strand==Shared.MINUS){flip();} } /*--------------------------------------------------------------*/ /*---------------- Init Helpers ----------------*/ /*--------------------------------------------------------------*/ /** * Grab the codon starting at from. * Assumes bases are in the correct strand * @param from * @param bases * @return */ private static int getCodon(int from, byte[] bases){ int codon=0; for(int i=0; i<3; i++){ // assert(i+from0){d=Math.sqrt(d);} assert(d!=Double.NaN); return (float)d; } public float averageKmerScore(){ return kmerScore/(length()-GeneModel.kInnerCDS-2); //This slightly affects score if kInnerCDS is changed } /*--------------------------------------------------------------*/ /*---------------- Public Methods ----------------*/ /*--------------------------------------------------------------*/ public boolean isValidPrev(Orf prev, int maxOverlap){ if(prev.stop>=stop || prev.stop>=start+maxOverlap || prev.start>=start){return false;} if(prev.frame==frame && prev.strand==strand && prev.stop>=start){return false;} return true; } public float pathScore() {return Tools.max(pathScorePlus, pathScoreMinus);} public float pathScore(int prevStrand) {return prevStrand==0 ? pathScorePlus : pathScoreMinus;} public Orf prev(){return pathScorePlus>=pathScoreMinus ? prevPlus : prevMinus;} public Orf prev(int prevStrand){return prevStrand==0 ? prevPlus : prevMinus;} public int pathLength(int prevStrand){return prevStrand==0 ? pathLengthPlus : pathLengthMinus;} public int pathLength(){return pathScorePlus>=pathScoreMinus ? pathLengthPlus : pathLengthMinus;} /*--------------------------------------------------------------*/ /*---------------- ToString ----------------*/ /*--------------------------------------------------------------*/ /** * @param orfs A list of called features * @param types Types of features to retain, e.g. "CDS,rRNA,tRNA" * @return GffLines subdivided by type */ public static ArrayList[] toGffLinesByType(ArrayList orfs, String types){ String[] typeArray=types.split(","); @SuppressWarnings("unchecked") ArrayList[] lists=new ArrayList[typeArray.length]; HashMap> map=new HashMap>(3*typeArray.length); for(int i=0; i(); map.put(type, lists[i]); } for(Orf orf : orfs){ String type=ProkObject.typeStrings2[orf.type]; ArrayList glist=map.get(type); if(glist!=null) { glist.add(new GffLine(orf)); } } return lists; } public static ArrayList toGffLines(ArrayList orfs){ if(orfs==null) {return null;} ArrayList list=new ArrayList(orfs.size()); for(Orf orf : orfs){list.add(new GffLine(orf));} return list; } public String toStringFlipped(){ if(strand==flipped()){ return toString(); } flip(); String s=toString(); flip(); return s; } @Override public String toString(){ return toGff(); } public String toGff(){ ByteBuilder bb=new ByteBuilder(); appendGff(bb); return bb.toString(); } public ByteBuilder appendGff(ByteBuilder bb){ if(scafName==null){ bb.append('.').tab(); }else{ for(int i=0, max=scafName.length(); i