SPAAM-community / AncientMetagenomeDir

Repository containing lists of all published ancient metagenomic (and related) samples and libraries
http://www.spaam-community.org/AncientMetagenomeDir/
Creative Commons Attribution 4.0 International
66 stars 30 forks source link

(Major) Add `autofil` to the GitHub Actions workflow #1131

Closed jfy133 closed 5 months ago

maxibor commented 8 months ago

@jfy133 This issue would be better in AncientMetagenomeDir :)

jfy133 commented 8 months ago

Very good point 🤣. It came from the auto issue generation... Does the issue moving thing work?

maxibor commented 8 months ago

Apparently yes @jfy133

jfy133 commented 7 months ago

My current idea:

jfy133 commented 7 months ago

Problems: diff doesn't work when other formatting changes have occured (or people fix upstream mistakes)

New approach, request bot to filter for the table and the new project ID e.g. @spaam-bot please autofill ancientsinglegenome-hostassociated majander2024

Then can use that info to filter the table to prepare the autofill command

jfy133 commented 7 months ago

e.g.: grep 'Nishimura2024' ancientmetagenome-hostassociated/samples/ancientmetagenome-hostassociated_samples.tsv | rev | cut -f 1 | rev to get the new accessions

jfy133 commented 7 months ago

X-ref for bot: https://stackoverflow.com/a/70244956

jfy133 commented 7 months ago

Basic bash script:

#!/usr/bin/env bash

##
## AMDirT autofill wrapper for github actions
##
## Given a specified table and a project name, this script will
##
## 0. Check the specified table is valid name
## 1. filter the specified sample table for the given project name.
## 2. collect collect the sample accession IDs of that project
## 3. give error if there is no output (i.e., 0 accessions)
## 4. run AMDirT autofill with the collected accessions and the specified table name
##
## Copyright 2024 James Fellows Yates on behalf of the SPAAM community under MIT license

verbose=false

while getopts t:p:v flag; do
    case "${flag}" in
    v) verbose=true ;;
    t) table_name=${OPTARG} ;;
    p) project_name=${OPTARG} ;;
    esac
done

## TODO: check valid table name
if [ $verbose ]; then
    echo RUNNING: grep $project_name $table_name/samples/"$table_name"_samples.tsv "| rev | cut -f 1 | rev | tr '\n' ' '"
    echo ""
fi

hits=$(grep "$project_name" "$table_name"/samples/"$table_name"_samples.tsv | rev | cut -f 1 | rev | tr '\n' ' ')

if [ $verbose ]; then
    echo RUNNING: "${#hits} -eq 0"
    echo ""
fi

if [ ${#hits} -eq 0 ]; then
    echo 'Project name or sample accessions were not found in table. Please check project name input (-p).'
    exit 1
fi

if [ $verbose ]; then
    echo RUNNING: AMDirT autofill -n $table_name $hits -l TEMPLATE_$project_name_"$table_name"_libraries.tsv
    echo ""
fi

AMDirT autofill -n $table_name $hits -l TEMPLATE_$project_name_"$table_name"_libraries.tsv
jfy133 commented 7 months ago

Better version, see: https://github.com/SPAAM-community/AncientMetagenomeDir/pull/1145

jfy133 commented 6 months ago

TODO: Parse the comment to extract the table name and project name

jfy133 commented 5 months ago

Done in a variety of commits on master, the final being: https://github.com/SPAAM-community/AncientMetagenomeDir/commit/7d564e914c3c98c482c323490cb09052c7ea5755