Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Similarity network
#1
Hello all,

I have to write a code to convert a .blastp file into a .sif one. For those of you that don't know what these are, a .blastp file look like that :

ProtA ProtB xx xxxxx xx xx.xxx E-value
ProtA ProtC xx xxxxx xx xx.xxx E-value
ProtD ProtE xx xxxxx xx xx.xxx E-value
.
.
.

and a sif one look like that :

ProtA <relationship type> ProtB
ProtC <relationship type> ProtA
ProtD <relationship type> ProtE ProtF ProtB
.
.
.

Prot being a protein

I need to ask for a S value, if that value is greater than the e-value, then those two protein are linked and I have to put them in the sif file as :
ProtA linked ProtB

I have started by creating a dictionary that store the first protein as a key and all the protein that are linked as a list in the value of the key.That worked well, but now I am stucked at writing the sif file, here are my code so far:

import re


namF = "xxxxxxxxxxx.blastp"
of = open(namF,'r')


Sif="Output.sif"
fo = open(Sif, 'w')

S = str(input('Choisissez le seuil  '))

dico={}

ligne = of.readline()
while (ligne != ""):
	ligne.rstrip('\n')
	L= ligne.split('\t')
	E= L[-1:]
	A=L[0]
	B=L[1]

	if E[0] <= S:
    
		if A in dico: 
			dico[A].append(B)
		else:
			dico[A]=list()
			dico[A].append(B)
              
		if B in dico: 
			dico[B].append(A)
		else:
			dico[B]=list()
			dico[B].append(A)
                 
    	for key in dico:
		fo.write(key+ ' lié '+ dico[key]+'\n')
	ligne= of.readline()
print(D)
Then I tried to put it in function as demanded :
import re


namF = "xxxxxxxxxxx.blastp"
of = open(namF,'r')


Sif="Output.sif"
fo = open(Sif, 'w')

S = str(input('Choisissez le seuil  '))


def sif(S):

		for key in dico:
			fo.write(key+ ' lié '+ dico[key]+'\n')


def dic():
	dico={}

	ligne = of.readline()
	while (ligne != ""):
		ligne.rstrip('\n')
		L= ligne.split('\t')
		E= L[-1:]
		A=L[0]
		B=L[1]

		if E[0] <= S:

			if A in dico: 
				dico[A].append(B)
			else:
				dico[A]=list()
				dico[A].append(B)
              
			if B in dico: 
				dico[B].append(A)
			else:
				dico[B]=list()
				dico[B].append(A)
		ligne= of.readline()

print(D)
I tried to use my dic function in the sif one to create my output.sif but I can't manage to do it. Any help ?

Thanks
Reply


Messages In This Thread
Similarity network - by Absolumentpasadrien - Apr-05-2019, 09:36 AM
RE: Similarity network - by Gribouillis - Apr-05-2019, 09:42 AM
RE: Similarity network - by Absolumentpasadrien - Apr-05-2019, 10:08 AM
RE: Similarity network - by DeaD_EyE - Apr-05-2019, 10:31 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Similarity function for couple system sunnydayxo 1 2,134 Apr-16-2021, 07:11 AM
Last Post: MH90000
  How do I improve string similarity in my current code? SUGSKY 3 2,399 May-28-2020, 05:16 AM
Last Post: deanhystad
  fingerprint similarity audio microphone alessandro87gatto 1 2,428 May-03-2019, 01:33 PM
Last Post: alessandro87gatto

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020