Last active
February 6, 2020 11:09
-
-
Save rogerhutchings/ea0b88c2c15956efc289788890bf01c1 to your computer and use it in GitHub Desktop.
Handy scripts for subject set management
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
# Downloads a subject set and writes it to a text file. | |
# | |
# Takes a subject set ID as an argument. | |
# | |
# Example usage: | |
# $ ./download_subject_set.sh 1234 | |
SUBJECT_SET_ID=$1 | |
OUTPUT_FILE="subject_set_${SUBJECT_SET_ID}.txt" | |
echo "Fetching subjects from set \`$SUBJECT_SET_ID\`" | |
IDS="$(panoptes subject ls -q -s $1)" | |
echo "Formatting" | |
FORMATTED_IDS="${IDS// /$'\n'}" | |
echo "Writing subjects to \`$OUTPUT_FILE\`" | |
cat <<< "$FORMATTED_IDS" > "$OUTPUT_FILE" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
# Splits a file into smaller files, of n lines each. | |
# | |
# Takes a source file and number of lines per file as arguments. | |
# | |
# Example usage: | |
# $ ./split_file_by_lines.sh example.txt 1000 | |
FILE=$1 | |
NUMBER_OF_LINES=$2 | |
split -l $NUMBER_OF_LINES $FILE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
# Uploads a directory of `.txt` files as new subject sets. | |
# | |
# Takes a project ID as an argument. | |
# | |
# Text files should consist of one subject ID per line. Subject set names are | |
# taken from the text file's filename. | |
# | |
# Example usage: | |
# $ ./upload_sets.sh 1234 | |
FILES=*.txt | |
PROJECT_ID=$1 | |
for f in $FILES | |
do | |
# Get the filename without the extension | |
NEW_SET_NAME="${f%.*}" | |
echo "Processing file \`$f\`..." | |
echo "Creating new set \`$NEW_SET_NAME\`" | |
create_set_output=$(panoptes subject-set create $PROJECT_ID $NEW_SET_NAME) | |
# Get the new set ID from the panoptes output | |
NEW_SET_ID="$( cut -d ' ' -f 1 <<< $create_set_output )" | |
echo "Uploading subjects from $f to set #$NEW_SET_ID" | |
panoptes subject-set add-subjects -f $f $NEW_SET_ID | |
echo "Done!" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment