Skip to content

Instantly share code, notes, and snippets.

@jeanmanguy
Last active January 18, 2020 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeanmanguy/5cd98ed4001117fee79c47c0d4b774e6 to your computer and use it in GitHub Desktop.
Save jeanmanguy/5cd98ed4001117fee79c47c0d4b774e6 to your computer and use it in GitHub Desktop.
convert uniprot file to TSV [WIP]
<?xml version='1.0' encoding="UTF-8"?>
<xsl:stylesheet
xmlns:u="http://uniprot.org/uniprot"
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
version='1.0'
>
<xsl:output method="text" encoding="UTF-8" />
<xsl:variable name="separator" select="'&#x9;'" />
<xsl:variable name="newline" select="'&#10;'" />
<xsl:param name="quote">"</xsl:param>
<xsl:template match="/">
<xsl:text>accession_number</xsl:text>
<xsl:value-of select="$separator" />
<xsl:text>name</xsl:text>
<xsl:value-of select="$separator" />
<xsl:text>protein_name</xsl:text>
<xsl:value-of select="$separator" />
<xsl:text>gene_name</xsl:text>
<xsl:value-of select="$separator" />
<xsl:text>EC</xsl:text>
<xsl:value-of select="$separator" />
<xsl:text>COG</xsl:text>
<xsl:value-of select="$separator" />
<xsl:text>sequence</xsl:text>
<xsl:value-of select="$newline" />
<xsl:for-each select="//u:entry">
<xsl:value-of select="$quote" /><xsl:value-of select="u:accession[1]" /><xsl:value-of select="$quote" />
<xsl:value-of select="$separator" />
<xsl:value-of select="$quote" /><xsl:value-of select="u:name[1]" /><xsl:value-of select="$quote" />
<xsl:value-of select="$separator" />
<xsl:value-of select="$quote" /><xsl:value-of select="u:protein/*/u:fullName[1]" /><xsl:value-of select="$quote" />
<xsl:value-of select="$separator" />
<xsl:value-of select="$quote" /><xsl:value-of select="u:gene/u:name[@type='primary' or @type='ordered locus']" /><xsl:value-of select="$quote" />
<xsl:value-of select="$separator" />
<xsl:value-of select="$quote" /><xsl:value-of select="u:dbReference[@type='EC']/@id" /><xsl:value-of select="$quote" />
<xsl:value-of select="$separator" />
<xsl:value-of select="$quote" /><xsl:value-of select="u:dbReference[@type='eggNOG' and u:property[@type='taxonomic scope' and @value='LUCA']]/@id" /><xsl:value-of select="$quote" />
<xsl:value-of select="$separator" />
<xsl:value-of select="$quote" /><xsl:value-of select="u:sequence[1]" /><xsl:value-of select="$quote" />
<xsl:value-of select="$newline" />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment