How To Get A Dbsnp Data From Java?
1
0
Entering edit mode
10.7 years ago
burcakotlu ▴ 40

Hi,

Is there a way to get chrName, chrPosition and observed alleles of a given dbSNP rsId in java program?

and

Is there a way to get observed alleles of a SNP given with chrName and chrPosition in java program?

Thanks, Burçak

dbsnp java • 3.5k views
ADD COMMENT
0
Entering edit mode

I have two questions: 1. question input dbSNP rsId output: chrName, chrPosition, observedAlleles 2. question input chrName, chrPosition output: observedAlleles, dnSNP rsId

I just edited the tags.

ADD REPLY
4
Entering edit mode
10.7 years ago

EDIT: You changed the original question

from

Is there a way to get chrName, chrPosition and observed alleles of a given dbSNP rsId in java program?

to

Is there a way to get observed alleles of a SNP given with chrName and chrPosition in java program?

=> This is not the same problem = I wasted my time.


use xjc to generate classes from the XML schema spec:

xjc "ftp://ftp.ncbi.nlm.nih.gov/snp/specs/docsum_3.3.xsd"

compile the following program: (it calls NCBI E-Efetch , parses the SNP structure and loop over the mapping components )

import gov.nih.nlm.ncbi.snp.docsum.*;

import java.util.ArrayList;
import java.io.InputStream;
import java.util.List;


import javax.xml.bind.*;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;
import javax.xml.transform.stream.StreamSource;

public class Biostar95284
    {
    private Unmarshaller unmarshaller;
    private static gov.nih.nlm.ncbi.snp.docsum.ObjectFactory _fool_javac=null;
    private  XMLInputFactory xmlInputFactory=null;
    private Biostar95284() throws Exception
        {
        this.xmlInputFactory = XMLInputFactory.newInstance();
        xmlInputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE);
        xmlInputFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
        xmlInputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.TRUE);
        xmlInputFactory.setXMLResolver(new javax.xml.stream.XMLResolver()
                {
                @Override
                public Object     resolveEntity(String publicID, String systemID, String baseURI, String namespace)
                    {

                    return new java.io.ByteArrayInputStream(new byte[0]);
                    }
                });

        JAXBContext jaxbCtxt=JAXBContext.newInstance("gov.nih.nlm.ncbi.snp.docsum");
        this.unmarshaller=jaxbCtxt.createUnmarshaller();


        }
    private void run(String rsId) throws Exception
        {
    if(rsId.startsWith("rs")) rsId=rsId.substring(2);
        String uri="http://www.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=snp&id="+rsId+"&retmode=xml";
            XMLEventReader reader= xmlInputFactory.createXMLEventReader(new StreamSource(uri)); 


            while(reader.hasNext())
                {
                XMLEvent evt=reader.peek();

                if(!evt.isStartElement())
                    {
                    reader.nextEvent();
                    continue;
                    }

                StartElement start=evt.asStartElement();
                String localName=start.getName().getLocalPart();

                if(!localName.equals("Rs"))
                    {
                    reader.nextEvent();
                    continue;
                    }

               Rs rs=unmarshaller.unmarshal(reader, Rs.class).getValue();

               for(Assembly as:rs.getAssembly())
                       {  
                        for(Component comp:as.getComponent())
                       {
                       for(MapLoc maploc: comp.getMapLoc())
                           {
                           System.out.print("rs"+rsId);
                           System.out.print("\t");
                           System.out.print(as.getGenomeBuild());
                           System.out.print("\t");
                           System.out.print(as.getGroupLabel());
                           System.out.print("\t");
                           System.out.print(comp.getChromosome());
                           System.out.print("\t");
                           System.out.print(maploc.getPhysMapInt());
                           System.out.println();
                           }
                           }
                           }
               }
            reader.close();
        }

    public static void main(String[] args)
        {
        try
            {
            Biostar95284 app=new Biostar95284();
            for(String arg:args)
                {
                app.run(arg);
                }
            }
        catch (Exception e)
            {
            e.printStackTrace();
            }
        }
    }

with :

javac Biostar95284.java

execute:

java Biostar95284 rs25 rs26
rs25    37.5    GRCh37.p10    7    11584141
rs25    37.5    HuRef    7    11442496
rs25    37.5    CRA_TCAGchr7v2    7    11637562
rs25    37.5    CHM1_1.0    7    11559989
rs26    37.5    GRCh37.p10    7    11583470
rs26    37.5    HuRef    7    11441825
rs26    37.5    CRA_TCAGchr7v2    7    11636891
rs26    37.5    CHM1_1.0    7    11559318
ADD COMMENT
0
Entering edit mode

Dear Pierre Lindenbaum,

Thanks for your answer. Although I have created the classes from the given xml schema using xjb successfully, the running the class Biostar95284 with given input data or any other data didn't give any output.

I have debugged the code and There are no found assembly. So it leaves the for loops. Any idea?

Thank you very much, Burcak

ADD REPLY
0
Entering edit mode

check your proxy. And sometimes, xjc is strange. In xmlInputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE); try to replace Boolean.FALSE with Boolean.TRUE

ADD REPLY
0
Entering edit mode

Replacing Boolean.FALSE with Boolean.TRUE works! Thank you. Burcak

ADD REPLY
0
Entering edit mode

I have the same problem but replacing FALSE with TRUE doesn't solve the problem.

ADD REPLY

Login before adding your answer.

Traffic: 1877 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6