
de.julielab.geneexpbase.genemodel.GeneLocation Maven / Gradle / Ivy
package de.julielab.geneexpbase.genemodel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Description taken from https://medlineplus.gov/genetics/understanding/howgeneswork/genelocation/
*/
public class GeneLocation {
public static final Pattern MAP_LOC_PATTERN = Pattern.compile("([0-9xyXY]+)([pq])([0-9]+)(\\.[0-9]+)?(-?[pq])?([0-9]+)?(\\.[0-9]+)?");
private final static Logger log = LoggerFactory.getLogger(GeneLocation.class);
/**
* The chromosome on which the gene can be found. The first number or letter used to describe a gene's location represents the chromosome. Chromosomes 1 through 22 (the autosomes) are designated by their chromosome number. The sex chromosomes are designated by X or Y.
*/
private String chromosome;
/**
* The arm of the chromosome. Each chromosome is divided into two sections (arms) based on the location of a narrowing (constriction) called the centromere. By convention, the shorter arm is called p, and the longer arm is called q. The chromosome arm is the second part of the gene's address. For example, 5q is the long arm of chromosome 5, and Xp is the short arm of the X chromosome.
*/
private String arm;
/**
* The position of the gene on the p or q arm. The position of a gene is based on a distinctive pattern of light and dark bands that appear when the chromosome is stained in a certain way. The position is usually designated by two digits (representing a region and a band), which are sometimes followed by a decimal point and one or more additional digits (representing sub-bands within a light or dark area). The number indicating the gene position increases with distance from the centromere. For example: 14q21 represents position 21 on the long arm of chromosome 14. 14q21 is closer to the centromere than 14q22.
*/
private String position;
/**
* [...] followed by a decimal point and one or more additional digits (representing sub-bands within a light or dark area).
*/
private String subband;
/**
* For ranges like 15q24-q25, this would be the second 'q'.
*/
private String armRange;
/**
* For ranges like 15q24-q25, this would the 25.
*/
private String positionRange;
/**
* For ranges like 15q24.3-q25.4, this would the 4.
*/
private String subbandRange;
public GeneLocation(String geneLocationString) {
Matcher m = MAP_LOC_PATTERN.matcher(geneLocationString);
m.matches();
try {
initFromMatcher(m);
} catch (IllegalStateException e) {
log.error("No chromosomal gene location match for string {}", geneLocationString);
throw e;
}
}
/**
* @param m A matcher retrieved from {@link #MAP_LOC_PATTERN}.
*/
public GeneLocation(Matcher m) {
initFromMatcher(m);
}
public GeneLocation() {
}
public void setChromosome(String chromosome) {
this.chromosome = chromosome;
}
public void setArm(String arm) {
this.arm = arm;
}
public void setPosition(String position) {
this.position = position;
}
public void setSubband(String subband) {
this.subband = subband;
}
public void setArmRange(String armRange) {
this.armRange = armRange;
}
public void setPositionRange(String positionRange) {
this.positionRange = positionRange;
}
public void setSubbandRange(String subbandRange) {
this.subbandRange = subbandRange;
}
public String getChromosome() {
return chromosome;
}
public String getArm() {
return arm;
}
public String getPosition() {
return position;
}
public String getSubband() {
return subband;
}
private void initFromMatcher(Matcher m) {
chromosome = m.group(1);
arm = m.group(2);
position = m.group(3);
String subbandGroup = m.group(4);
if (subbandGroup != null)
subband = subbandGroup.replace(".", "");
String armRangeGroup = m.group(5);
if (armRangeGroup != null)
armRange = armRangeGroup.replace("-", "");
positionRange = m.group(6);
String subbandRangeGroup = m.group(7);
if (subbandRangeGroup != null)
subbandRange = subbandRangeGroup.replace(".", "");
}
@Override
public String toString() {
StringBuilder loc = new StringBuilder(chromosome).append(arm).append(position);
if (subband != null)
loc.append(".").append(subband);
return loc.toString();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
GeneLocation that = (GeneLocation) o;
return chromosome.equals(that.chromosome) && arm.equals(that.arm) && position.equals(that.position) && Objects.equals(subband, that.subband);
}
@Override
public int hashCode() {
return Objects.hash(chromosome, arm, position, subband);
}
public String getArmRange() {
return armRange;
}
public String getPositionRange() {
return positionRange;
}
public String getSubbandRange() {
return subbandRange;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy