Skip to content

Commit

Permalink
Merge branch 'master' of github.com:VEuPathDB/ApiCommonWebsite
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanrdoherty committed Dec 6, 2023
2 parents cd7bea4 + 965573f commit 54795c9
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,26 @@ public List<List<String>> getRecordAsBedFields(RecordInstance record) throws Wdk
int featureEnd = Integer.valueOf(m.group(3));

StrandDirection strand = StrandDirection.fromSign(m.group(4));
if(_reverseAndComplement) {
strand = strand.opposite();
}

int fivePrimeUtrLength = integerValueWithZeroForEmpty(record, ATTR_FIVE_PRIME_UTR_LENGTH);
int threePrimeUtrLength = integerValueWithZeroForEmpty(record, ATTR_THREE_PRIME_UTR_LENGTH);

Integer segmentStart = getPositionGenomic(featureStart, featureEnd, _upstreamOffset, _upstreamSign, _upstreamAnchor, fivePrimeUtrLength, threePrimeUtrLength);
Integer segmentEnd = getPositionGenomic(featureStart, featureEnd, _downstreamOffset, _downstreamSign, _downstreamAnchor, fivePrimeUtrLength, threePrimeUtrLength);
Integer upstreamPosition = getPositionGenomic(featureStart, featureEnd, _upstreamOffset, _upstreamSign, _upstreamAnchor, fivePrimeUtrLength, threePrimeUtrLength, strand);
Integer downstreamPosition = getPositionGenomic(featureStart, featureEnd, _downstreamOffset, _downstreamSign, _downstreamAnchor, fivePrimeUtrLength, threePrimeUtrLength, strand);

Integer segmentStart = upstreamPosition;
Integer segmentEnd = downstreamPosition;
if(strand.getSign().equals("-")) {
segmentStart = downstreamPosition;
segmentEnd = upstreamPosition;
}

DeflineBuilder defline = new DeflineBuilder(featureId);

if(_reverseAndComplement) {
strand = strand.opposite();
}

if(_requestedDeflineFields.contains("organism")){
defline.appendRecordAttribute(record, ATTR_ORGANISM);
}
Expand Down Expand Up @@ -132,18 +141,35 @@ private Matcher matchLocationCoords(RecordInstance record, String key, Pattern p
private static int getPositionGenomic(
Integer featureStart, Integer featureEnd,
int offset, OffsetSign sign, Anchor anchor,
int fivePrimeUtrLength, int threePrimeUtrLength
int fivePrimeUtrLength, int threePrimeUtrLength,
StrandDirection strand
) throws WdkModelException{
if (sign == OffsetSign.minus) {
offset = - offset;
}
switch(anchor) {
case Start: return featureStart + offset;
case CodeStart: return featureStart + fivePrimeUtrLength + offset;
case End: return featureEnd + offset;
case CodeEnd: return featureEnd - threePrimeUtrLength + offset;
default: throw new WdkModelException("Unsupported anchor type: " + anchor);
}

if(strand.getSign().equals("-")) {

if (sign == OffsetSign.plus) {
offset = - offset;
}
switch(anchor) {
case Start: return featureEnd + offset;
case CodeStart: return featureEnd - fivePrimeUtrLength + offset;
case End: return featureStart + offset;
case CodeEnd: return featureStart + threePrimeUtrLength + offset;
default: throw new WdkModelException("Unsupported anchor type: " + anchor);
}
}
else {
if (sign == OffsetSign.minus) {
offset = - offset;
}
switch(anchor) {
case Start: return featureStart + offset;
case CodeStart: return featureStart + fivePrimeUtrLength + offset;
case End: return featureEnd + offset;
case CodeEnd: return featureEnd - threePrimeUtrLength + offset;
default: throw new WdkModelException("Unsupported anchor type: " + anchor);
}
}
}

private static String getPositionDescGenomic(int offset, OffsetSign sign, Anchor anchor) throws WdkModelException{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.apidb.apicommon.model.report.bed.util;

import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
Expand Down Expand Up @@ -30,6 +31,12 @@ public static List<String> bed6(String featureId, Integer start, Integer end, De


public static List<String> bed12(String featureId, DeflineBuilder defline, StrandDirection strand, List<Integer> subfeatureStarts, List<Integer> subfeatureEnds){

if(strand.getSign().equals("-")) {
Collections.reverse(subfeatureStarts);
Collections.reverse(subfeatureEnds);
}

Integer start = Collections.min(subfeatureStarts);
Integer end = Collections.max(subfeatureEnds);

Expand All @@ -44,9 +51,10 @@ public static List<String> bed12(String featureId, DeflineBuilder defline, Stran
.collect(Collectors.joining(","));

String blockStartsStr =
IntStream.range(0, numBlocks)
.mapToObj(i -> Integer.valueOf(subfeatureStarts.get(i) - start).toString())
.collect(Collectors.joining(","));
IntStream.range(0, numBlocks)
.mapToObj(i -> Integer.valueOf(subfeatureStarts.get(i) - start).toString())
.collect(Collectors.joining(","));


Integer zeroBasedStart = locationToZeroBased(start);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ private Optional<String> getBulkSubfeatureSql(String feature,
private static void appendAttributes(JSONObject json, ResultSet rs) throws SQLException {
String attrsStr = rs.getString("ATTS");
if (rs.wasNull()) return;
String attrs[] = attrsStr.split(";");
String attrs[] = attrsStr.split(";;");
for (int i = 0; i < attrs.length; i++) {
String attr[] = attrs[i].split("=");
if (attr.length > 1) {
Expand Down Expand Up @@ -499,7 +499,7 @@ private Optional<String> getSequenceId(String idColName, String attrsTableName,
private static String replaceSqlMacros(String sql, String start, String end, String seqId, Map<String, String> qp) {
sql = sql.replaceAll("\\$base_start", start);
sql = sql.replaceAll("\\$rend", end);
sql = sql.replaceAll("\\$dlm",";");
sql = sql.replaceAll("\\$dlm",";;");
sql = sql.replaceAll("\\$srcfeature_id", seqId);

// skip query params we know are used for "control" purposes (not SQL macros)
Expand Down
6 changes: 3 additions & 3 deletions Site/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@


"@veupathdb/genomics-site@^1.0.49":
version "1.0.87"
resolved "https://registry.yarnpkg.com/@veupathdb/genomics-site/-/genomics-site-1.0.87.tgz#2a1484957a0f54054664f333e7b099317b20fa0e"
integrity sha512-q2Jc1ifh+INBsxo3SJaX/ZC1ys5BfsTfpbKbRwS1dIeANC97nkMVMaj5OHH/tDA8B1ToxCKfokiweBIVoMmqLg==
version "1.0.100"
resolved "https://registry.yarnpkg.com/@veupathdb/genomics-site/-/genomics-site-1.0.100.tgz#ebb7d5a5fcd56d069d101a3ab71797d839b89f8f"
integrity sha512-xGdEKfqMAFOfhDxoIIynU6o7cGIq7xQJri2y0g3fFJNwHnOPavJnwEIADmx81i9vwAHaCAW8GG/r1sLW8pJbLA==

0 comments on commit 54795c9

Please sign in to comment.