code stringlengths 73 34.1k | label stringclasses 1 value |
|---|---|
public static Class getGenericClassFromParent(Object parent) {
return (Class) ((ParameterizedType) parent.getClass().getGenericSuperclass()).getActualTypeArguments()[0];
} | java |
public static String formatDouble(final Double amount, String pattern) {
if (pattern == null || pattern.equals("")) {
pattern = JKFormatUtil.DEFAULT_DOUBLE_FORMAT;
}
return JKFormatUtil.getNumberFormatter(pattern).format(amount);
} | java |
public synchronized static String formatTime(final Time object, String pattern) {
if (pattern == null || pattern.equals("")) {
pattern = JKFormatUtil.DEFAULT_TIME_PATTERN;
}
return JKFormatUtil.getDateFormatter(pattern).format(object);
} | java |
public synchronized static String formatTimeStamp(final Timestamp date, String pattern) {
if (pattern == null || pattern.equals("")) {
pattern = JKFormatUtil.DEFAULT_TIMESTAMP_PATTERN;
}
return JKFormatUtil.getDateFormatter(pattern).format(date);
} | java |
public static Format getDateFormatter(final String pattern) {
Format format = JKFormatUtil.formatMap.get(pattern);
if (format == null) {
format = new SimpleDateFormat(pattern);
JKFormatUtil.formatMap.put(pattern, format);
}
return format;
} | java |
public static Format getNumberFormatter(final String pattern) {
Format format = JKFormatUtil.formatMap.get(pattern);
if (format == null) {
format = new DecimalFormat(pattern);
JKFormatUtil.formatMap.put(pattern, format);
}
return format;
} | java |
public static String formatNumber(Number count) {
Format numberFormatter = getNumberFormatter(DEFAULT_NUMBER_FORMAT);
return numberFormatter.format(count);
} | java |
public static java.util.Date parseDate(String strDate, String pattern) {
try {
SimpleDateFormat parser = new SimpleDateFormat(pattern, Locale.US);
return parser.parse(strDate);
} catch (ParseException e) {
throw new JKException(e);
}
} | java |
public static int getYearFromData(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
return cal.get(Calendar.YEAR);
} | java |
public static boolean isTimesEqaualed(Date time1, Date time2) {
return formatTime(time1).equals(formatTime(time2));
} | java |
public static int getNumOfMonths(Date date1, Date date2) {
Calendar firstDate = Calendar.getInstance();
Date date = new Date(date1.getTime());
firstDate.setTime(date);
Calendar secondDate = Calendar.getInstance();
Date date3 = new Date(date2.getTime());
secondDate.setTime(date3);
int months = firstDate.get(Calendar.MONTH) - secondDate.get(Calendar.MONTH);
return months;
} | java |
public static CompareDates compareTwoDates(Date date1, Date date2) {
Date d1 = new Date(date1.getTime());// to unify the format of the dates
// before the compare
Date d2 = new Date(date2.getTime());
if (d1.compareTo(d2) < 0)
return CompareDates.DATE1_LESS_THAN_DATE2;
else if (d1.compareTo(d2) > 0)
return CompareDates.DATE1_GREATER_THAN_DATE2;
else
return CompareDates.DATE1_EQUAL_DATE2;
} | java |
public static Date adddDaysToCurrentDate(int numberOfDays) {
Date date = new Date();
Calendar instance = Calendar.getInstance();
instance.setTime(date);
instance.add(Calendar.DATE, numberOfDays);
return instance.getTime();
} | java |
public static boolean isDate(String strDate, String pattern) {
try {
parseDate(strDate, pattern);
return true;
} catch (Exception e) {
return false;
}
} | java |
public static Date addMonths(Date date, int numOfMonths) {
Calendar instance = Calendar.getInstance();
instance.setTime(date);
instance.add(Calendar.MONTH, numOfMonths);
return instance.getTime();
} | java |
public static long getDifference(Time timeFrom, Time timeTo) {
try {
DateFormat format = new SimpleDateFormat("HH:mm:ss");
// the a means am/pm marker
Date date = format.parse(timeFrom.toString());
Date date2 = format.parse(timeTo.toString());
long difference = (date2.getTime() - date.getTime()) / 1000 / 60;
return difference;
} catch (Exception e) {
throw new RuntimeException(e);
}
} | java |
private static int getDayOfMonth(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
return cal.get(Calendar.DAY_OF_MONTH);
} | java |
public static int getDayOfWeek(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
return cal.get(Calendar.DAY_OF_WEEK);
} | java |
public static int getHour(Date timeFrom) {
Calendar instance = Calendar.getInstance();
instance.setTime(timeFrom);
int hour = instance.get(Calendar.HOUR);
return hour;
} | java |
public static boolean isCurrentTimeBetweenTowTimes(Date fromDate, Date fromTime, Date toDate, Date timeTo) {
JKTimeObject currntTime = getCurrntTime();
JKTimeObject fromTimeObject = new JKTimeObject();
JKTimeObject toTimeObject = new JKTimeObject();
if (currntTime.after(fromTimeObject.toTimeObject(fromDate, fromTime)) && currntTime.before(toTimeObject.toTimeObject(toDate, timeTo))) {
return true;
}
return false;
} | java |
public static long getDayDifference(Date startDate, Date endDate) {
long startTime = startDate.getTime();
long endTime = endDate.getTime();
long diffTime = endTime - startTime;
long diffDays = TimeUnit.MILLISECONDS.toDays(diffTime);
return diffDays;
} | java |
public static long getSecondsDifference(Date startDate, Date endDate) {
long startTime = startDate.getTime();
long endTime = endDate.getTime();
long diffTime = endTime - startTime;
long diffInSeconds = TimeUnit.MILLISECONDS.toSeconds(diffTime);
return diffInSeconds;
} | java |
public static long getHoursDifference(Date startDate, Date endDate) {
long startTime = startDate.getTime();
long endTime = endDate.getTime();
long diffTime = endTime - startTime;
long diffInHours = TimeUnit.MILLISECONDS.toHours(diffTime);
return diffInHours;
} | java |
public static long getMillisDifference(Date startDate, Date endDate) {
long startTime = startDate.getTime();
long endTime = endDate.getTime();
long diffTime = endTime - startTime;
return diffTime;
} | java |
public static long getMinutesDifference(Date startDate, Date endDate) {
long startTime = startDate.getTime();
long endTime = endDate.getTime();
long diffTime = endTime - startTime;
long diffInMinutes = TimeUnit.MILLISECONDS.toMinutes(diffTime);
return diffInMinutes;
} | java |
public static boolean isDateEqaualed(final java.util.Date date1, final java.util.Date date2) {
final String d1 = JKFormatUtil.formatDate(date1, JKFormatUtil.MYSQL_DATE_DB_PATTERN);
final String d2 = JKFormatUtil.formatDate(date2, JKFormatUtil.MYSQL_DATE_DB_PATTERN);
return d1.equalsIgnoreCase(d2);
} | java |
public static boolean isPeriodActive(final Date startDate, final Date endDate) {
if (startDate == null && endDate == null) {
return true;
}
if (startDate == null) {
throw new JKException("START_DATE_CAN_NOT_BE_NULL");
}
if (endDate == null) {
throw new JKException("END_DATE_CAN_NOT_BE_NULL");
}
if (compareTwoDates(startDate, endDate).equals(CompareDates.DATE1_GREATER_THAN_DATE2)) {
throw new JKException("START_DATE_MUST_BE_BEFORE_END_DATE");
}
final boolean startLessThanCurrent = compareTwoDates(startDate, getSystemDate()).equals(CompareDates.DATE1_LESS_THAN_DATE2);
final boolean endGreaterThanCurrent = compareTwoDates(endDate, getSystemDate()).equals(CompareDates.DATE1_GREATER_THAN_DATE2);
return startLessThanCurrent && endGreaterThanCurrent;
} | java |
private static List<AbstractMolecule> buildMolecule(HELM2Notation helm2notation) throws BuilderMoleculeException, ChemistryException {
return BuilderMolecule.buildMoleculefromPolymers(helm2notation.getListOfPolymers(), HELM2NotationUtils.getAllEdgeConnections(helm2notation.getListOfConnections()));
} | java |
public static double getMolecularWeight(HELM2Notation helm2notation) throws BuilderMoleculeException, CTKException, ChemistryException {
/* First build one big molecule; List of molecules? */
List<AbstractMolecule> molecules = buildMolecule(helm2notation);
return calculateMolecularWeight(molecules);
} | java |
private static double calculateMolecularWeight(List<AbstractMolecule> molecules) throws BuilderMoleculeException, CTKException, ChemistryException {
Double result = 0.0;
for (AbstractMolecule molecule : molecules) {
molecule = BuilderMolecule.mergeRgroups(molecule);
result += Chemistry.getInstance().getManipulator().getMoleculeInfo(molecule).getMolecularWeight();
}
return result;
} | java |
public static double getExactMass(HELM2Notation helm2notation) throws BuilderMoleculeException, CTKException, ChemistryException {
/* First build one big molecule; List of molecules */
List<AbstractMolecule> molecules = buildMolecule(helm2notation);
return calculateExactMass(molecules);
} | java |
private static double calculateExactMass(List<AbstractMolecule> molecules) throws CTKException, ChemistryException, BuilderMoleculeException {
Double result = 0.0;
for (AbstractMolecule molecule : molecules) {
molecule = BuilderMolecule.mergeRgroups(molecule);
result += Chemistry.getInstance().getManipulator().getMoleculeInfo(molecule).getExactMass();
}
return result;
} | java |
public static String getMolecularFormular(HELM2Notation helm2notation) throws BuilderMoleculeException, CTKException, ChemistryException {
/* First build HELM molecule */
List<AbstractMolecule> molecules = buildMolecule(helm2notation);
LOG.info("Build process is finished");
return calculateMolecularFormula(molecules);
} | java |
private static String calculateMolecularFormula(List<AbstractMolecule> molecules) throws BuilderMoleculeException, CTKException, ChemistryException {
Map<String, Integer> atomNumberMap = new TreeMap<String, Integer>();
for (AbstractMolecule molecule : molecules) {
LOG.info(molecule.getMolecule().toString());
atomNumberMap = generateAtomNumberMap(molecule, atomNumberMap);
}
LOG.info("GET map");
StringBuilder sb = new StringBuilder();
Set<String> atoms = atomNumberMap.keySet();
for (Iterator<String> i = atoms.iterator(); i.hasNext();) {
String atom = i.next();
String num = atomNumberMap.get(atom).toString();
if (num.equals("1")) {
num = "";
}
sb.append(atom);
sb.append(num.toString());
}
return sb.toString();
} | java |
public static MoleculeProperty getMoleculeProperties(HELM2Notation helm2notation) throws BuilderMoleculeException, CTKException, ExtinctionCoefficientException, ChemistryException {
MoleculeProperty result = new MoleculeProperty();
/* First build HELM molecule */
List<AbstractMolecule> molecules = buildMolecule(helm2notation);
/* calculate molecular formula */
result.setMolecularFormula(calculateMolecularFormula(molecules));
/* calculate molecular weight */
result.setMolecularWeight(calculateMolecularWeight(molecules));
/* calculate exact mass */
result.setExactMass(calculateExactMass(molecules));
/* add Extinction Coefficient calculation to it */
result.setExtinctionCoefficient(ExtinctionCoefficient.getInstance().calculate(helm2notation));
return result;
} | java |
private static Map<String, Integer> generateAtomNumberMap(AbstractMolecule molecule, Map<String, Integer> mapAtoms) throws BuilderMoleculeException, CTKException, ChemistryException {
molecule = BuilderMolecule.mergeRgroups(molecule);
LOG.info("Merge group is finished");
String formula = Chemistry.getInstance().getManipulator().getMoleculeInfo(molecule).getMolecularFormula();
String atom = "";
String number = "";
for (int i = 0; i < formula.length(); i++) {
String oneChar = String.valueOf(formula.charAt(i));
if (oneChar.matches("[A-Z]")) {
if (atom.length() == 0) {
atom = oneChar;
} else {
if (number == "") {
number = "1";
}
if (mapAtoms.get(atom) != null) {
mapAtoms.put(atom, mapAtoms.get(atom) + Integer.valueOf(number));
} else {
mapAtoms.put(atom, Integer.valueOf(number));
}
atom = oneChar;
number = "";
}
} else if (oneChar.matches("[a-z]")) {
if (atom.length() > 0) {
atom = atom + oneChar;
}
} else {
if (number.length() == 0) {
number = oneChar;
} else {
number = number + oneChar;
}
}
}
if (number == "") {
number = "1";
}
if (mapAtoms.get(atom) != null) {
mapAtoms.put(atom, mapAtoms.get(atom) + Integer.valueOf(number));
} else {
mapAtoms.put(atom, Integer.valueOf(number));
}
return mapAtoms;
} | java |
public void switchOff(BitSet switchGroupAddress, int switchCode) {
if (switchGroupAddress.length() > 5) {
throw new IllegalArgumentException("switch group address has more than 5 bits!");
}
this.sendTriState(this.getCodeWordA(switchGroupAddress, switchCode, false));
} | java |
public void send(final String bitString) {
BitSet bitSet = new BitSet(bitString.length());
for (int i = 0; i < bitString.length(); i++) {
if (bitString.charAt(i) == '1') {
bitSet.set(i);
}
}
send(bitSet, bitString.length());
} | java |
public void send(final BitSet bitSet, int length) {
if (transmitterPin != null) {
for (int nRepeat = 0; nRepeat < repeatTransmit; nRepeat++) {
for (int i = 0; i < length; i++) {
if (bitSet.get(i)) {
transmit(protocol.getOneBit());
} else {
transmit(protocol.getZeroBit());
}
}
sendSync();
}
transmitterPin.low();
}
} | java |
public void sendTriState(String codeWord) {
if (transmitterPin != null) {
for (int nRepeat = 0; nRepeat < repeatTransmit; nRepeat++) {
for (int i = 0; i < codeWord.length(); ++i) {
switch (codeWord.charAt(i)) {
case '0':
this.sendT0();
break;
case 'F':
this.sendTF();
break;
case '1':
this.sendT1();
break;
}
}
this.sendSync();
}
transmitterPin.low();
}
} | java |
public static BitSet getSwitchGroupAddress(String address) {
if (address.length() != 5) {
throw new IllegalArgumentException("the switchGroupAddress must consist of exactly 5 bits!");
}
BitSet bitSet = new BitSet(5);
for (int i = 0; i < 5; i++) {
bitSet.set(i, address.charAt(i) == '1');
}
return bitSet;
} | java |
public static boolean start(RootDoc root) throws Exception {
umlProject = null;
mainGui = null;
Standard.start(root);
setOptions(root);
openOrCreateUmlProject(root);
generateUml(root);
return true;
} | java |
public static int optionLength(String option) {
int result = Standard.optionLength(option);
if(result == 0) {
if(option.equals(OPTION_PATH_UML_PROJECT)) {
result = 2;
}
}
return result;
} | java |
public final void add(final String problem, final Severity severity) {
this.problems.add(new Problem(problem, severity));
this.hasFatal |= severity == Severity.FATAL;
} | java |
public final Problem getLeadProblem() {
Collections.sort(this.problems);
return this.problems.isEmpty() ? null : this.problems.get(this.problems.size() - 1);
} | java |
public String toMutilLineString() {
final String newLine = System.getProperty("line.separator");
final StringBuffer problemStr = new StringBuffer();
for (final Problem problem : this.problems) {
problemStr.append(problem.getMessage() + newLine);
}
return problemStr.toString();
} | java |
public static int getTotalMonomerCount(PolymerNotation polymer) {
int count = 0;
for (MonomerNotation element : polymer.getPolymerElements().getListOfElements()) {
count += getMonomerCountFromMonomerNotation(element);
}
return count;
} | java |
private static int getMonomerCountFromMonomerNotation(MonomerNotation monomerNotation) {
int multiply;
try {
multiply = Integer.parseInt(monomerNotation.getCount());
if (multiply < 1) {
multiply = 1;
}
} catch (NumberFormatException e) {
multiply = 1;
}
if (monomerNotation instanceof MonomerNotationGroup) {
return 1 * multiply;
}
if (monomerNotation instanceof MonomerNotationList) {
int count = 0;
for (MonomerNotation unit : ((MonomerNotationList) monomerNotation).getListofMonomerUnits()) {
count += getMonomerCountFromMonomerNotation(unit);
}
return count * multiply;
}
if (monomerNotation instanceof MonomerNotationUnitRNA) {
int count = 0;
for (MonomerNotationUnit unit : ((MonomerNotationUnitRNA) monomerNotation).getContents()) {
count += getMonomerCountFromMonomerNotation(unit);
}
return count * multiply;
}
return 1 * multiply;
} | java |
public String nextGroup() {
int currentPosition = this.position;
do {
char currentCharacter = this.characters[currentPosition];
if (currentCharacter == '[') {
currentPosition = NucleotideParser.getMatchingBracketPosition(this.characters, currentPosition, '[', ']');
} else if (currentCharacter == '(') {
currentPosition = NucleotideParser.getMatchingBracketPosition(this.characters, currentPosition, '(', ')');
} else if (currentCharacter != '.') {
currentPosition++;
}
if (currentPosition < 0) {
currentPosition = this.characters.length;
}
} while ((currentPosition < this.characters.length)
&& (this.characters[currentPosition] != '.'));
String token = this.notationString.substring(this.position, currentPosition);
this.position = currentPosition + 1;
return token;
} | java |
public final static String toJSON(HELM2Notation helm2notation) throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
String jsonINString = mapper.writeValueAsString(helm2notation);
jsonINString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(helm2notation);
return jsonINString;
} | java |
public final static List<ConnectionNotation> getAllEdgeConnections(List<ConnectionNotation> connections) {
List<ConnectionNotation> listEdgeConnection = new ArrayList<ConnectionNotation>();
for (ConnectionNotation connection : connections) {
if (!(connection.getrGroupSource().equals("pair"))) {
listEdgeConnection.add(connection);
}
}
return listEdgeConnection;
} | java |
public final static List<PolymerNotation> getRNAPolymers(List<PolymerNotation> polymers) {
List<PolymerNotation> rnaPolymers = new ArrayList<PolymerNotation>();
for (PolymerNotation polymer : polymers) {
if (polymer.getPolymerID() instanceof RNAEntity) {
rnaPolymers.add(polymer);
}
}
return rnaPolymers;
} | java |
public final static List<PolymerNotation> getPeptidePolymers(List<PolymerNotation> polymers) {
List<PolymerNotation> peptidePolymers = new ArrayList<PolymerNotation>();
for (PolymerNotation polymer : polymers) {
if (polymer.getPolymerID() instanceof PeptideEntity) {
peptidePolymers.add(polymer);
}
}
return peptidePolymers;
} | java |
public final static List<PolymerNotation> getCHEMPolymers(List<PolymerNotation> polymers) {
List<PolymerNotation> chemPolymers = new ArrayList<PolymerNotation>();
for (PolymerNotation polymer : polymers) {
if (polymer.getPolymerID() instanceof ChemEntity) {
chemPolymers.add(polymer);
}
}
return chemPolymers;
} | java |
public final static List<PolymerNotation> getBLOBPolymers(List<PolymerNotation> polymers) {
List<PolymerNotation> blobPolymers = new ArrayList<PolymerNotation>();
for (PolymerNotation polymer : polymers) {
if (polymer.getPolymerID() instanceof BlobEntity) {
blobPolymers.add(polymer);
}
}
return blobPolymers;
} | java |
public final static void combineHELM2notation(HELM2Notation helm2notation, HELM2Notation newHELM2Notation) throws NotationException {
HELM2NotationUtils.helm2notation = helm2notation;
Map<String, String> mapIds = generateMapChangeIds(newHELM2Notation.getPolymerAndGroupingIDs());
/* method to merge the new HELM2Notation into the existing one */
/* section 1 */
/* id's have to changed */
section1(newHELM2Notation.getListOfPolymers(), mapIds);
/* section 2 */
section2(newHELM2Notation.getListOfConnections(), mapIds);
/* section 3 */
section3(newHELM2Notation.getListOfGroupings(), mapIds);
/* section 4 */
section4(newHELM2Notation.getListOfAnnotations(), mapIds);
} | java |
private static Map<String, String> generateMapChangeIds(List<String> newIDs) {
Map<String, String> mapIds = new HashMap<String, String>();
List<String> oldIds = HELM2NotationUtils.helm2notation.getPolymerAndGroupingIDs();
Map<String, String> mapOldIds = new HashMap<String, String>();
for (String oldID : oldIds) {
mapOldIds.put(oldID, "");
}
for (String newId : newIDs) {
if (mapOldIds.containsKey(newId)) {
int i = 1;
String type = newId.split("\\d")[0];
while (mapOldIds.containsKey(type + i)) {
i++;
}
mapIds.put(newId, type + i);
}
}
return mapIds;
} | java |
private static void section1(List<PolymerNotation> polymers, Map<String, String> mapIds) throws NotationException {
for (PolymerNotation polymer : polymers) {
if (mapIds.containsKey(polymer.getPolymerID().getId())) {
/* change id */
PolymerNotation newpolymer = new PolymerNotation(mapIds.get(polymer.getPolymerID().getId()));
newpolymer = new PolymerNotation(newpolymer.getPolymerID(), polymer.getPolymerElements());
helm2notation.addPolymer(newpolymer);
} else {
helm2notation.addPolymer(polymer);
}
}
} | java |
private static void section2(List<ConnectionNotation> connections, Map<String, String> mapIds) throws NotationException {
for (ConnectionNotation connection : connections) {
HELMEntity first = connection.getSourceId();
String idFirst = first.getId();
HELMEntity second = connection.getTargetId();
String idSecond = second.getId();
if (mapIds.containsKey(idFirst)) {
first = new ConnectionNotation(mapIds.get(idFirst)).getSourceId();
}
if (mapIds.containsKey(idSecond)) {
second = new ConnectionNotation(mapIds.get(idSecond)).getSourceId();
}
ConnectionNotation newConnection = new ConnectionNotation(first, second, connection.getSourceUnit(), connection.getrGroupSource(), connection.getTargetUnit(), connection.getrGroupTarget(),
connection.getAnnotation());
helm2notation.addConnection(newConnection);
}
} | java |
private static void section3(List<GroupingNotation> groupings, Map<String, String> mapIds) throws NotationException {
for (GroupingNotation grouping : groupings) {
GroupEntity groupID = grouping.getGroupID();
if (mapIds.containsKey(groupID.getId())) {
groupID = new GroupingNotation(mapIds.get(groupID.getId())).getGroupID();
}
String details = grouping.toHELM2().split("\\(")[1].split("\\)")[0];
details = changeIDs(details, mapIds);
helm2notation.addGrouping(new GroupingNotation(groupID, details));
}
} | java |
private static void section4(List<AnnotationNotation> annotations, Map<String, String> mapIds) {
for (AnnotationNotation annotation : annotations) {
String notation = annotation.getAnnotation();
notation = changeIDs(notation, mapIds);
helm2notation.addAnnotation(new AnnotationNotation(notation));
}
} | java |
private static String changeIDs(String text, Map<String, String> mapIds) {
String result = text;
for (String key : mapIds.keySet()) {
result = result.replace(key, mapIds.get(key));
}
return result;
} | java |
public static final int getTotalMonomerCount(HELM2Notation helm2notation) {
int result = 0;
for (PolymerNotation polymer : helm2notation.getListOfPolymers()) {
result += PolymerUtils.getTotalMonomerCount(polymer);
}
return result;
} | java |
public static boolean hasNucleotideModification(List<PolymerNotation> polymers) throws NotationException {
for (PolymerNotation polymer : getRNAPolymers(polymers)) {
if (RNAUtils.hasNucleotideModification(polymer)) {
return true;
}
}
return false;
} | java |
public static String[] getFormatedSirnaSequences(HELM2Notation helm2notation) throws NotationException, RNAUtilsException, HELM2HandledException, org.helm.notation2.exception.NotationException,
ChemistryException {
return getFormatedSirnaSequences(helm2notation, DEFAULT_PADDING_CHAR, DEFAULT_BASE_PAIR_CHAR);
} | java |
private static String reverseString(String source) {
int i;
int len = source.length();
StringBuffer dest = new StringBuffer();
for (i = (len - 1); i >= 0; i--) {
dest.append(source.charAt(i));
}
return dest.toString();
} | java |
public List<HELM2Notation> decompose(HELM2Notation helm2notation) {
List<HELM2Notation> list = new ArrayList<HELM2Notation>();
List<ConnectionNotation> allselfConnections = getAllSelfCycleConnections(helm2notation.getListOfConnections());
for (PolymerNotation polymer : helm2notation.getListOfPolymers()) {
HELM2Notation single = new HELM2Notation();
single.addPolymer(polymer);
List<ConnectionNotation> selfConnections = getSelfCycleConnections(polymer.getPolymerID().getId(), allselfConnections);
for (ConnectionNotation selfConnection : selfConnections) {
single.addConnection(selfConnection);
}
list.add(single);
}
return list;
} | java |
private static List<ConnectionNotation> getAllSelfCycleConnections(List<ConnectionNotation> connections) {
List<ConnectionNotation> listSelfCycle = new ArrayList<ConnectionNotation>();
for (ConnectionNotation connection : connections) {
if ((connection.getTargetId().getId().equals(connection.getSourceId().getId()))) {
listSelfCycle.add(connection);
}
}
return listSelfCycle;
} | java |
private static List<ConnectionNotation> getSelfCycleConnections(String id, List<ConnectionNotation> connections) {
List<ConnectionNotation> list = new ArrayList<ConnectionNotation>();
for (ConnectionNotation connection : connections) {
if (connection.getSourceId().getId().equals(id)) {
list.add(connection);
}
}
return list;
} | java |
public static List<PolymerNotation> getListOfPolymersSpecificType(String str, List<PolymerNotation> polymers) {
List<PolymerNotation> list = new ArrayList<PolymerNotation>();
for (PolymerNotation polymer : polymers) {
if (polymer.getPolymerID().getType().equals(str)) {
list.add(polymer);
}
}
return list;
} | java |
public static String buildDynamicKey(final Object[] paramNames, final Object[] paramValues) {
return Arrays.toString(paramNames).concat(Arrays.toString(paramValues));
} | java |
private Map<String, String> deserializeNucleotideStore(JsonParser parser)
throws JsonParseException, IOException {
Map<String, String> nucleotides = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
String currentNucleotideSymbol = "";
String currentNucleotideNotation = "";
boolean foundSymbol = false;
boolean foundNotation = false;
parser.nextToken();
while (parser.hasCurrentToken()) {
String fieldName = parser.getCurrentName();
if (fieldName != null) {
switch (fieldName) {
case "symbol":
parser.nextToken();
currentNucleotideSymbol = parser.getText();
foundSymbol = true;
break;
case "notation":
parser.nextToken();
currentNucleotideNotation = parser.getText();
foundNotation = true;
break;
default:
break;
}
if (foundSymbol && foundNotation) {
nucleotides.put(currentNucleotideSymbol,
currentNucleotideNotation);
foundNotation = false;
foundSymbol = false;
}
}
parser.nextToken();
}
return nucleotides;
} | java |
public static void fixPropertiesKeys(final Properties prop) {
final Enumeration<Object> keys = prop.keys();
while (keys.hasMoreElements()) {
String currentKey = (String) keys.nextElement();
String fixedKey = fixPropertyKey(currentKey);
String value = prop.getProperty(currentKey);
value = fixPropertyValue(value);
prop.remove(currentKey);
prop.setProperty(fixedKey, value);
}
} | java |
public static String fixPropertyValue(String value) {
// replace with predefined varialebls
value = value.replaceAll("\\{jk.appname\\}", JK.getAppName());
return value;
} | java |
public static Object unifyReferences(final Hashtable hash, Object object) {
final Object itemAtHash = hash.get(object.hashCode());
if (itemAtHash == null) {
hash.put(object.hashCode(), object);
} else {
object = itemAtHash;
}
return object;
} | java |
public static List<Entry> sortHashTable(final Hashtable<?, ?> hash, final boolean asc) {
// Put keys and values in to an arraylist using entryset
final ArrayList<Entry> myArrayList = new ArrayList(hash.entrySet());
// Sort the values based on values first and then keys.
Collections.sort(myArrayList, new HashComparator(asc));
return myArrayList;
} | java |
public static String formatProperties(Properties properties) {
StringBuffer buf = new StringBuffer();
Set<Object> keySet = properties.keySet();
for (Object key : keySet) {
buf.append(key.toString().trim().toUpperCase().replaceAll(" ", "_"));
buf.append("=");
buf.append(properties.get(key));
buf.append(System.getProperty("line.separator"));
}
return buf.toString();
} | java |
public static String getStandard(HELM2Notation helm2notation) throws HELM1FormatException, MonomerLoadingException, CTKException, ValidationException, ChemistryException {
try {
String firstSection = setStandardHELMFirstSection(helm2notation);
List<String> ListOfSecondAndThirdSection = setStandardHELMSecondSectionAndThirdSection(helm2notation.getListOfConnections());
String fourthSection = setStandardHELMFourthSection(helm2notation.getListOfAnnotations());
return firstSection + "$" + ListOfSecondAndThirdSection.get(0) + "$" + ListOfSecondAndThirdSection.get(1) + "$" + fourthSection + "$V2.0";
} catch (HELM1ConverterException | NotationException | org.helm.notation2.parser.exceptionparser.NotationException e) {
e.printStackTrace();
throw new HELM1FormatException(e.getMessage());
}
} | java |
private static String setStandardHELMFourthSection(List<AnnotationNotation> annotations) {
StringBuilder sb = new StringBuilder();
for (AnnotationNotation annotation : annotations) {
sb.append(annotation.toHELM2() + "|");
}
if (sb.length() > 1) {
sb.setLength(sb.length() - 1);
}
return sb.toString();
} | java |
public static String getCanonical(HELM2Notation helm2notation) throws HELM1FormatException, ChemistryException {
Map<String, String> convertsortedIdstoIds;
try {
Object[] temp = setCanonicalHELMFirstSection(helm2notation);
LOG.info("First Section of canonical HELM was generated");
convertsortedIdstoIds = (Map<String, String>) temp[0];
String firstSection = (String) temp[1];
String secondSection = setCanonicalHELMSecondSection(convertsortedIdstoIds, helm2notation.getListOfConnections());
LOG.info("Second Section of canonical HELM was generated");
return firstSection + "$" + secondSection + "$" + "" + "$" + "" + "$V2.0";
} catch (ClassNotFoundException | IOException | HELM1ConverterException | ValidationException | org.helm.notation2.parser.exceptionparser.NotationException e) {
e.printStackTrace();
LOG.error("Canonical HELM 1 can not be generated due to HELM2 features");
throw new HELM1FormatException("Canonical HELM 1 can not be generated due to HELM2 features " + e.getMessage() + e.getCause());
}
} | java |
private static String setCanonicalHELMSecondSection(Map<String, String> convertsortedIdstoIds, List<ConnectionNotation> connectionNotations) throws HELM1ConverterException {
StringBuilder notation = new StringBuilder();
for (ConnectionNotation connectionNotation : connectionNotations) {
/* canonicalize connection */
/* change the id's of the polymers to the sorted ids */
List<String> connections = new ArrayList<String>();
String source = connectionNotation.getSourceId().getId();
String target = connectionNotation.getTargetId().getId();
/* pairs will be not shown */
if (!(connectionNotation.toHELM().equals(""))) {
connections.add(convertConnection(connectionNotation.toHELM(), source, target, convertsortedIdstoIds));
connections.add(convertConnection(connectionNotation.toReverseHELM(), source, target, convertsortedIdstoIds));
Collections.sort(connections);
notation.append(connections.get(0) + "|");
}
}
if (notation.length() > 1) {
notation.setLength(notation.length() - 1);
}
return notation.toString();
} | java |
private static String convertConnection(String notation, String source, String target, Map<String, String> convertIds) throws HELM1ConverterException {
try {
String test = notation.replace(source, "one");
test = test.replace(target, "two");
test = test.replace("one", convertIds.get(source));
test = test.replace("two", convertIds.get(target));
return test;
} catch (NullPointerException ex) {
ex.printStackTrace();
LOG.error("Connection can't be downgraded to HELM1-Format");
throw new HELM1ConverterException("Connection can't be downgraded to HELM1-Format");
}
} | java |
private Element getXHELMRootElement(String resource) throws JDOMException, IOException {
ByteArrayInputStream stream = new ByteArrayInputStream(resource.getBytes());
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(stream);
return doc.getRootElement();
} | java |
private void updateMonomerStore(MonomerStore monomerStore)
throws MonomerLoadingException, IOException, MonomerException, ChemistryException {
for (Monomer monomer : monomerStore.getAllMonomersList()) {
MonomerFactory.getInstance().getMonomerStore().addNewMonomer(monomer);
// save monomer db to local file after successful update //
MonomerFactory.getInstance().saveMonomerCache();
}
} | java |
private HELM2Notation readNotation(String notation)
throws ParserException, JDOMException, IOException, MonomerException, ChemistryException {
/* xhelm notation */
if (notation.contains("<Xhelm>")) {
LOG.info("xhelm is used as input");
String xhelm = notation;
Element xHELMRootElement = getXHELMRootElement(xhelm);
notation = xHelmNotationParser.getHELMNotationString(xHELMRootElement);
MonomerStore store = xHelmNotationParser.getMonomerStore(xHELMRootElement);
updateMonomerStore(store);
}
return HELM2NotationUtils.readNotation(notation);
} | java |
private HELM2Notation validate(String helm) throws ValidationException, ChemistryException {
try {
/* Read */
HELM2Notation helm2notation = readNotation(helm);
/* Validate */
LOG.info("Validation of HELM is starting");
Validation.validateNotationObjects(helm2notation);
LOG.info("Validation was successful");
return helm2notation;
} catch (MonomerException | GroupingNotationException | ConnectionNotationException | PolymerIDsException
| ParserException | JDOMException | IOException | NotationException
| org.helm.notation2.parser.exceptionparser.NotationException e) {
e.printStackTrace();
LOG.info("Validation was not successful");
LOG.error(e.getMessage());
throw new ValidationException(e.getMessage());
}
} | java |
public void validateHELM(String helm) throws ValidationException, MonomerLoadingException, ChemistryException {
validate(helm);
setMonomerFactoryToDefault(helm);
} | java |
public String convertStandardHELMToCanonicalHELM(String notation)
throws HELM1FormatException, ValidationException, MonomerLoadingException, ChemistryException {
String result = HELM1Utils.getCanonical(validate(notation));
setMonomerFactoryToDefault(notation);
return result;
} | java |
public String convertIntoStandardHELM(String notation) throws HELM1FormatException, ValidationException,
MonomerLoadingException, CTKException, ChemistryException {
String result = HELM1Utils.getStandard(validate(notation));
setMonomerFactoryToDefault(notation);
return result;
} | java |
public Float calculateExtinctionCoefficient(String notation)
throws ExtinctionCoefficientException, ValidationException, MonomerLoadingException, ChemistryException {
Float result = ExtinctionCoefficient.getInstance().calculate(validate(notation));
setMonomerFactoryToDefault(notation);
return result;
} | java |
public String generateFasta(String notation)
throws FastaFormatException, ValidationException, MonomerLoadingException, ChemistryException {
String result = FastaFormat.generateFasta(validate(notation));
setMonomerFactoryToDefault(notation);
return result;
} | java |
public Double calculateMolecularWeight(String notation) throws MonomerLoadingException, BuilderMoleculeException,
CTKException, ValidationException, ChemistryException {
Double result = MoleculePropertyCalculator.getMolecularWeight(validate(notation));
setMonomerFactoryToDefault(notation);
return result;
} | java |
public String getMolecularFormula(String notation) throws BuilderMoleculeException, CTKException,
ValidationException, MonomerLoadingException, ChemistryException {
String result = MoleculePropertyCalculator.getMolecularFormular(validate(notation));
setMonomerFactoryToDefault(notation);
return result;
} | java |
public String readPeptide(String peptide) throws FastaFormatException,
org.helm.notation2.parser.exceptionparser.NotationException, ChemistryException {
return SequenceConverter.readPeptide(peptide).toHELM2();
} | java |
public String readRNA(String rna) throws org.helm.notation2.parser.exceptionparser.NotationException,
FastaFormatException, ChemistryException, org.helm.notation2.exception.NucleotideLoadingException {
return SequenceConverter.readRNA(rna).toHELM2();
} | java |
public byte[] generateImageForHELMMolecule(String notation)
throws BuilderMoleculeException, CTKException, IOException, ValidationException, ChemistryException {
byte[] result = Images.generateImageHELMMolecule(validate(notation));
setMonomerFactoryToDefault(notation);
return result;
} | java |
public byte[] generateImageForMonomer(Monomer monomer, boolean showRgroups)
throws BuilderMoleculeException, CTKException, ChemistryException {
return Images.generateImageofMonomer(monomer, showRgroups);
} | java |
public String generateJSON(String helm)
throws ValidationException, MonomerLoadingException, ChemistryException, JsonProcessingException {
String result = HELM2NotationUtils.toJSON(validate(helm));
setMonomerFactoryToDefault(helm);
return result;
} | java |
private void setMonomerFactoryToDefault(String helm) throws MonomerLoadingException, ChemistryException {
if (helm.contains("<Xhelm>")) {
LOG.info("Refresh local Monomer Store in case of Xhelm");
MonomerFactory.refreshMonomerCache();
}
} | java |
public String generateNaturalAnalogSequencePeptide(String notation)
throws HELM2HandledException, ValidationException, MonomerLoadingException, PeptideUtilsException,
org.helm.notation2.parser.exceptionparser.NotationException, ChemistryException {
String result = SequenceConverter.getPeptideNaturalAnalogSequenceFromNotation(validate(notation));
setMonomerFactoryToDefault(notation);
return result;
} | java |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.