gravatar for Joe

2 hours ago by

United Kingdom

Here's a low-tech solution that seems to do the job (I haven't tested it extensively):

#!/bin/bash
# Usage:
#   $ bash script.sh destination_folder
for file in ./*.fasta ; do
    entries=$(grep -c ">" $file)
    if [ $entries -gt 1 ]; then
        mv "$file" $1
    fi
done

If this is an especially critical step in a pipeline or something, you may want to consider a more robust approach (i.e. use an actual parser to check for multiple entries, use find to pick up the files etc.)

If you have very big fasta's this will be somewhat slow as it reads the whole file to count the number of >. It could terminate after finding just 2, but that's a more complicated task.


EDIT: slightly more flexible way to ingest from the commandline:

#!/bin/bash
# Usage:
#      $ bash script.sh destination_folder /path/to/dir/*.fasta   # replace fasta with whatever extension is relevant

for file in "${@:1:$#}" ; do
    entries=$(grep -c ">" "$file")
    if [ "$entries" -gt 1 ]; then
        mv -v "$file" "$1"
    fi
done

link

modified 2 hours ago

written
2 hours ago
by

Joe18k



Source link