vendredi 28 septembre 2018

if then else statement will not loop properly

Morning fellow stackers! I figured how to get an if then else statement to work but it now seems to have broken. =( can't work out what's going wrong! There are up to 10 directories in ./ called barcode01 - 09 and one called unclassified. This script is supposed to go into each one, prep the directory for ~/Taxonomy.R (Which requires all the fastq files to be gzipped and put into a subd titled "data". It then runs the ~/Taxonomy.R script to make a metadata file for each.

edit; the tmp.txt file is created using ls > tmp.txt then echo "0" >> tmp.txt to make a sacrificial list of directories for the script to chew through then stop when it gets to 0

#!/bin/bash
source deactivate
source activate R-Env
value=(sed -n 1p tmp.txt)
if [ "$value" = "0" ]; then 
rm tmp.txt
else
cd "$(sed -n 1p tmp.txt)"
gzip *fastq
#
for i in *.gz; do mv "$i" "${i%.*}_R1.fastq.gz"; done
#this adds the direction identifier "R1" to all the fastq.gzips
mkdir Data
mv *gz Data
~/Taxonomy3.R
cd Data
mv * ..
cd ..
rm -r Data
cd ..
sed '1d' tmp.txt > tmp2.txt
mv tmp2.txt tmp.txt
fi

Currently, it's only making the metadata file in the first barcode directory. I'm still very fresh to making scripts so I can take this question down if its too simple, I've looked everywhere but can't find any answers.

Aucun commentaire:

Enregistrer un commentaire