Contenu | Rechercher | Menus

Annonce

Si vous avez des soucis pour rester connecté, déconnectez-vous puis reconnectez-vous depuis ce lien en cochant la case
Me connecter automatiquement lors de mes prochaines visites.

À propos de l'équipe du forum.

#1 Le 18/03/2008, à 06:43

KsPeR

[PERL] Script d'analyse de fichier txt

Bonjour à tous,

Finalement, changement de programme pour ce topic. Je me suis apercu qu'en bash, la tâche serait difficile. J'ai donc décider de tenter le coup en Perl. Je pense que c'est l'outil adapter pour ce que je veux faire (corrigez moi si je me trompe ).

Et voila ce que je veux faire :

Je dispose de fichiers textes en entrée :

A	               2	          12 34
B	               4	          56 78 78 9
C	               3	          34 9 12
D	               1	          12
...etc

En gros, on a des chiffres de la colonne 3 qui sont présents sur plusieurs lignes. Par exemple pour la ligne "A", on retrouve 12 dans les lignes C et D et 34 dans la ligne C.
Mon but est, grâce à l'outil GraphViz (voir plus bas) de faire ressortir ces liaisons.
Pour utiliser ce programme, je dois lui fournir un fichier qui contient mes représentations.

J'aimerais donc modifier le fichier d'entrée pour obtenir un fichier exploitable par graphviz :

graph G {
           "A" -- "C" [label="12"];
           "A" -- "C" [label="34"];
           "A" -- "B" [label="34"];
           "A" -- "D" [label="12"];

           "B" -- "C" [label="9"];

           "C" -- "D" [label="12"];


etc ...

J'ai essayé pas mal de choses, mais je débute en Perl, et je n'arrive pas à obtenir quelquechose de correct en sortie.

Je pense a quelquechose comme ca pour le fonctionnement du script :

    1. Supprimer la 2e colonne (elle n'a pas d'utilité particulière).

boucle:
    2. Rechercher toutes les occurences de la premiere valeur de la colonne 3 (on va l'appeler tmp)
    3. Stocker les colonnes 1 de toutes lignes contenants la valeur tmp
    4. Supprimer toutes les occurences tmp du fichier source (pour eviter d'avoir des doublons)

Voila, si quelqu'un pouvait me donner un coup de main la dessus, ou me guider sur cette voie, car je nage un peu là...:/


Merci !

Dernière modification par KsPeR (Le 20/03/2008, à 09:12)

Hors ligne

#2 Le 18/03/2008, à 07:22

abetsic

Re : [PERL] Script d'analyse de fichier txt

Je suis pas sûr d'avoir compris comment générer la sortie à partir de l'entrée, mais à mon avis tu peux regarder du coté de awk et sed combiné avec grep.

Hors ligne

#3 Le 18/03/2008, à 07:38

whalexis

Re : [PERL] Script d'analyse de fichier txt

Je confirme ce qu'abetsic vient de dire. J'avais du faire ça pour un projet et ça marchais bien.
Par contre réserve toi quelque heures:D

#4 Le 18/03/2008, à 22:18

gene69

Re : [PERL] Script d'analyse de fichier txt

si tu n'as pas de language imposé moi je te conseille de faire ça en php ... en perl big_smile. la version en ligne de commande s'utilise comme un shell.

c'est bien mieux documenté, pis le traitement des chaines purement "bash" c'est l'horreur.


Quand le berger est lâche, le loup chie de la laine.
A (draft) guide to UFO Alien-Invasion

Hors ligne

#5 Le 18/03/2008, à 22:23

benjou

Re : [PERL] Script d'analyse de fichier txt

scilab octave ou matlab!

surtout si tu veux faire des graphiques.

Scilab est libre mais matlab est mieux hmm. Je pense que ton labo est en mesure de payer une license matlab!

J' ai fait tout mes microarray avec matlab...


écrasons l'infâme

Hors ligne

#6 Le 19/03/2008, à 01:10

KsPeR

Re : [PERL] Script d'analyse de fichier txt

salut !

Merci a tous pour vos réponses.

J'ai finalement trouvé un moyen de réaliser des représentations graphiques de reseaux.

Voici l'outil que j'ai découvert, un peu par hasard :

http://cyberzoide.developpez.com/graphviz/

http://www.karakas-online.de/forum/viewtopic.php?t=2647

ca à l'air vraiment puissant comme truc.

Mon but est donc maintenant, de transformer mes fichiers textes de base :

pathway  Gene number      Gene IDs

A                   2              34 78
B                   4              56 78  9
C                   3              34 9 23
D                   1              78
...

en fichier de ce genre :

graph G {
    C -- {A;B};
    B -- {D;A};
    A -- D;
}

ce qui donne en sortie une image de ce genre :

tes1tbu1.th.png

C'est pas très beau mais j'ai fait au plus simple.

C'est donc la conversion du fichier texte qui pose de gros pb.

Les commandes shell sont bien puissante mais même en faisant de grands pipe en combinant différentes cmd je n'arrive pas a obtenir un résultat correct.

Je vais essayer de me tourner vers quelquechose en Perl, mais je n'ai jamais touché à ce langage donc bon, je vais voir ce que ca donne.

En attendant si quelqu'un à une idée pour un script de conversion du texte, bash, php, Perl, du moment que ca marche lol. Il est le bienvenu !

@ benjou :
Matlab est il adapté pour ce genre de truc ? Je n'y ai jamais touché non plus donc je ne sais pas trop. Ce deuxiement post explique un peu mieux ce que j'ai envie de faire (mise en evidence des relations). Donc eut -etre que tu pourras m'en dire plus.


Merci

Hors ligne

#7 Le 19/03/2008, à 01:35

benjou

Re : [PERL] Script d'analyse de fichier txt

matlab ou scilab sont des outils prevus pour manipuler des matrices (listes en 2D, genre tableur).

Tes pathways avec listes de gènes sont typiquementdes matrices donc c' est clairement adapté.
Matlab peut même travailler avec des " matrices de matrices"

Typiquement, tu as une matrice de pathways et chaque pathway contient une matrice de gènes.

Je n' ai pas vraiment le temps d' entrer dans les détails mais algorhithmiquement je te conseillerais d' essayer d'obtenir un résultat de type

          A     B       C         D
A        \      x       x         x
B                 \      x         x
C                         \
D                                   \

que tu peux ensuite très facilement convertir dans ton fichier pour graphviz


écrasons l'infâme

Hors ligne

#8 Le 19/03/2008, à 09:59

KsPeR

Re : [PERL] Script d'analyse de fichier txt

Merci benjour pour l'exemple.

En effet, le résultats sous forme de matrice est clair.
Le problème reste quand même comment obtenir cette matrice à partir du fichier d'entrée... Je pense opter pour un script Perl, mais comme j'ai jamais touché à ce langages ca risque de me prendre un peu de temps.

Du temps justement j'en avais pas bcp aujourd'hui et je devais pondre quelquechose. J'ai donc fait ca à moitié à la main... mad

Je vous met ici un exemple de fichier d'entrée :

KEGG pathway 	Gene number 	Entrez Gene IDs
Axon guidance	 14	 137970 1630 2048 5362 57144 6091 6092 6387 6586 7852 8829 9037 9353 9901
Neuroactive ligand-receptor interaction	14	1131 1901 2890 2897 2898 2899 2904 2917 2918 3351 3354 56288 5733 7068
Focal adhesion	10	1284 2321 2889 3908 5294 5295 5649 57144 7424 83660
Tight junction	9	1496 2037 29119 5521 5588 56288 7122 8777 9863
Cytokine-cytokine receptor interaction	8	1435 2321 3458 3624 6387 650 7424 7852
Insulin signaling pathway	7	10891 2889 5139 5214 5294 5295 868
Calcium signaling pathway	7	1131 114 3708 4842 5733 6263 6546
Leukocyte transendothelial migration	7	1496 29119 5294 5295 6387 7122 7852
Phosphatidylinositol signaling system	6	1607 160851 3708 5289 5294 5295
T cell receptor signaling pathway	6	3458 5294 5295 5588 57144 868
Purine metabolism	5	114 2272 5139 5142 93034
Cell adhesion molecules (CAMs)	5	1002 5797 7122 9369 9378
Wnt signaling pathway	5	144165 166336 27123 5521 8325
Colorectal cancer	4	1630 5294 5295 8325
Regulation of actin cytoskeleton	4	1131 5294 5295 57144
Long-term depression	4	2890 3708 4842 5521
Long-term potentiation	4	114 2890 2904 3708
Natural killer cell mediated cytotoxicity	4	3458 5294 5295 6850
Jak-STAT signaling pathway	4	3458 5294 5295 868
Adherens junction	4	1496 29119 56288 5797
ECM-receptor interaction	4	1284 3908 5649 84624
TGF-beta signaling pathway	4	1634 3458 3624 650
Pancreatic cancer	4	5294 5295 5337 7424
Glycan structures - biosynthesis 1	4	114805 2530 4249 9951
Starch and sucrose metabolism	3	2632 6595 84569
Glycerophospholipid metabolism	3	1607 160851 5337
Cell Communication	3	1284 3908 5649
MAPK signaling pathway	3	11221 4803 4915
mTOR signaling pathway	3	5294 5295 7424
Apoptosis	3	4803 5294 5295
B cell receptor signaling pathway	3	5294 5295 6850
Fc epsilon RI signaling pathway	3	5294 5295 6850
GnRH signaling pathway	3	114 3708 5337
Adipocytokine signaling pathway	3	10891 5588 6258
Chronic myeloid leukemia	3	5294 5295 868
Gap junction	2	114 3708
VEGF signaling pathway	2	5294 5295
Inositol phosphate metabolism	2	5289 5294
Glycerolipid metabolism	2	1607 160851
Regulation of autophagy	2	3458 5289
ABC transporters - General	2	10257 4363
Type II diabetes mellitus	2	5294 5295
Glioma	2	5294 5295
N-Glycan biosynthesis	2	2530 4249
Toll-like receptor signaling pathway	2	5294 5295
Type I diabetes mellitus	2	3458 5799
Heparan sulfate biosynthesis	1	9951
Ether lipid metabolism	1	5337
Sphingolipid metabolism	1	2581
Propanoate metabolism	1	8801
Vitamin B6 metabolism	1	29968

-> et ce que je dois obtenir pour dessiner mon reseau en fichier de sortie :

graph Process {

	node [color=lightblue2, style=filled];

	// node 1
	"Axon guidance" -- "Colorectal cancer" [label="1630",len=1.00];

	"Axon guidance" -- "Focal adhesion" [label="57144",len=10.0];
	"Axon guidance" -- "T cell receptor signaling pathway" [label="57144"];
	"Axon guidance" -- "Regulation of actin cytoskeleton"[label="57144"];

	"Axon guidance" -- "Cytokine-cytokine receptor interaction" [label="6387"];
	"Axon guidance" -- "Leukocyte transendothelial migration" [label="6387"];

	"Axon guidance" -- "Insulin signaling pathway" [label="7852"];
	"Axon guidance" -- "Leukocyte transendothelial migration" [label="7852"];
	

	// Node 2
	"Neuroactive ligand-receptor interaction" -- "Calcium signaling pathway"  [label="1131"];
	"Neuroactive ligand-receptor interaction" -- "Regulation of actin cytoskeleton"  [label="1131"]; 

	"Neuroactive ligand-receptor interaction" -- "Long-term depression"  [label="2890"];
	"Neuroactive ligand-receptor interaction" -- "Long-term potentiation"  [label="2890"];

	"Neuroactive ligand-receptor interaction" -- "Long-term potentiation"  [label="2904"];

	"Neuroactive ligand-receptor interaction" -- "Tight junction"  [label="56288"];
	"Neuroactive ligand-receptor interaction" -- "Adherens junction"  [label="56288"];

	"Neuroactive ligand-receptor interaction" -- "Calcium signaling pathway"  [label="5733"];

	// Node 4
	"Tight junction" -- "Leukocyte transendothelial migration" [label="1496"];
	"Tight junction" -- "Adherens junction" [label="1496"];

	"Tight junction" -- "Leukocyte transendothelial migration" [label="29119"];
	"Tight junction" -- "Adherens junction" [label="29119"];

	"Tight junction" -- "Wnt signaling pathway" [label="5521"];
	"Tight junction" -- "Long-term depression" [label="5521"];

	"Tight junction" -- "T cell receptor signaling pathway" [label="5588"]

	"Tight junction" -- "Leukocyte transendothelial migration" [label="7122"];
	"Tight junction" -- "Cell adhesion molecules (CAMs)" [label="7122"];

	"Tight junction" -- "Dentatorubropallidoluysian atrophy (DRPLA)" [label="9863"];

	// Node 5
	"Insulin signaling pathway" -- "Adipocytokine signaling pathway" [label="10891"];

	"Insulin signaling pathway" -- "Purine metabolism" [label="5139"];

	"Insulin signaling pathway" -- "Fructose and mannose metabolism" [label="5214"];
	"Insulin signaling pathway" -- "Pentose phosphate pathway" [label="5214"];
	"Insulin signaling pathway" -- "Glycolysis-Gluconeogenesis" [label="5214"];

	"Insulin signaling pathway" -- "T cell receptor signaling pathway" [label="868"];
	"Insulin signaling pathway" -- "Jak-STAT signaling pathway" [label="868"];
	"Insulin signaling pathway" -- "Chronic myeloid leukemia" [label="868"];

	// Node 6
	"Calcium signaling pathway" -- "Purine metabolism" [label="114"];
	"Calcium signaling pathway" -- "Long-term potentiation" [label="114"];
	"Calcium signaling pathway" -- "GnRH signaling pathway" [label="114"];
	"Calcium signaling pathway" -- "Gap junction" [label="114"];
	"Calcium signaling pathway" -- "Taste transductionx" [label="114"];

	"Calcium signaling pathway" -- "Phosphatidylinositol signaling system" [label="3708"];
	"Calcium signaling pathway" -- "Long-term depression" [label="3708"];
	"Calcium signaling pathway" -- "Long-term potentiation" [label="3708"];
	"Calcium signaling pathway" -- "GnRH signaling pathway" [label="3708"];
	"Calcium signaling pathway" -- "Gap junction" [label="3708"];

	"Calcium signaling pathway" -- "Long-term depression" [label="4882"];
	"Calcium signaling pathway" -- "Arginine and proline metabolism" [label="4882"];

	// Node 7
	"Phosphatidylinositol signaling system" -- "Glycerophospholipid metabolism" [label="1607"];
	"Phosphatidylinositol signaling system" -- "Glycerolipid metabolism" [label="1607"];

	"Phosphatidylinositol signaling system" -- "Glycerophospholipid metabolism" [label="160851"];
	"Phosphatidylinositol signaling system" -- "Glycerolipid metabolism" [label="160851"];

	"Phosphatidylinositol signaling system" -- "Inositol phosphate metabolism" [label="5289"];
	"Phosphatidylinositol signaling system" -- "Regulation of autophagy" [label="5289"];

	// Node 8
	"Purine metabolism" -- "Nicotinate and nicotinamide metabolism" [label="93034"];

	// Node 9
	"Cell adhesion molecules (CAMs)" -- "Adherens junction" [label="5797"];

	// Node 10
	"Natural killer cell mediated cytotoxicity" -- "B cell receptor signaling pathway" [label="6850"];
	"Natural killer cell mediated cytotoxicity" -- "Fc epsilon RI signaling pathway" [label="6850"];

	// Node 11 
	"Pancreatic cancer" -- "Glycerophospholipid metabolism" [label="5337"];
	"Pancreatic cancer" -- "GnRH signaling pathway" [label="5337"];
	"Pancreatic cancer" -- "Ether lipid metabolism" [label="5337"];

	// Node 12
	"Starch and sucrose metabolism" -- "Folate biosynthesis" [label="6595"];

	// Node 13
	"MAPK signaling pathway" -- "Apoptosis" [label="4803"];

	// Node 14
	"Adipocytokine signaling pathway" -- "PPAR signaling pathway" [label="6258"];

	// Node 15 
	"Neurodegenerative Disorders" -- "Alzheimer's disease" [label="351"];

	// Node 16
	"Cholera - Infection" -- "Epithelial cell signaling in Helicobacter pylori infection" [label="51606"];
	"Cholera - Infection" -- "Oxidative phosphorylation" [label="51606"]
}

Je fais ca à la main ( gedit combiné a calc sad ) car j'avais besoin d'un resultat rapido et qu'il n'y avait pas énormément de données.

Mais j'aimerais automatiser un maximum la manip'...

ps : en passant graphviz est vraiment hyper puissant, ca genere de supers graphes.

Hors ligne

#9 Le 19/03/2008, à 17:58

benjou

Re : [PERL] Script d'analyse de fichier txt

scilab et matlab encore plus peuvent lire des fichiers texte de type tableur et en faire des matrices. Matlab peut meme importer un ficher excel ou csv ou tab-txt.

je te joins deux scripts scilab: un pour lire des fichiers de GPS au format gpx qui utilise mgetl et grep. et un qui lit des données csv a partir de données de luciferase acquise avec labview qui utilise fscanfMat


//Reads data from luciferase machine (ASCII format from LabView programm)
filename=xgetfile()
data=fscanfMat(filename)
for ii=2:size(data,2)
	clear sorted maxy
	sorted=sort(data(:,ii));
	maxy=sorted(120);
	
	subplot(3,3,ii-1), plot(data(:,1),data(:,ii))
	a=get("current_axes");
	a.data_bounds=[0 min(data(:,ii)); max(data(:,1)) maxy];
	a.grid=[1 -1];
	//a.auto_ticks=["off","off","off"];
	tlist1=a.x_ticks;
	tlist1.locations=[0;24;48;72;96;120];
	tlist1.labels=["";"1";"2";"3";"4";"5"];
	a.x_ticks=tlist1;
end

et

//path tou your gpxfiles:
gpx_path='/home/benoit/Tracks/GPStracks';

filepath=xgetfile('*.gpx',gpx_path,title='Choose a GPX file')
gpx=mgetl(filepath);

trkbounds=[grep(gpx,'<trk>');grep(gpx,'</trk>')];
rtebounds=[grep(gpx,'<rte>');grep(gpx,'</rte>')];

gpx_elev=gpx(grep(gpx,"ele"));
gpx_time=gpx(grep(gpx,"time"));
gpx_track=gpx(grep(gpx,"trkpt lat"));
gpx_route=gpx(grep(gpx,"rtept lat"));

clear route
clear track
clear height
clear time
clear ind

//read height values
if isempty(gpx_elev)
else
	for ii=1:size(gpx_elev,1)			
		execstr('height(ii)='+part(gpx_elev(ii),[strindex(gpx_elev(ii),'<ele>')+5:strindex(gpx_elev(ii),'</ele>')-1])   );
	end
end


//read track coordinates
if isempty(gpx_track)
else
	for ii=1:size(gpx_track,1)			
		execstr('track(ii,1)='+part(gpx_track(ii),[strindex(gpx_track(ii),'<trkpt lat=""')+12:strindex(gpx_track(ii),'"" ')-1])   );
		execstr('track(ii,2)='+part(gpx_track(ii),[strindex(gpx_track(ii),'lon=""')+5:strindex(gpx_track(ii),'"">')-1])   );
	end
end
//read route coordinates
if isempty(gpx_route)
else
	for ii=1:size(gpx_route,1)			
		execstr('route(ii,1)='+part(gpx_route(ii),[strindex(gpx_route(ii),'<rtept lat=""')+12:strindex(gpx_track(ii),'"" ')-1])   );
		execstr('route(ii,2)='+part(gpx_route(ii),[strindex(gpx_route(ii),'lon=""')+5:strindex(gpx_route(ii),'"">')-1])   );
	end
end
//read time values

if isempty(gpx_time)
else
	jj=1;
	for ii=1:size(gpx_time,1)			
		execstr("time(ii)="+part(gpx_time(ii),[strindex(gpx_time(ii),"<time>")+17:strindex(gpx_time(ii),"<time>")+18])+"+("+part(gpx_time(ii),[strindex(gpx_time(ii),"<time>")+20:strindex(gpx_time(ii),"<time>")+21])+"/60)+("+part(gpx_time(ii),[strindex(gpx_time(ii),"<time>")+23:strindex(gpx_time(ii),"<time>")+24])+"/3600)"  );
		//make an index(ind of different days)
		if ii==1
		elseif ii== size(gpx_time,1)
		elseif part(gpx_time(ii+1),1:16)~=part(gpx_time(ii),1:16)
			ind(jj)=(ii);
			jj=jj+1;
		else
		end
	end
end



//correction if one time occurence appears in heading lines
if isempty(gpx_time)
else
if size(track,1)<size(time,1)
	time=time(2:size(time,1));
end
end

Dernière modification par benjou (Le 19/03/2008, à 17:59)


écrasons l'infâme

Hors ligne

#10 Le 20/03/2008, à 09:18

KsPeR

Re : [PERL] Script d'analyse de fichier txt

Je te remerci benjou pour ces 2 scripts. Je les garde de côté smile

Je pense me tourner vers une solution qui me parait plus simple (faconde parler...)

J'ai regarder du côté du Perl, ca m'a vraiment l'air adapté pour ce genre de modif. Je tente de faire un script pour transformer mes fichiers textes, mais vu que c'est la premiere fois que je touche au Perl ... les débuts sont toujours difficiles !

si qqn a des idées !

Merci

Hors ligne