Skip to content

Commit d978f15

Browse files
committed
speed up the seq count summary
1 parent 744b940 commit d978f15

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

src/pipecraft-core/service_scripts/submodules/framework.functions.sh

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -539,23 +539,28 @@ fi
539539
### Compile a track reads summary file (seq_count_summary.txt)
540540
output_dir_for_sed=$(echo $output_dir | sed -e "s/\//\\\\\//g")
541541
sed -e "s/$output_dir_for_sed\///" < tempdir2/seq_count_after.txt > tempdir2/seq_count_after.temp
542-
printf "File\tReads_in\tReads_out\n" > $output_dir/seq_count_summary.txt
543-
while read LINE; do
544-
file1=$(echo $LINE | awk '{print $1}')
545-
count1=$(echo $LINE | awk '{print $2}')
546-
while read LINE2; do
547-
file2=$(echo $LINE2 | awk '{print $1}')
548-
count2=$(echo $LINE2 | awk '{print $2}')
549-
if [[ "$file1" == "$file2" ]]; then
550-
printf "$file1\t$count1\t$count2\n" >> $output_dir/seq_count_summary.txt
551-
fi
552-
done < tempdir2/seq_count_after.temp
553-
#Report file where no sequences were reoriented (i.e. the output was 0)
554-
grep -Fq $file1 tempdir2/seq_count_after.temp
555-
if [[ $? != 0 ]]; then
556-
printf "$file1\t$count1\t0\n" >> $output_dir/seq_count_summary.txt
557-
fi
558-
done < tempdir2/seq_count_before.txt
542+
543+
# Compile seq_count_summary.txt
544+
awk '
545+
BEGIN { print "File\tReads_in\tReads_out" }
546+
NR==FNR {
547+
before[$1] = $2;
548+
next
549+
}
550+
{
551+
file = $1;
552+
count_after = $2;
553+
if (file in before) {
554+
print file "\t" before[file] "\t" count_after;
555+
delete before[file];
556+
}
557+
}
558+
END {
559+
# Print files with 0 output
560+
for (file in before) {
561+
print file "\t" before[file] "\t0";
562+
}
563+
}' tempdir2/seq_count_before.txt tempdir2/seq_count_after.temp > $output_dir/seq_count_summary.txt
559564

560565
#Delete decompressed files if original set of files were compressed
561566
if [[ $check_compress == "gz" ]] || [[ $check_compress == "zip" ]]; then

0 commit comments

Comments
 (0)