Making my python code better
1
0
Entering edit mode
2.2 years ago
ciaki • 0

Hi,

I am looking for a way to make my current python code better. I am not advanced in python as I am a biologist.

Is there some way to make an if statement that reads if each line for my file starts with "+" or "-" and thus make a graph as blue and yellow per condition ? Basically the "+" or "-" for each line are prefixes for genes contained or not contained in my lists of interest.

I have no idea how could I even start this so yeah if you are python advanced and feel like helping me I would appreciate it.

for example

file_1.txt = AAAS,ACTB,LIMS1
file_2.txt = AAAS,ACTN4,ACTN1
if file_1> file_2
  print("The genes that differ are:")
  plot  (volacno plot, yellow dots)
elif file_1 == file_2:
  print("The common genes are:")
  plot  (volacno plot, blue dots)

thanks

python • 1.1k views
ADD COMMENT
1
Entering edit mode

show us the code, show us the input.

ADD REPLY
0
Entering edit mode

I do not have a code because i have no idea how to achieve this. The input is two gene files. and i am comparing the genes between the two files. my question is how to format the if statement for that.

ADD REPLY
1
Entering edit mode

Realistically nobody is going to want to / be able to help you unless they see some code and data, that's a minimum really.

ADD REPLY
0
Entering edit mode

Show us the sample input (the content of two files) and the desired output.

ADD REPLY
0
Entering edit mode

I updated the initial comment with an example

ADD REPLY
1
Entering edit mode
2.2 years ago

well, I know you're learning python, but this simple task is usually performed using bash. This is basic linux, really.

# replace comma with carriage returns, sort , keep the unique names
tr "," "\n" < file_1.txt | sort | uniq > genes1.txt
tr "," "\n" < file_2.txt | sort | uniq > genes2.txt


# common genes
comm -12 genes1.txt genes2.txt

# unique in 1
comm -23 genes1.txt genes2.txt


# unique in 2
comm -13 genes1.txt genes2.txt
ADD COMMENT
0
Entering edit mode

Thanks Pierre. I have actually done it before using bash commands but it does not sort out the fact that i am hoping to create a graph for this. But thank you for your input.

ADD REPLY

Login before adding your answer.

Traffic: 2375 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6