Sure John,
this is a very useful forum
Header Leaderboard Ad
Collapse
Scripting Help - Common Elements
Collapse
Announcement
Collapse
SEQanswers June Challenge Has Begun!
The competition has begun! We're giving away a $50 Amazon gift card to the member who answers the most questions on our site during the month. We want to encourage our community members to share their knowledge and help each other out by answering questions related to sequencing technologies, genomics, and bioinformatics. The competition is open to all members of the site, and the winner will be announced at the beginning of July. Best of luck!
For a list of the official rules, visit (https://www.seqanswers.com/forum/sit...wledge-and-win)
For a list of the official rules, visit (https://www.seqanswers.com/forum/sit...wledge-and-win)
See more
See less
X
-
This is a great discussion for a novice scriptor of Python and bash/C shells. Thank you Giorgio C for all of your questions. They provide food for my thoughts. And thanks to Richard Finney for pointing out the use of the "comm" and "awk" commands.
This code is a combo of my first thoughts on how to approach the problem with subsequent introduction of the "comm" command.
Code:bash-3.2$ cat junk chr1 chr2 chr2 chr1 chr3 chr4 chr5 chr4 bash-3.2$ cut -f1 junk | sort | uniq > junkcol1 bash-3.2$ cut -f2 junk | sort | uniq > junkcol2 bash-3.2$ comm -3 junkcol1 junkcol2 > commonjunk bash-3.2$ cat commonjunk chr3 chr4 chr5
John
Leave a comment:
-
Yes infact, that was one of the thing I've noticed, in the tab separeted file needs to add (\t) to the script.
By the way it works good !
Thank you again for your precious help.
Cheers,
Giorgio
Leave a comment:
-
Originally posted by Giorgio C View PostThank you Dariober,
as you said it was a problem of some empty lines in the middle of the list that I did not see at first. Now it works good and however the 'skip blank script' version works greatly.
Richard Finney thank you for your other suggestion, it works good too.
Good luck!
Dario
Leave a comment:
-
Thank you Dariober,
as you said it was a problem of some empty lines in the middle of the list that I did not see at first. Now it works good and however the 'skip blank script' version works greatly.
Richard Finney thank you for your other suggestion, it works good too.
Leave a comment:
-
Rather than write your own tool, BEDTools intersectBed can do exactly this, if you convert your lists to .bed format
Leave a comment:
-
"comm" command is useful for this stuff ..
Code:-bash-3.00$ cat junk chr1 chr2 chr2 chr1 chr3 chr4 chr5 chr4 -bash-3.00$ awk '{print $1}' < junk | sort | uniq > junkcol1 -bash-3.00$ awk '{print $2}' < junk | sort | uniq > junkcol2 -bash-3.00$ comm -3 junkcol1 junkcol2 chr3 chr4 chr5
check out the "comm" command with "man comm" or via search engine.
Leave a comment:
-
Originally posted by Giorgio C View PostThank you so much for your answer I've tried but it give me an error:
Traceback (most recent call last):
File "script.py", line 9, in <module>
a= line.strip().split()[0]
IndexError: list index out of range
Do you know what may be the problem?
In fact, this version will skip blank lines:
Code:python -c " fin= open('test.txt') col_a= set() for line in fin: if line.strip() == '': continue ## Unique elements in column A a= line.strip().split()[0] col_a.add(a) fin.seek(0) for line in fin: if line.strip() == '': continue ## Print out elements in column B not in set A b= line.strip().split()[1] if b not in col_a: print(b) fin.close() "
Leave a comment:
-
Thank you so much for your answer I've tried but it give me an error:
Traceback (most recent call last):
File "script.py", line 9, in <module>
a= line.strip().split()[0]
IndexError: list index out of range
Do you know what may be the problem?
Leave a comment:
-
Hi Giorgio,
See if this helps:
say you have test.txt like this (tab-separated):
Code:chr1 chr2 chr2 chr1 chr3 chr4 chr5 chr4
This python script should do it. It assumes that all the unique elements in column A can fit in memory:
Code:python -c " fin= open('test.txt') col_a= set() for line in fin: ## Unique elements in column A a= line.strip().split()[0] col_a.add(a) fin.seek(0) for line in fin: ## Print out elements in column B not in set A b= line.strip().split()[1] if b not in col_a: print(b) fin.close() "
Hope it helps and I haven't made any mistake!
Dario
Leave a comment:
-
Scripting Help - Common Elements
Hi all,
I have a question hoping someone can help me.
I have a file with two columns A and B with a list of gene coordinates in each of them:
I'd like to write in another file every element that is present in column A but not in B.
(I mean I'd like to write in output the NON common elements of the two columns).
Do you have any suggestions ( little script in perl or python) not exel cuz the list is huge.
Thanks you in advance,
GiorgioTags: None
Latest Articles
Collapse
-
by seqadmin
Developments in sequencing technologies and methodologies have transformed the field of epigenetics, giving researchers a better way to understand the complex world of gene regulation and heritable modifications. This article explores some of the diverse sequencing methods employed in the study of epigenetics, ranging from classic techniques to cutting-edge innovations while providing a brief overview of their processes, applications, and advances.
Methylation Detect...-
Channel: Articles
05-31-2023, 10:46 AM -
-
Differential Expression and Data Visualization: Recommended Tools for Next-Level Sequencing Analysisby seqadmin
After covering QC and alignment tools in the first segment and variant analysis and genome assembly in the second segment, we’re wrapping up with a discussion about tools for differential gene expression analysis and data visualization. In this article, we include recommendations from the following experts: Dr. Mark Ziemann, Senior Lecturer in Biotechnology and Bioinformatics, Deakin University; Dr. Medhat Mahmoud Postdoctoral Research Fellow at Baylor College of Medicine;...-
Channel: Articles
05-23-2023, 12:26 PM -
-
by seqadmin
Continuing from our previous article, we share variant analysis and genome assembly tools recommended by our experts Dr. Medhat Mahmoud, Postdoctoral Research Fellow at Baylor College of Medicine, and Dr. Ming "Tommy" Tang, Director of Computational Biology at Immunitas and author of From Cell Line to Command Line.
Variant detection and analysis tools
Mahmoud classifies variant detection work into two main groups: short variants (<50...-
Channel: Articles
05-19-2023, 10:03 AM -
ad_right_rmr
Collapse
News
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by seqadmin, Yesterday, 01:08 PM
|
0 responses
6 views
0 likes
|
Last Post
by seqadmin
Yesterday, 01:08 PM
|
||
Started by seqadmin, 06-01-2023, 08:56 PM
|
0 responses
12 views
0 likes
|
Last Post
by seqadmin
06-01-2023, 08:56 PM
|
||
Deep Sequencing Unearths Novel Genetic Variants: Enhancing Precision Medicine for Vascular Anomalies
by seqadmin
Started by seqadmin, 06-01-2023, 07:33 AM
|
0 responses
146 views
0 likes
|
Last Post
by seqadmin
06-01-2023, 07:33 AM
|
||
Unveiling Genetic Associations Through Transcription Factor Binding Quantitative Trait Loci
by seqadmin
Started by seqadmin, 05-31-2023, 07:50 AM
|
0 responses
186 views
0 likes
|
Last Post
by seqadmin
05-31-2023, 07:50 AM
|
Leave a comment: