英文:
How to use for-loops and if-else statements to iteratively run a software on command line
问题
I extract the id
from all .mcool files
, which is the string before the .mcool
extension. If the substring of id
after the last /
is 5000, 10000, or 50000, I want to run predictSV
from EagleC.
For a single .mcool
file, the command would be:
cooler ls SKNAS-MboI-allReps-filtered.mcool
predictSV --hic-5k SKNAS-MboI-allReps-filtered.mcool::/resolutions/5000 \
--hic-10k SKNAS-MboI-allReps-filtered.mcool::/resolutions/10000 \
--hic-50k SKNAS-MboI-allReps-filtered.mcool::/resolutions/50000 \
-O SK-N-AS -g hg38 --balance-type CNV --output-format full \
--prob-cutoff-5k 0.8 --prob-cutoff-10k 0.8 --prob-cutoff-50k 0.99999
Now, I want to run EagleC iteratively for multiple .mcool
files:
for id in cooler ls ./input/*.mcool; do
if [[ "${id##*/}" = 5000 ]] || [[ "${id##*/}" = 10000 ]] || [[ "${id##*/}" = 50000 ]]; then
num=$(echo "${id##*/}" | awk -F '-' '{print $1}')
predictSV --hic-"${num}"k "${id}" -g hg38 --balance-type CNV --output-format full \
--prob-cutoff-5k 0.8 --prob-cutoff-10k 0.8 --prob-cutoff-50k 0.99999;
fi;
done
My code exits without returning any output.
The provided code output:
cooler
ls
./input/A001C007.hg38.nodups.pairs.mcool
./input/A001C008.hg38.nodups.pairs.mcool
./input/A001C011.hg38.nodups.pairs.mcool
...
(EagleC)
英文:
For all the .mcool files
, I extract the id
, which is the string before the .mcool
extension.
If the substring of id
after the last /
is either 5000, 10000, or 50000 (i.e., 5k, 10k, or 50k), I want to run predictSV
from EagleC.
For a single .mcool
file, as per described on EagleC, it would be:
cooler ls SKNAS-MboI-allReps-filtered.mcool
predictSV --hic-5k SKNAS-MboI-allReps-filtered.mcool::/resolutions/5000 \
--hic-10k SKNAS-MboI-allReps-filtered.mcool::/resolutions/10000 \
--hic-50k SKNAS-MboI-allReps-filtered.mcool::/resolutions/50000 \
-O SK-N-AS -g hg38 --balance-type CNV --output-format full \
--prob-cutoff-5k 0.8 --prob-cutoff-10k 0.8 --prob-cutoff-50k 0.99999
However, now I want to run EagleC iteratively for multiple .mcool
files.
for id in cooler ls ./input/*.mcool; do
if [ "${id##*/}" = 5000 ] || [ "${id##*/}" = 10000 ] || [ "${id##*/}" = 50000 ]; then
for num in ${id##*/:0:1}; do
predictSV --hic-"${num}"k "${id##*/}" -g hg38 --balance-type CNV --output-format full \
--prob-cutoff-5k 0.8 --prob-cutoff-10k 0.8 --prob-cutoff-50k 0.99999;
done;
fi;
done
My code exits without returning any output.
The following code
for id in cooler ls ./input/*.mcool; do echo "$id"; done
returns:
cooler
ls
./input/A001C007.hg38.nodups.pairs.mcool
./input/A001C008.hg38.nodups.pairs.mcool
./input/A001C011.hg38.nodups.pairs.mcool
./input/A001C013.hg38.nodups.pairs.mcool
./input/A001C019.hg38.nodups.pairs.mcool
./input/A001C023.hg38.nodups.pairs.mcool
./input/A001C024.hg38.nodups.pairs.mcool
./input/A002C001.hg38.nodups.pairs.mcool
./input/A002C002.hg38.nodups.pairs.mcool
./input/A002C006.hg38.nodups.pairs.mcool
./input/A002C010.hg38.nodups.pairs.mcool
./input/A002C012.hg38.nodups.pairs.mcool
./input/A002C013.hg38.nodups.pairs.mcool
./input/A002C122.hg38.nodups.pairs.mcool
./input/A002C212.hg38.nodups.pairs.mcool
./input/A014C004.hg38.nodups.pairs.mcool
./input/A014C012.hg38.nodups.pairs.mcool
./input/A014C038.hg38.nodups.pairs.mcool
./input/A014C040.hg38.nodups.pairs.mcool
./input/A014C041.hg38.nodups.pairs.mcool
./input/A014C045.hg38.nodups.pairs.mcool
./input/A014C046.hg38.nodups.pairs.mcool
./input/A014C053.hg38.nodups.pairs.mcool
./input/A014C054.hg38.nodups.pairs.mcool
./input/A015C004.hg38.nodups.pairs.mcool
./input/A015C006.hg38.nodups.pairs.mcool
./input/A015C010.hg38.nodups.pairs.mcool
./input/combined.hg38.nodups.pairs.mcool
./input/CRC15157.hg38.nodups.pairs.mcool
./input/CRC19779.hg38.nodups.pairs.mcool
./input/CRC25135.hg38.nodups.pairs.mcool
./input/CRC25988.hg38.nodups.pairs.mcool
./input/CRC26616.hg38.nodups.pairs.mcool
./input/CRC8396.hg38.nodups.pairs.mcool
(EagleC)
答案1
得分: 1
这是您提供的代码部分的中文翻译:
# 在迭代运行`cooler ls`命令输出的行之前,似乎您需要迭代处理文件。
for mcool_file in ./input/*.mcool; do
while IFS= read -r id; do
id_suffix=${id##*/}
case $id_suffix in 5000|10000|50000)
num=${id_suffix:0:1}
predictSV \
--hic-"${num}k" "$id_suffix" \
-g hg38 \
--balance-type CNV \
--output-format full \
--prob-cutoff-5k 0.8 \
--prob-cutoff-10k 0.8 \
--prob-cutoff-50k 0.99999
;;
esac
done < <(cooler ls "$mcool_file")
done
注意:上述代码翻译仅包括代码部分,不包括任何其他内容。
英文:
It sounds like you need to iterate over files before you iterate over lines of output from running cooler ls
against those files.
for mcool_file in ./input/*.mcool; do
while IFS= read -r id; do
id_suffix=${id##*/}
case $id_suffix in 5000|10000|50000)
num=${id_suffix:0:1}
predictSV \
--hic-"${num}k" "$id_suffix" \
-g hg38 \
--balance-type CNV \
--output-format full \
--prob-cutoff-5k 0.8 \
--prob-cutoff-10k 0.8 \
--prob-cutoff-50k 0.99999
;;
esac
done < <(cooler ls "$mcool_file")
done
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论