Question: Delete ID only if not presnt in next line (lines are in pair)
0
gravatar for waqasnayab
2.8 years ago by
waqasnayab200
Pakistan
waqasnayab200 wrote:

Dear Community,

My this question is the follow-up / extension of C: Copy Sample ID from VCF file to ID column

I have a file like:

rsid1:sample1,sample2,sample3
rsid2:sample1,sample5
rsid3:sample4, sample6
rsid4:sample6

Each line is paired with the second line, that is , rsid1 and rsid2 are paired, rsid3 and rsid4 are paired and so on. I want to print only those samples that are present in a pair, so the desired output would be:

rsid1:sample1
rsid2:sample1
rsids3:sample6
rsid4:sample6

or is it possible to get the direct output like this from a VCF file (answered by PIERRE in the above link, but last time I did not ask this pair feature).

Any help appreciated.

Thanks,

Waqas.

sequencing snp • 793 views
ADD COMMENTlink modified 2.8 years ago by cpad011213k • written 2.8 years ago by waqasnayab200
6
gravatar for Pierre Lindenbaum
2.8 years ago by
France/Nantes/Institut du Thorax - INSERM UMR1087
Pierre Lindenbaum129k wrote:

using awk and sort:

cat input.txt |\
awk -F ':' '{n=split($2,a,/[, ]+/);for(i=1;i<=n;i++) {printf("%d %s %s\n",int((NR-1)/2),$1,a[i]);}}' |\
sort -t ' ' -k1,1 -k3,3   |\
awk '{if(NR>1 && i1==$1 && i3==$3 ) printf("%s:%s\n%s:%s\n",i2,$3,$2,$3);i1=$1;i2=$2;i3=$3;}'


rsid1:sample1
rsid2:sample1
rsid3:sample6
rsid4:sample6
ADD COMMENTlink written 2.8 years ago by Pierre Lindenbaum129k
1

Pierre or the man who always has awk-one-liners for your case! :D

ADD REPLYlink written 2.8 years ago by glihm620

Yes, it worked really very well, in fact perfect..,,,,,!!!!

Thanks Pierre

ADD REPLYlink written 2.8 years ago by waqasnayab200
0
gravatar for cpad0112
2.8 years ago by
cpad011213k
India
cpad011213k wrote:
$ awk -F: '{split($2,a,",");for(i in a)print $1"\t"a[i]}' test | sort -k2  | uniq -D -f1 | sed 's/\t/:/g'



 rsid1:sample1
 rsid2:sample1
 rsid3:sample6
 rsid4:sample6

input (test):

rsid1:sample1,sample2,sample3
rsid2:sample1,sample5
rsid3:sample4,sample6
rsid4:sample6
ADD COMMENTlink modified 2.8 years ago • written 2.8 years ago by cpad011213k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1457 users visited in the last hour