Everyone,
R cannot open the connection.
https://support.10xgenomics.com/single-cell-gene-expression/software/pipelines/latest/output/matrices
Thanks in advance for great help!
Best,
Yue
library(Matrix)
matrix_dir = "/opt/filtered_feature_bc_matrix/"
barcode.path <- paste0(matrix_dir, "barcodes.tsv")
features.path <- paste0(matrix_dir, "features.tsv")
matrix_dir = "/opt/filtered_feature_bc_matrix/"
mat <- readMM(file = matrix.path)
Error in open.connection(file) : cannot open the connection
In addition: Warning message:
In open.connection(file) :
cannot open file '/opt/filtered_feature_bc_matrix/matrix.mtx': No such file or directory>
> library(Matrix)
> matrix_dir = "/home/li/"
> barcode.path <- paste0(matrix_dir, "barcodes.tsv")
> features.path <- paste0(matrix_dir, "features.tsv")
> matrix.path <- paste0(matrix_dir, "matrix.mtx")
> mat <- readMM(file = matrix.path)
> feature.names = read.delim(features.path,
+ header = FALSE,
+ stringsAsFactors = FALSE)
> barcode.names = read.delim(barcode.path,
+ header = FALSE,
+ stringsAsFactors = FALSE)
> colnames(mat) = barcode.names$V1
> rownames(mat) = feature.names$V1
Related
guys!
I'm using this sintaxe but when I use the last part ("modelo = ...") it shows the following: "Error in merge.zoo(difetanol, detanol, mes2, mes3, mes4, mes5, mes6, mes7, :
all(sapply(args, function(x) is.zoo(x) || !is.plain(x) || (is.plain(x) && .... is not TRUE"
ethidra = (tsrelatorio[,"etanol"])
ethidra
length(ethidra)
acuavhp = (tsrelatorio[,"avhp"])
acuavhp
length(acuavhp)```
matr <- matrix(0, nr = 12, nc = 12)
matr[row(matr) == col(matr)] <- 1
matr
Djt <- rbind(matr,matr,matr,matr); Djt
dim(Djt)
names(Djt)
dimnames(Djt) = list(c(),c("M1", "M2", "M3", "M4","M5","M6","M7","M8","M9","M10","M11","M12"))
Djt
dim(Djt)```
teste=data.frame(Djt)
attach(teste)
mes2= teste[1:47,2]
mes2
length(mes2)
mes3= teste[1:47,3]
mes3
length(mes3)
mes4= teste[1:47,4]
mes4
length(mes4)
mes5= teste[1:47,5]
mes5
length(mes5)
mes6= teste[1:47,6]
mes6
length(mes6)
mes7= teste[1:47,7]
mes7
length(mes7)
mes8= teste[1:47,8]
mes8
length(mes8)
mes9= teste[1:47,9]
mes9
length(mes9)
mes10= teste[1:47,10]
mes10
length(mes10)
mes11= teste[1:47,11]
mes11
length(mes11)
mes12= teste[1:47,12]
mes12
length(mes12)
detanol = (ethidra[1:47])
detanol
length(detanol)
difetanol=diff(detanol)
difetanol
length(difetanol)
tempo = tempo <- seq(1:47)
modelo = dynlm(difetanol ~ detanol + mes2 +mes3 +mes4 + mes5 + mes6 + mes7 + mes8 + mes9 + mes10 + mes11 + mes12 + tempo + L(difetanol,1) + L(difetanol,2))
summary(modelo)
Rader DFT algorithm implemented using GNU Octave (for example, length 11). I used this wikipedia article. The values obtained are correct, but they are incorrectly reindexed. I can not understand where the error is?
upd. Add function for finds the smallest generator of the group.
Fin = [1,2,3,4,5,6,7,8,9,10,11];
nfft = columns(Fin);
snfft = nfft - 1;
function [m one_per] = find_gen(p)
m = 1;
a = factor(p);
if (length(a) > 1)
m = p + 1;
one_per = [];
endif
if (m == 1)
finished = 0;
for cur = 2:p-2
not_yet = 0;
test = cur;
single_per = [1 cur];
for k = 2:p-2
test = test * cur;
test = mod(test,p);
single_per = [single_per test];
if (test == 1)
not_yet = 1;
endif
endfor
if (not_yet == 0)
m = cur;
one_per = single_per;
finished = 1;
break;
endif
endfor
endif
endfunction
q = find_gen(nfft)
p = mod((q^(nfft-2)),nfft)
Tq_idx = [];
Tq = [];
for k = 0 : snfft-1
A = mod(q^k, nfft);
Tq_idx = [A Tq_idx];
Tq = [Fin(A+1) Tq];
endfor
Tq_idx, Tq
Tp_idx = [];
Tp = [];
for k = 0 : snfft-1
A = mod(p^k, nfft);
Tp_idx = [A Tp_idx];
Tp = [Fin(A+1) Tp];
endfor
Tp_idx, Tp
Twp = [];
for k = 1 : snfft
ecpx = complex(cos(-2*pi*Tp_idx(k) / nfft),sin(-2*pi*Tp_idx(k) / nfft));
Twp = [Twp ecpx];
endfor
Tq_fft = fft(Tq);
Twp_fft = fft(Twp);
Tm_fft = Tq_fft .* Twp_fft;
Tm_ffti = ifft(Tm_fft);
Tm_ffti
Res = [Fin(1)];
for k = 1 : snfft
Res(1) += Fin(k+1);
Res = [Res (Tm_ffti(Tp_idx(k)) + Fin(1))];
endfor
Res
Fbest = fft(Fin)
Fdiff = Fbest .- Res
ResI = ifft(Res)
Result
Res =
Columns 1 through 3:
66.0000 + 0.0000i -5.5000 - 4.7658i -5.5000 - 18.7313i
Columns 4 through 6:
-5.5000 - 0.7908i -5.5000 - 8.5582i -5.5000 + 8.5582i
Columns 7 through 9:
-5.5000 + 18.7313i -5.5000 + 4.7658i -5.5000 + 0.7908i
Columns 10 and 11:
-5.5000 - 2.5118i -5.5000 + 2.5118i
Using the GNU Octave fft () internal function as standard
Fbest =
Columns 1 through 3:
66.0000 + 0.0000i -5.5000 + 18.7313i -5.5000 + 8.5582i
Columns 4 through 6:
-5.5000 + 4.7658i -5.5000 + 2.5118i -5.5000 + 0.7908i
Columns 7 through 9:
-5.5000 - 0.7908i -5.5000 - 2.5118i -5.5000 - 4.7658i
Columns 10 and 11:
-5.5000 - 8.5582i -5.5000 - 18.7313i
I fixed the error. Working code here
function [m one_per] = find_gen(p)
m = 1;
a = factor(p);
if (length(a) > 1)
m = p + 1;
one_per = [];
endif
if (m == 1)
finished = 0;
for cur = 2:p-2
not_yet = 0;
test = cur;
single_per = [1 cur];
for k = 2:p-2
test = test * cur;
test = mod(test,p);
single_per = [single_per test];
if (test == 1)
not_yet = 1;
endif
endfor
if (not_yet == 0)
m = cur;
one_per = single_per;
finished = 1;
break;
endif
endfor
endif
endfunction
function [Fout] = fast_conv (F1,F2, seq_lenght)
F1_fft = fft(F1);
F2_fft = fft(F2);
Fm_fft = F1_fft .* F2_fft;
Fout = ifft(Fm_fft);
endfunction
function [Res] = rader_algo (Fin)
nfft = columns(Fin);
snfft = nfft - 1;
q = find_gen(nfft)
p = mod((q^(nfft-2)),nfft)
Tq_idx = []; Tq = [];
for k = 0 : snfft-1
A = mod(q^k, nfft);
Tq_idx = [Tq_idx A];
Tq = [Tq Fin(A+1)];
endfor
Tq_idx, Tq
Tp_idx = []; Tp = [];
for k = 0 : snfft-1
A = mod(p^k, nfft);
Tp_idx = [Tp_idx A];
Tp = [Tp Fin(A+1)];
endfor
Tp_idx, Tp
Twp = [];
for k = 1 : snfft
ecpx = complex(cos(-2*pi*Tp_idx(k) / nfft),sin(-2*pi*Tp_idx(k) / nfft));
Twp = [Twp ecpx];
endfor
Twp
Tm_ffti = fast_conv(Tq, Twp, nfft);
Res = zeros(1, nfft);
Res(1) = Fin(1);
for k = 1 : snfft
Res(1) += Fin(k+1);
Res(Tp_idx(k)+1) = Tm_ffti(k) + Fin(1);
endfor
endfunction
Fin = [1,2,3,4,5];
Res = rader_algo (Fin)
% === VERIFY ===
Fbest = fft(Fin)
Fdiff = Fbest .- Res
ResI = ifft(Res)
Im trying to get the global minimum of a non linear function with linear constraints. I share you the code:
rho = 1.0
g = 9.8
C = 1.0 #roughness coefficient
J = rho*g/(float(1e6)) #constant of function
capacity = [0.3875, 0.607, 0.374] #Supply data
demand = [0.768, 0.315, 0.38,] #Demand data
m= len(capacity)
n = len(demand)
x0 = np.array(m*n*[0.01]) #Initial point for algorithm
# In[59]:
#READ L AND d FROM ARCGIS !!!
L = (314376.57, 277097.9663, 253756.9869 ,265786.5632, 316712.6028, 232857.1468, 112063.9914, 135762.94, 131152.8206)
h= (75, 75, 75, 75, 75, 75, 1320,75,75)
K = np.zeros(m*n)
N=np.zeros(m*n)
# In[60]:
#Each path has its own L,d, therefore, own constant
# In[61]:
#np.seterr(all='ignore')
def diameter(x):
d = 1.484
if x >= 0.276:
d = 1.484
elif x >= 0.212:
d = 1.299
elif x >= 0.148:
d = 1.086
elif x >= 0.0975:
d = 0.881
elif x >= 0.079:
d = 0.793
elif x >= 0.062:
d = 0.705
elif x >= 0.049:
d = 0.626
elif x >= 0.038:
d = 0.555
elif x >= 0.030:
d = 0.494
elif x >= 0.024:
d = 0.441
elif x >= 0.0198:
d = 0.397
elif x >= 0.01565:
d = 0.353
elif x >= 0.0123:
d = 0.313
elif x >= 0.0097:
d = 0.278
elif x >= 0.0077:
d = 0.247
elif x >= 0.0061:
d = 0.22
elif x >= 0.0049:
d = 0.198
elif x >= 0.00389:
d = 0.176
elif x >= 0.0032:
d = 0.159
elif x >= 0.0025:
d = 0.141
elif x >= 0:
d = 0.123
return d
#Definition of Objetive function
def objective(x):
sum_obj = 0.0
for i in range(len(L)):
K = 10.674*L[i]/(C**1.852*diameter(x[i])**4.871)
N[i] = K*x[i]**2.852*J+x[i]*J*h[i]
sum_obj = sum_obj + N[i]
return sum_obj
print(str(objective(x0)))
#Definition of the constraints
GB=[]
for i in range(m):
GB.append(n*i*[0]+n*[1]+(m-1-i)*n*[0])
P=[]
for i in range(n):
P.append(m*(i*[0]+[1]+(n-1-i)*[0]))
DU=np.array(GB+P)
lb = np.array(m*[0] + demand) # Supply
ub = np.array(capacity + n*[np.inf]) # Demand
# In[62]:
b = (0, 1)
bnds = []
for i in range(m*n):
bnds.append(b)
cons = LinearConstraint(DU,lb,ub)
solution = differential_evolution(objective,x0,cons,bnds)
x = solution.x
# show initial objective
print('Initial SSE Objective: ' + str(objective(x0)))
# show final objective
print('Final SSE Objective: ' + str(objective(x)))
# print solution
print('Solution Supply to Demand:')
print('Q = ' + str(((np.around(x,6)).reshape(10,18))))
I dont know why, but when I run appear the following:
"if strategy in self._binomial:
TypeError: unhashable type: 'list'
Anyone have gotten the same mistake ? Its my first time trying to solve optimization problem, so I need a little bit of help. Any advice is welcome !!
Thanks a lot !
You're not calling differential_evolution correctly. For your example you should call it as:
differential_evolution(objective, bnds, contraints=(cons,))
(I'm not sure if there are additional problems)
I picked up VBScript yesterday, and I am trying to take in a file, copy the file, change some text within the file and output a new file with a new name. The file is copying and saving in the correct location, however I am not sure where my code is wrong. The 'filter' text is changing in all of the files but it is only changing to filter(14).
Any help, guidance or instruction is greatly appreciated. I've placed the code I have so far below:
Const ForReading = 1
Const ForWriting = 2
Dim outputFile(14)
outputFile(0) = "MMCLAgenda_BehavioralHealth.txt"
outputFile(1) ="MMCLAgenda_CaseandCareSupport.txt"
outputFile(2) ="MMCLAgenda_CaseManagement.txt"
outputFile(3) ="MMCLAgenda_ChangeOrder.txt"
outputFile(4) ="MMCLAgenda_DM_BehavioralHealth.txt"
outputFile(5) ="MMCLAgenda_DM_Overarching.txt"
outputFile(6) ="MMCLAgenda_DM_PhysicalHealth.txt"
outputFile(7) ="MMCLAgenda_DM_Supervisors.txt"
outputFile(8) ="MMCLAgenda_DM_SupportStaff.txt"
outputFile(9) ="MMCLAgenda_DM_Workgroups.txt"
outputFile(10) ="MMCLAgenda_InpatientUM.txt"
outputFile(11) ="MMCLAgenda_LeadershipCommittee.txt"
outputFile(12) ="MMCLAgenda_OutpatientUM.txt"
outputFile(13) ="MMCLAgenda_PolicyAndProcedureGroup.txt"
outputFile(14) ="MMCLAgenda_UMCommittee.txt"
Dim filter(14)
filter(0) = "<Formula>#Created > #Date(2015;12;31)& COL_Name = 'Behavior Health' : 'Behavioral Health'</Formula>"
filter(1) = "<Formula>#Created > #Date(2015;12;31)& COL_Name = 'Medical Management Call Center'</Formula>"
filter(2) = "<Formula>#Created > #Date(2015;12;31)& COL_Name = 'Case Management'</Formula>"
filter(3) = "<Formula>#Created > #Date(2015;12;31)& COL_Name = 'Change Orders'</Formula>"
filter(4) = "<Formula>#Created > #Date(2015;12;31)& COL_Name = 'Disease Management/Behavior Health/Anxiety' : 'DM Behavioral Health - Anxiety and Depression'</Formula>"
filter(5) = "<Formula>#Created > #Date(2015;12;31)& COL_Name = 'Disease Management/Overarching'</Formula>"
filter(6) = "<Formula>#Created > #Date(2015;12;31)& COL_Name = 'Disease Management/Clinical Staff'</Formula>"
filter(7) = "<Formula>#Created > #Date(2015;12;31) & COL_Name = 'Disease Management/Supervisors'</Formula>"
filter(8) = "<Formula>#Created > #Date(2015;12;31) & COL_Name = 'Disease Management/Support Staff'</Formula>"
filter(9) = "<Formula>#Created > #Date(2015;12;31)</Formula>"
filter(10) = "<Formula>#Created > #Date(2015;12;31)& COL_Name = 'Transitional Care'</Formula>"
filter(11) = "<Formula>#Created > #Date(2015;12;31)& COL_Name = 'Leadership Committee'</Formula>"
filter(12) = "<Formula>#Created > #Date(2015;12;31) & COL_Name = 'Utilization Management'</Formula>"
filter(13) = "<Formula>#Created > #Date(2015;12;31)& COL_Name = 'Policy & Procedures Workgroup'</Formula>"
filter(14) = "<Formula>#Created > #Date(2015;12;31)& COL_Name = 'TEST'</Formula>"
Dim destination(14)
destination(0) = "https://testcnet.centene.com/sites/LNTestMigration/Issac/MMCL/BH"
destination(1) = "https://testcnet.centene.com/sites/LNTestMigration/Issac/MMCL/CCS"
destination(2) = "https://testcnet.centene.com/sites/LNTestMigration/Issac/MMCL/CM"
destination(3) = "https://testcnet.centene.com/sites/LNTestMigration/Issac/MMCL/CO"
destination(4) = "https://testcnet.centene.com/sites/LNTestMigration/Issac/MMCL/DMBH"
destination(5) = "https://testcnet.centene.com/sites/LNTestMigration/Issac/MMCL/DMO"
destination(6) = "https://testcnet.centene.com/sites/LNTestMigration/Issac/MMCL/DMPH"
destination(7) = "https://testcnet.centene.com/sites/LNTestMigration/Issac/MMCL/DMS"
destination(8) = "https://testcnet.centene.com/sites/LNTestMigration/Issac/MMCL/DMSS"
destination(9) = "https://testcnet.centene.com/sites/LNTestMigration/Issac/MMCL/DMW"
destination(10) = "https://testcnet.centene.com/sites/LNTestMigration/Issac/MMCL/IUM"
destination(11) = "https://testcnet.centene.com/sites/LNTestMigration/Issac/MMCL/LC"
destination(12) = "https://testcnet.centene.com/sites/LNTestMigration/Issac/MMCL/OUM"
destination(13) = "https://testcnet.centene.com/sites/LNTestMigration/Issac/MMCL/PPG"
destination(14) = "https://testcnet.centene.com/sites/LNTestMigration/Issac/MMCL/UMC"
fileLocation = "C:\Users\HN142083\Desktop\MigrationJobAutomation\Jobs\"
'**********************************************************************************************************************************
'***for each file in outputFiles -> take FileIn, FileOut = outputFiles(i) -> change strNewText and change destination -> go next***
'**********************************************************************************************************************************
For each x in outputFile
FileIn = "C:\Users\HN142083\Desktop\MigrationJobAutomation\Jobs\MMCLAgenda_BehavioralHealth.txt"
FileOut = fileLocation+x
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(FileIn, ForReading)
strText = objFile.ReadAll
strTextDestination = strText
objFile.Close
For each item in filter
strNewText = Replace(strText, "<Formula>#Created > #Date(2015; 12; 31)</Formula>", item)
Next
For each record in destination
strTextDestination = Replace(strTextDestination, "<Web>https://testcnet.centene.com/sites/LNTestMigration/Issac/MMCL</Web>", record)
Next
Set objFile = objFSO.OpenTextFile(FileOut, ForWriting)
objFile.WriteLine strNewText
objFile.Close
Next
Because this loop
For each item in filter
strNewText = Replace(strText, "<Formula>#Created > #Date(2015; 12; 31)</Formula>", item)
Next
is executed for every item against strText, which you set to be the content of the file x. On the first iteration of the filter loop the strNewText variable is set to the replaced version of strText using filter(0). Then it's set to the replaced version of strText using filter(1) and so on, until filter(14) after which the loop is complete and strNewText is no longer being set.
strText is never being changed, so effectively the loop just gives strNewText the equivalent of the replace using only filter(14).
Let me know if that needs further explanation?
int Fib1, Fib2, Fib3, FibSum;
Fib1 = 0;
Fib2 = 1;
while(Fib3 < 500000)
{
Fib3 = Fib1 + Fib2;
Fib1 = Fib2;
Fib2 = Fib3;
FibSum = Fib3 + Fib1;
}
printf("%d\n", FibSum);
return 0;
I want to sum every third term of a fibonacci series but my answers is 832040 and it must be 158905...any help will be grateful!
This seems like homework but hey, I was once a student too. Still learning.
I wrote the following code in R but you can follow along enough:
fib1 <- 0
fib2 <- 1
fib3 <- 0
fib_sum <- 0
placeholder <- 0
while(fib3 < 500000)
{
placeholder <- placeholder + 1
f1 <- fib1
f2 <- fib2
f3 <- fib3
fib3 <- fib1 + fib2
fib1 <- fib2
fib2 <- fib3
if(placeholder %% 3 == 0)
{
fib_sum <- fib_sum + f1
print(paste('postsum [placeholder, fib_sum, fib1, fib2, fib3]: ',
placeholder, ' ', fib_sum, ' ', f1, ' ', f2, ' ', f3))
}
}
print(fib_sum)
Which results in what you were looking for. Lesson time, since this seems to be homework help. To help you out on the path of being a better programmer I would suggest taking the approach of scaffolding (just simply printing out everything after each line or so) when doing programming.
This will help you to see how you program is evolving as you do it.
Is there a better solution to the one below? I am sure there is but since I output the code as I was programming, I was able to come to the conclusion a lot quicker.
Hope that helps.
There is a shortcut to calculate every third fibonacci number:
If you want to sum up 1,5,21,89,377 ...then you sum up the first two numbers you have (fibsum = 1 + 5) and calculate and add the next numbers as follows in a loop.
fib1 = 1
fib2 = 5
fib3 = 0
fibsum = fib1 + fib2
while fib3 < 500000 :
fib3 = fib2*4+fib1
if fib3 < 500000:
fibsum += fib3
fib1 = fib2
fib2 = fib3
print fibsum
Here is some working code applying a formula found at HERE
double phi1 = (1 + sqrt(5)) / 2.0;
double phi2 = (1 - sqrt(5)) / 2.0;
int counter = 2;//Third term
int total = 0, term;
while (true) {
term = (pow(phi1, counter) - pow(phi2, counter)) / (phi1 - phi2);
if (term >= 500000)
break;
total += term;
counter += 3;
}
printf("%d\n", total);
return 0;
EDIT: Just realized this was posted OVER A YEAR AGO