要解释吗?从大数组中选择 1000 个元素?
Explanation wanted? Selecting 1000 elements from large array?
我有 2987 个文件需要以 1000 个文件为一组进行处理(我们的 SLURM 调度程序不喜欢更多)。现在我有以下 bash 代码:
# collecting all the dataset files into an array called FILES
FILES=($(ls *.fast5))
echo ${#FILES[@]}
# select only the first 1000 items in the array
SUBSET=(${FILES[@]:0:1000}) #selecting elements 0 to 1000 --> 1000 elements
SUBSET=(${FILES[@]:1000:2000}) #selecting elements 1000 to 2000 --> 1987 elements
SUBSET=(${FILES[@]:2000:2987}) #selecting elements 2000 to 2987 --> 987 elements
#determine length of array Subset
echo ${#SUBSET[@]}
## determine which dataset to analyze
MYFILE=${SUBSET[$SLURM_ARRAY_TASK_ID]} ## identify which dataset is analyzed
## starting analysis
echo current dataset is: $MYFILE
现在我的问题是,选择 1000 到 2000 的元素后,我得到了一个长度为 1987 的数组。
我不知道为什么会这样,或者我的代码有什么问题,为什么我得到一个超过 1000 个元素的数组。
欢迎任何建议、指点等。
subselect 的最后一个参数不是要停止的数量,而是限制自身的结果数量。
您要求从 1,000 开始的 2,000 个结果,而不是 1,000 到 2,000 之间的结果。
SUBSET=(${FILES[@]:0:1000}) #selecting elements 0 to 999
SUBSET=(${FILES[@]:1000:1000}) #selecting elements 1000 to 1999
SUBSET=(${FILES[@]:2000:1000}) #selecting elements 2000 to 2999
我有 2987 个文件需要以 1000 个文件为一组进行处理(我们的 SLURM 调度程序不喜欢更多)。现在我有以下 bash 代码:
# collecting all the dataset files into an array called FILES
FILES=($(ls *.fast5))
echo ${#FILES[@]}
# select only the first 1000 items in the array
SUBSET=(${FILES[@]:0:1000}) #selecting elements 0 to 1000 --> 1000 elements
SUBSET=(${FILES[@]:1000:2000}) #selecting elements 1000 to 2000 --> 1987 elements
SUBSET=(${FILES[@]:2000:2987}) #selecting elements 2000 to 2987 --> 987 elements
#determine length of array Subset
echo ${#SUBSET[@]}
## determine which dataset to analyze
MYFILE=${SUBSET[$SLURM_ARRAY_TASK_ID]} ## identify which dataset is analyzed
## starting analysis
echo current dataset is: $MYFILE
现在我的问题是,选择 1000 到 2000 的元素后,我得到了一个长度为 1987 的数组。 我不知道为什么会这样,或者我的代码有什么问题,为什么我得到一个超过 1000 个元素的数组。
欢迎任何建议、指点等。
subselect 的最后一个参数不是要停止的数量,而是限制自身的结果数量。 您要求从 1,000 开始的 2,000 个结果,而不是 1,000 到 2,000 之间的结果。
SUBSET=(${FILES[@]:0:1000}) #selecting elements 0 to 999
SUBSET=(${FILES[@]:1000:1000}) #selecting elements 1000 to 1999
SUBSET=(${FILES[@]:2000:1000}) #selecting elements 2000 to 2999