Connect with us

Bioinformatics Programming

How to search for a specific character in a file using Python?

Dr. Muniba Faiza

Published

on

python programming

In this article, a simple python script is provided that can be used to search for a specific character in a file.

If you have a file consisting of some information including name, address, email, post, and so on. You want to extract only email addresses present in that file, then use the following script/block of code. Here, this input file is named “employee_info.txt”.

#!/usr/bin/env python


value = ''
str = 'Email ID:'

file = open('employee_info.txt')

result = ''
for line in file:
			if '@' in line:				#looking for specific character
				value = line.splitlines()
				print ("Email ID:", value)
file.close()				

Save this script with .py extension. Suppose, save it as ‘script.py’. Open a terminal on Ubuntu or command prompt on Windows and type:

$ python script.py

If you want to redirect the output to a file, then type:

$ python script.py > output.txt

Dr. Muniba is a Bioinformatician based in New Delhi, India. She has completed her PhD in Bioinformatics from South China University of Technology, Guangzhou, China. She has cutting edge knowledge of bioinformatics tools, algorithms, and drug designing. When she is not reading she is found enjoying with the family. Know more about Muniba

Advertisement
Click to comment

You must be logged in to post a comment Login

Leave a Reply

Algorithms

VS-Analysis: A Python Script to Analyze Virtual Screening Results of Autodock Vina

Dr. Muniba Faiza

Published

on

VS-Analysis: A Python Script to Analyze Virtual Screening Results of Autodock Vina

The output files obtained as a result of virtual screening (VS) using Autodock Vina may be large in number. It is difficult or quite impossible to analyze them manually. Therefore, we are providing a Python script to fetch top results (i.e., compounds showing low binding affinities). (more…)

Continue Reading

Bioinformatics Programming

How to execute Unix/shell commands in PHP?

Dr. Muniba Faiza

Published

on

programming in php

Besides, Python & Perl, PHP is another language mostly used in bioinformatics programming. In this article, we provide a simple command to execute shell commands in a PHP script. (more…)

Continue Reading

Bioinformatics Programming

Nested SQL queries and aggregate functions for complex information retrieval from a database

Dr. Muniba Faiza

Published

on

SQL queries for complex information retrieval

In one of our previous articles, we have mentioned a few basic SQL queries to search in a database. In this article, we have described a few nested SQL queries and aggregate functions for information retrieval from a biological database. (more…)

Continue Reading

LATEST ISSUE

ADVERT

Feedback
Feedback
How Would You Rate the Design of Bioinformatics Review Website?
Do you have any additional comment?
Next
Enter your email if you'd like us to contact you regarding with your feedback.
Back
Submit
Thank you for submitting your feedback!