diff --git a/applyAllFixesForExperiment.sh b/applyAllFixesForExperiment.sh new file mode 100644 index 00000000..9f0fad9d --- /dev/null +++ b/applyAllFixesForExperiment.sh @@ -0,0 +1,80 @@ +#!/usr/bin/env bash + + +usage() { echo "Usage: $0 path-to-atlas-exps" 1>&2; } + +expAcc=$1 + +if [ -z "${expAcc}" ]; then + usage + exit 1 +fi + +scriptDir=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) + +exp=$1 +echo "Applying fixes for $exp ..." + +# Applies fixes encoded in $fixesFile to $exp.$fileTypeToBeFixed.txt +applyFixes() { + exp=$1 + fixesFile=$2 + fileTypeToBeFixed=$3 + + # Apply factor type fixes in ${fileTypeToBeFixed} file + for l in $(cat $scriptDir/$fixesFile | sed 's|[[:space:]]*$||g'); + do + if [ ! -s "$exp/$exp.${fileTypeToBeFixed}" ]; then + echo "ERROR: $exp/$exp.${fileTypeToBeFixed} not found or is empty" >&2 + return 1 + fi + echo $l | grep -P '\t' > /dev/null + if [ $? -ne 0 ]; then + echo "WARNING: line: '$l' in automatic_fixes_properties.txt is missing a tab character - not applying the fix " + fi + correct=`echo $l | awk -F"\t" '{print $1}'` + toBeReplaced=`echo $l | awk -F"\t" '{print $2}' | sed 's/[^-A-Za-z0-9_ ]/\\\&/g'` + + if [ "$fixesFile" == "automatic_fixes_properties.txt" ]; then + # in sdrf or condensed-sdrv fix factor/characteristic types only + #if [ "$fileTypeToBeFixed" == "sdrf.txt" ]; then + #perl -pi -e "s|\[${toBeReplaced}\]|[${correct}]|g" $exp/$exp.${fileTypeToBeFixed} + if [ "$fileTypeToBeFixed" == "condensed-sdrf.tsv" ]; then + # In condensed-sdrf, the factor/characteristic type is the penultimate column - so tabs on both sides + perl -pi -e "s|\t${toBeReplaced}\t|\t${correct}\t|g" $exp/$exp.${fileTypeToBeFixed} + else + # idf + perl -pi -e "s|\t${toBeReplaced}\t|\t${correct}\t|g" $exp/$exp.${fileTypeToBeFixed} + perl -pi -e "s|\t${toBeReplaced}$|\t${correct}|g" $exp/$exp.${fileTypeToBeFixed} + fi + elif [ "$fixesFile" == "automatic_fixes_values.txt" ]; then + #if [ "$fileTypeToBeFixed" == "sdrf.txt" ]; then + #perl -pi -e "s|\t${toBeReplaced}\t|\t${correct}\t|g" $exp/$exp.${fileTypeToBeFixed} + #perl -pi -e "s|\t${toBeReplaced}$|\t${correct}|g" $exp/$exp.${fileTypeToBeFixed} + if [ "$fileTypeToBeFixed" == "condensed-sdrf.tsv" ]; then + # In condensed-sdrf, the factor/characteristic value is the last column - so tab on the left and line ending on the right + perl -pi -e "s|\t${toBeReplaced}$|\t${correct}|g" $exp/$exp.${fileTypeToBeFixed} + fi + fi + done +} + +# Apply factor type fixes in idf file +applyFixes $exp automatic_fixes_properties.txt idf.txt +if [ $? -ne 0 ]; then + echo "ERROR: Applying factor type fixes in idf file for $exp failed" >&2 + return 1 +fi + +# Apply factor/sample characteristic type fixes to the condensed-sdrf file +applyFixes $exp automatic_fixes_properties.txt condensed-sdrf.tsv +if [ $? -ne 0 ]; then + echo "ERROR: Applying sample characteristic/factor types fixes in sdrf file for $exp failed" >&2 + return 1 +fi +# Apply sample characteristic/factor value fixes to the condensed-sdrf file +applyFixes $exp automatic_fixes_values.txt condensed-sdrf.tsv +if [ $? -ne 0 ]; then + echo "ERROR: Applying sample characteristic/factor value fixes in sdrf file for $exp failed" >&2 + return 1 +fi diff --git a/atlas-experiment-metadata-test.bats b/atlas-experiment-metadata-test.bats index 69f8f391..4e731a62 100755 --- a/atlas-experiment-metadata-test.bats +++ b/atlas-experiment-metadata-test.bats @@ -92,3 +92,6 @@ setup() { [ -f "$test_unmelted_sdrf" ] } +@test "Test get experiment type from XML" { + run perl get_experiment_type_from_xml.pl +} diff --git a/get_experiment_type_from_xml.pl b/get_experiment_type_from_xml.pl new file mode 100644 index 00000000..b3ba37e0 --- /dev/null +++ b/get_experiment_type_from_xml.pl @@ -0,0 +1,14 @@ +#!/usr/bin/env perl +# + +use strict; +use warnings; +use 5.10.0; + +use Atlas::AtlasConfig::Reader qw( parseAtlasConfig ); + +my $xmlFilename = shift; +my $experimentConfig = parseAtlasConfig( $xmlFilename ); +my $experimentType = $experimentConfig->get_atlas_experiment_type; + +print $experimentType; diff --git a/get_magetab_for_experiment.sh b/get_magetab_for_experiment.sh new file mode 100644 index 00000000..1c3aec6a --- /dev/null +++ b/get_magetab_for_experiment.sh @@ -0,0 +1,62 @@ +#!/usr/bin/env bash + + +usage() { echo "Usage: $0 path-to-atlas-exps" 1>&2; } + +expAcc=$1 +ATLAS_EXPS=$2 + +if [ -z "${expAcc}" ] || [ -z "${ATLAS_EXPS}" ]; then + usage + exit 1 +fi + +scriptDir=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) + +# Get the experiment type from the XML config. +expType=$(${scriptDir}/get_experiment_type_from_xml.pl $expAcc/$expAcc-configuration.xml) +if [ $? -ne 0 ]; then + echo "ERROR: failed to get $expAcc experiment type from XML config. Cannot generate condensed SDRF." + exit 1 +fi + +# Now generate condensed sdrf containing ontology mappings from Zooma. This +# will also copy IDF from ArrayExpress load directory (using "-i" option). +# If this is a baseline experiment, pass the factors XML filename as well to ensure factors match in condensed SDRF. +if [[ $expType == *baseline ]]; then + + ${scriptDir}/condense_sdrf.pl -e $expAcc -f $expAcc/$expAcc-factors.xml -z -i -o $expAcc + if [ $? -ne 0 ]; then + echo "ERROR: Failed to generate $expAcc/${expAcc}.condensed-sdrf.tsv with Zooma mappings, trying without..." + ${scriptDir}/condense_sdrf.pl -e $expAcc -f $expAcc/$expAcc-factors.xml -i -o $expAcc + fi + if [ $? -ne 0 ]; then + echo "ERROR: Failed to generate $expAcc/${expAcc}.condensed-sdrf.tsv" + return 1 + fi +else + + ${scriptDir}/condense_sdrf.pl -e $expAcc -z -i -o $expAcc + if [ $? -ne 0 ]; then + echo "ERROR: Failed to generate $expAcc/${expAcc}.condensed-sdrf.tsv with Zooma mappings, trying without..." + ${scriptDir}/condense_sdrf.pl -e $expAcc -i -o $expAcc + fi + if [ $? -ne 0 ]; then + echo "ERROR: Failed to generate $expAcc/${expAcc}.condensed-sdrf.tsv" + return 1 + fi +fi + +if [ ! -s "$expAcc/${expAcc}.condensed-sdrf.tsv" ]; then +echo "ERROR: Failed to generate $expAcc/${expAcc}.condensed-sdrf.tsv" +return 1 +fi + +applyAllFixesForExperiment $expAcc +if [ $? -ne 0 ]; then +echo "ERROR: Applying fixes for experiment $e failed" >&2 +return 1 +fi + +rm -rf $expAcc/$expAcc-zoomifications-log.tsv +popd