Showing posts sorted by relevance for query xslt. Sort by date Show all posts
Showing posts sorted by relevance for query xslt. Sort by date Show all posts

29 October 2008

EMBL/Strings: find interactors at 2 degrees of separation my notebook.

Thank (again) to the Life Scientists on FriendFeed I've discoreved the API of STRING8 ( STRING 8—a global view on proteins and their functional interactions in 630 organisms NAR 2008): STRING is a database and web resource dedicated to protein–protein interactions, including both physical and functional interactions..


I've used this API to find the partners of a protein at two degrees of separations, here is my notebook:
First download the network for each protein (Note : the database is also available for download) using their HTTP-based API: e.g.: http://string.embl.de/api/psi-mi/interactions?identifier=Roxan. The Ensembl gene ID seems to be the more efficient (non ambiguous) identifiers (e.g. http://string.embl.de/api/psi-mi/interactions?identifier=ENSP00000263243). Note that the STRING database is available for download.

I also wrote a basic XSLT stylesheet transforming the PSI/XML to graphiz-dot format. The stylesheet is available here: http://code.google.com/p/lindenb/source/browse/trunk/src/xsl/psi2dot.xslt. e.g:

xsltproc psi2dot.xslt ROXAN.xml | dot -opicture.png -Tpng



Another XSLT stylesheet (psi2sql.xslt creates the statements to insert one or more psi file into a mysql database ).
xsltproc --stringparam temporary "" psi2sql.xslt interaction1.xml | mysql -u login --password=password -D database -N
xsltproc --stringparam temporary "" psi2sql.xslt interaction2.xml | mysql -u login --password=password -D database -N
xsltproc --stringparam temporary "" psi2sql.xslt interaction3.xml | mysql -u login --password=password -D database -N

The parameter temporary is an argument for the stylesheet telling mysql not to work with temporary tables.

Two of the tables created (interactions and interactors) are described below:
mysql> desc interactor;
+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| pk | varchar(50) | NO | UNI | NULL | |
| shortLabel | varchar(255) | YES | | NULL | |
| fullName | text | YES | | NULL | |
+------------+--------------+------+-----+---------+----------------+

mysql> desc interaction;
+----------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| interactor1_id | int(11) | NO | MUL | NULL | |
| interactor2_id | int(11) | NO | MUL | NULL | |
| unitLabel | varchar(50) | YES | | NULL | |
| unitFullName | varchar(100) | YES | | NULL | |
| confidence | float | YES | | NULL | |
| experiment_id | int(11) | NO | MUL | NULL | |
+----------------+--------------+------+-----+---------+----------------+
7 rows in set (0.00 sec)



And here are the mysql statements finding the protein linked to EIF4G1 at two degrees of separation:
create a temporary table containing a the 2-deg interactions.
create temporary table t1
(
id1 int,
id2 int,
id3 int
);

insert into t1(id1,id2,id3)
select distinct
P1.id,P2.id,P3.id
from
interactor as P1,
interactor as P2,
interactor as P3,
interaction as I1,
interaction as I2
where
P1.shortLabel="EIF4G1" and
P3.shortLabel!="EIF4G1" and
((P1.id= I1.interactor1_id AND P2.id= I1.interactor2_id) or (P2.id= I1.interactor1_id AND P1.id= I1.interactor2_id)) and
((P2.id= I2.interactor1_id and P3.id= I2.interactor2_id) or (P3.id= I2.interactor1_id and P2.id= I2.interactor2_id))
;

Remove the simple interactions from the temporary table:
delete t1 from
t1,
interactor as P1,
interactor as P3,
interaction as I1
where
((t1.id1=P1.id and t1.id3=P3.id) or (t1.id1=P3.id and t1.id3=P1.id)) and
((P1.id= I1.interactor1_id and P3.id= I1.interactor2_id) or (P3.id= I1.interactor1_id and P1.id= I1.interactor2_id))
;


And dump the results:
select
P1.shortLabel as "Partner1",
P2.shortLabel as "Partner2",
P3.shortLabel as "Partner3"
from
t1,
interactor as P1,
interactor as P2,
interactor as P3
where
t1.id1 = P1.id
and
t1.id2 = P2.id
and
t1.id3=P3.id
;


Here is the result:
Partner1 Partner2 Partner3
EIF4G1 ZC3H7B HMGB1
EIF4G1 ZC3H7B KCTD12
EIF4G1 ZC3H7B FGB
EIF4G1 ZC3H7B GLUD1
EIF4G1 ZC3H7B PDGFRA
EIF4G1 ZC3H7B PXN



That's it
Pierre

18 September 2009

Translating DNA with XALAN: A custom extension for XSLT

In this post, I'll show how I've create a custom extension for XALAN , a java-based XSLT engine. My favorite XSLT processor has always been xsltproc but I was missing the capacity to create a custom function to process the XML document: Here I show how a java class can be plugged to XALAN to translate a DNA sequence to a peptide.

The Java class

The following class test.Translate translate a DNA to an amino acid sequence, the argument of the constructor is the transl_table given by the NCBI (see http://www.ncbi.nlm.nih.gov/Taxonomy/Utils/wprintgc.cgi). This is not Rocket Science.
package test;
public class Translate
{
static String geneticCode;

public Translate(String geneticCode)
{
this.geneticCode=geneticCode;
}

private static int base2index(char c)
{
switch(Character.toLowerCase(c))
{
case 't': return 0;
case 'c': return 1;
case 'a': return 2;
case 'g': return 3;
default: return -1;
}
}

public String translate(String sequence) {
StringBuilder b= new StringBuilder(1+sequence.length()/3);
for(int i=0;i+2< sequence.length();i+=3)
{
int base1= base2index(sequence.charAt(i));
int base2= base2index(sequence.charAt(i+1));
int base3= base2index(sequence.charAt(i+2));
if(base1==-1 || base2==-1 || base3==-1)
{
b.append('?');
}
else
{
b.append(geneticCode.charAt(base1*16+base2*4+base3));
}
}
return b.toString();
}
}

Compiling and packaging the source


javac test/Translate.java
jar cvf translate.jar test

The XML source


The XML source is a set of INSDSeq sequences downloaded from the NCBI/Genbank
<?xml version="1.0"?>
<!DOCTYPE INSDSet PUBLIC "-//NCBI//INSD INSDSeq/EN" "http://ww
w.ncbi.nlm.nih.gov/dtd/INSD_INSDSeq.dtd">
<INSDSet>
<INSDSeq>
<INSDSeq_locus>NM_004953</INSDSeq_locus>
<INSDSeq_length>4888</INSDSeq_length>
<INSDSeq_strandedness>single</INSDSeq_strandedness>
<INSDSeq_moltype>mRNA</INSDSeq_moltype>
<INSDSeq_topology>linear</INSDSeq_topology>
<INSDSeq_division>PRI</INSDSeq_division>
<INSDSeq_update-date>03-SEP-2009</INSDSeq_update-date>
<INSDSeq_create-date>14-MAY-1999</INSDSeq_create-date>
<INSDSeq_definition>Homo sapiens eukaryotic translation initiation factor 4 gamma, 1 (EIF4G1), transcript variant 5, mRNA</INSDSeq_definition>
<INSDSeq_primary-accession>NM_004953</INSDSeq_primary-accession>
<INSDSeq_accession-version>NM_004953.3</INSDSeq_accession-version>
<INSDSeq_other-seqids>
<INSDSeqid>ref|NM_004953.3|</INSDSeqid>
<INSDSeqid>gi|148277098</INSDSeqid>
</INSDSeq_other-seqids>
<INSDSeq_source>Homo sapiens (human)</INSDSeq_source>
<INSDSeq_organism>Homo sapiens</INSDSeq_organism>
<INSDSeq_taxonomy>Eukaryota; Metazoa; Chordata; Craniata; Vertebrata; Eu
teleostomi; Mammalia; Eutheria; Euarchontoglires; Primates; Haplorrhini; Catarrh
ini; Hominidae; Homo</INSDSeq_taxonomy>
(...)
<INSDFeature_key>CDS</INSDFeature_key>
<INSDFeature_location>207..4418</INSDFeature_location>
<INSDFeature_intervals>
<INSDInterval>
<INSDInterval_from>207</INSDInterval_from>
<INSDInterval_to>4418</INSDInterval_to>
<INSDInterval_accession>NM_004953.3</INSDInterval_accession>
</INSDInterval>
</INSDFeature_intervals>
<INSDFeature_quals>
<INSDQualifier>
<INSDQualifier_name>gene</INSDQualifier_name>
<INSDQualifier_value>EIF4G1</INSDQualifier_value>
</INSDQualifier>
<INSDQualifier>
<INSDQualifier_name>gene_synonym</INSDQualifier_name>
<INSDQualifier_value>DKFZp686A1451; EIF4F; EIF4G; p220</INSDQualifier_value>
</INSDQualifier>
(...)
cttttaatgatgagggtaactatttcagttgtgagccttctagggccccaggctgggaggctcagaggactgaatctgggacctgtgttccccccggcaggcagggacaagatggcatggcaagcatgggggcggggtgggtggggagggatgctgcatttctcagctgggcagtaatcaatttaatggtcctttaaaatgtctgtgtattaaaaatttaagaataccacactttaatattaaatattcataaggtctagtatcttgataataatgtagatgttttaataacaatttttgtccttcttaaaataaaatgaaagaaacttgcttcccttagcctttgttctagaaaataaacttgtgcactttga</INSDSeq_sequence>
</INSDSeq>
</INSDSet>

The XSLT stylesseet

In the following XSLT stylesheet:
in the header, the prefix bio is associated with our Translate class
a parameter named GENETICCODE defines the default transl_table
A new Translate object named code is created with bio:new($GENETICCODE)
This code is then called on the sub-string of DNA containing the CDS: bio:translate($code,substring($dna,$start,1+($end - $start)))


<xsl:stylesheet version="1.0"
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
xmlns:bio="xalan://test.Translate"
extension-element-prefixes="bio">

<xsl:output method="xml" indent="yes"/>

<xsl:param name="GENETICCODE">FFLLSSSSYY**CC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG</xsl:param>

<xsl:template match="/INSDSet">
<html><body>
<xsl:apply-templates select="INSDSeq"/>
</body></html>
</xsl:template>


<xsl:template match="INSDSeq">
<xsl:variable name="dna" select="INSDSeq_sequence"/>
<div>
<h2><xsl:value-of select="INSDSeq_locus"/><xsl:text> : </xsl:text><xsl:value-of select="INSDSeq_definition"/></h2>
<xsl:for-each select="INSDSeq_feature-table/INSDFeature[INSDFeature_key='CDS']/INSDFeature_intervals">
<xsl:variable name="code" select="bio:new($GENETICCODE)"/>
<xsl:variable name="start" select="number(INSDInterval/INSDInterval_from)"/>
<xsl:variable name="end" select="number(INSDInterval/INSDInterval_to)"/>
<div style="font-family:monospace;word-wrap:break-word;width:400px;background-color:rgb(230,230,230);"><xsl:value-of select="bio:translate($code,substring($dna,$start,1+($end - $start)))"/></div>
</xsl:for-each>
</div>
</xsl:template>


</xsl:stylesheet>

Running this XSLT stylesheet with XALAN


java -cp ${XALAN_PATH}/org.apache.xalan_2.7.1.v200905122109.jar:${XALAN_PATH}/org.apache.xml.serializer_2.7.1.v200902170519.jar:translate.jar org.apache.xalan.xslt.Process -IN sequences.gbc -XSL seq2html.xsl

Result


NM_004953 : Homo sapiens eukaryotic translation initiation factor 4 gamma, 1
(EIF4G1), transcript variant 5, mRNA


MSGARTASTPTPPQTGGGLEPQANGETPQVAVIVRPDDRSQGAIIADRPGLPGPEHSPSESQPSSPSPTPSPSPVLEPGSEPNLAVLSIPGDTMTTIQMSVEESTPISRETGEPYRLSPEPTPLAEPILEVEVTLSKPVPESEFSS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LKEGSSNQRVFDWIEANLSEQQIVSNTLVRALMTAVCYSAIIFETPLRVDVAVLKARAKLLQKYLCDEQKELQALYALQALVVTLEQPPNLLRMFFDALYDEDVVKEDAFYSWESSKDPAEQQGKGVALKSVTAFFKWLREAEEESDHN*



NM_182917 : Homo sapiens eukaryotic translation initiation factor 4 gamma, 1
(EIF4G1), transcript variant 1, mRNA


MNKAPQSTGPPPAPSPGLPQPAFPPGQTAPVVFSTPQATQMNTPSQPRQHFYPSRAQPPSSAASRVQSAAPARPGPAAHVYPAGSQVMMIPSQISYPASQGAYYIPGQGRSTYVVPTQQYPVQPGAPGFYPGASPTEFGTYAGAYYPAQGVQQFPTGVAPAPVLMNQPPQIAPKRERKTIRIRDPNQGGKDITEEIMSGARTASTPTPPQTGGGLEPQANGETPQVAVIVRPDDRSQGAIIADRPGLPGPEHSPSESQPSSPSPTPSPSPVLEPGSEPNLAVLSIPGDTMTTIQMSVEESTPISRETGEPYRLSPEPTPLAEPILEVEVTLSKPVPESEFSSSPLQAPTPLASHTVEIHEPNGMVPSEDLEPEVESSPELAPPPACPSESPVPIAPTAQPEELLNGAPSPPAVDLSPVSEPEEQAKEVTASMAPPTIPSATPATAPSATSPAQEEEMEEEEEEEEGEAGEAGEAESEKGGEELLPPESTPIPANLSQNLEAAAATQVAVSVPKRRRKIKELNKKEAVGDLLDAFKEANPAVPEVENQPPAGSNPGPESEGSGVPPRPEEADETWDSKEDKIHNAENIQPGEQKYEYKSDQWKPLNLEEKKRYDREFLLGFQFIFASMQKPEGLPHISDVVLDKANKTPLRPLDPTRLQGINCGPDFTPSFANLGRTTLSTRGPPRGGPGGELPRGPAGLGPRRSQQGPRKEPRKIIATVLMTEDIKLNKAEKAWKPSSKRTAADKDRGEEDADGSKTQDLFRRVRSILNKLTPQMFQQLMKQVTQLAIDTEERLKGVIDLIFEKAISEPNFSVAYANMCRCLMALKVPTTEKPTVTVNFRKLLLNRCQKEFEKDKDDDEVFEKKQKEMDEAATAEERGRLKEELEEARDIARRRSLGNIKFIGELFKLKMLTEAIMHDCVVKLLKNHDEESLECLCRLLTTIGKDLDFEKAKPRMDQYFNQMEKIIKEKKTSSRIRFMLQDVLDLRGSNWVPRRGDQGPKTIDQIHKEAEMEEHREHIKVQQLMAKGSDKRRGGPPGPPISRGLPLVDDGGWNTVPISKGSRPIDTSRLTKITKPGSIDSNNQLFAPGGRLSWGKGSSGGSGAKPSDAASEAARPATSTLNRFSALQQAVPTESTDNRRVVQRSSLSRERGEKAGDRGDRLERSERGGDRGDRLDRARTPATKRSFSKEVEERSRERPSQPEGLRKAASLTEDRDRGRDAVKREAALPPVSPLKAALSEEELEKKSKAIIEEYLHLNDMKEAVQCVQELASPSLLFIFVRHGVESTLERSAIAREHMGQLLHQLLCAGHLSTAQYYQGLYEILELAEDMEIDIPHVWLYLAELVTPILQEGGVPMGELFREITKPLRPLGKAASLLLEILGLLCKSMGPKKVGTLWREAGLSWKEFLPEGQDIGAFVAEQKVEYTLGEESEAPGQRALPSEELNRQLEKLLKEGSSNQRVFDWIEANLSEQQIVSNTLVRALMTAVCYSAIIFETPLRVDVAVLKARAKLLQKYLCDEQKELQALYALQALVVTLEQPPNLLRMFFDALYDEDVVKEDAFYSWESSKDPAEQQGKGVALKSVTAFFKWLREAEEESDHN*



Running this XSLT stylesheet with XALAN and another genetic code


We set the param GENETICCODE to the Scenedesmus obliquus mitochondrial Code:
java -cp ${XALAN_PATH}/org.apache.xalan_2.7.1.v200905122109.jar:${XALAN_PATH}/org.apache.xml.serializer_2.7.1.v200902170519.jar:translate.jar org.apache.xalan.xslt.Process -IN sequences.gbc -XSL seq2html.xsl -PARAM GENETICCODE "'FFLLSSSSYY*QCC*WLLLLPPPPHHQQRRRRIIIMTTTTNNKKSSRRVVVVAAAADDEEGGGG'"

Result



NM_004953 : Homo sapiens eukaryotic translation initiation factor 4 gamma, 1
(EIF4G1), transcript variant 5, mRNA


ILGARMASTPTLPQTGGELELHVTGETPQRVVRVRPADRSQGAIRVDRPGLLGP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LVTPRLQDEGVPIGELFRERTKLLSPLGNVVSLLLEILGLLCNSIELNKVGTL*RDAGWS*KD'LLDGQDREAFVVDQKVESTLGEESDALGQRALPSEELNRQLEKLLKEGSKNQRVFD*IEANLKEQQIVSNTFRRALITVVCSLARR'EMPLRVDRAVLNARAKLLQNYLQDEQKELQALYALQAWVVTFDQLPNLLRIF'DALSDEDVVKEAAFYK*EKSKDPVEQQGKEVAWNLVTAFFK*LQDAEEELDHNC



NM_182917 : Homo sapiens eukaryotic translation initiation factor 4 gamma, 1
(EIF4G1), transcript variant 1, mRNA


INNVPQSTGPPPAPSPGLPQPA'PPGQTAPVVFKTPHATHINTLLQPRQHFYLSRAQPPSKAASRVQKAALARLGPVAPVYLVGSHVIIILSQISYPASQGAYYILGQGQSTYRVPTQQYLVQPGAPGFSPEASLTD'GTYVGAYSPAHGVQQ'PMGVAPAPRLINQPPQRVPKREQKTIRRRAPNHGGKAITEEIILGARMASTPTLPQTGGELELHVTGETPQRVVRVRPADRSQGAIRVDRPGLLGPEPSLSDSQLSSLLPTPSPSPVLDPGLELTLAVLLRLGDMITMIHILVDDSTPISQDMGEPSRLLPDPMLLADPILDVDVTWSNPRPDLE'LSKLLQVPTLLALHTVDRPELTGIVPLDALDPEVESSPEWVLPPVCPSDSLVPRVPMAHLEDLLNGAPSPPVVDFSPVKEPEEQAKEVTASIAPPTIPLVMPVTVLSVMSPVQEEDIDDDDDEDDGDAGDAGDVEKENGGEDLLPPEKTLRPANLLQTLEAAAAMHVAVLVPKRSRNRKELTKKEVRGDWLAAFKEANPAVPEVDTQLLAGSTPGPELEGKEVPPQLEDAAET*DSKDDNRHTVENIQPGDQKSDSKSAQ*KLLNLEENNQYDQEFLWE'QFI'AKIQKPEGLPPIKDVVLDKATNTPLRPLAPMSLHGITQGPDFMPS'ANWGRTTWSTQGPPREGPEGELPQGPVGLGPRRLQQGPRNDPRKIRATVFITDAINLNNAENA*NPSSKRTAVAKARGDDAVAGSNTQDLFRRVRSILTNLTPQIFQQLIKHVTQLAIDTEDRLNGVRDLR'EKARSEPNFLVASANICRCLIALNVPMTDKPTVMVNFRKLLLTRQQKE'ENDNAAAER'EKKHNEIADVVTAEDRGRLKDELDEVRDIARRRLFGTIK'RGELFNLKIFTEAIIPDQVVNLWKNPADESWECWQQLLTTRGNDLD'DNAKPRIAQSFNQIDNIRNDKKTSSRIR'ILQDVLALRGST*VPRRGAQEPKTRDQIPKEVEIDDPREHINVQQLIAKGKDKQRGELPGLPISQGWPWVAAEG*NTRPISNESRPRDTSRLTKITKLGSIALNNQL'ALGGRLS*GKGSSGGSGAKPSDAASDVVRPVMKMLTRFSAWHHAVPTDSTATSQVVQRKSLSRDRGENVGDRGDRLERKDRGGDQGDRWAQARTLVTKRSFSKDVEERKSDRPSQLEGLRKAVSLTEARDQGRAAVKRDVALPPVSPLKAVLLEEEFEKNSKVIREDSLPLTDINEAVQCVQELASPSLLFI'VRPEVELTLERKARVQEPIGQLLHQLLQVGPLLMVQYYHGLSDILDLVEDIDRDIPHV*LYLADLVTPRLQDEGVPIGELFRERTKLLSPLGNVVSLLLEILGLLCNSIELNKVGTL*RDAGWS*KD'LLDGQDREAFVVDQKVESTLGEESDALGQRALPSEELNRQLEKLLKEGSKNQRVFD*IEANLKEQQIVSNTFRRALITVVCSLARR'EMPLRVDRAVLNARAKLLQNYLQDEQKELQALYALQAWVVTFDQLPNLLRIF'DALSDEDVVKEAAFYK*EKSKDPVEQQGKEVAWNLVTAFFK*LQDAEEELDHNC



That's it
Pierre

12 February 2010

Processing large XML documents with XSLT

I've resurrected an old java program called xsltstream which might be useful for biohackathon2010. This program applies a XSLT stylesheet only for the given node from a large xml document. The DOM is read from a SAX stream, built in memory for each target element , processed with XSLT and then disposed. Now, say you want to transform a XML file from dbSNP with XSLT to make a RDF document. You cannot do that with xsltproc because the XML file is just too big ( e.g. ftp://ftp.ncbi.nih.gov/snp/organisms/human_9606/XML/ds_ch1.xml.gz is 1,099,375 KB ).
But an xslt stylesheet can be applied with xsltstream to all the <Rs> elements of 'ds_ch1.xml.gz':

java -jar xsltstream.jar -x 'http://lindenb.googlecode.com/svn/trunk/src/xsl/dbsnp2rdf.xsl' -q Rs \
'ftp://ftp.ncbi.nih.gov/snp/organisms/human_9606/XML/ds_ch1.xml.gz' |\
grep -v "rdf:RDF" | grep -v "<?xml version"


(...)
<o:SNP rdf:about="http://www.ncbi.nlm.nih.gov/snp/830">
<dc:title>rs830</dc:title>
<o:taxon rdf:resource="http://www.ncbi.nlm.nih.gov/taxonomy/9606"/>
<o:het rdf:datatype="http://www.w3.org/2001/XMLSchema#float">0.02</o:het>
<o:hasHandle rdf:resource="urn:void:ncbi:snp:handle:WIAF"/>
<o:hasHandle rdf:resource="urn:void:ncbi:snp:handle:SNP500CANCER"/>
<o:hasHandle rdf:resource="urn:void:ncbi:snp:handle:SEQUENOM"/>
<o:hasMapping>
<o:Mapping>
<o:build rdf:resource="urn:void:ncbi:build:Celera/36_3"/>
<o:chrom rdf:resource="urn:void:ncbi:chromosome:9606/chr1"/>
<o:start rdf:datatype="http://www.w3.org/2001/XMLSchema#int">66444409</o:start>
<o:end rdf:datatype="http://www.w3.org/2001/XMLSchema#int">66444410</o:end>
<o:orient>+</o:orient>
</o:Mapping>
</o:hasMapping>
<o:hasMapping>
<o:Mapping>
<o:build rdf:resource="urn:void:ncbi:build:HuRef/36_3"/>
<o:chrom rdf:resource="urn:void:ncbi:chromosome:9606/chr1"/>
<o:start rdf:datatype="http://www.w3.org/2001/XMLSchema#int">66263806</o:start>
<o:end rdf:datatype="http://www.w3.org/2001/XMLSchema#int">66263807</o:end>
<o:orient>-</o:orient>
</o:Mapping>
</o:hasMapping>
<o:hasMapping>
<o:Mapping>
<o:build rdf:resource="urn:void:ncbi:build:reference/36_3"/>
<o:chrom rdf:resource="urn:void:ncbi:chromosome:9606/chr1"/>
<o:start rdf:datatype="http://www.w3.org/2001/XMLSchema#int">67926134</o:start>
<o:end rdf:datatype="http://www.w3.org/2001/XMLSchema#int">67926135</o:end>
<o:orient>+</o:orient>
</o:Mapping>
</o:hasMapping>
</o:SNP>


<o:SNP rdf:about="http://www.ncbi.nlm.nih.gov/snp/844">
<dc:title>rs844</dc:title>
<o:taxon rdf:resource="http://www.ncbi.nlm.nih.gov/taxonomy/9606"/>
<o:het rdf:datatype="http://www.w3.org/2001/XMLSchema#float">0.42</o:het>
<o:hasHandle rdf:resource="urn:void:ncbi:snp:handle:WIAF"/>
<o:hasHandle rdf:resource="urn:void:ncbi:snp:handle:LEE"/>
<o:hasHandle rdf:resource="urn:void:ncbi:snp:handle:HGBASE"/>
<o:hasHandle rdf:resource="urn:void:ncbi:snp:handle:SC_JCM"/>
<o:hasHandle rdf:resource="urn:void:ncbi:snp:handle:TSC-CSHL"/>
<o:hasHandle rdf:resource="urn:void:ncbi:snp:handle:LEE"/>
<o:hasHandle rdf:resource="urn:void:ncbi:snp:handle:YUSUKE"/>
<o:hasHandle rdf:resource="urn:void:ncbi:snp:handle:CGAP-GAI"/>
<o:hasHandle rdf:resource="urn:void:ncbi:snp:handle:CSHL-HAPMAP"/>
<o:hasHandle rdf:resource="urn:void:ncbi:snp:handle:PERLEGEN"/>
<o:hasHandle rdf:resource="urn:void:ncbi:snp:handle:ABI"/>
<o:hasHandle rdf:resource="urn:void:ncbi:snp:handle:SI_EXO"/>
<o:hasHandle rdf:resource="urn:void:ncbi:snp:handle:BCMHGSC_JDW"/>
<o:hasHandle rdf:resource="urn:void:ncbi:snp:handle:HUMANGENOME_JCVI"/>
<o:hasHandle rdf:resource="urn:void:ncbi:snp:handle:SNP500CANCER"/>
<o:hasHandle rdf:resource="urn:void:ncbi:snp:handle:1000GENOMES"/>
<o:hasHandle rdf:resource="urn:void:ncbi:snp:handle:ILLUMINA-UK"/>
<o:hasMapping>
<o:Mapping>
<o:build rdf:resource="urn:void:ncbi:build:Celera/36_3"/>
<o:chrom rdf:resource="urn:void:ncbi:chromosome:9606/chr1"/>
<o:start rdf:datatype="http://www.w3.org/2001/XMLSchema#int">134750981</o:start>
<o:end rdf:datatype="http://www.w3.org/2001/XMLSchema#int">134750982</o:end>
<o:orient>+</o:orient>
</o:Mapping>
</o:hasMapping>
<o:hasMapping>
<o:Mapping>
<o:build rdf:resource="urn:void:ncbi:build:HuRef/36_3"/>
<o:chrom rdf:resource="urn:void:ncbi:chromosome:9606/chr1"/>
<o:start rdf:datatype="http://www.w3.org/2001/XMLSchema#int">132892081</o:start>
<o:end rdf:datatype="http://www.w3.org/2001/XMLSchema#int">132892082</o:end>
<o:orient>-</o:orient>
(...)


The java archive for xsltstream is available at http://lindenb.googlecode.com/files/xsltstream.jar

Usage:
  -x <xslt-stylesheet file/url> required
-p <param-name> <param-value> (add parameter to the xslt engine)
-d depth (0 based) default:-1
-q qName target default:null
<file>|stdin



That's it !
Pierre

20 December 2012

RDF/Jena: a simple extension for XSLT/XALAN. Testing with NCBI-Gene

In a previous post, I've shown that the XALAN XSLT engine can be extended with custom function returning a DOM Document that will be used by the xslt-stylesheet. Here, I'll create an extension for XALAN getting some RDF statements from a Jena/RDF model. The RDF model will be loaded in memory but one can imagine to use a persistent model ( TDB or SDB). I'll download a record from NCBI-gene, transform it to html and use the disease-ontology database as RDF to annotate it.

A Gene record is downloaded as XML from NCBI gene:

curl "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=gene&id=4853&retmode=xml" > notch2.html
The disease ontology is downloaded as RDF/XML:
curl -odoid.owl "http://www.berkeleybop.org/ontologies/doid.owl"

The XSLT Stylesheet

The stylesheet declares the extension jena, loads the RDF model ("$model"), searches for the OMIM identifiers in the Gene record and loads the RDF statements related to that OMIM-ID.
For example the following xpath expression:
jena:query(
   $model,
   $doiid,
   'http://www.geneontology.org/formats/oboInOwl#hasExactSynonym',
   ''
   )
returns a rdf/XML document containing the RDF statements having a subject=$doiid, a property "http://www.geneontology.org/formats/oboInOwl#hasExactSynonym" and any object.
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <rdf:Statement>
    <rdf:subject rdf:resource="http://purl.obolibrary.org/obo/DOID_0050721"/>
    <rdf:predicate rdf:resource="http://www.geneontology.org/formats/oboInOwl#hasExactSynonym"/>
    <rdf:object>Phosphoserine phosphatase deficiency</rdf:object>
  </rdf:Statement>
</rdf:RDF>
The stylesheet:

The Java code

This is the java extension: the constructor loads the RDF model in memory. The function query(..) returns a RDF/XML document matching the query.

Makefile




config.mk:

Result

java -cp ${class.path} org.apache.xalan.xslt.Process \
 -IN notch2.xml \
 -XSL gene2html.xsl -EDUMP -OUT result.html


NOTCH2

Omim ID 610205

Label
Alagille syndrome
Synonym
Arteriohepatic dysplasia (disorder)
Sub-Class Of
Label
gastrointestinal system disease
Synonym
gastrointestinal disease
Sub-Class Of
Label
disease of anatomical entity
Sub-Class Of
Label
disease



Omim ID 102500

Label
Hajdu-Cheney syndrome
Synonym
Hajdu-Cheney syndrome (disorder)
Sub-Class Of
Label
autosomal dominant disease
Sub-Class Of
Label
autosomal genetic disease
Sub-Class Of
Label
monogenic disease
Sub-Class Of
Label
genetic disease
Sub-Class Of
Label
disease









That's it,


Pierre


10 June 2011

An extension for Inkscape processing a sequence from Genbank

Let's create a new extension for inkscape by recycling an old XSLT stylsheet producing a SVG image !

For example, we're going to use this xslt stylsheet: https://github.com/lindenb/xslt-sandbox/blob/master/stylesheets/bio/ncbi/gb2svg.xsl that transforms a Genbank XML INSDSeq to SVG. It is downloaded into the extension directory;

${HOME}/.config/inkscape/extensions/gb2svg.xsl

Now let's tell inkscape about this new extension by defining the following XML file (INX):

${HOME}/.config/inkscape/extensions/gb2svg.inx


<inkscape-extension>
<name>Genbank Input</name>
<id>org.inkscape.input.ncbi.genbank</id>
<input>
<extension>.xml</extension>
<mimetype>text/xml</mimetype>
<filetypename>NCBI Genbank (*.xml)</filetypename>
<filetypetooltip>NCBI Genbank XML</filetypetooltip>
</input>
<xslt>
<file reldir="extensions">gb2svg.xsl</file>
</xslt>
</inkscape-extension>



Now let's test this new extension: download a sequence from Genbank and save it as a XML/INSDSeq file. For example: http://www.ncbi.nlm.nih.gov/nuccore/NM_001200001.1.

Open Inkscape. Do Menu File > Import > and select the file sequence.gbc.xml and the Genbank format.


Press OK. Et voila !!






That's it,

Pierre