This is a test version of Biostars. For the public version, visit https://www.biostars.org.
use of 2 covariate files for association analysis in plink

Dear all, I want to use 2 covariate file in my association analysis in plink, is this possible ?, (without combining all the covariates in 1 file) Is it valid to use ? --bfile file \ --logistic \ --covar /covarfile1.txt \ --covar-number 1-3 \ --covar/covarfile2.txt --covar-number2-3 \ --out filename Thanks

cov plink association

Please use:
-A more informative title: adding stuff like "association analysis" and "plink" would be good
-More precise tags: for example "plink"

1 answer

No; you'll need to merge the files with a short script.

Many thanks for your response. Could you please advice how the covariate files can be merged based on FID and IID in bash/ plink? (The individuals can be uniquely identified only by using both FID and IID information). And not al individuals in first covariate file are present in the second covariate file and vice versa.

With a bash script:

A. Merge the FID and IID fields with something like

cat orig_covar_1.txt | awk '{out=$1"_"$2; for(i=3;i<=NF;++i){out=out"\t"$i}; print out}' > covar_merged_ids_1.txt

cat orig_covar_2.txt | awk '{out=$1"_"$2; for(i=3;i<=NF;++i){out=out"\t"$i}; print out}' > covar_merged_ids_2.txt

If underscores are already present in your file, replace "_" with some other character that isn't used.

B. Use the Unix "join" command (https://en.wikipedia.org/wiki/Join_(Unix) ) to merge covar_merged_ids_1.txt and _2.txt.

C. Split the merged IDs back into FID/IID with e.g.

cat covar_joined_merged_ids.txt | tr '_' '\t' > covar_joined.txt

Thank you very much.

Suppose your files doesn't has header row, and using space as separator. then the following code could be applied for your question.

awk 'FNR==NR{j=$1 FS $2;arr[j]=$3;for(i=4;i<=NF;i++){arr[j]=arr[j] FS $i};next}{m=$1 FS $2;print $0,arr[m];delete arr[m]}END{for(k in arr){print k,arr[k]}}' test1 test 

where test1 looks like

a b c q
a c q x
a i o a
b c q q
b d p e
b w a h

test looks like

a b c e
a c e z
b c a w
b w a w

and the result would be like

a b c e c q
a c e z q x
b c a w q q
b w a w a h
a i o a
b d p e

the above awk code match first two columns in test1 and test, and then merge two files together. and there are two rows in test1 that do now appear in test ,so i print these lines in the end of the output.

Log in to answer this question.