Commit 2a921bfb authored by TomKellyGenetics's avatar TomKellyGenetics
Browse files

automate detection of I1 index and R4 read

parent a658b112
Loading
Loading
Loading
Loading
+47 −0
Original line number Diff line number Diff line
@@ -860,6 +860,53 @@ if [[ $setup == "false" ]]; then
            echo " Error: number of index1 files is not matching the number of R1 and R2 files"
            echo " either give no index1 file, or give index1 file for each and every read1 file"
            exit 1
        else
            r1_list=("${read1[@]}")
            r2_list=("${read2[@]}")
            i1_list=()
            for j in ${!r1_list[@]}; do
                read=${r1_list[$j]}
                R1_file=$read
                R2_file=$(echo $indexfile | perl -pne 's/(.*)_R1/$1_R2/' )
                R4_file=$(echo $indexfile | perl -pne 's/(.*)_R1/$1_R4/' )
                I1_file=$(echo $indexfile | perl -pne 's/(.*)_R1/$1_I1/' )
                if [[ -f $R4_file ]] || [[  -f $(find $(dirname ${read}) -name $(basename ${R4_file})'*.gz') ]] || [[  -f $(find $(dirname ${read}) -name $(basename ${R4_file})'*.fastq') ]] || [[  -f $(find $(dirname ${read}) -name $(basename ${R4_file})'*.fq') ]]; then
                    if [[ $verbose ]]; then
                        echo "file $R4_file found, replacing $R1_file ..." 
                    fi
                    r1_read=$R4_file
                    r1_list[$j]=$r1_read
                    if [[ $verbose ]]; then
                        echo "file $R1_file found, replacing $R2_file ..."
                    fi
                    r2_read=$R1_file
                    r2_list[$j]=$r2_read
                    if [[ $verbose ]]; then
                         echo "file $R2_file found, replacing $I1_file ..."
                    fi
                    i1_read=$R2_file
                    i1_list[$j]=$i1_read
                fi
                if [[ -f $I1_file ]] || [[  -f $(find $(dirname ${read}) -name $(basename ${I1_file})'*.gz') ]] || [[  -f $(find $(dirname ${read}) -name $(basename ${I1_file})'*.fastq') ]] || [[  -f $(find $(dirname ${read}) -name $(basename ${I1_file})'*.fq') ]]; then
                    if [[ $verbose ]]; then
                         echo "file $I1_file found..."
                    fi
                    i1_read=$I1_file
                    i1_list[$j]=$i1_read
                fi
            done
            read1=("$r1_{list[@]}")
            read2=("$r2_{list[@]}")
            if [ ${#i1_list[@]} -eq 0 ]; then
                if [[ $verbose ]]; then
                    echo "No index files found"
                fi
            else
            if [ ${#i1_list[@]} -eq 0 ]; then
                 if [[ $verbose ]]; then
                     echo "echo "  index files found ${#index1[@]} I1s: ${index1[@]}"
                 fi
            fi
        fi
    fi
fi