Extracts the boundaries of the coding regions in chromosomal coordinates

@param chromPos
@return
437029
public static List<Range<Integer>> getChromosomalRangesForCDS(GeneChromosomePosition chromPos){
		if ( chromPos.getOrientation() == '+')
			return getCDSExonRangesForward(chromPos,CHROMOSOME);
		return getCDSExonRangesReverse(chromPos,CHROMOSOME);
	}
583746
public static List<LineString> getSectionsFromCoordinates( List<Coordinate> coordinates, double width ) {

        if (coordinates.size() < 3) {
            throw new IllegalArgumentException("This method works only on lines with at least 3 coordinates.");
        }
        double halfWidth = width / 2.0;
        List<LineString> linesList = new ArrayList<LineString>();
        // first section
        Coordinate centerCoordinate = coordinates.get(0);
        LineSegment l1 = new LineSegment(centerCoordinate, coordinates.get(1));
        Coordinate leftCoordinate = l1.pointAlongOffset(0.0, halfWidth);
        Coordinate rightCoordinate = l1.pointAlongOffset(0.0, -halfWidth);
        LineString lineString = geomFactory.createLineString(new Coordinate[]{leftCoordinate, centerCoordinate, rightCoordinate});
        linesList.add(lineString);

        for( int i = 1; i < coordinates.size() - 1; i++ ) {
            Coordinate previous = coordinates.get(i - 1);
            Coordinate current = coordinates.get(i);
            Coordinate after = coordinates.get(i + 1);

            double firstAngle = azimuth(current, previous);
            double secondAngle = azimuth(current, after);

            double a1 = min(firstAngle, secondAngle);
            double a2 = max(firstAngle, secondAngle);

            double centerAngle = a1 + (a2 - a1) / 2.0;

            AffineTransformation rotationInstance = AffineTransformation.rotationInstance(-toRadians(centerAngle), current.x,
                    current.y);

            LineString vertical = geomFactory.createLineString(new Coordinate[]{new Coordinate(current.x, current.y + halfWidth),
                    current, new Coordinate(current.x, current.y - halfWidth)});
            Geometry transformed = rotationInstance.transform(vertical);
            linesList.add((LineString) transformed);
        }

        // last section
        centerCoordinate = coordinates.get(coordinates.size() - 1);
        LineSegment l2 = new LineSegment(centerCoordinate, coordinates.get(coordinates.size() - 2));
        leftCoordinate = l2.pointAlongOffset(0.0, halfWidth);
        rightCoordinate = l2.pointAlongOffset(0.0, -halfWidth);
        lineString = geomFactory.createLineString(new Coordinate[]{leftCoordinate, centerCoordinate, rightCoordinate});
        linesList.add(lineString);

        return linesList;
    }
544556
public static String fromHex(String string, int minLength, Pattern separator) {
        StringBuilder buffer = new StringBuilder();
        String[] parts = separator.split(string);
        for (String part : parts) {
            if (part.length() < minLength) {
                throw new IllegalArgumentException("code point too short: " + part);
            }
            int cp = Integer.parseInt(part, 16);
            buffer.appendCodePoint(cp);
        }
        return buffer.toString();
    }
649221
private int scanToken(int startPos) {
        int position = startPos;
        while (position < maxPosition) {
            if (!hasSurrogates) {
                char c = str.charAt(position);
                if ((c <= maxDelimCodePoint) && (delimiters.indexOf(c) >= 0))
                    break;
                position++;
            } else {
                int c = str.codePointAt(position);
                if ((c <= maxDelimCodePoint) && isDelimiter(c))
                    break;
                position += Character.charCount(c);
            }
        }
        if (retDelims && (startPos == position)) {
            if (!hasSurrogates) {
                char c = str.charAt(position);
                if ((c <= maxDelimCodePoint) && (delimiters.indexOf(c) >= 0))
                    position++;
            } else {
                int c = str.codePointAt(position);
                if ((c <= maxDelimCodePoint) && isDelimiter(c))
                    position += Character.charCount(c);
            }
        }
        return position;
    }
312388
def get_cytoband_coord(chrom, pos):
    
    chrom = chrom.strip('chr')
    pos = int(pos)
    result = None
    logger.debug("Finding Cytoband for chrom:{0} pos:{1}".format(chrom, pos))
    if chrom in CYTOBANDS:
        for interval in CYTOBANDS[chrom][pos]:
            result = "{0}{1}".format(chrom, interval.data)

    return result
1351483
def parse_chromosome_string(job, chromosome_string):
    
    if chromosome_string is None:
        return []
    else:
        assert isinstance(chromosome_string, str)
        chroms = [c.strip() for c in chromosome_string.split(',')]
        if 'canonical' in chroms:
            assert 'canonical_chr' not in chroms, 'Cannot have canonical and canonical_chr'
            chr_prefix = False
            chroms.remove('canonical')
            out_chroms = [str(c) for c in range(1, 23)] + ['X', 'Y']
        elif 'canonical_chr' in chroms:
            assert 'canonical' not in chroms, 'Cannot have canonical and canonical_chr'
            chr_prefix = True
            chroms.remove('canonical_chr')
            out_chroms = ['chr' + str(c) for c in range(1, 23)] + ['chrX', 'chrY']
        else:
            chr_prefix = None
            out_chroms = []
        for chrom in chroms:
            if chr_prefix is not None and chrom.startswith('chr') is not chr_prefix:
                job.fileStore.logToMaster('chromosome %s does not match the rest that %s begin '
                                          'with "chr".' % (chrom,
                                                           'all' if chr_prefix else 'don\'t'),
                                          level=logging.WARNING)
            out_chroms.append(chrom)
        return chrom_sorted(out_chroms)
1310392
public String readLineUntilBoundary() throws IOException {
		StringBuilder bldr = new StringBuilder();
		while (true) {
			int b = read();
			if (bldr.indexOf(boundary) == 0) {
				leftover = ByteBuffer.wrap(boundaryBytes);
				return null;
			} else if (b == -1 || b == 10) {
				break;
			} else if (b != '\r') {
				bldr.append((char) ((byte) b));
			}
		}
		return bldr.toString();
	}
1044858
def map_type_of_region(self, regiontype):
        

        if regiontype in self.localtt:
            so_id = self.resolve(regiontype)
        else:
            so_id = self.globaltt['chromosome_part']
            LOG.warning(
                "Unmapped code %s. Defaulting to chr_part '" +
                self.globaltt['chromosome_part'] + "'.", regiontype)

        return so_id
584828
def get_region (self, rs,cs, re,ce):
        '''
        '''

        rs = constrain (rs, 1, self.rows)
        re = constrain (re, 1, self.rows)
        cs = constrain (cs, 1, self.cols)
        ce = constrain (ce, 1, self.cols)
        if rs > re:
            rs, re = re, rs
        if cs > ce:
            cs, ce = ce, cs
        sc = []
        for r in range (rs, re+1):
            line = u''
            for c in range (cs, ce + 1):
                ch = self.get_abs (r,c)
                line = line + ch
            sc.append (line)
        return sc
959317
def _extract_sections(data_block):
    ''''''
    structure_block = data_block[:, COLS.TYPE:COLS.COL_COUNT].astype(np.int)

    # SWC ID -> structure_block position
    id_map = {-1: -1}
    for i, row in enumerate(structure_block):
        id_map[row[ID]] = i

    # end points have either no children, more than one, or are the start
    # of a new gap
    sec_end_pts = _section_end_points(structure_block, id_map)

    # a 'gap' is when a section has part of it's segments interleaved
    # with those of another section
    gap_sections = set()

    sections = []

    def new_section():
        '''new_section'''
        sections.append(DataBlockSection())
        return sections[-1]

    curr_section = new_section()

    parent_section = {-1: -1}

    for row in structure_block:
        row_id = id_map[row[ID]]
        parent_id = id_map[row[PID]]
        if not curr_section.ids:
            # first in section point is parent
            curr_section.ids.append(parent_id)
            curr_section.ntype = row[TYPE]

        gap = parent_id != curr_section.ids[-1]

        # If parent is not the previous point, create a section end-point.
        # Else add the point to this section
        if gap:
            sec_end_pts.add(row_id)
        else:
            curr_section.ids.append(row_id)

        if row_id in sec_end_pts:
            parent_section[curr_section.ids[-1]] = len(sections) - 1
            # Parent-child discontinuity section
            if gap:
                curr_section = new_section()
                curr_section.ids.extend((parent_id, row_id))
                curr_section.ntype = row[TYPE]
                gap_sections.add(len(sections) - 2)
            elif row_id != len(data_block) - 1:
                # avoid creating an extra DataBlockSection for last row if it's a leaf
                curr_section = new_section()

    for sec in sections:
        # get the section parent ID from the id of the first point.
        if sec.ids:
            sec.pid = parent_section[sec.ids[0]]

        # join gap sections and "disable" first half
        if sec.pid in gap_sections:
            _merge_sections(sections[sec.pid], sec)

    # TODO find a way to remove empty sections.  Currently they are
    # required to maintain tree integrity.
    return sections
471341
private Set<LineString> getSegments(Collection<LineString> lines) {
        Set<LineString> set = new HashSet<>();
        for (LineString line : lines) {
            Coordinate[] cc = line.getCoordinates();
            for (int i = 1; i < cc.length; i++) {
                if (!cc[i - 1].equals(cc[i])) {
                    LineString segment = line.getFactory().createLineString(
                            new Coordinate[]{new Coordinate(cc[i - 1]), new Coordinate(cc[i])});
                    set.add(segment);
                }
            }
        }
        return set;
    }
1010951
private static int[] toBoundaries(String str) {
    int[] res = new int[9];
    String[] split = str.split("\\s+");
    for (int i = 0; i < 9; i++) {
      res[i] = Integer.valueOf(split[i]).intValue();
    }
    return res;
  }
616146
public static int[] stringToCodePoints(final String s) {
        final int m = s.codePointCount(0, s.length());
        final int[] codePoints = new int[m];
        int j = 0;
        for (int offset = 0; offset < s.length();) {
            final int codepoint = s.codePointAt(offset);
            codePoints[j++] = codepoint;
            offset += Character.charCount(codepoint);
        }
        return codePoints;
    }
1208159
public static List<Range<Long>> gaps(final GappedSymbolList gappedSymbols) {
        checkNotNull(gappedSymbols);
        List<Range<Long>> gaps = new ArrayList<Range<Long>>();
        int gapStart = -1;
        for (int i = 1, length = gappedSymbols.length() + 1; i < length; i++) {
            if (isGapSymbol(gappedSymbols.symbolAt(i))) {
                if (gapStart < 0) {
                    gapStart = i;
                }
            }
            else {
                if (gapStart > 0) {
                    // biojava coordinates are 1-based
                    gaps.add(Range.closedOpen(Long.valueOf(gapStart - 1L), Long.valueOf(i - 1L)));
                    gapStart = -1;
                }
            }
        }
        if (gapStart > 0) {
            gaps.add(Range.closedOpen(Long.valueOf(gapStart - 1L), Long.valueOf(gappedSymbols.length())));
        }
        return gaps;
    }
682498
@Override
  protected Long stringToBoundary(String boundary, Integer segmentNumber)
      throws IOException {
    if (segmentRegistration.equals(SEGMENT_BOUNDARY_ASC)
        || segmentRegistration.equals(SEGMENT_BOUNDARY_DESC)) {
      if (segmentNumber == null) {
        return Long.valueOf(boundary);
      } else {
        return Math.floorDiv(Long.parseLong(boundary), segmentNumber);
      }
    } else {
      throw new IOException(
          "not available for segmentRegistration " + segmentRegistration);
    }
  }
323959
public static ChromPos getChromPosForward(int cdsPos, List<Integer> exonStarts, List<Integer> exonEnds, int cdsStart, int cdsEnd) {
		boolean inCoding = false;
		int codingLength = 0;

		@SuppressWarnings("unused")
		int lengthExons = 0;
		// map forward
		for (int i = 0; i < exonStarts.size(); i++) {

			// start can include UTR
			int start = exonStarts.get(i);
			int end = exonEnds.get(i);

			lengthExons += end - start;

			if (start <= cdsStart +1 && end >= cdsStart+1) {
				// first exon with UTR
				if (codingLength + (end - cdsStart-1) >= cdsPos) {
					// we are reaching our target position
					int tmp = cdsPos - codingLength;


					logger.debug(cdsStart + " | " + codingLength + " | " + tmp);
					logger.debug(" -> found position in UTR exon:  #"+(i+1)+ " cdsPos:" + cdsPos +
							" return:"+(cdsStart +1 + tmp) +" start:" + format(start + 1) + " " + format(tmp) + " " + cdsStart + " " + codingLength);

					// we start 1 after cdsStart...
					return new ChromPos((cdsStart +1 + tmp),-1);
				}
				inCoding = true;
				codingLength += (end - cdsStart);

				logger.debug("     UTR         : " + format(start+1) + " - " + (cdsStart ));
				logger.debug(" ->  Exon        : " + format(cdsStart+1) + " - " + format(end) + " | " + format(end - cdsStart) + " | " + codingLength + " | " + (codingLength % 3));

			} else if (start+1 <= cdsEnd && end >= cdsEnd) {
				// LAST EXON with UTR
				//logger.debug(" <-- CDS end at: " + cdsEnd );
				inCoding = false;
				if (codingLength + (cdsEnd - start-1) >= cdsPos) {
					int tmp = cdsPos - codingLength;

					logger.debug(" <-  Exon        : " + format(start+1) + " - " + format(cdsEnd) + " | " + format(cdsEnd - start) + " | " + codingLength + " | " + (codingLength % 3));
					logger.debug("     UTR         : " + format(cdsEnd + 1) + " - " + format(end));
					logger.debug( codingLength + " | " + tmp + " | " + format(start+1));
					logger.debug(" -> chromPosForward found position in non coding exon:  " + cdsPos + " " + format(start+1) + " " + format(tmp) + " " + format(cdsStart) + " " + codingLength);

					return new ChromPos((start +1 + tmp),cdsPos%3);
				}
				codingLength += (cdsEnd - start-1);

				logger.debug(" <-  Exon        : " + format(start+1) + " - " + format(cdsEnd) + " | " + format(cdsEnd - start) + " | " + codingLength + " | " + (codingLength % 3));
				logger.debug("     UTR         : " + format(cdsEnd + 1) + " - " + format(end));


			} else if (inCoding) {
				// A standard coding Exon
				// tests for the maximum length of this coding exon
				if (codingLength + (end - start -1)  >= cdsPos) {

					// we are within the range of this exon
					int tmp = cdsPos - codingLength ;

					logger.debug("     Exon        : " + format(start+1) + " - " + format(end) + " | " + format(end - start) + " | " + tmp + " | " + codingLength);
					logger.debug(" -> found chr position in coding exon #" + (i+1) + ":  cdsPos:" + format(cdsPos) + " s:" + format(start) + "-" + format(end) + " tmp:" + format(tmp) + " cdsStart:" + format(cdsStart) + " codingLength:" + codingLength);

					return new ChromPos((start +1 + tmp),cdsPos%3);
				}
				// full exon is coding
				codingLength += (end - start );

				logger.debug("     Exon        : " + format(start+1) + " - " + format(end) + " | " + format(end - start) + " | " + codingLength + " | " + (codingLength % 3));
			}
		}
		return new ChromPos(-1,-1);
	}
269471
private boolean readFormatRegion0(QrCode qr) {
		// set the coordinate system to the closest pp to reduce position errors
		gridReader.setSquare(qr.ppCorner,(float)qr.threshCorner);

		bits.resize(15);
		bits.zero();
		for (int i = 0; i < 6; i++) {
			read(i,i,8);
		}

		read(6,7,8);
		read(7,8,8);
		read(8,8,7);

		for (int i = 0; i < 6; i++) {
			read(9+i,8,5-i);
		}

		return true;
	}