#๐Ÿ”’ super simple python help , js neewd like 10 seconds of ur time

50 messages ยท Page 1 of 1 (latest)

white dawn
#

Hey

elder mangoBOT
#

@white dawn

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

white dawn
#

hi

#

so someone told me to get

#

this thing where it gives u a progress bar

#

and i installed it

#

then ran

#

for x in tqdm.tqdm(somelist)

#

acc i didnt run it yet but

#

where do i put it

#

like

#

at the end of my code

#

under

#

print('done')

#

or at the beggining

#

or like where

#

@ me if anyones got an answer

tame nova
#

what

white dawn
tame nova
#

can you paste your current code

white dawn
#

import pandas as pd
import requests

Read protein names from Excel file

file_path = r'C:\Users\hi\Desktop\2024_07_01_Abreviated final ref_all protein coding genes.xlsx'
df = pd.read_excel(file_path)
protein_names = df['Offical symbol'].unique()

def get_go_annotations(protein_name: str):
l = []
try:
j = requests.get(f"https://rest.uniprot.org/uniprotkb/search?query={protein_name}").json()
for ref in j["results"][0]["uniProtKBCrossReferences"]:
if ref["database"] == "GO" and ref["properties"][0]["value"].split(":")[0] == "F":
l.append(ref["properties"][0]["value"].split(":")[1].split(",")[0])
except Exception as e:
print(f"Error processing {protein_name}: {e}")
return l

Collect all unique GO annotations

all_go_annotations = set()
protein_go_annotations = {}

for protein_name in protein_names:
go_annotations = get_go_annotations(protein_name)
protein_go_annotations[protein_name] = go_annotations
all_go_annotations.update(go_annotations)

all_go_annotations = list(all_go_annotations)

Create the matrix

matrix = pd.DataFrame(0, index=protein_names, columns=all_go_annotations)

for protein_name, go_annotations in protein_go_annotations.items():
for go_annotation in go_annotations:
matrix.at[protein_name, go_annotation] = 1

Save the matrix to a file

matrix.to_csv("go_annotations_matrix.csv")

print("Matrix of GO annotations saved to go_annotations_matrix.csv")
print("done")

elder mangoBOT
#

Hey @white dawn!

It looks like you're trying to paste code into this channel.

Discord has support for Markdown, which allows you to post code with full syntax highlighting. Please use these whenever you paste code, as this helps improve the legibility and makes it easier for us to help you.

To do this, use the following method:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
gilded oyster
white dawn
#

yes

#

i wan know where to put it in my code

#

to have the bar

tame nova
#

you did all that but you cant add a progress bar ok

white dawn
#

chill

#

i js dont know where to put it

#

all i gotta do is

#

for x in tqdm.tqdm(somelist)

#

right

tame nova
#

I think you need to go manual with something like py with tqdm(total=100) as pbar: for i in range(10): sleep(0.1) pbar.update(10) since you have existing loops

gilded oyster
#

From what I see in the documentation, we can try this:

from tqdm import tqdm
...
for go_annotation in tqdm(go_annotations):
tame nova
#

ah ok

misty needle
#

he got muted btw

tame nova
#

that is probably better than manual

misty needle
#

2enom

tame nova
#

why

misty needle
#

#python-discussion

tame nova
#

oh damn

#

well you definetely wantr something like ```py
for protein_name in tqdm(protein_names):

#

same thing for all the other for loops

misty needle
#

@2emon said thank you

tame nova
#

oke

#

lol

elder mangoBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.