Convert from an X position in the JPanel to the position
in the sequence alignment.

@param aligSeq sequence number
@param p point on panel
@return the sequence position for a point on the Panel
763658
public int getSeqPos(int aligSeq, Point p) {

		int x = p.x - DEFAULT_X_SPACE - DEFAULT_LEGEND_SIZE;
		int y = p.y - DEFAULT_Y_SPACE ;

		y -=  (DEFAULT_LINE_SEPARATION * aligSeq) - DEFAULT_CHAR_SIZE;

		int lineNr = y / DEFAULT_Y_STEP;
		int linePos = x / DEFAULT_CHAR_SIZE;
		return lineNr * DEFAULT_LINE_LENGTH + linePos ;

	}
342415
public static AminoAcidSequence translate(NucleotideSequence sequence) {
        if (sequence.size() % 3 != 0)
            throw new IllegalArgumentException("Only nucleotide sequences with size multiple " +
                    "of three are supported (in-frame).");
        byte[] aaData = new byte[sequence.size() / 3];
        GeneticCode.translate(aaData, 0, sequence, 0, sequence.size());
        return new AminoAcidSequence(aaData, true);
    }
657577
function postSequence(elems, fin) {
    // Treat the final value of a sequence as its return value
    var toReturn = elems[elems.length - 1];
    return fin(null, toReturn);
}
1101458
@Deprecated
	@Override
	public String getSequence(Long beginPosition, Long endPosition) {

		if (beginPosition == null || endPosition == null
				|| (beginPosition > endPosition) || beginPosition < 1
				|| endPosition >getLength()) {
			return null;
		}
		
       int length = (int) (endPosition.longValue() - beginPosition.longValue()) + 1;
	   int offset = beginPosition.intValue() - 1;
	   String subSequence=null;
		try{
			subSequence= ByteBufferUtils.string(getSequenceBuffer(), offset, length);
		}
		catch(Exception e)
		{
			e.printStackTrace();
			return subSequence;
		}
        return subSequence;
		/*// note begin:1 end:4 has length 4
		

		byte[] subsequence = new byte[length];

		
		synchronized (sequence) {
			sequence.position(offset);
			sequence.get(subsequence, 0, length);
		}
		
		String string = new String(subsequence);

		return string;*/
	}
125223
public static final List<Integer> getEQRAlignmentPos(AFPChain afpChain){
		List<Integer> lst = new ArrayList<Integer>();

		char[] s1 = afpChain.getAlnseq1();
		char[] s2 = afpChain.getAlnseq2();
		char[] symb = afpChain.getAlnsymb();
		boolean isFatCat = afpChain.getAlgorithmName().startsWith("jFatCat");

		for ( int i =0 ; i< s1.length; i++){
			char c1 = s1[i];
			char c2 = s2[i];

			if ( isAlignedPosition(i,c1,c2,isFatCat, symb)) {
				lst.add(i);
			}

		}
		return lst;

	}
872806
public static <T> Parser<T> sequence(
      Parser<?> p1, Parser<?> p2, Parser<?> p3, Parser<?> p4, Parser<T> p5) {
    return sequence(p1, p2, p3, p4, p5,
        InternalFunctors.<Object, Object, Object, Object, T>lastOfFive());
  }
768683
@Override
    public Sequence<T> next() {
        Sequence<T> sequence = new Sequence<>();

        int startPosition = position.getAndIncrement();
        int lastId = -1;
        int currentPoint = order[startPosition];
        int startPoint = currentPoint;
        for (int i = 0; i < walkLength; i++) {

            if (alpha > 0 && lastId != startPoint && lastId != -1 && alpha > rng.nextDouble()) {
                startPosition = startPoint;
                continue;
            }


            Vertex<T> vertex = sourceGraph.getVertex(currentPoint);
            sequence.addElement(vertex.getValue());

            List<? extends Edge<? extends Number>> edges = sourceGraph.getEdgesOut(currentPoint);

            if (edges == null || edges.isEmpty()) {
                switch (noEdgeHandling) {
                    case CUTOFF_ON_DISCONNECTED:
                        // we just break this sequence
                        i = walkLength;
                        break;
                    case EXCEPTION_ON_DISCONNECTED:
                        throw new NoEdgesException("No available edges left");
                    case PADDING_ON_DISCONNECTED:
                        // TODO: implement padding
                        throw new UnsupportedOperationException("Padding isn't implemented yet");
                    case RESTART_ON_DISCONNECTED:
                        currentPoint = order[startPosition];
                        break;
                    case SELF_LOOP_ON_DISCONNECTED:
                        // we pad walk with this vertex, to do that - we just don't do anything, and currentPoint will be the same till the end of walk
                        break;
                }
            } else {
                double totalWeight = 0.0;
                for (Edge<? extends Number> edge : edges) {
                    totalWeight += edge.getValue().doubleValue();
                }

                double d = rng.nextDouble();
                double threshold = d * totalWeight;
                double sumWeight = 0.0;
                for (Edge<? extends Number> edge : edges) {
                    sumWeight += edge.getValue().doubleValue();
                    if (sumWeight >= threshold) {
                        if (edge.isDirected()) {
                            currentPoint = edge.getTo();
                        } else {
                            if (edge.getFrom() == currentPoint) {
                                currentPoint = edge.getTo();
                            } else {
                                currentPoint = edge.getFrom(); //Undirected edge: might be next--currVertexIdx instead of currVertexIdx--next
                            }
                        }
                        lastId = currentPoint;
                        break;
                    }
                }
            }
        }

        return sequence;
    }
980068
@IntRange(from = 0, to = OPAQUE)
    private static int resolveLineAlpha(
            @IntRange(from = 0, to = OPAQUE) final int sceneAlpha,
            final float maxDistance,
            final float distance) {
        final float alphaPercent = 1f - distance / maxDistance;
        final int alpha = (int) ((float) OPAQUE * alphaPercent);
        return alpha * sceneAlpha / OPAQUE;
    }
226914
void favors(CharSequence sequence) {
    for (int i = 0; i < sequence.length(); i++) {
      CharPriority c = priorityLookupMap.get(sequence.charAt(i));
      if (c != null) {
        c.occurrence++;
      }
    }
  }
1168489
public int getValueForPosition(int p)
	{
		int pt = nPoints - 1;
		for (int i=0; i<pt; i++)
		{
			if (p <= position[i]) 
			{ 
				pt = i; 
				break; 
			}
		}
		int x2 = position[pt];
		int x1, v;
		if (p>=x2)
		{
			v = value[pt]<<SHIFT;
			x1 = x2;
		}
		else
		if (pt>0)
		{
			v = value[pt-1]<<SHIFT;
			x1 = position[pt-1];
		}
		else
		{
			v = x1 = 0;
		}
		
		if (p>x2) p=x2;
		if ((x2>x1) && (p>x1))
		{
			v += ((p - x1) * ((value[pt]<<SHIFT) - v)) / (x2 - x1);
		}
		if (v<0) v=0;
		else
		if (v>MAXVALUE) v = MAXVALUE;
		
		return v;
	}
361016
private int getSeqPos(MouseEvent e) {

		int x = e.getX();
		//int y = e.getY();
		//float scale = seqScale.getScale();
		//int DEFAULT_X_START = SequenceScalePanel.DEFAULT_X_START;

		float scale = parent.getScale();

		coordManager.setScale(scale);
		int seqpos = coordManager.getSeqPos(x-2);


		return seqpos  ;
	}
727975
private static long scanForSequence(final ImageInputStream pStream, final byte[] pSequence) throws IOException {
        long start = -1l;

        int index = 0;
        int nullBytes = 0;

        for (int read; (read = pStream.read()) >= 0;) {
            if (pSequence[index] == (byte) read) {
                // If this is the first byte in the sequence, store position
                if (start == -1) {
                    start = pStream.getStreamPosition() - 1;
                }

                // Inside the sequence, there might be 1 or 3 null bytes, depending on 16/32 byte encoding
                if (nullBytes == 1 || nullBytes == 3) {
                    pStream.skipBytes(nullBytes);
                }

                index++;

                // If we found the entire sequence, we're done, return start position
                if (index == pSequence.length) {
                    return start;
                }
            }
            else if (index == 1 && read == 0 && nullBytes < 3) {
                // Skip 1 or 3 null bytes for 16/32 bit encoding
                nullBytes++;
            }
            else if (index != 0) {
                // Start over
                index = 0;
                start = -1;
                nullBytes = 0;
            }
        }

        return -1l;
    }
326198
@Override
    public Object mapSequence(Object sequence) {
        List<List<Float>> seq = (List<List<Float>>) sequence;
        List<Float> ret = new ArrayList<>();
        for (List<Float> step : seq)
            ret.add((Float) map(step));
        return ret;
    }
398368
public static char[] sequenceToArray(CharSequence seq) {
    if (seq == null) {
      throw new NullPointerException("CharSequence can't be NULL");
    }
    char[] chars = new char[seq.length()];
    for (int i = 0; i < seq.length(); i++) {
      chars[i] = seq.charAt(i);
    }
    return chars;
  }
1171769
public Sequence getSequence(String sequenceKey, SequenceConfig sequenceConfig) {
        Sequence sequence = sequences.get(checkNotNull(sequenceKey));
        if (null == sequence) {
            sequence = sequenceDB().openSequence(null, 
                    sequenceDB().getEntry(sequenceKey), firstNonNull(sequenceConfig, defaultSequenceConfig()));
            sequences.put(sequenceKey, sequence);
        }
        
        return sequence;
    }
303754
public static float pointLineDistSq (float px, float py,
                                         float x1, float y1, float x2, float y2) {
        x2 -= x1;
        y2 -= y1;
        px -= x1;
        py -= y1;
        float s = px * y2 - py * x2;
        return (s * s) / (x2 * x2 + y2 * y2);
    }
757703
public static <T> Sequence<T> sort(final Sequence<T> sequence, final Comparator<T> comparator)
  {
    List<T> seqList = sequence.toList();
    Collections.sort(seqList, comparator);
    return simple(seqList);
  }