The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 LabTalk Forum
 comparing amino acid protein positions graphically
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

coll@inia.

Spain
125 Posts

Posted - 09/03/2024 :  4:33:02 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
2022 Origin Ver. and Service Release (Select Help-->About Origin):
Operating System:windows 10-64

I have the data from docking of differnt drugs to the same protein on a worksheet of positions+aminoacids-chain columns whose positions I would like to compare in a graph. I would like to put all the X axis positions and the columns in the Y axis.
I do not care about the amino acids, nor about the chains.


As a short example with 6 columns (they come from docking different drugs and only one protein chain):
1 2 3 4 5 6
114W-A 5T-A 86K-A 86K-A 85T-A 112Y-A
116P-A 8Y-A 89R-A 89R-A 86K-A 114W-A
119Q-A 9N-A 117D-A 117D-A 89R-A 115D-A
123R-A 18R-A 121A-A 120E-A 120E-A 117D-A
177R-A 19R-A 121A-A 121A-A
209R-A 20N-A 124S-A 124S-A
219N-A
220Q-A
221R-A
252W-A
253K-A
260Y-A

I am trying the following code in Labtalk that I got from ChatGPT but I am finding numerous problems (i.e., atoi, reading the string cellValue$, etc, etc ....)

It was very work-intensive by hand when facing ~100 columns just for an easy comparative scatter graphic. It appeared to be an easy script to design, but I try several solutions during months to face the "easy" code with small success...

Could anyone help me?

here is the suggested best approach:

// Define the number of columns and rows in the worksheet
int nCols = wks.ncols; // Number of columns in the worksheet
int nRows = wks.maxRows; // Number of rows in the worksheet

// Initialize arrays to hold position data
int positions[];
int dataMarkers[nCols-1][];

// Loop through each column to extract and store the positions
for (int col = 1; col <= nCols; col++) {
for (int row = 1; row <= nRows; row++) {
string cellValue$ = cell(row, col)$;
if (cellValue$ != "") {
// Extract position number from the cell value
int pos = atoi(cellValue$.GetToken(1, "-"));
// If it's the first column, store all positions
if (col == 1) {
positions.Add(pos);
dataMarkers[col-1][positions.GetSize()] = 1;
} else {
// Check if the position already exists
int idx = positions.Find(pos);
if (idx < 0) {
positions.Add(pos);
dataMarkers[col-1][positions.GetSize()] = 0;
for (int k = 1; k < col-1; k++) {
dataMarkers[k][positions.GetSize()] = 0;
}
}
dataMarkers[col-1][positions.GetSize()] = 1;
}
}
}
}

// Sort positions and adjust data markers accordingly
ArraySort(positions, positions.GetSize(), 1);
for (int i = 1; i <= positions.GetSize(); i++) {
for (int col = 1; col <= nCols; col++) {
if (dataMarkers[col-1][i] != 1) {
dataMarkers[col-1][i] = 0;
}
}
}

// Transfer sorted positions and data markers to the worksheet
wks.ncols = nCols + 1; // Create an extra column for positions
wks.col1.name$ = "Position";
for (int col = 1; col <= nCols; col++) {
wks.col$(col+1).name$ = "Y Value " + col; // Rename columns
wks.col$(col+1).setData(dataMarkers[col-1]);
}
wks.col1.setData(positions);

// Plotting the data
plotxy (1, 2:$(nCols+1)) plot:=200 ogl:=<new template:=scatter>;

aplotnikov

Germany
162 Posts

Posted - 09/04/2024 :  03:00:17 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
I am trying the following code in Labtalk that I got from ChatGPT

And why not to ask ChatGPT why the generated code doesn't work? Be consistent!
Go to Top of Page

coll@inia.

Spain
125 Posts

Posted - 09/04/2024 :  05:00:27 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I tried your suggested way with chatGTP before but could not get useful code for Origin except for the one suggested for Python which works well and it is simple to use, except that Origin is much better for graphics .....

ChatGTP, Origin and me do not seem to mix well.....

Go to Top of Page

aplotnikov

Germany
162 Posts

Posted - 09/04/2024 :  05:51:20 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I really apologize for the overly trite advice, but there is also such an old-fashioned way of learning a programming language as reading a manual...
Go to Top of Page

coll@inia.

Spain
125 Posts

Posted - 09/05/2024 :  12:21:48 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Here is a recent proposal that again fails to recognize the content of the cells because string expression errors.

I tried different ways to read the content of each of the cells which contain both numbers and texts (ie,114W-A...), but have no sucess with the alternatives that I used during years for many other Origin old version scripts.
I think that is the key reason that needs to be solved.
Neither chatGTP (it keeps trying random solutions during a dozen of alternatives and repeats similar errors), nor me by manual tests, are capable to solve.

// Get the number of columns and rows in the active worksheet
int nCols = wks.nCols;
int nRows = wks.nRows;

// Create a new column for storing X values (positions)
wks.addcol(Position);

// Initialize the Y column to store dataset identifiers
wks.addcol(Dataset);

// Loop through each column (dataset)
for (int col = 1; col <= nCols; col++) {
// Loop through each row in the current column
for (int row = 1; row <= nRows; row++) {
// Get the cell value as a string
string cellValue$ = cell$(row, col)$;

// If the cell is not empty
if (cellValue$ != "") {
// Extract the numeric position (X value)
string position$ = "";
int i = 1;
while (isdigit(cellValue.GetAt(i)$)) {
position$ += cellValue.GetAt(i)$;
i++;
}

// Convert the extracted position string to an integer
int positionNum = pos(position$);

// Add the position to the Position column
col(Position)[row] = positionNum;

// Add the dataset number to the Dataset column
col(Dataset)[row] = col;
}
}
}

// Assuming that "Position" is in the last column and "Dataset" is in the second to last column
int colPosition = wks.nCols - 1; // Position column
int colDataset = wks.nCols; // Dataset column

// Plot the data as a 2D scatter plot
plotxy iy:=(colPosition, colDataset) plot:=200;

cell$(row, col)$
string expression error!
CELLVALUE:failed to add variable to local stack!
#Command Error!


is there anybody that can really help to solve the issue?
thanks for your attention
julio
Go to Top of Page

aplotnikov

Germany
162 Posts

Posted - 09/05/2024 :  03:00:29 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
The problem is, you don't realize that what you need is indeed "please do my job from the beginning", not "please solve the issue with a string variable". The code provided by ChatGPT is _totally_ wrong despite of correct operators/constructions/etc. and does not correspond the paradigm of the LT usage.
But kind guys from Originlab have so much time to do the user's job, so you have a good chance to get help here.

PS. Seems that the disadvantages of the AI use are seriously underestimated.

Edited by - aplotnikov on 09/05/2024 03:00:58 AM
Go to Top of Page

NicholasSupport

USA
46 Posts

Posted - 09/05/2024 :  11:36:32 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
A major limitation of this script is that it is written partly in LabTalk and partly in OriginC. Perhaps you can ask ChatGPT to avoid using an OriginC when composing the code.

Best,
Nicholas
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000