.
The Open Protein Structure Annotation Network
PDB Keyword
.

Convert:Pfam

    Table of contents
    No headers
    using System;
    using System.Xml;
    using System.Text;
    using System.Net;
    using System.Collections.Generic;
    using System.IO;
    using System.Security.Cryptography.X509Certificates;
    using System.Net.Security;
    using System.Text.RegularExpressions;
    
    	public class PfamImport : ConvertInterface.ConvertPlugin {
    		
    		public static bool Validator (object sender, X509Certificate certificate, X509Chain chain, 
                                          SslPolicyErrors sslPolicyErrors)
    		{
    			return true;
    		}
    		
    		
    		private Stream getURIStream( Uri uri ) {
    			ServicePointManager.ServerCertificateValidationCallback = Validator;
    			HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(uri);
                HttpWebResponse response = null;
                try
                {
                    response = (HttpWebResponse)httpRequest.GetResponse();
                }
                catch (WebException e)
                {
                    Console.WriteLine("WebException: " + e.Message);
                }
    			Stream stream = response.GetResponseStream();
    			return stream;
    		}
    			
    
    		string rdfNS = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
    		string rdfsNS = "http://www.w3.org/2000/01/rdf-schema#";
    		string pfamNS = "http://purl.uniprot.org/pfam/";
    		string coreNS = "http://purl.uniprot.org/core/";
    		string pmidNS = "http://purl.uniprot.org/citation/";
    		string wikiNS = "http://en.wikipedia.org/wiki/";
    		
    		Dictionary<string,string> dbLinks = new Dictionary<string, string>(){ 
    			{ "SCOP", "http://scop.mrc-lmb.cam.ac.uk/scop/search.cgi?key={0}" },
    			{ "TC", "http://www.tcdb.org/search/result.php?tc={0}" },
    			{ "HOMSTRAD", "http://tardis.nibio.go.jp/cgi-bin/homstrad/showpage.cgi?family={0}" },
    			{ "PROSITE", "http://au.expasy.org/cgi-bin/prosite-search-ac?{0}" },
    			{ "CAZY", "http://www.cazy.org/{0}.html" },
    			{ "MEROPS", "http://merops.sanger.ac.uk/cgi-bin/famsum?family={0}"},
    			{ "CATH", "http://www.cathdb.info/cathnode/{0}" }
    		};
    		
    		Regex dbRegex = new Regex(@"(\S*); (\S*);");
    		Regex scoreRegex = new Regex(@"^\S* (\S*)\..*/");
    		
    		public XmlDocument ConvertAlias(string alias) {
    			
    			string curType = null;
    			string uristr = null;
    			
    			List<string> uniprotMembers = new List<string>();
    			
    			if ( alias.StartsWith("PF") ) {			
    				uristr = "https://pfamsvn.sanger.ac.uk/svn/pfam/trunk/Data/Families/" + alias + "/DESC";
    				curType = "Pfam_Family";
    				
    				string scoreURIstr =  "https://pfamsvn.sanger.ac.uk/svn/pfam/trunk/Data/Families/" + alias + "/scores";
    				Uri scoreURI = new Uri(scoreURIstr);
    				Stream scoreStream = getURIStream( scoreURI );
    				StreamReader scoreReader = new StreamReader(scoreStream);
    				
    				string scoreLine;
    				while ( null != (scoreLine = scoreReader.ReadLine()) ) {
    					Match m = scoreRegex.Match( scoreLine );
    					string uniprot = m.Groups[1].ToString();
    					uniprotMembers.Add( uniprot );
    				}
    				scoreStream.Close();
    			}
    			
    			if ( alias.StartsWith("CL") ) {			
    				uristr = "https://pfamsvn.sanger.ac.uk/svn/pfam/trunk/Data/Clans/" + alias + "/CLANDESC";
    				curType = "Pfam_Clan";
    			}
    			if ( curType == null )
    				return null;
    			//Console.Out.WriteLine( uristr );
                Uri uri = new Uri(uristr);
                // create the initial request
    			
    			Stream stream = getURIStream( uri );
    			StreamReader reader = new StreamReader(stream);
    
    			XmlDocument xdoc = new XmlDocument();
    			XmlElement root = xdoc.CreateElement( "rdf:RDF", rdfNS );
    			//root.SetAttribute( "xmlns:rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#" );
    			
    			xdoc.AppendChild( root );
    			
    			XmlElement desc = xdoc.CreateElement( "rdf:Description", rdfNS );
    			root.AppendChild( desc );
    			string line, accession = null, pfamID = null, descText = null, clan = null,
    			comment = "", author = null, wiki = null;
    			List<string> citations = new List<string>();
    			List<string> dbRefs = new List<string>();
    			List<string> members = new List<string>();
    			
    			
    			while ( null != (line = reader.ReadLine() ) ) {
    				string code = line.Substring(0,2);
    				string def = line.Substring(5).TrimEnd();
    				switch (code) {
    				case "AC": 
    					accession = def;
    					break;
    				case "ID":
    					pfamID = def;
    					break;
    				case "DE":
    					descText = def;
    					break;
    				case "CL":
    					clan = def;
    					break;
    				case "CC":
    					comment += def + " ";
    					break;
    				case "RM":
    					citations.Add( def );
    					break;
    				case "AU":
    					author = def;
    					break;
    				case "WK":
    					wiki = def;
    					break;
    				case "DR":
    					//Console.Out.WriteLine( def );
    					Match m = dbRegex.Match( def );
    					if ( m.Success ) {
    						string dbNS = m.Groups[1].ToString();
    						string dbID = m.Groups[2].ToString();
    						if ( dbLinks.ContainsKey( dbNS ) ) {
    							//Console.Out.WriteLine( dbLinks[ dbNS ] + dbID );
    							dbRefs.Add( String.Format( dbLinks[ dbNS ], dbID ) );
    						}
    					}
    					break;
    				case "MB":
    					members.Add( def.Replace(";", "" ) );
    					break;
    				}
    			}
    			
    			desc.SetAttribute( "rdf:about", rdfNS, pfamNS + accession );
    									
    			XmlElement typeNode = xdoc.CreateElement( "rdf:type", rdfNS );
    			typeNode.SetAttribute( "rdf:resource", rdfNS, coreNS + curType );
    			desc.AppendChild( typeNode );			
    
    			if ( pfamID != null ) {
    				XmlElement nameNode = xdoc.CreateElement( "core:name", coreNS );
    				nameNode.AppendChild( xdoc.CreateTextNode( pfamID ) );
    				desc.AppendChild( nameNode );
    			}
    			
    			if ( author != null ) {
    				XmlElement authorNode = xdoc.CreateElement( "core:author", coreNS );
    				authorNode.AppendChild( xdoc.CreateTextNode( author ) );
    				desc.AppendChild( authorNode );
    			}
    			
    			if ( accession != null ) {
    				XmlElement aliasNode = xdoc.CreateElement( "core:alias", coreNS );
    				aliasNode.AppendChild( xdoc.CreateTextNode( accession ) );
    				desc.AppendChild( aliasNode );
    			}
    			
    			if ( descText != null ) {
    				XmlElement descTextNode = xdoc.CreateElement( "core:description", coreNS );
    				descTextNode.AppendChild( xdoc.CreateTextNode( descText ) );
    				desc.AppendChild( descTextNode );
    			}
    			
    			if ( comment != null ) {
    				XmlElement commentTextNode = xdoc.CreateElement( "core:comment", coreNS );
    				commentTextNode.AppendChild( xdoc.CreateTextNode( comment ) );
    				desc.AppendChild( commentTextNode );
    			}
    			
    			if ( clan != null ) {
    				XmlElement clanNode = xdoc.CreateElement( "core:memberOf", coreNS );
    				clanNode.SetAttribute( "rdf:resource", rdfNS, pfamNS + clan );
    				desc.AppendChild( clanNode );
    			}
    			
    			if ( wiki != null ) {
    				XmlElement wikiNode = xdoc.CreateElement( "rdfs:seeAlso", rdfsNS );
    				wikiNode.SetAttribute( "rdf:resource", rdfNS, wikiNS + wiki );
    				desc.AppendChild( wikiNode );
    			}
    			
    			foreach ( string member in members ) {
    				XmlElement memberNode = xdoc.CreateElement( "core:member", coreNS );
    				memberNode.SetAttribute( "rdf:resource", rdfNS, pfamNS + member );
    				desc.AppendChild( memberNode );
    			}
    			
    			foreach ( string link in dbRefs ) {
    				XmlElement citationNode = xdoc.CreateElement( "rdfs:seeAlso", rdfsNS );
    				citationNode.SetAttribute( "rdf:resource", rdfNS, link );
    				desc.AppendChild( citationNode );
    			}
    			
    			foreach ( string id in citations ) {
    				XmlElement citationNode = xdoc.CreateElement( "core:citation", coreNS );
    				citationNode.SetAttribute( "rdf:resource", rdfNS, pmidNS + id );
    				desc.AppendChild( citationNode );
    			}
    			
    			foreach ( string uniprot in uniprotMembers ) {
    				XmlElement uniprotNode = xdoc.CreateElement( "core:member", coreNS );
    				uniprotNode.SetAttribute( "rdf:resource", rdfNS, "http://purl.uniprot.org/uniprot/" + uniprot );
    				desc.AppendChild( uniprotNode );
    			}
    			return xdoc;
    		}
    	}
    	
    
    

    Reviews

    References

     

    No references found.

    Tag page
    • No tags

    Files (0)

     
    You must login to post a comment.
    All content on this site is licensed under a Creative Commons Attribution 3.0 License
    Powered by MindTouch