-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathModule_PedigreeCheck.sh
executable file
·108 lines (89 loc) · 3.8 KB
/
Module_PedigreeCheck.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/bash
#$ -cwd -V
#$ -pe smp 1
#$ -l h_vmem=1G
#$ -e ~/log
#$ -o ~/log
source ~/.bash_profile
#-------------------------------------------------------------------------------------------#
# Author : Andrew J Skelton |
# Language : Bash |
# Study : Exome Project |
# Data Owner : Newcastle University - Prof. Sophie Hambleton |
# Type : Gateway Script |
# Description : Create PED File from Filemap, and Check for sample's existence |
# Version : 1.0 |
# Input : Base Directory to Batch Preprocessing Directory |
# Input : Path to Reference Files |
# Input : Log Output Folder |
#-------------------------------------------------------------------------------------------#
##'Create Folder Structure and output File
##'-----------------------------------------------------------------------------------------#
mkdir -p ${3}
LOG=${3}PedigreeCheck.log
PED=${2}Samples.ped
##'-----------------------------------------------------------------------------------------#
##'Check if Log File Exists
##'-----------------------------------------------------------------------------------------#
if ls ${LOG} 1> /dev/null 2>&1; then
echo "*** New Run ***" >> ${LOG}
else
touch ${PED}
echo "*** New Run ***" >> ${LOG}
fi
##'-----------------------------------------------------------------------------------------#
##'Check if PED File Exists
##'-----------------------------------------------------------------------------------------#
if ls ${PED} 1> /dev/null 2>&1; then
echo "Ped File Exists, deleting old version" >> ${LOG}
rm ${PED}
fi
touch ${PED}
echo "Created Ped File" >> ${LOG}
##'-----------------------------------------------------------------------------------------#
##' Loop through Samples in filemap
##' Check if P/Maternal Sample Exists
##' False: Set Entry to 0
##' Recode for Gender
##' Check if File Exists
##' True: Make Ped Entry
##' False: Add to Log
##'-----------------------------------------------------------------------------------------#
while read line
do
FAM_ID=$(echo "${line}" | cut -f 1)
SAM_ID=$(echo "${line}" | cut -f 2)
PROBAN=$(echo "${line}" | cut -f 6)
PAT_ID=$(echo "${line}" | cut -f 3)
MAT_ID=$(echo "${line}" | cut -f 4)
# Check Paternal Sample Exists
PAT_QUERY=`find ${1} -type f -name "${PAT_ID}.g.vcf" | wc -l`
if (( PAT_QUERY == 0 )); then
echo "Pedigree Error: ${SAM_ID} is part of ${FAM_ID}, ${PAT_ID} Not Found, setting to 0" >> ${LOG}
PAT_ID="0"
fi
# Check Maternal Sample Exists
MAT_QUERY=`find ${1} -type f -name "${MAT_ID}.g.vcf" | wc -l`
if (( MAT_QUERY == 0 )); then
echo "Pedigree Error: ${SAM_ID} is part of ${FAM_ID}, ${MAT_ID} Not Found, setting to 0" >> ${LOG}
MAT_ID="0"
fi
# Recode for Gender
if [ $(echo "${line}" | cut -f 5) = "M" ]; then
SEX="1"
else
SEX="2"
fi
# Check if File Exists
query_list=`find ${1} -type f -name "${SAM_ID}.g.vcf" | wc -l`
if (( query_list > 0 )); then
echo -e "${FAM_ID}\t${SAM_ID}\t${PAT_ID}\t${MAT_ID}\t${SEX}\t${PROBAN}" >> ${PED}
else
if [[ ${FAM_ID} == "FAM"* ]]; then
echo "Sample Missing: *WARNING* ${SAM_ID} is part of ${FAM_ID}" >> ${LOG}
else
echo "Sample Missing: ${SAM_ID}" >> ${LOG}
fi
fi
done < ${2}SampleMap.txt
##'-----------------------------------------------------------------------------------------#