Skip to content

Commit

Permalink
Prepare Port Patch 2.2.2 -> 2.3.0 #TASK-7038
Browse files Browse the repository at this point in the history
  • Loading branch information
juanfeSanahuja committed Oct 8, 2024
2 parents 7a6518c + 80903ca commit 48d12b5
Show file tree
Hide file tree
Showing 10 changed files with 888 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pull-request-approved.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
chmod +x ./.github/workflows/scripts/get-xetabase-branch.sh
echo "github.event.pull_request.base.ref: ${{ github.event.pull_request.base.ref }}"
echo "github.event.pull_request.head.ref: ${{ github.event.pull_request.head.ref }}"
xetabase_branch=$(./.github/workflows/scripts/get-xetabase-branch.sh ${{ github.event.pull_request.head.ref }})
xetabase_branch=$(./.github/workflows/scripts/get-xetabase-branch.sh ${{ github.event.pull_request.base.ref }})
echo "__Xetabase ref:__ \"${xetabase_branch}\"" | tee -a ${GITHUB_STEP_SUMMARY}
echo "xetabase_branch=${xetabase_branch}" >> $GITHUB_OUTPUT
env:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/scripts/get-xetabase-branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ get_xetabase_branch() {
return 0
fi

# Check if the branch name starts with "release-" and follows the patterns "release-a.b.x" or "release-a.b.c.x"
if [[ "$input_branch" =~ ^release-([0-9]+)\.([0-9]+)\.x$ ]] || [[ "$input_branch" =~ ^release-([0-9]+)\.([0-9]+)\.([0-9]+)\.x$ ]]; then
# Check if the branch name starts with "release-" and follows the patterns "release-a.x.x" or "release-a.b.x"
if [[ "$input_branch" =~ ^release-([0-9]+)\.x\.x$ ]] || [[ "$input_branch" =~ ^release-([0-9]+)\.([0-9]+)\.x$ ]]; then
# Extract the MAJOR part of the branch name
MAJOR=${BASH_REMATCH[1]}
# Calculate the XETABASE_MAJOR by subtracting 3 from MAJOR
# Calculate the XETABASE_MAJOR by subtracting 1 from MAJOR
XETABASE_MAJOR=$((MAJOR - 1))
# Check if the XETABASE_MAJOR is negative
if (( XETABASE_MAJOR < 0 )); then
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright 2015-2020 OpenCB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.opencb.biodata.formats.variant;

import org.opencb.biodata.models.variant.avro.AlleleOrigin;

import java.util.HashMap;
import java.util.Map;

/**
* Created by fjlopez on 22/06/15.
*/
public class VariantAnnotationUtils {

private static final Map<String, AlleleOrigin> ORIGIN_STRING_TO_ALLELE_ORIGIN = new HashMap<>();
private static final Map<Character, Character> COMPLEMENTARY_NT = new HashMap<>();

static {

///////////////////////////////////////////////////////////////////////
///// ClinVar and Cosmic allele origins to SO terms ///////////////
///////////////////////////////////////////////////////////////////////
ORIGIN_STRING_TO_ALLELE_ORIGIN.put("germline", AlleleOrigin.germline_variant);
ORIGIN_STRING_TO_ALLELE_ORIGIN.put("maternal", AlleleOrigin.maternal_variant);
ORIGIN_STRING_TO_ALLELE_ORIGIN.put("de novo", AlleleOrigin.de_novo_variant);
ORIGIN_STRING_TO_ALLELE_ORIGIN.put("paternal", AlleleOrigin.paternal_variant);
ORIGIN_STRING_TO_ALLELE_ORIGIN.put("somatic", AlleleOrigin.somatic_variant);

COMPLEMENTARY_NT.put('A', 'T');
COMPLEMENTARY_NT.put('a', 't');
COMPLEMENTARY_NT.put('C', 'G');
COMPLEMENTARY_NT.put('c', 'g');
COMPLEMENTARY_NT.put('G', 'C');
COMPLEMENTARY_NT.put('g', 'c');
COMPLEMENTARY_NT.put('T', 'A');
COMPLEMENTARY_NT.put('t', 'a');
COMPLEMENTARY_NT.put('N', 'N');
COMPLEMENTARY_NT.put('n', 'n');
}

public static String reverseComplement(String string) {
return reverseComplement(string, false);
}

public static String reverseComplement(String string, boolean failOnUnknownNt) {
StringBuilder stringBuilder = new StringBuilder(string).reverse();
for (int i = 0; i < stringBuilder.length(); i++) {
char nextNt = stringBuilder.charAt(i);
// Protection against weird characters, e.g. alternate:"TBS" found in ClinVar
if (VariantAnnotationUtils.COMPLEMENTARY_NT.containsKey(nextNt)) {
stringBuilder.setCharAt(i, VariantAnnotationUtils.COMPLEMENTARY_NT.get(nextNt));
} else {
if (failOnUnknownNt) {
throw new IllegalArgumentException("Unknown nucleotide: '" + nextNt+ "'. "
+ "Unable to reverse-complement sequence '" + string + "'.");
} else {
return null;
}
}
}
return stringBuilder.toString();
}

public static AlleleOrigin parseAlleleOrigin(String alleleOrigin) {
return ORIGIN_STRING_TO_ALLELE_ORIGIN.get(alleleOrigin);
}

}
Loading

0 comments on commit 48d12b5

Please sign in to comment.