Skip to content

Commit

Permalink
Merge pull request #103 from kantale/master
Browse files Browse the repository at this point in the history
Removed Process Substitution
  • Loading branch information
freerkvandijk committed Feb 13, 2014
2 parents decbaae + 7403307 commit b3d758d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
4 changes: 3 additions & 1 deletion compute5/Imputation_impute2/protocols/alignWithReference.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
#string genotypeAlignerJar
#string vcf
#string refType
#string javaExecutable

echo "chr: ${chr}"
echo "outputFolder: ${outputFolder}"
echo "knownHapsG: ${knownHapsG}"
echo "genotypeAlignerJar: ${genotypeAlignerJar}"
echo "vcf: ${vcf}"
echo "refType: ${refType}"
echo "javaExecutable: $(javaExecutable)"

haps_input=${knownHapsG}
sample_input="${knownHapsG%.haps}.sample"
Expand All @@ -41,7 +43,7 @@ getFile ${sample_input}
inputs ${sample_input}

#Do the alignment
if java -jar ${genotypeAlignerJar} \
if ${javaExecutable} -jar ${genotypeAlignerJar} \
--input ${basename_input} \
--inputType SHAPEIT2 \
--ref ${vcf} \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,29 @@ rm -f ${imputationIntermediatesFolder}/chr${chr}_${fromChrPos}-${toChrPos}_info

#Merging chunks
toExecute="paste <(cut -d ' ' -f 1-5 ${imputation__has__impute2ChunkOutput[0]})"
concatCommandColumns="cut -d ' ' -f 1-5 ${imputation__has__impute2ChunkOutput[0]} > ${imputationIntermediatesFolder}/~chr${chr}_${fromChrPos}-${toChrPos}.columns"
concatCommand="paste ${imputationIntermediatesFolder}/~chr${chr}_${fromChrPos}-${toChrPos}.columns "
echo "Running: ${concatCommandColumns}"
eval ${concatCommandColumns}
indexVar=0
for element in ${imputation__has__impute2ChunkOutput[@]}
do
indexVar=`expr $indexVar + 1`
toExecute="${toExecute} <( cut -d ' ' -f 6- ${element} )"
concatCommandColumns="cut -d ' ' -f 6- ${element} > ${imputationIntermediatesFolder}/~chr${chr}_${fromChrPos}-${toChrPos}.${indexVar}"
echo "Running: ${concatCommandColumns}"
eval ${concatCommandColumns}
concatCommand="${concatCommand} ${imputationIntermediatesFolder}/~chr${chr}_${fromChrPos}-${toChrPos}.${indexVar} "
done
toExecute="${toExecute} > ${imputationIntermediatesFolder}/~chr${chr}_${fromChrPos}-${toChrPos}"
concatCommand="${concatCommand} > ${imputationIntermediatesFolder}/~chr${chr}_${fromChrPos}-${toChrPos}"

echo "Executing: $toExecute"
eval ${toExecute}
# Process substitution is not available in all Unix shells
#echo "Executing: $toExecute"
#eval ${toExecute}

echo "Executing: ${concatCommand}"
eval ${concatCommand}

returnCode=$?
if [ $returnCode -eq 0 ]
Expand Down
8 changes: 7 additions & 1 deletion compute5/Imputation_impute2/protocols/impute2Imputation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,14 @@ mkdir -p ${imputationIntermediatesFolder}
#Create subset of samples to exclude
sample_subset_to_exclude=${tmpOutput}.toExclude
echo "Samples excluded from this run: ${sample_subset_to_exclude}"
cat <(cat ${genotype_aligner_output_sample} | tail -n +3 | head -n `expr ${fromSample} - 1`) <(cat ${genotype_aligner_output_sample} | tail -n +3 | tail -n +`expr ${toSample} + 1`) | cut -f 2 -d ' ' > ${sample_subset_to_exclude}

# Process substitution is not supported from all shells : http://www.gnu.org/software/bash/manual/bashref.html#Process-Substitution so it's better to avoid it.
# This is the way to implement the following three lines in a single command with process substitution:
# cat <(cat ${genotype_aligner_output_sample} | tail -n +3 | head -n `expr ${fromSample} - 1`) <(cat ${genotype_aligner_output_sample} | tail -n +3 | tail -n +`expr ${toSample} + 1`) | cut -f 2 -d ' ' > ${sample_subset_to_exclude}

cat ${genotype_aligner_output_sample} | tail -n +3 | head -n `expr ${fromSample} - 1` > ${sample_subset_to_exclude}.part1
cat ${genotype_aligner_output_sample} | tail -n +3 | tail -n +`expr ${toSample} + 1` > ${sample_subset_to_exclude}.part2
cat ${sample_subset_to_exclude}.part1 ${sample_subset_to_exclude}.part2 | cut -f 2 -d ' ' > ${sample_subset_to_exclude}

#From http://mathgen.stats.ox.ac.uk/impute/impute_v2.html
#To use pre-phased study data in this example, you would replace the -g file with a -known_haps_g file and add the -use_prephased_g flag to your IMPUTE2 command.
Expand Down

0 comments on commit b3d758d

Please sign in to comment.