Schrift
[thread]7528[/thread]

empty Files



<< >> 10 Einträge, 1 Seite
paidopoieo
 2005-12-07 03:12
#60736 #60736
User since
2005-12-02
96 Artikel
BenutzerIn
[default_avatar]
Hi,
Ich habe folgendes kleines Problem, ich will ein File parsen, und die Resultate in ein anderes rausschreiben....ich weiss nichts aussergewoehnliches.....
trotzdem waere eure Hilfe nett... ;)

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/perl -w

my @raw_data;
my $wrestler;
my @work_array;

print "Starting Program......Hopefully.....\n";

open (bigShot, "BigOne.txt") || die ("Could not open file. $!");
print "File bigShot openend successfully \n";

@raw_data = <bigShot>;
print "stored entire file in Array \n";
close (bigShot);
print "closed file bigShot \n";

print "trying to enter foreach....\n";
foreach $wrestler (@raw_data) {
print "entered foreach successfully \n";


print $wrestler, "\n";
#@work_array = $wrestler;
print "trying to enter if Condition....\n";
if ($wrestler =~ m/^>sp/ || $wrestler =~ m/^Query/ || $wrestler =~ m/^Sbjct/) {
print "if condition entered successfully\n";



open (cuttedFile, ">cuttedFile.txt") || die ("Could not open file. $!");

print "File cuttedFile opend successfully \n";

print $wrestler;

close (cuttedFile);
}
}
print "finished foreach \n";




Dankeschoen im Voraus

mfg
Hubert
esskar
 2005-12-07 03:41
#60737 #60737
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
du solltest cuttedFile.txt außerhalb der foreach schleife öffnen und schliessen... nicht bei jedem durchlauf... weil so überschreibst du dir alte sachen
renee
 2005-12-07 04:39
#60738 #60738
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
BTW ueberschreibt er hier nix, weil erst gar nichts in die Dateien geschrieben wird ;)

Damit Du in eine Datei schreibst, musst Du auch print FILEHANDLE $value; machen, in dem Code oben also :
Code: (dl )
1
2
3
4
5
6
7
 open (cuttedFile, ">cuttedFile.txt") || die ("Could not open file. $!");
foreach $wrestler(@array){
print "File cuttedFile opend successfully \n";
print cuttedFile $wrestler;
}

close (cuttedFile);


Eine etwas andere Einrueckung des Codes wuerde den Code lesbarer machen ;)\n\n

<!--EDIT|renee|1133923528-->
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/
esskar
 2005-12-07 11:40
#60739 #60739
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
[quote=renee,07.12.2005, 03:39]BTW ueberschreibt er hier nix, weil erst gar nichts in die Dateien geschrieben wird ;)[/quote]
war schon spät... :)
paidopoieo
 2005-12-07 23:02
#60740 #60740
User since
2005-12-02
96 Artikel
BenutzerIn
[default_avatar]
Hallo renee,
Dankeschoen, ja das wars....und

open (cuttedFile, ">>cuttedFile.txt") || die ("Could not open file. $!");

anstatt
open (cuttedFile, ">cuttedFile.txt") || die ("Could not open file. $!");

Thanks
paidopoieo
 2005-12-08 01:26
#60741 #60741
User since
2005-12-02
96 Artikel
BenutzerIn
[default_avatar]
Hi,
Sorry, ich haett da noch eine Frage....derselbe Code.....
nur diesesmal hab ich mein File sortiert.....und will alle doppelten rausloeschen und in ein neues File schreiben.....

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/perl -w

my @raw_data;
my $wrestler;
my @work_array;
my $wrestlerPrevious = '';

print "Starting Program......Hopefully.....\n";

open (sortedFile, "Out.txt") || die ("Could not open file. $!");
print "File sortedFile openend successfully \n";

@raw_data = <sortedFile>;
print "stored entire file in Array \n";
close (sortedFile);
print "closed file sortedFile \n";
print "\n";

print "trying to enter foreach....\n";
print "\n";

#======================================================================================
foreach $wrestler (@raw_data) {
print "entered foreach successfully \n";


#print $wrestler, "\n";
#@work_array = $wrestler;
#print "trying to enter if Condition....\n";
if ($wrestler !~ m/$wrestlerPrevious/) {
print "if condition entered successfully\n";



open (cleaned_Blasthits_wo_AlignmentsFile, ">>cleaned_Blasthits_wo_AlignmentsFile.txt") || die ("Could not open file. $!");

print "File cleaned_Blasthits_wo_AlignmentsFile opend successfully \n";

print cleaned_Blasthits_wo_AlignmentsFile $wrestler;

close (cleaned_Blasthits_wo_AlignmentsFile);
} else {



print "THAT WAS A DOUBLED ONE....SORRY \n";

}

$wrestlerPrevious = $wrestler;
}
print "finished foreach \n";


nur das Problem ist, das Programm geht mir die ersten beiden Male immer in den else Zweig....und bricht dann ab......

Sorry ich bin nicht sehr gut in Perl.....bin kein Programmierer....

mfg
Hubert
renee
 2005-12-08 04:20
#60742 #60742
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Dazu muesstest Du uns auch ein paar Beispieldaten geben...

Ein paar Hinweise zum Code:
*) benutze Wiki:use strict
*) Schreibe die Filehandles am besten komplett gross (zB SORTEDFILE). Damit lassen sie sich besser erkennen. Oder benutze Variablen...
*) ruecke bitte konsistent ein. z.B. mit 2 oder 4 Leerzeichen nach einer oeffnenden Klammer. z.B.
Code: (dl )
1
2
3
4
5
6
7
8
if($bedingung){
#zwei leerzeichen
my $return = machwas();
if($return){
#noch zwei Leerzeichen mehr
machwasanderes();
}
}

Damit wird Code lesbarer...
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/
paidopoieo
 2005-12-08 19:36
#60743 #60743
User since
2005-12-02
96 Artikel
BenutzerIn
[default_avatar]
Hallo renee,
ok, sorry, hier nocheinmal der "hoffentlich den Richtlinien angepasste Code" ;) mit Beispieldaten:

Out.txt
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
>sp|O00398|P2Y10_HUMAN Putative P2Y purinoceptor 10 (P2Y10) (P2Y-like receptor)
>sp|O00507|USP9Y_HUMAN Probable ubiquitin carboxyl-terminal hydrolase FAF-Y (Ubiquitin
>sp|O00507|USP9Y_HUMAN Probable ubiquitin carboxyl-terminal hydrolase FAF-Y (Ubiquitin
>sp|O08967|CYH3_MOUSE Cytohesin-3 (ARF nucleotide-binding site opener 3) (ARNO3 protein)
>sp|O15321|TM9S1_HUMAN Transmembrane 9 superfamily protein member 1 precursor (hMP70)
>sp|O28970|TF2B_ARCFU Transcription initiation factor IIB (TFIIB)
>sp|O35902|DSG3_MOUSE Desmoglein-3 precursor (130 kDa pemphigus vulgaris antigen homolog)
>sp|O55112|AFF2_MOUSE AF4/FMR2 family member 2 (Fragile X mental retardation protein
>sp|O59248|RNP4_PYRHO Ribonuclease P protein component 4 (RNase P component 4)
>sp|O59248|RNP4_PYRHO Ribonuclease P protein component 4 (RNase P component 4)
>sp|O59425|RNP1_PYRHO Ribonuclease P protein component 1 (RNase P component 1)
>sp|O59425|RNP1_PYRHO Ribonuclease P protein component 1 (RNase P component 1)
>sp|O60563|CCNT1_HUMAN Cyclin-T1 (Cyclin-T) (CycT1)
>sp|O65388|PEL2_ARATH Putative pectate lyase 2 precursor
>sp|O70582|LX12B_MOUSE Arachidonate 12-lipoxygenase, 12R type (Epidermis-type lipoxygenase
>sp|O70582|LX12B_MOUSE Arachidonate 12-lipoxygenase, 12R type (Epidermis-type lipoxygenase
>sp|O70582|LX12B_MOUSE Arachidonate 12-lipoxygenase, 12R type (Epidermis-type lipoxygenase
>sp|O73700|CAC1D_CHICK Voltage-dependent L-type calcium channel alpha-1D subunit (Voltage-gated
>sp|O73700|CAC1D_CHICK Voltage-dependent L-type calcium channel alpha-1D subunit (Voltage-gated
>sp|O75923|DYSF_HUMAN Dysferlin (Dystrophy associated fer-1-like protein) (Fer-1-like
>sp|O84630|END4_CHLTR Probable endonuclease IV (Endodeoxyribonuclease IV)
>sp|O91734|POLG_EC01F Genome polyprotein [Contains: Coat protein VP4 (P1A); Coat protein
>sp|O91734|POLG_EC01F Genome polyprotein [Contains: Coat protein VP4 (P1A); Coat protein
>sp|O94761|RECQ4_HUMAN ATP-dependent DNA helicase Q4 (RecQ protein-like 4) (RecQ4) (RTS)
>sp|O94880|PHF14_HUMAN PHD finger protein 14


Code:

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/perl -w

use strict;
my @raw_data;
my $wrestler;
my @work_array;
my $wrestlerPrevious = '';

print "Starting Program......Hopefully.....\n";

open (SORTEDFILE, "Out.txt") || die ("Could not open file. $!");
print "File sortedFile openend successfully \n";

@raw_data = <SORTEDFILE>;
print "stored entire file in Array \n";
close (SORTEDFILE);
print "closed file sortedFile \n";
print "\n";

print "trying to enter foreach....\n";
print "\n";

#======================================================================================
foreach $wrestler (@raw_data) {
print "entered foreach successfully \n";

if ($wrestler !~ m/$wrestlerPrevious/) {
print "if condition entered successfully\n";


open (CLEANED_BLASTHITS_WO_ALIGNMENTSFILE, ">>cleaned_Blasthits_wo_AlignmentsFile.txt") || die ("Could not open file. $!");
print "File cleaned_Blasthits_wo_AlignmentsFile opend successfully \n";
print CLEANED_BLASTHITS_WO_ALIGNMENTSFILE $wrestler;
close (CLEANED_BLASTHITS_WO_ALIGNMENTSFILE);

} else {


print "THAT WAS A DOUBLED ONE....SORRY \n";

}

$wrestlerPrevious = $wrestler;

}

print "finished foreach \n";


Dankeschoen,
mfg
Hubert
renee
 2005-12-09 09:04
#60744 #60744
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Hi,

es sind keine Richtlinien, es sind nur Tipps...

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/perl -w

use strict;
use warnings;

my $infile = '/path/to/infile.fa';
my $outfile = '/out/outfile.txt';
my %single_hash;

open(INFILE,"<$infile") or die $!;
while(my $line = <INFILE>){
chomp $line;
$single_hash{$line} = 1;
}
close INFILE;

open(OUTFILE,">$outfile") or die $!;
for my $key(keys(%single_hash)){
print OUTFILE $key,"\n";
}
close OUTFILE;
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/
Crian
 2005-12-20 16:59
#60745 #60745
User since
2003-08-04
5866 Artikel
ModeratorIn
[Homepage]
user image
nimm 4 (Leerzeichen) :)
s--Pevna-;s.([a-z]).chr((ord($1)-84)%26+97).gee; s^([A-Z])^chr((ord($1)-52)%26+65)^gee;print;

use strict; use warnings; Link zu meiner Perlseite
<< >> 10 Einträge, 1 Seite



View all threads created 2005-12-07 03:12.