how can change two value become one value?

 
0
 

Hi all,

I have one problem. I have two value ($gia and $name1) and now I want to do it become one value to run in the next step.Ex:

$gia =12 $name = Tai
$gia =$gia.$name
out put : 12Tai

But I hope the data will sepera two colums for the next step.

12 Tai

Could you show me how can I do that in perl?

 
0
 
#!/usr/bin/perl
use strict; 
use warnings; 

my $gia = '12tai';

#Capture sequence of digits into one variable,
#capture sequence of non-digits into another variable
my ($number, $name) = $gia =~ m/(\d+)(\D+)/;

print "$number $name\n";#Two values separated by one space
 
0
 

Hi d5e5. I think biojet wants opposite.
biojet, try this one:

my $first = 12;
my $second = "Tai";
my $oneval = "$first$second";
say $oneval;
 
0
 

Thanks d5e5!
But I want to use the script that you show me at the last question http://www.daniweb.com/software-development/perl/threads/413279
It has line

read_positions('data1.txt');

But I did not put out the data1.txt I hope to insert dicrecly two value $gia and $name1 into your script so I try to do two value become one value to insert into the line read_positions($gia) with $gia=$gia.$name1 but it is not secceessful.
Could you show me how to solve this problems?
Thank you so much.

#!/usr/bin/perl
use strict; 
use warnings; 

my $gia = '12tai';

#Capture sequence of digits into one variable,
#capture sequence of non-digits into another variable
my ($number, $name) = $gia =~ m/(\d+)(\D+)/;

print "$number $name\n";#Two values separated by one space
 
0
 

Thanks neo so much! I tried it but I am not seccessful.
when I used the $oneval in my script It has foul I think beacause I can not sepeare two value.

Hi d5e5. I think biojet wants opposite.
biojet, try this one:

my $first = 12;
my $second = "Tai";
my $oneval = "$first$second";
say $oneval;
 
0
 

can you post error message here?

 
0
 

The erro: Failed open 6114067_contig34:No such file or directory at c:\users\PCUSER\desktop\thu.pl line 129
Below is my script I sorry it is long.
Would you show me how to mix this error?

#!/usr/bin/perl;
use strict;
use warnings;


my %aas; #Hash to store amino acids
my $out = 'result.txt';
my $filename3 = 'Found_out.txt';
my $filename4 = 'output1.txt';
my $filename5 = 'Not_found.txt';
my %ranges;
my ($ref1,$base,$num3,@ref1, $posi1,$DNA,@posi1, $posi2);
print 'ENTER THE DNA SNP POSITION := '; 
     	my $filename1 = <STDIN>; 
	chomp $filename1;
	unless (open(DNAFILE, $filename1)) 
	{ 
    	die 'Cannot open file "' . $filename1 . '"' . "\n\n"; 
	} 
print 'ENTER THE DNA OF GENLIST := '; 
     	my $filename2 = <STDIN>; 
	chomp $filename2;
	unless (open(DNAFILE, $filename2)) 
	{ 
    	die 'Cannot open file "' . $filename2 . '"' . "\n\n"; 
	} 
print 'ENTER THE DNA SNP POSITION := '; 
     	my $aa= <STDIN>;
	chomp $aa;
	unless (open(DNAFILE, $aa)) 
	{ 
    	die 'Cannot open file "' . $aa . '"' . "\n\n"; 
	} 
print "???????????????????????? \n"; 
open my $fh, '<', $filename2 or die "Failed to open $filename2: $!";
while (<$fh>){
    next unless m/^\d/; #skip unless line starts with number
    chomp;
    my ($num, $start, $end, $name , $ORF, $product) = split;
    $ranges{$num}{Star_posi} = $start;
    $ranges{$num}{End_posi} = $end;
    $ranges{$num}{'Name'} = $name;
    $ranges{$num}{'ORF Name'} = $ORF;
    $ranges{$num}{'Product'} = $product;
    
}
close $fh;

open $fh, '<', $filename1 or die "Failed to open $filename1: $!";
open my $fho1, '>', $filename4 or die "Failed to open $filename4: $!";#Open file for output1
open my $fho2, '>', $filename5 or die "Failed to open $filename5: $!";#Open file for output1
open my $fho, '>', $filename3 or die "Failed to open $filename3: $!";#Open file for output
print $fho "Name\tgen\tProduct\tSNP_posi\tstar\tend\tSNP_site\tRef_aa\tRef\tmut\tTripret_1\n";
print $fho1 "SNP\tSNP_site\tRef_base\tRef\tname\tgen\tProduct\n";

while (<$fh>){
    next unless m/^\d/; #skip unless line starts with number
    chomp;    
    my ($num, $posi, $mut, $ref) = split;
    my $range_num = search_ranges($posi); 
 
    if ($range_num){
        #print to output file instead of STDOUT
        my $name1=$ranges{$range_num}{'Name'} ;
        my $ORF1=$ranges{$range_num}{'ORF Name'} ;
        my $proc1=$ranges{$range_num}{'Product'};
        my $mod = (($posi -$ranges{$range_num}{Star_posi} )% 3) + 1;
        my $int = int(($posi -$ranges{$range_num}{Star_posi})/3);
        my $gia =($int*3)+$ranges{$range_num}{Star_posi};         
    
     # tim aa tu chuoi DNA
	read_amino_acids ($aa); 

     # I have problem in here

          my $position= "$gia$name1";      
          my @position1 =$position;    
          my ($position1) =join ("",@position1);      
          read_positions ($position1);      
       
     

        print $fho1 "$posi\t$mod\t$mut\t$name1\t$ORF1\t$proc1\n";
        print $fho " $name1\t$ORF1\t$proc1\t$posi\t$ranges{$range_num}{Star_posi}\t$ranges{$range_num}{End_posi}\t$mod\t$ref\t$mut\t$gia\t";
   }
    else{
        print $fho2 "SNP record number $posi not found in Genlist\n";
    }
   

}
   print "\n????Found_out.txt??????????????????????????\n";
   print "??Step?120127_pro_basechange??????????????\n";
   
 sub search_ranges{
    my $pos = shift;
    foreach (keys %ranges){
        return $_ if $pos >= $ranges{$_}{Star_posi}
                    and $pos <= $ranges{$_}{End_posi};
    }
}


sub read_amino_acids{
    my ($filename) = @_;
    open my $fh, '<', $filename or die "Failed to open $filename: $!";
    my ($name, $key);
    while (<$fh>){
        s/\s+$//; #Remove end-of-line characters
        my @flds = split /\|/;
        if (@flds > 1){
            $name = $flds[4];
            $name =~ m/(\d+)\s(\w+\d\d)/;
            $key = lc("$1_$2");
            undef $aas{$key} unless exists $aas{$key};
        }
        else{
            $aas{$key} .= $_;
        }
    }
}



sub read_positions{
    my ($filename) = @_;
    open my $fh, '<', $filename or die "Failed to open $filename: $!";
   

    while (<$fh>){
        s/\s+$//; #Remove end-of-line characters
        my ($name, $pos) = split;
        next unless $name =~ m/^\d+_/;
        my $tuple = substr $aas{$name}, $pos - 1, 3;
        printf  $fho1 "$tuple\n";
      
    }
}

can you post error message here?

Attachments genlist.txt (135.67 KB)
The attachment preview is chopped off after the first 10 KB. Please download the entire file.
Num	start	end	Name	gen	Product
1	710	1225	14067_contig01	gene=KIQ_00010	protein=hypothetical protein
2	2791	5166	14067_contig01	gene=KIQ_00025	protein=RND superfamily drug exporter
3	5153	5734	14067_contig01	gene=KIQ_00035	protein=TETR-family transcriptional regulator
4	2022	2137	14067_contig02	gene=KIQ_00060	protein=hypothetical protein
5	1	330	14067_contig03	gene=KIQ_00065	protein=hypothetical protein
6	327	698	14067_contig03	gene=KIQ_00070	protein=hypothetical protein
7	691	1104	14067_contig03	gene=KIQ_00075	protein=hypothetical protein
8	1115	1246	14067_contig03	gene=KIQ_00080	protein=hypothetical protein
9	1297	1575	14067_contig03	gene=KIQ_00085	protein=hypothetical protein
10	1751	2449	14067_contig03	gene=KIQ_00090	protein=HTH-type transcriptional regulator
11	2459	2968	14067_contig03	gene=KIQ_00095	protein=hypothetical protein
12	2969	3529	14067_contig03	gene=KIQ_00100	protein=hypothetical protein
13	3539	3805	14067_contig03	gene=KIQ_00105	protein=hypothetical protein
14	3802	4128	14067_contig03	gene=KIQ_00110	protein=hypothetical protein
15	4189	4581	14067_contig03	gene=KIQ_00115	protein=hypothetical protein
16	4574	4837	14067_contig03	gene=KIQ_00120	protein=hypothetical protein
17	4837	5310	14067_contig03	gene=KIQ_00125	protein=hypothetical protein
18	5334	5804	14067_contig03	gene=KIQ_00130	protein=putative methyltransferase
19	5801	6088	14067_contig03	gene=KIQ_00135	protein=hypothetical protein
20	6081	6599	14067_contig03	gene=KIQ_00140	protein=hypothetical protein
21	6596	6895	14067_contig03	gene=KIQ_00145	protein=hypothetical protein
22	6895	7605	14067_contig03	gene=KIQ_00150	protein=hypothetical protein
23	7592	7945	14067_contig03	gene=KIQ_00155	protein=hypothetical protein
24	7932	8360	14067_contig03	gene=KIQ_00160	protein=hypothetical protein
25	8357	8584	14067_contig03	gene=KIQ_00165	protein=hypothetical protein
26	8577	9020	14067_contig03	gene=KIQ_00170	protein=hypothetical protein
27	9020	9223	14067_contig03	gene=KIQ_00175	protein=hypothetical protein
28	9234	9458	14067_contig03	gene=KIQ_00180	protein=hypothetical protein
29	9536	9868	14067_contig03	gene=KIQ_00185	protein=hypothetical protein
30	9865	10041	14067_contig03	gene=KIQ_00190	protein=hypothetical protein
31	10034	10414	14067_contig03	gene=KIQ_00195	protein=hypothetical protein
32	10411	10791	14067_contig03	gene=KIQ_00200	protein=hypothetical protein
33	10761	11036	14067_contig03	gene=KIQ_00205	protein=hypothetical protein
34	11311	11520	14067_contig03	gene=KIQ_00210	protein=hypothetical protein
35	11513	11821	14067_contig03	gene=KIQ_00215	protein=hypothetical protein
36	11818	12456	14067_contig03	gene=KIQ_00220	protein=hypothetical protein
37	12661	12903	14067_contig03	gene=KIQ_00225	protein=hypothetical protein
38	12907	13515	14067_contig03	gene=KIQ_00230	protein=hypothetical protein
39	13505	13750	14067_contig03	gene=KIQ_00235	protein=hypothetical protein
40	14535	14861	14067_contig03	gene=KIQ_00245	protein=hypothetical protein
41	14960	15142	14067_contig03	gene=KIQ_00250	protein=hypothetical protein
42	15163	16428	14067_contig03	gene=KIQ_00255	protein=hypothetical protein
43	16561	16932	14067_contig03	gene=KIQ_00260	protein=hypothetical protein
44	16895	18433	14067_contig03	gene=KIQ_00265	protein=putative phage associated protein
45	18443	19726	14067_contig03	gene=KIQ_00270	protein=hypothetical protein
46	19701	20888	14067_contig03	gene=KIQ_00275	protein=peptidase S14 ClpP
47	20902	21306	14067_contig03	gene=KIQ_00280	protein=hypothetical protein
48	21389	22312	14067_contig03	gene=KIQ_00285	protein=hypothetical protein
49	22312	22695	14067_contig03	gene=KIQ_00290	protein=hypothetical protein
50	22705	23142	14067_contig03	gene=KIQ_00295	protein=hypothetical protein
51	23139	23471	14067_contig03	gene=KIQ_00300	protein=hypothetical protein
52	23471	23770	14067_contig03	gene=KIQ_00305	protein=hypothetical protein
53	23770	24177	14067_contig03	gene=KIQ_00310	protein=hypothetical protein
54	24167	24862	14067_contig03	gene=KIQ_00315	protein=hypothetical protein
55	24990	25358	14067_contig03	gene=KIQ_00320	protein=hypothetical protein
56	25394	25720	14067_contig03	gene=KIQ_00325	protein=hypothetical protein
57	25767	32201	14067_contig03	gene=KIQ_00330	protein=hypothetical protein
58	32211	32978	14067_contig03	gene=KIQ_00335	protein=immunity-specific protein beta201
59	32982	33866	14067_contig03	gene=KIQ_00340	protein=hypothetical protein
60	33868	34707	14067_contig03	gene=KIQ_00345	protein=immunity-specific protein beta371
61	34719	35903	14067_contig03	gene=KIQ_00350	protein=hypothetical protein
62	35900	36265	14067_contig03	gene=KIQ_00355	protein=hypothetical protein
63	36339	36614	14067_contig03	gene=KIQ_00360	protein=hypothetical protein
64	36777	38024	14067_contig03	gene=KIQ_00365	protein=glycosyl hydrolase
65	38024	38365	14067_contig03	gene=KIQ_00370	protein=hypothetical protein
66	38368	38799	14067_contig03	gene=KIQ_00375	protein=hypothetical protein
67	38796	39140	14067_contig03	gene=KIQ_00380	protein=hypothetical protein
68	39838	40536	14067_contig03	gene=KIQ_00385	protein=hypothetical protein
69	40681	41154	14067_contig03	gene=KIQ_00390	protein=ribose-5-phosphate isomerase B
70	46959	48308	14067_contig03	gene=tig	protein=trigger factor
71	48497	49090	14067_contig03	gene=clpP	protein=ATP-dependent Clp protease proteolytic subunit
72	49125	49751	14067_contig03	gene=KIQ_00450	protein=ATP-dependent Clp protease proteolytic subunit
73	60191	61048	14067_contig03	gene=KIQ_00490	protein=catechol 1,2-dioxygenase
74	61089	62252	14067_contig03	gene=KIQ_00495	protein=hypothetical protein
75	62265	62558	14067_contig03	gene=KIQ_00500	protein=muconolactone delta-isomerase
76	62717	63883	14067_contig03	gene=KIQ_00505	protein=hypothetical protein
77	64043	64735	14067_contig03	gene=KIQ_00510	protein=protocatechuate 3,4-dioxygenase, beta subunit
78	64747	65361	14067_contig03	gene=KIQ_00515	protein=protocatechuate 3,4-dioxygenase, alpha subunit
79	65453	66454	14067_contig03	gene=KIQ_00520	protein=3-carboxy-cis,cis-muconate cycloisomerase
80	66454	66822	14067_contig03	gene=KIQ_00525	protein=hypothetical protein
81	71723	72466	14067_contig03	gene=KIQ_00550	protein=hypothetical protein
82	72466	73101	14067_contig03	gene=KIQ_00555	protein=hypothetical protein
83	74306	75586	14067_contig03	gene=clpX	protein=ATP-dependent protease ATP-binding subunit ClpX
84	75587	76519	14067_contig03	gene=KIQ_00570	protein=hypothetical protein
85	80197	80730	14067_contig03	gene=KIQ_00590	protein=PadR-like family transcriptional regulator
86	81819	82805	14067_contig03	gene=KIQ_00600	protein=malate dehydrogenase
87	82816	83403	14067_contig03	gene=KIQ_00605	protein=Rossmann fold nucleotide-binding protein
88	85094	86671	14067_contig03	gene=KIQ_00615	protein=hypothetical protein
89	86730	89432	14067_contig03	gene=valS	protein=valyl-tRNA synthetase
90	89432	90955	14067_contig03	gene=KIQ_00625	protein=folylpolyglutamate synthase
91	90952	91377	14067_contig03	gene=KIQ_00630	protein=hypothetical protein
92	91448	91915	14067_contig03	gene=KIQ_00635	protein=hypothetical protein
93	92340	92660	14067_contig03	gene=KIQ_00645	protein=hypothetical protein
94	92710	93120	14067_contig03	gene=ndk	protein=mulitfunctional nucleoside diphosphate kinase/apyrimidinic endonuclease/3'-phosphodiesterase
95	95701	98766	14067_contig03	gene=KIQ_00670	protein=ribonuclease E
96	98992	99297	14067_contig03	gene=rplU	protein=50S ribosomal protein L21
97	99347	99613	14067_contig03	gene=rpmA	protein=50S ribosomal protein L27
98	100945	101862	14067_contig03	gene=KIQ_00695	protein=2,5-diketo-D-gluconic acid reductase
99	104085	105590	14067_contig03	gene=obgE	protein=GTPase CgtA
100	105700	106929	14067_contig03	gene=KIQ_00710	protein=gamma-glutamyl kinase
101	106989	107903	14067_contig03	gene=KIQ_00715	protein=phosphoglycerate dehydrogenase
102	107962	109260	14067_contig03	gene=proA	protein=gamma-glutamyl phosphate reductase
103	109359	110384	14067_contig03	gene=KIQ_00725	protein=hypothetical protein
104	110454	111098	14067_contig03	gene=nadD	protein=nicotinic acid mononucleotide adenylyltransferase
105	111253	111726	14067_contig03	gene=KIQ_00735	protein=hypothetical protein
106	111738	112448	14067_contig03	gene=KIQ_00740	protein=hypothetical protein
107	112485	113309	14067_contig03	gene=KIQ_00745	protein=DegV family protein
108	113373	114026	14067_contig03	gene=KIQ_00750	protein=DNA uptake protein
109	114023	115687	14067_contig03	gene=KIQ_00755	protein=hypothetical protein
110	115694	116689	14067_contig03	gene=KIQ_00760	protein=hypothetical protein
111	116721	117122	14067_contig03	gene=KIQ_00765	protein=ankyrin repeat-containing protein
112	117127	117798	14067_contig03	gene=KIQ_00770	protein=hypothetical protein
113	119204	121051	14067_contig03	gene=KIQ_00785	protein=GTP-binding protein LepA
114	121209	121865	14067_contig03	gene=KIQ_00790	protein=C4-dicarboxylate-binding protein
115	121862	122434	14067_contig03	gene=KIQ_00795	protein=hypothetical protein
116	122436	123716	14067_contig03	gene=KIQ_00800	protein=hypothetical protein
117	127444	127725	14067_contig03	gene=KIQ_00820	protein=hypothetical protein
118	130009	130671	14067_contig03	gene=KIQ_00830	protein=hypothetical protein
119	133434	135653	14067_contig03	gene=KIQ_00845	protein=malate synthase G
120	136565	137539	14067_contig03	gene=KIQ_00855	protein=Na+-dependent transporter
121	139305	139418	14067_contig03	gene=KIQ_00865	protein=hypothetical protein
122	140425	140976	14067_contig03	gene=KIQ_00875	protein=2'-5' RNA ligase
123	145877	146170	14067_contig03	gene=KIQ_00900	protein=hypothetical protein
124	146438	147787	14067_contig03	gene=KIQ_00905	protein=hypothetical protein
125	148867	151713	14067_contig03	gene=KIQ_00915	protein=glycolate oxidase FAD-linked subunit oxidoreductase
126	151719	152648	14067_contig03	gene=KIQ_00920	protein=permease
127	152666	153184	14067_contig03	gene=KIQ_00925	protein=or membrane protein
128	153332	155179	14067_contig03	gene=KIQ_00930	protein=ectoine/proline/glycine betaine carrier EctP
129	158953	159474	14067_contig03	gene=KIQ_00950	protein=hypothetical protein
130	159586	160152	14067_contig03	gene=KIQ_00955	protein=hypotheti
posi.txt (9.86 KB)
num	Pos_End	genotype	reference
1	61	C	T
2	283	A	G
3	734	A	G
4	801	A	G
5	812	A	G
6	872	A	G
7	888	T	C
8	913	A	G
9	1089	A	G
10	1202	T	C
11	1407	A	G
12	1457	T	C
13	1575	T	C
14	1808	T	C
15	2022	A	G
16	2048	T	C
17	2310	A	G
18	2484	A	G
19	2776	T	C
20	2906	T	C
21	3068	A	G
22	3215	T	C
23	3489	A	G
24	3605	T	C
25	3622	A	G
26	3649	T	C
27	3751	T	C
28	3924	C	A
29	3983	A	G
30	3985	A	G
31	4029	T	C
32	4056	C	T
33	4125	A	G
34	4325	T	C
35	4329	T	C
36	4524	T	G
37	4528	A	T
38	4977	T	C
39	5031	A	G
40	5151	T	C
41	5169	A	G
42	5225	T	C
43	5277	T	C
44	5354	A	G
45	5573	A	G
46	5672	T	C
47	5680	T	C
48	5687	T	C
49	5802	T	C
50	5926	T	C
51	5996	A	G
52	6140	T	C
53	6180	T	C
54	6218	T	C
55	6387	A	G
56	6433	T	C
57	6450	T	C
58	6615	A	G
59	6768	A	G
60	7036	A	G
61	7192	T	C
62	7336	A	G
63	7336	T	C
64	7525	A	G
65	7851	A	G
66	7990	A	G
67	8116	A	G
68	8253	G	C
69	8393	T	C
70	8491	T	C
71	8540	T	C
72	8658	A	G
73	8749	A	G
74	8749	T	C
75	8849	A	G
76	8880	A	G
77	9101	A	G
78	9142	T	C
79	9219	T	C
80	9232	T	C
81	9244	T	C
82	9280	A	G
83	9375	T	C
84	9538	T	C
85	9565	T	C
86	9584	A	G
87	9844	T	C
88	10332	A	G
89	10443	A	G
90	10526	A	G
91	10802	A	G
92	10907	T	C
93	10929	G	A
94	11184	T	C
95	11406	T	C
96	11482	A	G
97	11485	A	G
98	11518	A	G
99	11624	A	G
100	11895	A	G
101	12424	A	G
102	12484	A	G
103	12526	T	C
104	12569	C	T
105	12659	T	C
106	12743	A	G
107	12779	T	C
108	12793	T	C
109	12905	A	G
110	13274	T	C
111	13359	A	G
112	13457	A	G
113	13830	C	T
114	14064	A	G
115	14207	A	G
116	14382	A	G
117	14567	T	C
118	14692	T	C
119	14805	T	C
120	14838	A	G
121	14854	A	G
122	14920	A	G
123	15224	A	G
124	15302	A	G
125	15997	T	C
126	16169	A	G
127	16449	T	C
128	16613	T	C
129	16621	T	C
130	16774	A	G
131	16797	T	C
132	16870	T	C
133	17241	T	C
134	17263	A	G
135	17336	T	C
136	17469	T	C
137	17587	A	G
138	17712	A	G
139	18062	T	C
140	18084	T	C
141	18169	A	G
142	18279	T	C
143	18648	T	C
144	18650	A	G
145	18718	T	C
146	18728	T	C
147	18775	A	G
148	18895	T	C
149	19502	A	G
150	19785	A	G
151	19995	A	G
152	20123	T	C
153	20148	T	C
154	20209	A	G
155	20218	T	C
156	20401	A	G
157	20451	T	C
158	20657	T	C
159	20778	T	C
160	20821	T	C
161	20862	A	G
162	20934	T	C
163	20960	T	C
164	21656	G	A
165	21941	A	G
166	21966	T	C
167	21990	T	C
168	22126	T	C
169	22536	T	C
170	22619	T	C
171	22667	T	C
172	22671	A	G
173	22761	T	C
174	23017	A	G
175	23145	T	C
176	23220	T	C
177	23283	A	G
178	23364	T	C
179	23452	A	G
180	23486	A	G
181	23508	A	G
182	23588	T	C
183	23600	T	C
184	23807	T	C
185	24396	T	C
186	24559	A	G
187	24834	A	G
188	24946	A	G
189	24979	A	G
190	25038	T	C
191	25461	T	C
192	25691	T	C
193	25724	A	G
194	26025	T	C
195	26082	T	C
196	26091	T	C
197	26189	A	G
198	26508	A	G
199	26726	A	G
200	27076	A	G
201	27165	T	C
202	27237	A	G
203	27336	A	G
204	27395	A	G
205	27404	T	C
206	28460	T	C
207	28665	T	C
208	28708	T	C
209	28883	T	C
210	29129	A	G
211	29207	T	C
212	29220	A	G
213	29233	A	G
214	30479	T	C
215	30879	A	G
216	31129	T	C
217	31268	A	G
218	31565	A	G
219	31840	A	G
220	32407	A	G
221	32510	A	G
222	32527	A	G
223	32647	G	A
224	32999	T	C
225	33226	T	C
226	33642	T	C
227	33909	A	G
228	34056	T	C
229	34074	A	G
230	34141	T	C
231	34143	T	C
232	34515	T	C
233	34610	T	C
234	34736	T	C
235	34824	T	C
236	34847	A	G
237	35219	A	G
238	35363	T	C
239	35917	C	T
240	35996	T	C
241	36152	T	C
242	36494	A	G
243	36743	T	C
244	36903	T	C
245	37240	A	G
246	37309	A	G
247	37419	T	C
248	38167	A	G
249	38314	T	C
250	39163	T	C
251	39627	A	G
252	39680	T	C
253	39883	T	C
254	40039	T	C
255	40040	T	C
256	40225	A	G
257	40432	T	C
258	40457	A	G
259	40460	T	C
260	40486	A	G
261	40700	A	G
262	41057	A	G
263	41242	A	G
264	41945	A	G
265	42509	A	G
266	42577	T	C
267	42776	A	G
268	43114	A	G
269	43672	A	G
270	43858	T	C
271	44035	A	G
272	44055	T	C
273	44087	A	G
274	44128	T	C
275	44192	A	G
276	44868	T	C
277	44934	A	G
278	45060	T	C
279	45068	A	G
280	45378	A	G
281	45569	A	G
282	45794	T	C
283	46318	T	C
284	46320	T	C
285	46636	A	G
286	46915	A	G
287	47102	A	G
288	47121	A	G
289	47700	T	C
290	47944	A	G
291	47993	T	C
292	48458	A	G
293	49302	A	G
294	49359	T	C
295	49385	A	G
296	49454	A	G
297	49555	T	C
298	49892	T	C
299	50047	T	C
300	50721	T	C
301	50916	T	C
302	50933	T	C
303	51039	T	C
304	51099	T	C
305	51149	A	C
306	51276	T	C
307	51362	T	C
308	51463	A	G
309	51561	A	G
310	51766	T	C
311	52636	T	C
312	53065	T	C
313	53430	T	C
314	53816	A	G
315	54293	A	G
316	54324	A	G
317	54700	T	C
318	55098	A	G
319	55126	A	G
320	55158	A	G
321	55277	T	C
322	55477	T	C
323	56368	T	C
324	57342	T	C
325	58401	A	G
326	58782	A	G
327	58960	A	G
328	58973	A	G
329	58996	T	C
330	60535	T	C
331	60642	A	G
332	60784	A	G
333	60917	T	C
334	61181	A	G
335	61253	T	C
336	61843	A	G
337	61994	A	G
338	62595	A	G
339	63069	T	C
340	63329	T	C
341	63743	A	G
342	63752	A	G
343	63870	A	G
344	64961	T	C
345	64994	A	G
346	65077	T	C
347	65301	G	T
348	65322	A	G
349	65840	T	C
350	66517	A	G
351	66720	T	C
352	67486	T	C
353	67902	T	C
354	67937	A	G
355	68421	A	G
356	68576	T	C
357	68655	A	G
358	69044	T	C
359	69156	T	C
360	69270	T	C
361	70022	T	C
362	70044	T	C
363	70331	A	G
364	70628	A	G
365	70799	T	C
366	71654	T	C
367	71674	T	C
368	72076	A	G
369	72264	A	G
370	72589	A	G
371	72801	A	G
372	73159	A	G
373	73886	T	C
374	73913	T	C
375	73982	A	G
376	74097	T	C
377	74185	T	C
378	74264	A	G
379	74284	T	C
380	74365	A	G
381	74547	T	C
382	75463	T	C
383	75539	T	C
384	75671	T	C
385	75707	T	C
386	75827	T	C
387	76309	A	G
388	77347	T	C
389	77602	A	G
390	78021	T	C
391	79289	T	C
392	79426	T	C
393	79429	T	C
394	79745	T	C
395	79929	A	G
396	80181	A	G
397	80283	A	G
398	80439	T	C
399	81595	A	G
400	81780	T	C
401	81846	A	G
402	81980	T	C
403	82052	T	C
404	82095	A	G
405	83141	A	G
406	83236	A	G
407	83306	A	G
408	83607	A	G
409	83929	A	G
410	84068	A	G
411	84088	T	C
412	84245	A	G
413	84530	A	G
414	85186	T	C
415	85484	T	C
416	85591	T	C
417	86043	A	G
418	86116	A	G
419	86205	T	C
420	86334	A	G
421	86550	T	C
422	87235	T	C
423	88864	T	C
424	89173	T	C
425	89365	T	C
426	89971	T	C
427	91032	T	C
428	92411	A	G
429	92735	T	C
430	93143	T	C
431	94030	T	C
432	95170	T	C
433	95208	A	G
434	95519	T	C
435	95530	A	G
436	95585	T	C
437	95606	A	C
438	95638	T	G
439	95660	C	T
440	96247	A	G
441	96364	G	A
442	97006	T	C
443	97099	A	G
444	97323	T	C
445	98018	A	G
446	98100	A	G
447	98333	A	G
448	98864	A	G
449	99042	A	G
450	100330	A	G
451	100468	T	C
452	101216	T	C
453	101362	T	C
454	101591	T	C
455	101769	T	C
456	103740	A	G
457	104131	T	C
458	104574	A	G
459	104896	T	C
460	104985	A	G
461	106240	A	G
462	106294	A	G
463	106929	T	C
464	107303	T	C
465	107477	A	G
466	108076	T	C
467	108572	T	C
468	108700	T	C
469	109146	T	C
470	109548	T	C
471	109709	A	G
472	110475	A	G
473	110669	T	C
474	112024	A	G
475	113098	T	C
476	113372	A	G
477	113485	T	C
478	113543	T	C
479	113655	T	C
480	113735	T	C
481	114918	T	C
482	115369	T	C
483	116443	T	C
484	118117	T	C
485	118153	T	C
486	118909	T	C
487	119164	T	C
488	119185	A	G
489	121221	T	C
490	121317	T	C
491	122767	A	G
492	124435	T	C
493	124803	T	C
494	124953	T	C
495	125214	T	C
496	125821	T	C
497	126218	T	C
498	126492	A	G
499	126505	G	A
500	126959	T	C
501	127072	T	C
502	127143	T	C
503	127151	G	A
504	127348	T	C
505	127364	T	C
506	127567	T	C
507	127889	T	C
508	127945	A	G
509	128107	A	G
510	129591	A	G
511	129637	T	C
512	129839	C	T
513	130006	A	G
514	130589	A	G
515	131185	T	C
516	131906	A	T
517	132165	T	C
518	132427	A	G
519	132454	A	G
520	133820	C	T
521	134601	A	G
522	134647	A	G
523	135086	A	G
524	135436	T	A
525	135655	G	A
526	135843	T	C
527	136162	T	C
528	136206	A	G
529	136357	A	G
530	136807	T	C
531	137480	T	C
532	139758	T	C
533	141620	A	G
534	142352	A	G
535	142496	A	G
536	143844	T	C
537	145238	A	G
538	145268	T	C
539	145389	T	C
540	145989	A	G
541	146905	T	C
542	147190	T	C
543	149266	A	G
544	149737	A	G
545	150472	A	G
546	150799	A	G
547	151909	A	G
548	152008	T	C
549	152303	G	A
550	154306	T	C
551	156629	T	C
552	156835	T	C
553	157047	A	C
554	158997	T	C
555	159211	T	C
556	159945	T	C
557	161307	T	C
558	161735	A	G
559	163360	A	T
560	164131	A	G
561	165888	A	G
562	167887	T	C
563	168196	A	G
564	168215	T	C
565	168920	A	G
566	169459	A	G
567	170181	A	G
568	171217	T	C
569	171606	A	G
570	172762	A	G
571	174084	A	G
572	174469	T	C
573	174725	A	G
574	176850	A	G
575	177691	A	G
576	182141	T	C
577	182273	A	G
578	182360	A	G
579	182701	A	G
580	184303	A	G
581	184556	T	C
582	184780	A	G
583	185677	A	G
584	188225	A	G
585	189731	T	C
586	189774	T	C
587	190048	T	C
588	190949	A	G
589	191012	T	C
590	191684	A	C
591	193088	T	C
592	194128	A	G
593	195826	A	G
594	195963	T	C
595	195999	T	C
596	196727	A	G
597	197019	A	G
598	199243	T	C
599	200720	A	G
600	202835	T	C
601	203226	A	G
602	203943	T	C
603	208790	A	G
604	210228	A	G
605	210552	A	G
606	211100	A	G
607	211419	A	C
608	211424	A	G
609	211711	T	C
610	213690	T	C
611	218899	A	G
612	220702	A	G
613	224103	T	C
614	224244	A	G
615	224427	A	G
616	224775	A	G
617	227842	T	C
618	230075	A	G
619	231780	A	G
620	234378	A	G
621	235024	A	G
622	236075	T	C
623	236621	T	C
624	237096	A	G
625	239425	A	G
626	239570	T	C
627	240143	A	G
628	244391	A	G
629	254036	A	G
630	255408	T	C
631	255651	A	G
632	256595	T	C
633	260790	T	C
634	263564	T	C
635	263904	T	C
636	264907	T	C
637	267177	T	C
638	279409	A	G
639	279570	T	C
640	282952	A	G
641	286731	A	G
642	290221	A	G
643	292115	T	C
644	292869	A	G
645	304370	T	C
646	305888	A	G
647	310293	A	G
648	324808	A	G
649	328933	A	G
650	343000	T	C
651	345674	A	G
652	356116	A	G
653	356416	A	G
654	356884	G	A
655	372502	A	G
656	375316	T	C
657	378759	T	C
658	388464	A	G
659	390315	A	G
660	391718	A	G
661	397296	C	G
662	405517	A	G
663	406391	A	G
664	415473	A	G
665	416781	A	G
666	416839	A	G
667	422685	A	G
668	445255	T	C
669	456494	C	T
670	457637	A	G
data2.txt (0.84 KB)
>gi|354512101|gb|AGQQ01000001.1| Corynebacterium glutamicum ATCC 14067 Contig01, whole genome shotgun sequence
TTAGCCAGGAAACGCTTCGCTGCCGCGACGT
>gi|354512096|gb|AGQQ01000002.1| Corynebacterium glutamicum ATCC 14067 Contig02, whole genome shotgun sequence
TTAGCCAGGAAACGCTTCGCTGCCGCGACGTTGCGCTTCGGAGAGAGGTAAAAGTCCAGG
TTGAGGGTGGGGCGCAGCAGGAGCATCGCAATCGCGA
>gi|354511893|gb|AGQQ01000003.1| Corynebacterium glutamicum ATCC 14067 Contig03, whole genome shotgun sequence
GTTTGTATCCGTATTACTGCGGATCGTATCGAAGAGGGCGTCGGGAAGGTCAAACGCGCC
>gi|354511890|gb|AGQQ01000004.1| Corynebacterium glutamicum ATCC 14067 Contig04, whole genome shotgun sequence
GGTGTGTAAATTAATTCCAGTCAGCGCGACCAACAACGCC
>gi|354511864|gb|AGQQ01000005.1| Corynebacterium glutamicum ATCC 14067 Contig05, whole genome shotgun sequence
CGTGCCTTGCCCTTTCCGCAATGAGTGCATCGCCTCCATCCTTTCAACGTCCGATATGCA
 
0
 

You want to put the content of $gia and $name together to have the name of an existing file that you can pass to a subroutine which will open and read that file, right? I don't know why you would ask how to separate that file name into columns, but the following is an example of passing a variable containing one scalar value that should be a valid file name.

#!/usr/bin/perl
use strict; 
use warnings; 

my $gia = 12;
my $name = 'tai';

my $oneval = $gia.$name; #Name of file should be '12tai', right?

print_first_argument($oneval);#Call subroutine and pass one scalar value as argument

sub print_first_argument{
    my ($filename) = @_;#Assign argument to lexical variable
    print "The first argument is '$filename'\n";
    #If $filename contains the name of a file that exists 
    #then you should be able to open and read it.
}

If my ($filename) = @_;#Assign argument to lexical variable looks confusing you can substitute with my $filename = shift(@_);#Assign argument to lexical variable which does exactly the same thing.

 
0
 
my $position="$gia$name1";      
read_positions ($position);

try above changes

 
0
 

Hi neo!
thanks for your comment!
I had used the same it but it all have the same error.

my $position="$gia$name1";      
read_positions ($position);

try above changes

 
0
 

That file you want to read is in the directory with your perl script?
Because you give only file name (without path) to read_positions() routine...

 
0
 

Because I hope to use two value $gia and $name1 in my script. And I tried to use

my $position="$gia$name1";
    read_positions ($position);

but it has error to read file.

The erro: Failed open 6114067_contig34:No such file or directory at c:\users\PCUSER\desktop\thu.pl line 129

I do not know how to solve that error. Could you show me how to solve this error?

You want to put the content of $gia and $name together to have the name of an existing file that you can pass to a subroutine which will open and read that file, right? I don't know why you would ask how to separate that file name into columns, but the following is an example of passing a variable containing one scalar value that should be a valid file name.

#!/usr/bin/perl
use strict; 
use warnings; 

my $gia = 12;
my $name = 'tai';

my $oneval = $gia.$name; #Name of file should be '12tai', right?

print_first_argument($oneval);#Call subroutine and pass one scalar value as argument

sub print_first_argument{
    my ($filename) = @_;#Assign argument to lexical variable
    print "The first argument is '$filename'\n";
    #If $filename contains the name of a file that exists 
    #then you should be able to open and read it.
}

If my ($filename) = @_;#Assign argument to lexical variable looks confusing you can substitute with my $filename = shift(@_);#Assign argument to lexical variable which does exactly the same thing.

 
0
 

Because I hope to use two value $gia and $name1 in my script. And I tried to use

my $position="$gia$name1";
    read_positions ($position);

but it has error to read file.

The erro: Failed open 6114067_contig34:No such file or directory at c:\users\PCUSER\desktop\thu.pl line 129

I do not know how to solve that error. Could you show me how to solve this error?

That message says that a file named '6114067_contig34' does not exist in your current directory. Either the file named '6114067_contig34' is in a different directory or it has a different name. Should it have an extension (such as dot something). For example if the file is really named '6114067_contig34.txt' then trying to open '6114067_contig34' will result in the error message you are getting.

Do you know what the current directory is when perl runs your scripts? What is the output when you run the following?

#!/usr/bin/perl
use strict; 
use warnings; 

use Cwd qw();
my $path = Cwd::cwd();
print "$path\n";

my @files = <6114067_contig34*>;

foreach my $file (@files) {
    print $file . "\n";
}

print "No files exist starting with '6114067_contig34' in $path\n" if @files == 0;
 
0
 

Thanks d5e5!
I fix the problem and it run well.

That message says that a file named '6114067_contig34' does not exist in your current directory. Either the file named '6114067_contig34' is in a different directory or it has a different name. Should it have an extension (such as dot something). For example if the file is really named '6114067_contig34.txt' then trying to open '6114067_contig34' will result in the error message you are getting.

Do you know what the current directory is when perl runs your scripts? What is the output when you run the following?

#!/usr/bin/perl
use strict; 
use warnings; 

use Cwd qw();
my $path = Cwd::cwd();
print "$path\n";

my @files = <6114067_contig34*>;

foreach my $file (@files) {
    print $file . "\n";
}

print "No files exist starting with '6114067_contig34' in $path\n" if @files == 0;
Question Answered as of 3 Years Ago by _neo_ and d5e5
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article