htsjdk库BEDFeature接口及相关类介绍

htsjdk 库中的 BEDFeature 接口用于表示 BED 文件格式中的一个特征(feature)。BED 文件格式是用于描述基因组数据的文本文件格式,广泛用于基因组学和生物信息学领域。

BEDFeature接口的继承关系:

NamedFeature源码

/*
 * The MIT License
 *
 * Copyright (c) 2023 The Broad Institute
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package htsjdk.tribble;


/**
 * An interface for features provided via an interval file, e.g. bed or interval_list.
 * Provides a common interface for accessing the name column for both of these file types.
 */
public interface NamedFeature extends Feature {
    String getName();
}

BEDFeature源码

/*
 * The MIT License
 *
 * Copyright (c) 2013 The Broad Institute
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package htsjdk.tribble.bed;

import htsjdk.tribble.NamedFeature;
import htsjdk.tribble.annotation.Strand;

import java.awt.*;

/**
 * @author jrobinso
 * @date Dec 24, 2009
 *
 * BED feature start and end positions must adhere to the Feature interval specifications.
 * This is different than the 0-based representation in a BED file.  This conversion is handled by {@link BEDCodec}.
 * Anyone writing a bed file should be aware of this difference.
 */
public interface BEDFeature extends NamedFeature {
    Strand getStrand();

    String getType();

    Color getColor();

    String getDescription();

    java.util.List<FullBEDFeature.Exon> getExons();

    float getScore();

    String getLink();
}

SimpleBEDFeature源码

/*
 * The MIT License
 *
 * Copyright (c) 2013 The Broad Institute
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package htsjdk.tribble.bed;

import htsjdk.tribble.annotation.Strand;

import java.awt.*;
import java.util.ArrayList;
import java.util.List;

/**
 *  Feature from a BED file without exon blocks.
 */
public class SimpleBEDFeature implements BEDFeature {
    protected String chr;
    protected int start = -1;
    protected int end = -1;
    protected Strand strand = Strand.NONE;
    private String name = "";
    private float score = Float.NaN;
    private String type = "";
    private Color color;
    private String description;//protected float confidence;
    //private String identifier;
    private String link;

    public SimpleBEDFeature(int start, int end, String chr) {
        this.start = start;
        this.end = end;
        this.chr = chr;
    }

    @Override
    public String getContig() {
        return chr;
    }

    @Override
    public int getStart() {
        return start;
    }

    @Override
    public int getEnd() {
        return end;
    }

    @Override
    public Strand getStrand() {
        return strand;
    }

    public void setStrand(Strand strand) {
        this.strand = strand;
    }

    public void setChr(String chr) {
        this.chr = chr;
    }

    public void setStart(int start) {
        this.start = start;
    }

    public void setEnd(int end) {
        this.end = end;
    }

    @Override
    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    @Override
    public Color getColor() {
        return color;
    }

    public void setColor(Color color) {
        this.color = color;
    }

    @Override
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Override
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public float getScore() {
        return score;
    }

    public void setScore(float score) {
        this.score = score;
    }

    @Override
    public String getLink() {
        return link;
    }

    public void setLink(String link) {
        this.link = link;
    }

    final static List<FullBEDFeature.Exon> emptyExonList = new ArrayList();

    @Override
    public java.util.List<FullBEDFeature.Exon> getExons() {
        return emptyExonList;
    }
}

FullBEDFeature源码

/*
 * The MIT License
 *
 * Copyright (c) 2013 The Broad Institute
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package htsjdk.tribble.bed;

import htsjdk.tribble.annotation.Strand;

import java.util.ArrayList;

/**
 * Object for full BED file.
 */
public class FullBEDFeature extends SimpleBEDFeature implements BEDFeature {

    private java.util.List<Exon> exons = new ArrayList();

    public FullBEDFeature(String chr, int start, int end) {
        super(start, end, chr);

    }

    @Override
    public java.util.List<Exon> getExons() {
        return exons;
    }

    public void setExons(java.util.List<Exon> exons) {
        this.exons = exons;
    }

    public void addExon(Exon exon) {
        if (exon == null) {
            this.exons = new ArrayList();
        }
        exons.add(exon);
    }

    public void addExon(int exonStart, int exonEnd, int cdStart, int cdEnd, int exonNumber) {
        Exon exon = new Exon(exonStart, exonEnd);
        exon.setCodingStart(cdStart);
        exon.setCodingEnd(cdEnd);
        exon.setNumber(exonNumber);
        addExon(exon);
    }

    /**
     * A sub region of a feature.  For example,  a Gene exon
     *
     * @author jrobinso
     */
    public class Exon {

        int start;
        int end;
        /**
         * The index of the exon relative to the start codon.  The exon with the start
         * codon is number "1".
         */
        private int number;
        private int readingFrame = -1;

        /**
         * Coding start position.  This is the leftmost position of the coding region, not neccessarily the 5'utr end
         */
        private int codingStart;
        private int codingEnd;
        boolean utr = false;

        // The position of the first base of this exon relative to the start of the mRNA.  This will correspond
        // to either the beginning or end of the exon, depending on the strand
        private int mrnaBase = -1;


        public void setMrnaBase(int base) {
            this.mrnaBase = base;
        }


        /**
         * Constructs ...
         *
         * @param start
         * @param end
         */
        public Exon(int start, int end) {
            this.start = start;
            this.end = end;

            // By default the entre exon is a coding region
            this.codingStart = start;
            this.codingEnd = end;
        }

        /**
         * Flag indicating that the entire exon is the UTR.
         *
         * @param utr
         */
        public void setUTR(boolean utr) {
            this.utr = utr;
            if (strand == Strand.POSITIVE) {
                codingStart = codingEnd = end;
            } else {
                codingStart = codingEnd = start;
            }
        }

        /**
         * Method description
         *
         * @param codingStart
         */
        public void setCodingStart(int codingStart) {
            this.codingStart = Math.max(start, codingStart);
        }

        /**
         * Method description
         *
         * @param codingEnd
         */
        public void setCodingEnd(int codingEnd) {
            this.codingEnd = Math.min(end, codingEnd);
        }

        /**
         * Method description
         *
         * @param offset
         */
        public void setReadingFrame(int offset) {
            this.readingFrame = offset;
        }

        /**
         * Method description
         *
         * @param phase
         */
        public void setPhase(int phase) {
            if (strand == Strand.POSITIVE) {
                readingFrame = phase;
            } else if (strand == Strand.NEGATIVE) {
                int modLen = (getCodingLength() - phase) % 3;
                readingFrame = modLen;
            }
        }


        /**
         * Method description
         *
         * @return
         */
        public int getCdStart() {
            return codingStart;
        }

        /**
         * Method description
         *
         * @return
         */
        public int getCdEnd() {
            return this.codingEnd;
        }

        /**
         * Method description
         *
         * @return
         */
        public int getCodingLength() {
            return utr ? 0 : Math.max(0, codingEnd - codingStart + 1);
        }

        /**
         * This is exposed for unit tests.
         *
         * @return
         */
        int getReadingShift() {
            return readingFrame;
        }


        public String getValueString(double position) {
            String msg = number > 0 ? "Exon number: " + number : "";
            return msg;
        }

        public int getNumber() {
            return number;
        }

        public void setNumber(int number) {
            this.number = number;
        }
    }


    public class Exon2 {

        /**
         * The index of the exon relative to the start codon.  The exon with the start
         * codon is number "1".
         */
        private int number;
        private int readingFrame = -1;

        /**
         * Coding start position.  This is the leftmost position of the coding region, not neccessarily the 5'utr end
         */
        private int start;
        private int end;
        private int codingStart;
        private int codingEnd;
        //private AminoAcidSequence aminoAcidSequence;
        boolean utr = false;

        // The position of the first base of this exon relative to the start of the mRNA.  This will correspond
        // to either the beginning or end of the exon, depending on the strand
        private int mrnaBase = -1;


        public Exon2(int start, int end, int codingStart, int codingDne) {

            this.start = start;
            this.end = end;
            this.codingStart = codingStart;
            this.codingEnd = codingDne;
        }


        public void setMrnaBase(int base) {
            this.mrnaBase = base;
        }

        public int getAminoAcidNumber(int genomeCoordinate) {
            if (mrnaBase < 0) {
                return -1;
            }
            if (genomeCoordinate < getStart() || genomeCoordinate > getEnd()) {
                throw new IndexOutOfBoundsException();
            }
            if (getStrand() == Strand.POSITIVE) {
                int mrnaCoord = mrnaBase + (genomeCoordinate - codingStart) - 1;
                return mrnaCoord < 0 ? -1 : mrnaCoord / 3 + 1;

            } else if (getStrand() == Strand.NEGATIVE) {
                int mrnaCoord = mrnaBase + (codingEnd - genomeCoordinate);
                return mrnaCoord < 0 ? -1 : mrnaCoord / 3 + 1;

            } else {
                return 0;
            }
        }

        /**
         * Flag indicating that the entire exon is the UTR.
         *
         * @param utr
         */
        public void setUTR(boolean utr) {
            this.utr = utr;
            if (getStrand() == Strand.POSITIVE) {
                codingStart = codingEnd = getEnd();
            } else {
                codingStart = codingEnd = getStart();
            }
        }

        /**
         * Method description
         *
         * @param codingStart
         */
        public void setCodingStart(int codingStart) {
            this.codingStart = Math.max(getStart(), codingStart);
        }

        /**
         * Method description
         *
         * @param codingEnd
         */
        public void setCodingEnd(int codingEnd) {
            this.codingEnd = Math.min(getEnd(), codingEnd);
        }

        /**
         * Method description
         *
         * @param offset
         */
        public void setReadingFrame(int offset) {
            this.readingFrame = offset;
        }

        /**
         * Method description
         *
         * @param phase
         */
        public void setPhase(int phase) {
            if (getStrand() == Strand.POSITIVE) {
                readingFrame = phase;
            } else if (getStrand() == Strand.NEGATIVE) {
                int modLen = (getCodingLength() - phase) % 3;
                readingFrame = modLen;
            }
        }


        /**
         * Method description
         *
         * @return
         */
        public int getCdStart() {
            return codingStart;
        }

        /**
         * Method description
         *
         * @return
         */
        public int getCdEnd() {
            return this.codingEnd;
        }

        /**
         * Method description
         *
         * @return
         */
        public int getCodingLength() {
            return utr ? 0 : Math.max(0, codingEnd - codingStart);
        }

        /**
         * This is exposed for unit tests.
         *
         * @return
         */
        int getReadingShift() {
            return readingFrame;
        }


        /**
         * Method description
         *
         * @return
         */
        /*
        public AminoAcidSequence getAminoAcidSequence() {
            if (aminoAcidSequence == null) {
                computeAminoAcidSequence();
            }
            return aminoAcidSequence;
        }
        */


        /*
        public void setAminoAcidSequence(AminoAcidSequence aminoAcidSequence) {
            this.aminoAcidSequence = aminoAcidSequence;
        }
        */

        /*
        private void computeAminoAcidSequence() {

            if (utr) {
                return;
            }
            int start = getStart();
            int end = getEnd();
            String chr = getChr();
            if (readingFrame >= 0) {
                int readStart = (codingStart > start) ? codingStart : start + readingFrame;
                int readEnd = Math.min(end, codingEnd);
                if (readEnd > readStart + 3) {
                    String genome = IGVModel.getInstance().getViewContext().getGenomeId();
                    aminoAcidSequence = AminoAcidManager.getAminoAcidSequence(genome, chr, readStart,
                            readEnd, getStrand());
                }
            }
        }
        */


        public String getValueString(double position) {
            String msg = number > 0 ? "Exon number: " + number : "";
            int aaNumber = this.getAminoAcidNumber((int) position);
            if (aaNumber > 0) {
                msg += "<br>Amino acid number: " + aaNumber;
            }
            return msg;
        }

        public int getNumber() {
            return number;
        }

        public void setNumber(int number) {
            this.number = number;
        }

    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值