Mercurial > repos > timpalpant > java_genomics_toolkit
comparison src/edu/unc/genomics/nucleosomes/NucleosomeCall.java @ 2:e16016635b2a
Uploaded
| author | timpalpant |
|---|---|
| date | Mon, 13 Feb 2012 22:12:06 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:a54db233ee3d | 2:e16016635b2a |
|---|---|
| 1 package edu.unc.genomics.nucleosomes; | |
| 2 | |
| 3 import java.util.Comparator; | |
| 4 | |
| 5 import edu.unc.genomics.ValuedInterval; | |
| 6 import edu.unc.genomics.io.IntervalFileFormatException; | |
| 7 | |
| 8 /** | |
| 9 * @author timpalpant | |
| 10 * | |
| 11 */ | |
| 12 public class NucleosomeCall extends ValuedInterval implements Comparable<NucleosomeCall> { | |
| 13 | |
| 14 private static final long serialVersionUID = 6522702303121259979L; | |
| 15 | |
| 16 private int dyad; | |
| 17 private double dyadStdev; | |
| 18 private double dyadMean; | |
| 19 private double conditionalPosition; | |
| 20 private int length; | |
| 21 private double lengthStdev; | |
| 22 | |
| 23 /** | |
| 24 * @param chr | |
| 25 * @param start | |
| 26 * @param stop | |
| 27 */ | |
| 28 public NucleosomeCall(String chr, int start, int stop) { | |
| 29 super(chr, start, stop); | |
| 30 } | |
| 31 | |
| 32 public static NucleosomeCall parse(String line) { | |
| 33 if (line.startsWith("#")) return null; | |
| 34 | |
| 35 String[] entry = line.split("\t"); | |
| 36 if (entry.length < 10) { | |
| 37 throw new IntervalFileFormatException("Invalid nucleosome call has < 10 columns"); | |
| 38 } | |
| 39 | |
| 40 String chr = entry[0]; | |
| 41 int start = Integer.parseInt(entry[1]); | |
| 42 int stop = Integer.parseInt(entry[2]); | |
| 43 | |
| 44 NucleosomeCall call = new NucleosomeCall(chr, start, stop); | |
| 45 call.setLength(Integer.parseInt(entry[3])); | |
| 46 call.setLengthStdev(Double.parseDouble(entry[4])); | |
| 47 call.setDyad(Integer.parseInt(entry[5])); | |
| 48 call.setDyadStdev(Double.parseDouble(entry[6])); | |
| 49 call.setConditionalPosition(Double.parseDouble(entry[7])); | |
| 50 call.setDyadMean(Double.parseDouble(entry[8])); | |
| 51 call.setValue(Double.parseDouble(entry[9])); | |
| 52 | |
| 53 return call; | |
| 54 } | |
| 55 | |
| 56 @Override | |
| 57 public String toString() { | |
| 58 return chr+"\t"+start+"\t"+stop+"\t"+length()+"\t"+lengthStdev+"\t"+dyad+"\t"+dyadStdev+"\t"+conditionalPosition+"\t"+dyadMean+"\t"+occupancy(); | |
| 59 } | |
| 60 | |
| 61 /** | |
| 62 * @return the dyad | |
| 63 */ | |
| 64 public int getDyad() { | |
| 65 return dyad; | |
| 66 } | |
| 67 | |
| 68 /** | |
| 69 * @param dyad the dyad to set | |
| 70 */ | |
| 71 public void setDyad(int dyad) { | |
| 72 this.dyad = dyad; | |
| 73 } | |
| 74 | |
| 75 /** | |
| 76 * @return the dyadStdev | |
| 77 */ | |
| 78 public double getDyadStdev() { | |
| 79 return dyadStdev; | |
| 80 } | |
| 81 | |
| 82 /** | |
| 83 * @param dyadStdev the dyadStdev to set | |
| 84 */ | |
| 85 public void setDyadStdev(double dyadStdev) { | |
| 86 this.dyadStdev = dyadStdev; | |
| 87 } | |
| 88 | |
| 89 /** | |
| 90 * @return the dyadMean | |
| 91 */ | |
| 92 public double getDyadMean() { | |
| 93 return dyadMean; | |
| 94 } | |
| 95 | |
| 96 /** | |
| 97 * @param dyadMean the dyadMean to set | |
| 98 */ | |
| 99 public void setDyadMean(double dyadMean) { | |
| 100 this.dyadMean = dyadMean; | |
| 101 } | |
| 102 | |
| 103 /** | |
| 104 * @return the conditionalPosition | |
| 105 */ | |
| 106 public double getConditionalPosition() { | |
| 107 return conditionalPosition; | |
| 108 } | |
| 109 | |
| 110 /** | |
| 111 * @param conditionalPosition the conditionalPosition to set | |
| 112 */ | |
| 113 public void setConditionalPosition(double conditionalPosition) { | |
| 114 this.conditionalPosition = conditionalPosition; | |
| 115 } | |
| 116 | |
| 117 /** | |
| 118 * @return the length | |
| 119 */ | |
| 120 public int getLength() { | |
| 121 return length; | |
| 122 } | |
| 123 | |
| 124 /** | |
| 125 * @param length the length to set | |
| 126 */ | |
| 127 public void setLength(int length) { | |
| 128 this.length = length; | |
| 129 } | |
| 130 | |
| 131 /** | |
| 132 * @return the lengthStdev | |
| 133 */ | |
| 134 public double getLengthStdev() { | |
| 135 return lengthStdev; | |
| 136 } | |
| 137 | |
| 138 /** | |
| 139 * @param lengthStdev the lengthStdev to set | |
| 140 */ | |
| 141 public void setLengthStdev(double lengthStdev) { | |
| 142 this.lengthStdev = lengthStdev; | |
| 143 } | |
| 144 | |
| 145 public double occupancy() { | |
| 146 return value; | |
| 147 } | |
| 148 | |
| 149 public void setOccupancy(double value) { | |
| 150 this.value = value; | |
| 151 } | |
| 152 | |
| 153 @Override | |
| 154 public int compareTo(NucleosomeCall o) { | |
| 155 DyadComparator comparator = new DyadComparator(); | |
| 156 return comparator.compare(this, o); | |
| 157 } | |
| 158 | |
| 159 public static class DyadComparator implements Comparator<NucleosomeCall> { | |
| 160 | |
| 161 @Override | |
| 162 public int compare(NucleosomeCall o1, NucleosomeCall o2) { | |
| 163 if (o1.getDyad() == o2.getDyad()) { | |
| 164 return 0; | |
| 165 } else if (o1.getDyad() < o2.getDyad()) { | |
| 166 return -1; | |
| 167 } else { | |
| 168 return 1; | |
| 169 } | |
| 170 } | |
| 171 | |
| 172 } | |
| 173 | |
| 174 } |
