view from_imgt.sh @ 0:5560672b1ca4 draft default tip

Uploaded
author davidvanzessen
date Fri, 24 Jul 2015 04:44:39 -0400
parents
children
line wrap: on
line source

set -e

dir="$(cd "$(dirname "$0")" && pwd)"

args=($@)
inputs=(${args[@]:1})
output="${args[0]}"
echo "$PWD"

function get_summary_file
{
	imgt_zip=$1
	summary_file=$2
	
	mkdir ${PWD}/tmp/
	type="`file ${imgt_zip}`"
	if [[ "$type" == *"Zip archive"* ]] ; then
		unzip ${imgt_zip} -d $PWD/tmp/
	elif [[ "$type" == *"XZ compressed data"* ]] ; then
		mkdir "$PWD/tmp/files"
		tar -xJf ${imgt_zip} -C $PWD/tmp/files
	fi
	
	cat $PWD/tmp/*/1_* > ${summary_file}
	rm -rf $PWD/tmp
}

index=0

echo -e "Patient\tReceptor\tSample\tCell_Count\tClone_Molecule_Count_From_Spikes\tLog10_Frequency\tTotal_Read_Count\tV_Segment_Major_Gene\tJ_Segment_Major_Gene\tClone_Sequence\tCDR3_Sense_Sequence\tRelated_to_leukemia_clone" > "$output"

while true
do
	patient="${inputs[$index]}"
	index=$((index + 1))
	cell_count="${inputs[$index]}"
	index=$((index + 1))
	receptor="${inputs[$index]}"
	index=$((index + 1))
	sample_count="${inputs[$index]}"
	index=$((index + 1))
	
	sample_name="${inputs[$index]}"
	index=$((index + 1))
	
	sample_file="${inputs[$index]}"
	index=$((index + 1))
	
	echo "patient: $patient"
	echo "cell_count: ${cell_count}"
	echo "receptor: $receptor"
	echo "sample_count: ${sample_count}"
	echo "sample_name: ${sample_name}"
	echo "sample_file: ${sample_file}"
	
	get_summary_file ${sample_file} ${PWD}/summ.txt
	
	Rscript --verbose $dir/from_imgt.r ${PWD}/summ.txt ${patient} ${sample_name} ${cell_count} ${receptor} ${PWD}/tmp.txt 2>&1
	cat "${PWD}/tmp.txt" >> "$output"
	
	if [[ "${sample_count}" -gt "1" ]]; then
		sample_name="${inputs[$index]}"
		index=$((index + 1))
		
		sample_file="${inputs[$index]}"
		index=$((index + 1))
		
		echo "sample_name: ${sample_name}"
		echo "sample_file: ${sample_file}"
		
		get_summary_file ${sample_file} ${PWD}/summ.txt
		
		Rscript --verbose $dir/from_imgt.r ${PWD}/summ.txt ${patient} ${sample_name} ${cell_count} ${receptor} ${PWD}/tmp.txt 2>&1
		cat "${PWD}/tmp.txt" >> "$output"
	fi
	
	if [[ "${sample_count}" -eq "3" ]]; then		
		sample_name="${inputs[$index]}"
		index=$((index + 1))
		
		sample_file="${inputs[$index]}"
		index=$((index + 1))
		
		echo "sample_name: ${sample_name}"
		echo "sample_file: ${sample_file}"
				
		get_summary_file ${sample_file} ${PWD}/summ.txt
		
		Rscript --verbose $dir/from_imgt.r ${PWD}/summ.txt ${patient} ${sample_name} ${cell_count} ${receptor} ${PWD}/tmp.txt 2>&1
		cat "${PWD}/tmp.txt" >> "$output"
	fi
	if [[ "${index}" -eq "${#inputs[@]}" ]]; then
		exit 0
	fi
done