Commit 5bf7a9de authored by TomKellyGenetics's avatar TomKellyGenetics
Browse files

automatically correct file names if R1 and R2 are missing from file names

parent 0f520750
Loading
Loading
Loading
Loading
+60 −40
Original line number Diff line number Diff line
@@ -890,6 +890,7 @@ if [[ $setup == "false" ]]; then
            for j in ${!r1_list[@]}; do
                read=${r1_list[$j]}
                R1_file=$read
                if [[ $read == *R1* ]]; then
                    R2_file=$(echo $read | perl -pne 's/(.*)_R1/$1_R2/' )
                    R4_file=$(echo $read | perl -pne 's/(.*)_R1/$1_R4/' )
                    I1_file=$(echo $read | perl -pne 's/(.*)_R1/$1_I1/' )
@@ -917,6 +918,7 @@ if [[ $setup == "false" ]]; then
                        i1_read=$I1_file
                        i1_list[$j]=$i1_read
                    fi
                fi
            done
            read1=("${r1_list[@]}")
            read2=("${r2_list[@]}")
@@ -953,6 +955,7 @@ if [[ $setup == "false" ]]; then
                for j in ${!r1_list[@]}; do
                    read=${r1_list[$j]}
                    R1_file=$read
                    if [[ $read == *R1* ]]; then
                        R2_file=$(echo $read | perl -pne 's/(.*)_R1/$1_R2/' )
                        R3_file=$(echo $read | perl -pne 's/(.*)_R1/$1_R3/' )
                        I2_file=$(echo $read | perl -pne 's/(.*)_R1/$1_I2/' )
@@ -970,6 +973,7 @@ if [[ $setup == "false" ]]; then
                            i2_read=$I2_file
                            i2_list[$j]=$i2_read
                        fi
                    fi
                done
                if [[ ${#i2_list[@]} -eq 0 ]]; then
                    if [[ $verbose ]]; then
@@ -1143,6 +1147,22 @@ for key in ${keys[@]}; do
            fi
            read=${fullpath}
        fi
        if [[ $read == *$readkey* ]]; then
            if [[ $verbose ]]; then
                echo " (file) $read contains $readkey"
            fi
        else
            if [[ $verbose ]]; then
                echo " (file) $read does not contain $readkey"
            fi
            readsuffix="${readkey: -1}"
            rename -f "s/_${readsuffix}\./_R${readsuffix}_001./" $read
            read=`echo $read | sed -e "s/_${readsuffix}\./_R${readsuffix}_001./g"`
            if [[ $verbose ]]; then
                echo " (file) $read contains $readkey"
            fi
        fi

        case $read in
            #check if contains lane before read
            *_L0[0123456789][0123456789]_$readkey*)