diff --git a/README.md b/README.md index 8c62b984b3eac139c390d140faf9f198e1e571e8..143e1036b25c5b3978b806dfccbfc2ca46e81547 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # contig_info -_contig_info_ is a command line program written in [Bash](https://www.gnu.org/software/bash/) that allows estimating several standard descriptive statistics from a FASTA-formatted contig file inferred by a _de novo_ genome assembly method. Estimated statistics are sequence number, residue counts, sequence length distribution, N50 (Lander et al. 2001), NG50 (Earl et al. 2011), and its related N75, NG75, N90, and NG90. +_contig_info_ is a command line program written in [Bash](https://www.gnu.org/software/bash/) that allows several standard descriptive statistics to be quickly estimated from FASTA-formatted contig files inferred by _de novo_ genome assembly methods. +Estimated statistics are sequence number, residue counts, AT- and GC-content, sequence lengths, N50 (Lander et al. 2001), NG50 (Earl et al. 2011), and the related N75, NG75, N90, NG90, L50, LG50, L75, LG75, L90, LG90. ## Installation and execution @@ -18,20 +19,118 @@ and launch it with the following command line model: Launch _contig_info_ without option to read the following documentation: ``` - USAGE: contig_info.sh [options] <contig_file> + USAGE: contig_info.sh [options] <contig_files> where 'options' are: -m <int> minimum contig length; every contig sequence of length - shorter than this cutoff will be discarded (default: 0) - -g <int> expected genome size for computing NG50, NG75 and NG90 - values instead of N50, N75 and N90 ones, respectively - -d print contig sequence length distribution - -l print length of each contig sequence - -r print residue counts + shorter than this cutoff will be discarded (default: 1) + -g <int> expected genome size for computing {N,L}G{50,75,90} + values instead of {N,L}{50,75,90} ones, respectively -t tab-delimited output ``` +## Examples + +The following [Bash](https://www.gnu.org/software/bash/) command lines allows the genome sequences of the 5 _Mucor circinelloides_ strains 1006PhL, CBS 277.49, WJ11, B8987 and JCM 22480 to be downloaded from the [NCBI genome repository](https://www.ncbi.nlm.nih.gov/genome): +```bash +NCBIFTP="wget -q -O- https://ftp.ncbi.nlm.nih.gov/sra/wgs_aux/"; Z=".1.fsa_nt.gz"; +echo -e "1006PhL\tAOCY01\nCBS277.49\tAMYB01\nWJ11\tLGTF01\nB8987\tJNDM01\nJCM22480\tBCHG01" | + while read -r s a; do echo -n "$s ... ";$NCBIFTP${a:0:2}/${a:2:2}/$a/$a$Z|zcat>Mucor.$s.fasta;echo "[ok]";done +``` + +The following command line allows the script `contig_info.sh` to be launched to analyze the first downloaded file _Mucor.1006PhL.fasta_: +```bash +./contig_info.sh Mucor.1006PhL.fasta +``` +leading to the following standard output: +``` +File Mucor.1006PhL.fasta + +Number of sequences 1459 + +Residue counts: + Number of A's 10320010 30.23 % + Number of C's 6747611 19.76 % + Number of G's 6731530 19.72 % + Number of T's 10335465 30.27 % + Number of N's 0 0 % + Total 34134616 + + %AT 60.52 % + %GC 39.48 % + +Sequence lengths: + Minimum 410 + Quartile 25% 1660 + Median 6176 + Quartile 75% 37608 + Maximum 213712 + Average 23395.89 + +Contiguity statistics: + N50 58982 + N75 36291 + N90 18584 + L50 194 + L75 376 + L90 562 +``` + +The same results could be outputted in tab-delimited format with the following command line: +```bash +./contig_info.sh -t Mucor.1006PhL.fasta +``` + +``` +#File Nseq Nres A C G T N %A %C %G %T %N %AT %GC Min Q25 Med Q75 Max Avg N50 N75 N90 L50 L75 L90 +Mucor.1006PhL.fasta 1459 34134616 10320010 6747611 6731530 10335465 0 30.23% 19.76% 19.72% 30.27% 0% 60.52% 39.48% 410 1660 6176 37608 213712 23395.89 58982 36291 18584 194 376 562 +``` + +Of note, the five downloaded FASTA files could be analyzed with a single command line: +```bash +./contig_info.sh -t Mucor.*.fasta +``` + +``` +#File Nseq Nres A C G T N %A %C %G %T %N %AT %GC Min Q25 Med Q75 Max Avg N50 N75 N90 L50 L75 L90 +Mucor.1006PhL.fasta 1459 34134616 10320010 6747611 6731530 10335465 0 30.23% 19.76% 19.72% 30.27% 0% 60.52% 39.48% 410 1660 6176 37608 213712 23395.89 58982 36291 18584 194 376 562 +Mucor.B8987.fasta 2210 36700617 11096810 7247117 7233795 11122895 0 30.23% 19.74% 19.71% 30.30% 0% 60.55% 39.45% 206 839 2482 20727 258792 16606.61 58460 30025 13274 193 416 674 +Mucor.CBS277.49.fasta 21 36567582 10571030 7715901 7705901 10574750 0 28.90% 21.10% 21.07% 28.91% 0% 57.83% 42.17% 4155 41542 934259 3187354 6050249 1741313.42 4318338 3096690 1074709 4 7 9 +Mucor.JCM22480.fasta 401 36616466 10586281 6882218 6899109 10581984 1659222 28.91% 18.79% 18.84% 28.89% 4.53% 60.57% 39.43% 1038 4814 50332 135940 659822 91312.88 197059 109360 63107 61 121 183 +Mucor.WJ11.fasta 2519 33065171 9974064 6559358 6556539 9975210 0 30.16% 19.83% 19.82% 30.16% 0% 60.34% 39.66% 430 3275 7692 18010 118704 13126.30 24148 12884 5672 429 898 1455 +``` + +The tab-delimited output format could be useful for focusing on specific fields like, e.g. the six contiguity statistics: +```bash +./contig_info.sh -t Mucor.*.fasta | cut -f1,22- +``` + +``` +#File N50 N75 N90 L50 L75 L90 +Mucor.1006PhL.fasta 58982 36291 18584 194 376 562 +Mucor.B8987.fasta 58460 30025 13274 193 416 674 +Mucor.CBS277.49.fasta 4318338 3096690 1074709 4 7 9 +Mucor.JCM22480.fasta 197059 109360 63107 61 121 183 +Mucor.WJ11.fasta 24148 12884 5672 429 898 1455 +``` + + +Finally, the option -g could be used to set an expected genome size for obtaining {N,L}G{50,75,90} statistics instead of {N,L}{50,75,90} ones: +```bash +./contig_info.sh -t -g 36000000 Mucor.*.fasta | cut -f1,22- +``` + +``` +#File N50 N75 N90 L50 L75 L90 ExpSize +Mucor.1006PhL.fasta 57499 32472 7652 210 417 692 36000000 +Mucor.B8987.fasta 59771 30857 15730 187 399 631 36000000 +Mucor.CBS277.49.fasta 4318338 3096690 1074709 4 7 9 36000000 +Mucor.JCM22480.fasta 197663 113006 69531 59 117 175 36000000 +Mucor.WJ11.fasta 21799 9865 2445 493 1092 2146 36000000 +``` + + ## References Earl D, Bradnam K, St John J, Darling A, Lin D, Fass J, Yu HO, Buffalo V, Zerbino DR, Diekhans M, Nguyen N, Ariyaratne PN, Sung WK, Ning Z, Haimel M, Simpson JT, Fonseca NA, Birol Ä°, Docking TR, Ho IY, Rokhsar DS, Chikhi R, Lavenier D, Chapuis G, Naquin D, Maillet N, Schatz MC, Kelley DR, Phillippy AM, Koren S, Yang SP, Wu W, Chou WC, Srivastava A, Shaw TI, Ruby JG, Skewes-Cox P, Betegon M, Dimon MT, Solovyev V, Seledtsov I, Kosarev P, Vorobyev D, Ramirez-Gonzalez R, Leggett R, MacLean D, Xia F, Luo R, Li Z, Xie Y, Liu B, Gnerre S, MacCallum I, Przybylski D, Ribeiro FJ, Yin S, Sharpe T, Hall G, Kersey PJ, Durbin R, Jackman SD, Chapman JA, Huang X, DeRisi JL, Caccamo M, Li Y, Jaffe DB, Green RE, Haussler D, Korf I, Paten B (2011) Assemblathon 1: a competitive assessment of de novo short read assembly methods. Genome Research, 21(12):2224-2241. [doi:10.1101/gr.126599.111](https://genome.cshlp.org/content/21/12/2224). diff --git a/contig_info.sh b/contig_info.sh index 8b123e3c03ad690b5f1c6cef49b3963201f52a5c..a9a081a68a8da7e26fe0f8c9451838d9ca74423b 100755 --- a/contig_info.sh +++ b/contig_info.sh @@ -1,263 +1,205 @@ #!/bin/bash -########################################################################## -# # -# contig_info: a BASH script to estimate standard statistics from # -# FASTA contig file # -# # - VERSION=0.3.180515ac # -# # -# Copyright (C) 2015,2018 Alexis Criscuolo # -# # -# This program is free software: you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation, either version 3 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, but # -# WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # -# General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program. If not, see <http://www.gnu.org/licenses/>. # -# # -# Contact: # -# Institut Pasteur # -# Bioinformatics and Biostatistics Hub # -# C3BI, USR 3756 IP CNRS # -# Paris, FRANCE # -# # -# alexis.criscuolo@pasteur.fr # -# # -########################################################################## - -########################################################################## -# # -# ================ # -# = INSTALLATION = # -# ================ # -# # -# Just give the execute permission to the script contig_info.sh by # -# using the following command: # -# # -# chmod +x contig_info.sh # -# # -########################################################################## +######################################################################################## +# # +# contig_info: a BASH script to estimate standard statistics from FASTA contig files # +# # +# Copyright (C) 2015,2018,2019 Alexis Criscuolo # +# # +# This program is free software: you can redistribute it and/or modify it under the # +# terms of the GNU General Public License as published by the Free Software # +# Foundation, either version 3 of the License, or (at your option) any later version # +# # +# This program is distributed in the hope that it will be useful, but WITHOUT ANY # +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A # +# PARTICULAR PURPOSE. See the GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License along with this # +# program. If not, see <http://www.gnu.org/licenses/>. # +# # +# Contact: # +# Institut Pasteur # +# Bioinformatics and Biostatistics Hub # +# C3BI, USR 3756 IP CNRS # +# Paris, FRANCE # +# # +# alexis.criscuolo@pasteur.fr # +# # +######################################################################################## -########################################################################## -# Help displaying # -########################################################################## +######################################################################################## +# # +# ============ # +# = VERSIONS = # +# ============ # +# # + VERSION=1.0.190426ac # +# + options -l and -d (i.e. printing sequence lengths and length distribution, resp.) # +# are no longer supported # +# + residue count always computed (option -r discarded) # +# + ultrafast residue count (based on tr + wc) # +# + estimating %AT, %GC, L50, L75, L90 # +# + faster estimation of the sequence length statistics (100% awk) # +# + ability to read multiple input files # +# # +# VERSION=0.3.180515ac # +# # +######################################################################################## + +######################################################################################## +# # +# ================ # +# = INSTALLATION = # +# ================ # +# # +# Just give the execute permission to the script contig_info.sh with the following # +# command line: # +# # +# chmod +x contig_info.sh # +# # +######################################################################################## +######################################################################################## +# # +# ================ # +# = MANUAL = # +# ================ # +# # +# # if [ "$1" = "-?" ] || [ $# -lt 1 ] then cat <<EOF contig_info v.$VERSION - USAGE: contig_info.sh [options] <contig_file> + USAGE: contig_info.sh [options] <contig_files> where 'options' are: -m <int> minimum contig length; every contig sequence of length - shorter than this cutoff will be discarded (default: 0) - -g <int> expected genome size for computing NG50, NG75 and NG90 - values instead of N50, N75 and N90 ones, respectively - -d print contig sequence length distribution - -l print length of each contig sequence - -r print residue counts + shorter than this cutoff will be discarded (default: 1) + -g <int> expected genome size for computing {N,L}G{50,75,90} + values instead of {N,L}{50,75,90} ones, respectively -t tab-delimited output EOF exit fi - - -######################################################################################## -# Functions # +# # ######################################################################################## -# randomfile $INFILE -# -# INFILE: file name, this will returns the randomly generated file name INFILE.RANDOM -# +######################################################################################## +# # +# ================ # +# = FUNCTIONS = # +# ================ # +# # +# = randomfile() ==================================================================== # +# returns a random file name within /tmp/ # +# # randomfile() { - rdmf=$1.$RANDOM; while [ -e $rdmf ]; do rdmf=$1.$RANDOM ; done + rdmf=/tmp/$RANDOM; while [ -e $rdmf ]; do rdmf=/tmp/$RANDOM ; done echo $rdmf ; } - - +# # +######################################################################################## ######################################################################################## -# Beginning contig_info # +#### #### +#### INITIALIZING PARAMETERS AND READING OPTIONS #### +#### #### ######################################################################################## - -############################### -# Reading options # -############################### -INFILE="XXX"; for param in "$@"; do INFILE="$param"; done; if [ ! -e $INFILE ]; then echo " no input file" ; exit ; fi -MIN_CONTIG_LGT=0; +MIN_CONTIG_LGT=1; GENOME_SIZE=0; -PRINT_LGT=false; -PRINT_RESIDUE=false; -PRINT_DIST=false; -CSVOUT=false; -while getopts m:g:ldrt option +TSVOUT=false; +while getopts m:g:t option do case $option in - m) MIN_CONTIG_LGT=$OPTARG; if [ $MIN_CONTIG_LGT -lt 0 ]; then echo " the min contig length threshold must be a positive integer (option -m)" ; exit 1 ; fi ;; - g) GENOME_SIZE=$OPTARG; if [ $GENOME_SIZE -lt 0 ]; then echo " the expected genome size must be a positive integer (option -g)" ; exit 1 ; fi ;; - r) PRINT_RESIDUE=true ;; - l) PRINT_LGT=true ;; - d) PRINT_DIST=true ;; - t) CSVOUT=true ;; + m) MIN_CONTIG_LGT=$OPTARG ;; + g) GENOME_SIZE=$OPTARG ;; + t) TSVOUT=true ;; + :) echo "option $OPTARG : missing argument" ; exit 1 ;; + \?) echo "$OPTARG : option invalide" ; exit 1 ;; esac done +if [ $MIN_CONTIG_LGT -lt 1 ]; then echo " the min contig length threshold must be a positive integer (option -m)" ; exit 1 ; fi +if [ $GENOME_SIZE -lt 0 ]; then echo " the expected genome size must be a positive integer (option -g)" ; exit 1 ; fi -############################### -# Conversion (for dos files) # -############################### -INFILE_UNIX=$(randomfile $INFILE); tr -d '\15\32' < $INFILE > $INFILE_UNIX ; - -############################### -# Computing info # -############################### -FH=$(randomfile $INFILE); ##### FH : txt file containing fhs -SEQS=$(randomfile $INFILE); ##### SEQS : txt file with one sequence per line -SUBSEQS=$(randomfile $INFILE); ##### SUBSEQS : txt file with sequence per line larger than $MIN_CONTIG_LGT -LGTFILE=$(randomfile $INFILE); ##### LGTFILE : length of each sequence -INFOFILE=$(randomfile $INFILE); ##### INFOFILE : output if $PRINT_LGT="true" - -grep "^>" $INFILE_UNIX | cut -c2- > $FH ; -awk 'BEGIN {seq=""} !/^>/ {seq=seq$0} /^>/ {if(seq!=""){print seq ; seq=""} {print $0}} END {print seq}' $INFILE_UNIX | grep -v "^>" | tr '[:lower:]' '[:upper:]' > $SEQS ; - -(echo -e -n "\r \r0.0%" >&2); awk -v threshold=$MIN_CONTIG_LGT '( length($0) >= threshold ) {print length($0)}' $SEQS > $LGTFILE ; -(echo -e -n "\r \r20.0%" >&2); NUMBER_OF_SEQUENCE=$(cat $LGTFILE | wc -l); -(echo -e -n "\r \r40.0%" >&2); R=$(awk '{ sum += $1 } END { print sum }' $LGTFILE); -(echo -e -n "\r \r60.0%" >&2); if $PRINT_RESIDUE ; then awk -v threshold=$MIN_CONTIG_LGT '( length($0) >= threshold ) {print $0}' $SEQS > $SUBSEQS ; fi -(echo -e -n "\r \r80.0%" >&2); if $PRINT_LGT ; then lgt=$(cat $SEQS | wc -l); i=0; while read seq; do let i++; (echo -e -n "\r \r$(( 80 + 19 * $i / $lgt )).0%" >&2); r=${#seq}; if [ $r -ge $MIN_CONTIG_LGT ]; then echo " $(sed -n "$i p" $FH) $r" >> $INFOFILE ; fi ; done < $SEQS ; fi - -if $PRINT_RESIDUE +######################################################################################## +#### #### +#### CONTIG INFO #### +#### #### +######################################################################################## +if $TSVOUT then - (echo -e -n "\r \r99.0%" >&2); A=$(cat $SUBSEQS | tr -d '[:cntrl:]' | awk '{x=0;x+=gsub("A","");print x}') - (echo -e -n "\r \r99.2%" >&2); C=$(cat $SUBSEQS | tr -d '[:cntrl:]' | awk '{x=0;x+=gsub("C","");print x}') - (echo -e -n "\r \r99.4%" >&2); G=$(cat $SUBSEQS | tr -d '[:cntrl:]' | awk '{x=0;x+=gsub("G","");print x}') - (echo -e -n "\r \r99.6%" >&2); T=$(cat $SUBSEQS | tr -d '[:cntrl:]' | awk '{x=0;x+=gsub("T","");print x}') - (echo -e -n "\r \r99.8%" >&2); N=$(cat $SUBSEQS | tr -d '[:cntrl:]' | awk '{x=0;x+=gsub("N","");print x}') - rm $SUBSEQS ; + CSVCAPT="#File\tNseq\tNres\tA\tC\tG\tT\tN\t%A\t%C\t%G\t%T\t%N\t%AT\t%GC\tMin\tQ25\tMed\tQ75\tMax\tAvg\tN50\tN75\tN90\tL50\tL75\tL90"; + [ $GENOME_SIZE -ne 0 ]&&CSVCAPT="$CSVCAPT\tExpSize"; + echo -e "$CSVCAPT" ; fi -(echo -e -n "\r \r" >&2); - -if ! $CSVOUT -then - echo ; - echo "File $(basename $INFILE)" ; - echo ; - echo "Number of sequences $NUMBER_OF_SEQUENCE" ; - echo ; - echo "Residue counts:" ; - if $PRINT_RESIDUE - then - echo " Number of A's $A $(echo "scale=2;100*$A/$R" | bc -l) %" ; - echo " Number of C's $C $(echo "scale=2;100*$C/$R" | bc -l) %" ; - echo " Number of G's $G $(echo "scale=2;100*$G/$R" | bc -l) %" ; - echo " Number of T's $T $(echo "scale=2;100*$T/$R" | bc -l) %" ; - echo " Number of N's $N $(echo "scale=2;100*$N/$R" | bc -l) %" ; - fi - echo " Total $R" ; - if [ $GENOME_SIZE -ne 0 ]; then echo " Expected genome size $GENOME_SIZE"; fi -else - CSVCAPT="#File\tNseq"; CSVLINE="$(basename $INFILE)\t$NUMBER_OF_SEQUENCE"; - if $PRINT_RESIDUE +SEQS=$(randomfile); ## txt file with one sequence per line +for INFILE in "$@" +do + if [ ! -e $INFILE ] || [ ! -f $INFILE ] || [ ! -r $INFILE ]; then continue; fi + + tr -d '\15\32' < $INFILE | awk -v thr=$MIN_CONTIG_LGT '/^>/{if(length(s)>=thr)print s;s="";next}{s=s$0}END{if(length(s)>=thr)print s}' | tr '[:lower:]' '[:upper:]' > $SEQS ; + R=$(tr -d [:cntrl:] < $SEQS | wc -c); S=$(wc -l < $SEQS); AVG=$(bc -l<<<"scale=2;$R/$S" | sed 's/^\./0./'); + A=$(tr -cd A < $SEQS | wc -c); fA=$(bc -l <<<"scale=2;100*$A/$R" | sed 's/^\./0./'); + C=$(tr -cd C < $SEQS | wc -c); fC=$(bc -l <<<"scale=2;100*$C/$R" | sed 's/^\./0./'); + G=$(tr -cd G < $SEQS | wc -c); fG=$(bc -l <<<"scale=2;100*$G/$R" | sed 's/^\./0./'); + T=$(tr -cd T < $SEQS | wc -c); fT=$(bc -l <<<"scale=2;100*$T/$R" | sed 's/^\./0./'); + N=$(tr -cd N < $SEQS | wc -c); fN=$(bc -l <<<"scale=2;100*$N/$R" | sed 's/^\./0./'); + fGC=$(bc -l <<<"scale=2;100*($C+$G)/($A+$C+$G+$T)" | sed 's/^\./0./'); fAT=$(bc -l <<<"scale=2;100-$fGC" | sed 's/^\./0./'); + ER=$R; [ $GENOME_SIZE != 0 ] && ER=$GENOME_SIZE; + STATS=$(awk '{print length}' $SEQS | sort -rn | awk -v g=$ER '{l[++n]=$0}END{g50=g/2;g75=3*g/4;g90=9*g/10;i=s=n50=n75=n90=0;while(++i<=n&&n90==0){s+=l[i];n50==0&&s>=g50&&n50=l[i]+(l50=i);n75==0&&s>=g75&&n75=l[i]+(l75=i);n90==0&&s>=g90&&n90=l[i]+(l90=i)}print (n50-l50)"\t"(n75-l75)"\t"(n90-l90)"\t"l50"\t"l75"\t"l90"\t"l[1]"\t"l[int(n/4+1)]"\t"l[int(n/2+1)]"\t"l[int(3*n/4+1)]"\t"l[n]}'); + N50=$(cut -f1 <<<"$STATS"); N75=$(cut -f2 <<<"$STATS"); N90=$(cut -f3 <<<"$STATS"); + L50=$(cut -f4 <<<"$STATS"); L75=$(cut -f5 <<<"$STATS"); L90=$(cut -f6 <<<"$STATS"); + MAX=$(cut -f7 <<<"$STATS"); + Q75=$(cut -f8 <<<"$STATS"); Q50=$(cut -f9 <<<"$STATS"); Q25=$(cut -f10 <<<"$STATS"); + MIN=$(cut -f11 <<<"$STATS"); + + if ! $TSVOUT then - CSVCAPT="$CSVCAPT\tA\tC\tG\tT\tN\t%A\t%C\t%G\t%T\t%N"; - CSVLINE="$CSVLINE\t$A\t$C\t$G\t$T\t$N"; - CSVLINE="$CSVLINE\t$(echo "scale=2;100*$A/$R" | bc -l)%"; - CSVLINE="$CSVLINE\t$(echo "scale=2;100*$C/$R" | bc -l)%"; - CSVLINE="$CSVLINE\t$(echo "scale=2;100*$G/$R" | bc -l)%"; - CSVLINE="$CSVLINE\t$(echo "scale=2;100*$T/$R" | bc -l)%"; - CSVLINE="$CSVLINE\t$(echo "scale=2;100*$N/$R" | bc -l)%"; + echo ; + echo "File $(basename $INFILE)" ; + echo ; + echo "Number of sequences $S" ; + echo ; + echo "Residue counts:" ; + echo " Number of A's $A $fA %" ; + echo " Number of C's $C $fC %" ; + echo " Number of G's $G $fG %" ; + echo " Number of T's $T $fT %" ; + echo " Number of N's $N $fN %" ; + echo " Total $R" ; + echo ; + echo " %AT $fAT %" ; + echo " %GC $fGC %" ; + echo ; + echo "Sequence lengths:" ; + echo " Minimum $MIN" ; + echo " Quartile 25% $Q25" ; + echo " Median $Q50" ; + echo " Quartile 75% $Q75" ; + echo " Maximum $MAX" ; + echo " Average $AVG" ; + echo ; + echo "Contiguity statistics:" ; + echo " N50 $N50" ; + echo " N75 $N75" ; + echo " N90 $N90" ; + echo " L50 $L50" ; + echo " L75 $L75" ; + echo " L90 $L90" ; + if [ $GENOME_SIZE -ne 0 ]; then echo " Expected genome size $GENOME_SIZE"; fi + echo ; + else + CSVLINE="$(basename $INFILE)\t$S\t$R\t$A\t$C\t$G\t$T\t$N\t$fA%\t$fC%\t$fG%\t$fT%\t$fN%\t$fAT%\t$fGC%\t$MIN\t$Q25\t$Q50\t$Q75\t$MAX\t$AVG\t$N50\t$N75\t$N90\t$L50\t$L75\t$L90"; + [ $GENOME_SIZE -ne 0 ]&&CSVLINE="$CSVLINE\t$ER"; + echo -e "$CSVLINE" ; fi - CSVCAPT="$CSVCAPT\tNres"; CSVLINE="$CSVLINE\t$R"; - if [ $GENOME_SIZE -ne 0 ]; then CSVCAPT="$CSVCAPT\tExpSize"; CSVLINE="$CSVLINE\t$GENOME_SIZE"; fi -fi - -tmp=$(randomfile $INFILE); cat $LGTFILE | sort -n > $tmp; mv $tmp $LGTFILE ; -MIN=$(head -1 $LGTFILE); -MAX=$(tail -1 $LGTFILE); -Q25=$(head -$(( $NUMBER_OF_SEQUENCE / 4 )) $LGTFILE | tail -1); -Q50=$(head -$(( $NUMBER_OF_SEQUENCE / 2 )) $LGTFILE | tail -1); -Q75=$(head -$(( 3 * $NUMBER_OF_SEQUENCE / 4 )) $LGTFILE | tail -1); -AVG=$(echo "scale=2;$R/$NUMBER_OF_SEQUENCE" | bc -l); - -tmp=$(randomfile $INFILE); cat $LGTFILE | sort -r -n > $tmp; mv $tmp $LGTFILE ; -N50=0 -N75=0 -N90=0 -if [ $GENOME_SIZE -eq 0 ]; then GENOME_SIZE=$R; fi -size=0 -while read lgt -do - size=$(( $size + $lgt )) - if [ $N50 -eq 0 ] && [ $size -ge $(( $GENOME_SIZE / 2 )) ]; then N50=$lgt; fi - if [ $N75 -eq 0 ] && [ $size -ge $(( 3 * $GENOME_SIZE / 4 )) ]; then N75=$lgt; fi - if [ $N90 -eq 0 ] && [ $size -ge $(( 9 * $GENOME_SIZE / 10 )) ]; then N90=$lgt; break; fi -done < $LGTFILE - -if ! $CSVOUT -then - echo ; - echo "Sequence lengths:" ; - echo " Minimum $MIN" ; - echo " Quartile 25% $Q25" ; - echo " Median $Q50" ; - echo " Quartile 75% $Q75" ; - echo " Maximum $MAX" ; - echo " Average $AVG" ; - echo " N50 $N50" ; - echo " N75 $N75" ; - echo " N90 $N90" ; - echo ; -else - CSVCAPT="$CSVCAPT\tMin\tQ25\tMed\tQ75\tMax\tAvg\tN50\tN75\tN90"; - CSVLINE="$CSVLINE\t$MIN\t$Q25\t$Q50\t$Q75\t$MAX\t$AVG\t$N50\t$N75\t$N90"; - echo -e "$CSVCAPT" ; - echo -e "$CSVLINE" ; -fi - - - -if $PRINT_LGT ; then cat $INFOFILE; echo; fi - -if $PRINT_DIST -then - tmp=$(randomfile $INFILE); cat $LGTFILE | sort -n > tmp; mv tmp $LGTFILE ; - echo "Sequence length distribution:" - min=1 - max=100 - while [ $max -le 1000 ] - do - nb=0; while read lgt; do if [ $lgt -lt $min ]; then continue; elif [ $lgt -le $max ]; then nb=$(( $nb + 1 )); else break; fi; done < $LGTFILE; - echo " $min $max $nb"; min=$(( $min + 100 )); max=$(( $max + 100 )); - done - max=2000 - while [ $max -le 10000 ] - do - nb=0; while read lgt; do if [ $lgt -lt $min ]; then continue; elif [ $lgt -le $max ]; then nb=$(( $nb + 1 )); else break; fi; done < $LGTFILE; - echo " $min $max $nb"; min=$(( $max + 1 )); max=$(( $max + 1000 )); - done - up=$(( $MAX + 5000 )) - max=15000 - while [ $max -le $up ] - do - nb=0; while read lgt; do if [ $lgt -lt $min ]; then continue; elif [ $lgt -le $max ]; then nb=$(( $nb + 1 )); else break; fi; done < $LGTFILE; - echo " $min $max $nb"; min=$(( $max + 1 )); max=$(( $max + 5000 )); - done - echo -fi +done -rm $LGTFILE $FH $INFILE_UNIX $SEQS; -if [ -e $INFOFILE ]; then rm $INFOFILE; fi +rm -f $SEQS ; exit @@ -267,3 +209,4 @@ exit +