This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Match col values in two datasets and merge the matched rows in a final o/p_SNPs

Dataset A is annotated, Dataset B is diseased & phenotype info.

I have two datasets (A & B) which contain snp id's. I have to match snp ID's in both the datasets, where common SNP ID's found, I have to extract other col values (from dataset B) and merge with dataset A using shell scripting or R.

genome next-gen gene snp r

Please give some example of your datasets and the expected result. Also, is this a school assignment ?

Thanks all for your response. I am new to Bioinformatics. enter image description here

In Dataset A, I have the snpIDs and I have to match them with datasetB. Where-ever it matched, it will fetch other cols from DatasetA and join in DatasetB corresponding to that matched snpID.

Pls check image for ref. https://ibb.co/3vXBv75

in R check dplyr's full_join (or left_join) using SNP ID as key . Then use select() to extract the columns of interest. Basic R stuff.

Thanks all for your response. I am new to Bioinformatics. enter image description here

In Dataset A, I have the snpIDs and I have to match them with datasetB. Where-ever it matched, it will fetch other cols from DatasetA and join in DatasetB corresponding to that matched snpID.

Pls check image for ref. https://ibb.co/3vXBv75

Am very thankful for your suggestion. I am learning R too. Tomorrow I have to submit my thesis and I need some string calculations so asked or requested for the algo.

2 answers

join <parameters> <(sort <parameters> file1) <(sort <parameters> file2) > output

To resolve this issue, I wrote a basic python script. Size of abc is 18MB (1lakh rows>), size of xyz is 120MB (>40lakh rows) I am getting desired output but it is taking long computing hours. Can we modify this script or write using pandas?

F1 = open('xyz.csv','r').read()
F2 = open('abc.tsv','r').read()
z = 0
for line in F1.strip().split('\n'):
    l = line.strip().split(',')
    for row in F2.strip().split('\n'):
        r = row.strip().split('\t')
        if "CHROM" in line:
            print(line+'\t'+row)
            continue
        if l[20] == r[0]:
            print(line+'\t'+row)
            z=1
            break
        else:
            z=0

Yes, it is only showing merging cols across datasets. I have to match all rows of one col to another col dataset.

Log in to answer this question.