Spreadsheet::WriteExcel something wrong with write_formula - perl

I'm trying to write an formula using WriteExcel
=SUMIF(J3:J54;"=xxx";H3:H54)
but that code:
$sheet->write_formula($row+1, 0, "=SUMIF(J" . ($row-($row-3)) . ":J" . ($row-2) . ";\"=xxx\";H" . ($row-($row-3)) . ":H" . ($row-2) . ")");
ends with
Unknown defined name SUMIF in formula at test.pl line 196
But when I print out that formula (using print) I got exactly the same string as wanted one (calculations on $row are good)
I'm pretty sure this code should work

You need to us the US style union operator "," instead of the European style ";":
=SUMIF(J3:J54,"=xxx",H3:H54)
If you modifiy your formula string to replace ; with , it will work. I tested it.

Related

Why does my PHP Calculator doesn't evaluate a error message after typing letters into number fields?

I tried to code a simple calculator in PHP, and if I type in numbers everything ist perfect, but if I try to type in letters or words into the number fields, there should be shown a error message, that one of the numbers isn't a numeric sign. But for some reason it is not working. I showed my PHP Code in the follwing picture I will show my html-Code which is named Taschenrechner.php and my php-Code which is named Taschenrechner2.php.
Thank you very much for your time and help
best wishes
Here is my Code of the PHP-Form1
<?php include("kopf.inc.php");?>
And here is my PHP Code from the Evaluation of the typed in numbers
<?php include("kopf.inc.php");?>
Here are two pictures of the failure text
Picture of my PHP-form output
And Picture of the PHP output
I Cant see much of your code besides include statements.
of you Declare a variable in php you dont assign the datatype. The Datatype is assigned when you assign a Value to a variable.
<?php
$Variable = 1; //makes $Variable a Integer
echo $Variable . "\r\n";
echo gettype ($Variable) . "\r\n";
$Variable = 'nun ist $Variable ein String'; //changes the datatype from Integer to String.
echo $Variable . "\r\n";
echo gettype ($Variable) . "\r\n";
$StringOne = 'S1';
$StringTwo = 'S2';
$ResultTwoStrings = 'ResultTwoStrings';
$StringOne + $StringTwo = $ResultTwoStrings;
echo $ResultTwoStrings;
?>
This will Result in the fallowing output:
1
integer
nun ist $Variable ein String
string
Warning: A non-numeric value encountered in ./Playground/file0.php on line 13
Warning: A non-numeric value encountered in ./Playground/file0.php on line 13
ResultTwoStrings
I am not sure why you dont get an error message.
Good evening everybody, after I lacked a little bit in motivaton during the last few months I noticed, that I forgot posting my code. A little bit embarassing. But now, I had a spelling mistake with my variables so they were not the same but thank you everybody

Countif date in range exceeds date in other range excell 2013

I want to count the amount of times a date in one column exceeds the date in another column. I already seem to have found a way to do this, but I would like to know what exactly is wrong with my first formula.
17-4-2016 . . . 21-3-2016
17-6-2016 . . . 11-11-2016
17-6-2016 . . . 15-4-2016
23-3-2017 . . . 1-4-2016
23-3-2017 . . . 23-3-2016
23-3-2017 . . . 26-9-2016
23-3-2017 . . . 1-4-2016
23-3-2017 . . . 12-4-2016
23-3-2017 . . . 11-4-2016
23-3-2017 . . . 15-4-2016
My own formula: =COUNTIF(B1:B10;">"&A1:A10) , which gives me a value of 0, while 1 date clearly exceeds the date in the corresponding cell.
I found this formula to work: =SUMPRODUCT(--(B1:B10>A1:A10)) , which gives the correct value of 1.
I would like to know the error in my own formula and how the second one does work.
You need to convert all of the cells values into a Date format that Excel will recognize and treat as a Date. Right now it is treating most of them as text. Once you do that a small change to your formula will get the results that you want, even if you change some of the dates to have more that 1 that is later in column "B".
=COUNTIF(B1:B10,">"&A1:A10)-1
Something like this will convert them into Dates:
=CONCATENATE(MID(A1,FIND("-",A1)+1,FIND("-",A1,FIND("-",A1)+1)-(FIND("-",A1)+1)),"/",LEFT(A1,FIND("-",A1)-1),"/",RIGHT(A1,4))

Error in Linkdatagen : Use of uninitiated value $chr in concatenation (.) or string

Hi I was trying to use linkdatagen, which is a perl based tool. It requires a vcf file (using mpileup from SAMtools) and a hapmap annotation file (provided). I have followed the instructions but the moment I use the perl script provided, I get this error.
The codes I used are:
samtools mpileup -d10000 -q13 -Q13 -gf hg19.fa -l annotHapMap2U.txt samplex.bam | bcftools view -cg -t0.5 - > samplex.HM.vcf
Perl vcf2linkdatagen.pl -variantCaller mpileup -annotfile annotHapMap2U.txt -pop CEU -mindepth 10 -missingness 0 samplex.HM.vcf > samplex.brlmm
Use of uninitiated value $chr in concatenation (.) or string at vcf2linkdatagentest.pl line 487, <IN> line 1.... it goes on and on.. I have mailed the authors, and haven't heard from them yet. Can anyone here please help me? What am I doing wrong?
The perl script is :
http://bioinf.wehi.edu.au/software/linkdatagen/vcf2linkdatagen.pl
The HapMap file can be downloaded from the website mentioned below.
http://bioinf.wehi.edu.au/software/linkdatagen/
Thanks so much
Ignoring lines starting with #, vcf2linkdatagen.pl expects the first field of the first line of the VCF to contain something of the form "chrsomething", and your file doesn't meet that expectation. Examples from a comment in the code:
chr1 888659 . T C 226 . DP=26;AF1=1;CI95=1,1;DP4=0,0,9,17;MQ=49;FQ=-81 GT:PL:GQ 1/1:234,78,0:99
chr1 990380 . C . 44.4 . DP=13;AF1=7.924e-09;CI95=1.5,0;DP4=3,10,0,0;MQ=49;FQ=-42 PL 0
The warning means that a variable used in a string is not initialized (undefined). It is an indication that something might be wrong. The line in question can be traced to this statement
my $chr = $1 if ($tmp[0] =~ /chr([\S]+)/);
It is bad practice to use postfix if statements on a my statement.
As ikegami notes a workaround for this might be
my ($chr) = $tmp[0] =~ /chr([\S])/;
But since the match failed, it will likely return the same error. The only way to solve is to know more about the purpose of this variable, if the error should be fatal or not. The author has not handled this case, so we do not know.
If you want to know more about the problem, you might add a debug line such as this:
warn "'chr' value not found in the string '$tmp[0]'" unless defined $chr;
Typically, an error like this occurs when someone gives input to a program that the author did not expect. So if you see which lines give this warning, you might find out what to do about it.

How to extract some text from a column to create a new column

Dear stackoverflow community,
I have a 2 columns file that looks like this:
Ccrux.00013.c0_g1_i1 .
Ccrux.00013.c0_g2_i1 .
Ccrux.00014.c0_g1_i1 .
Ccrux.00014.c0_g2_i1 .
Ccrux.00015.c0_g1_i1 .
Ccrux.00015.c0_g1_i1 GO:0005789^cellular_component^endoplasmic reticulum membrane`GO:0016021^cellular_component^integral component of membrane`GO:0005509^molecular_function^calcium ion binding`GO:0005506^molecular_function^iron ion binding`GO:0031418^molecular_function^L-ascorbic acid binding`GO:0016706^molecular_function^oxidoreductase activity, acting on paired donors, with incorporation or reduction of molecular oxygen, 2-oxoglutarate as one donor, and incorporation of one atom each of oxygen into both donors`GO:0045646^biological_process^regulation of erythrocyte differentiation
Ccrux.00015.c0_g2_i1 GO:0005789^cellular_component^endoplasmic reticulum membrane`GO:0016021^cellular_component^integral component of membrane`GO:0005509^molecular_function^calcium ion binding`GO:0005506^molecular_function^iron ion binding`GO:0031418^molecular_function^L-ascorbic acid binding`GO:0016706^molecular_function^oxidoreductase activity, acting on paired donors, with incorporation or reduction of molecular oxygen, 2-oxoglutarate as one donor, and incorporation of one atom each of oxygen into both donors`GO:0045646^biological_process^regulation of erythrocyte differentiation
Ccrux.00016.c0_g1_i1 .
Ccrux.00016.c0_g2_i1 .
Ccrux.00017.c0_g1_i1 .
Ccrux.00018.c0_g1_i1 .
Ccrux.00019.c0_g1_i1 .
I need a new 2 columns file that:
Doesn't contain the rows where the 2nd column value is .
Only contains GO:XXXXXXX as 2nd column value (i.e. eliminates from the 2nd column all the text and only retains the GO numbers)
The new file should look like:
Ccrux.00015.c0_g1_i1 GO:0005789,GO:0016021,GO:0005509,GO:0005506,GO:0031418,GO:0016706,GO:0045646
Ccrux.00015.c0_g2_i1 GO:0005789,GO:0016021,GO:0005509,GO:0005506,GO:0031418,GO:0016706,GO:0045646
Ccrux.00029.c0_g1_i1 GO:0035869,GO:0005737,GO:0005615,GO:0016020,GO:0021956,GO:0060271,GO:0021904,GO:0001701,GO:0001841,GO:0008589,GO:0021523,GO:0021537
I've been trying with perl:
perl -ne '/(GO:\d+)/ && print "$1"' input.file > output.file
But prints me all the GO numbers in just one column. I'm really lost about how to do it. Any suggestions will be more than welcome.
Thank you all in advance.
What you've got there pattern matches a piece of text, and just prints that.
From what it sounds like you're doing:
GO:0005789^cellular_component^endoplasmic reticulum membrane`
You're trying to remove any 'bits' between ^ and the next GO?
The nice thing with perl is that that syntax -ne just creates a little while loop around the commands - so it will let you do multiple statements.
So - expanded example:
#!/usr/bin/env perl
use strict;
use warnings;
while (<DATA>) {
next unless m/GO/;
s/\^[^`]+`/,/g;
s/\^[^`]+$/\n/g;
print;
}
__DATA__
Ccrux.00013.c0_g1_i1 .
Ccrux.00013.c0_g2_i1 .
Ccrux.00014.c0_g1_i1 .
Ccrux.00014.c0_g2_i1 .
Ccrux.00015.c0_g1_i1 .
Ccrux.00015.c0_g1_i1 GO:0005789^cellular_component^endoplasmic reticulum membrane`GO:0016021^cellular_component^integral component of membrane`GO:0005509^molecular_function^calcium ion binding`GO:0005506^molecular_function^iron ion binding`GO:0031418^molecular_function^L-ascorbic acid binding`GO:0016706^molecular_function^oxidoreductase activity, acting on paired donors, with incorporation or reduction of molecular oxygen, 2-oxoglutarate as one donor, and incorporation of one atom each of oxygen into both donors`GO:0045646^biological_process^regulation of erythrocyte differentiation
Ccrux.00015.c0_g2_i1 GO:0005789^cellular_component^endoplasmic reticulum membrane`GO:0016021^cellular_component^integral component of membrane`GO:0005509^molecular_function^calcium ion binding`GO:0005506^molecular_function^iron ion binding`GO:0031418^molecular_function^L-ascorbic acid binding`GO:0016706^molecular_function^oxidoreductase activity, acting on paired donors, with incorporation or reduction of molecular oxygen, 2-oxoglutarate as one donor, and incorporation of one atom each of oxygen into both donors`GO:0045646^biological_process^regulation of erythrocyte differentiation
Ccrux.00016.c0_g1_i1 .
Ccrux.00016.c0_g2_i1 .
Ccrux.00017.c0_g1_i1 .
Ccrux.00018.c0_g1_i1 .
Ccrux.00019.c0_g1_i1 .
This will generate as output:
Ccrux.00015.c0_g1_i1 GO:0005789,GO:0016021,GO:0005509,GO:0005506,GO:0031418,GO:0016706,GO:0045646
Ccrux.00015.c0_g2_i1 GO:0005789,GO:0016021,GO:0005509,GO:0005506,GO:0031418,GO:0016706,GO:0045646
We:
skip any line without the word GO in it.
replace any instance of literal ^, one or more not ^ and then backtick - with a comma.
and replace the same terminated at end of line with \n.
This we can condense to a one liner thus:
perl -ne 'next unless m/GO/;s/\^[^`]+`/,/g;s/\^[^`]+$/\n/g;print' inputfile > outputfile
Or perhaps better - without the print - see perlrun - -p is similar to -n but it builds in the print (so works a bit more like sed).
perl -pe 'next unless m/GO/;s/\^[^`]+`/,/g;s/\^[^`]+$/\n/g;' inputfile > outputfile
I think your requirement is a little too long for a one-line solution, but it can be very brief. This program will produce the output that you describe. It expects the path to the input file as a parameter on the command line
use strict;
use warnings;
while ( <> ) {
next unless my #values = /GO:\d+/g;
local $" = ',';
s/\S\s+\K.+/#values/;
print;
}
A one-line version would be a little clunky
perl -pe '#v=/GO:\d+/g or next; $"=","; s/\S\s+\K.+/#v/; print;' myfile > newfile

Writing a table and string to a text file in matlab

I'm new to matlab and have tried looking in matworks for a solution but have had no success.
My code produces a string and table that looks like this
Run number 3
Slope -0.00354, Intercept 0.02289
x y Predictied_y
___ _________ ____________
0 0 0.022894
30 -0.070808 -0.083405
. . .
. . .
. . .
. . .
My issue is that I can't seem to get the dlmwrite function to work at all. I've tried converting the table into an array with no success and I;m now stuck.
To make things worse the code has to write this table into the file three times without writing over the data in the file.
Sorry if I left out any details.