#!/bin/bash # creates .pair and singleton files . Acts on a folder containing all the # files and generates an output folder containing pair and singleton # files. Surprisingly the bash script i wrote to do the whole thing was # incredibly slower than the perl script that Sam was already using. # This bash script basically calls the perl script to do all the work. function usage(){ echo -e "Usage: /create_pairs \n"; } input_folder=$1 output_folder=$2 max_rate=$3 slash_string=$4 #show help if [ "$input_folder" == "--help" ] then echo -e "Help\n" usage; exit; fi #check if the input and output folder are defined in command line if [ -z "$input_folder" ] then echo -e "Input folder is not defined \n" usage; exit; elif [ -z "$output_folder" ] then echo -e "Output folder is not defined \n" usage; exit; #check if max_rate is defined elif [ -z "$max_rate" ] then echo -e "max rate is not defined \n" usage; else if [ -d "$output_folder" ]; then echo "output directory already exists. Exiting now!" exit; fi mkdir $output_folder # call the illumina parse script. This script converts the fastq # files to fasta format and removes low quality entries. By doing # this, we can speed up. ./illumina_parse.pl -fi "$input_folder" "$output_folder" "$max_rate" "$slash_string" # files array1.txt and array2.txt are temporary files containing # the file names . ls "$output_folder/" | grep "R1" | sort > "array1.txt" ls "$output_folder/" | grep "R2" | sort > "array2.txt" # read files array1 and array2.txt to create an array in bash. index1=0; while read line ; do array1[$index1]="$line" index1=$(($index1+1)) done < array1.txt index2=0; while read line ; do array2[$index2]="$line" index2=$(($index2+1)) done < array2.txt # make sure array1 and array2 are of equal size. If not, it means # some readings are missing. Print a warning message about it and # move along if [ $index1 -eq $index2 ] then size=$index1; elif [ $index1 > $index2 ] then size=$index2; echo -e "Reading R2 misses one or few files\n"; else size=$index1; echo -e "Reading R1 misses one or few files\n"; fi echo -e "size is $size\n"; i=0; # loop throught the array. # 1. combine files from read 1 and read2. # 2. and then run sam's script to create pair and singleton files while [ $i -lt $size ]; do echo -e "Copying $output_folder/${array2[$i]} into $output_folder/${array1[$i]}\n"; infile="$output_folder/${array2[$i]}"; infile1="$output_folder/${array1[$i]}"; # append file from reading 2 into file from reading 1 cat "$infile" >> "$infile1"; # remove file from reading2 now that it is appended to # file form read1. rm -f "$infile"; echo -e "Creating singleton and pair files from $infile1\n" ./break_pile_to_pairs.pl "$infile1" # we don't need the file anymore. remove it rm -f $infile1 i=$(($i+1)) done fi