-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
156 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
|
||
|
||
# Script to remove unwanted samples from mothur shared file | ||
|
||
# Read list of unwanted samples | ||
# Read line | ||
|
||
|
||
# Write if not in list | ||
|
||
|
||
import sys | ||
import re | ||
|
||
# Inputs | ||
filein = open(sys.argv[1], 'r') | ||
filelist = open(sys.argv[2], 'r') | ||
|
||
shared_shortname = re.sub('[.](shared)', '', sys.argv[1], re.I) | ||
fileout_handle = shared_shortname + "_filtered.shared" | ||
fileout = open(fileout_handle, 'w') | ||
|
||
|
||
#create a list with the names of the samples requested | ||
requested_samples = [] | ||
for sample in filelist: | ||
sample = sample.strip('\n').strip('\r') | ||
requested_samples.append(sample) | ||
filelist.close() | ||
|
||
# Print number of requested samples | ||
print "%s records requested" % len(requested_samples) | ||
|
||
found_counter = 0 | ||
for line in filein: | ||
line2 = line.strip('\n').strip('\r') | ||
line2 = line2.split('\t') | ||
# Second column correspond to the sample in the otu table | ||
if line2[1] in requested_samples: | ||
found_counter = found_counter + 1 | ||
continue | ||
else: | ||
fileout.write("%s" % line) | ||
|
||
print "%s samples removed" % found_counter | ||
|
||
fileout.close() | ||
filein.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#! /usr/bin/python | ||
|
||
# author__ = "Erick Cardenas Poire" | ||
# Usage python ./score_butyrate.py -i <input file> -d <dictionary file> | ||
|
||
import sys | ||
import re | ||
from optparse import OptionParser | ||
|
||
|
||
#config = load_config() | ||
script_info = {} | ||
script_info['brief_description'] = """Converts a tabular BLAST output | ||
into a table with count for butyrate synthesis genes. | ||
It requires a table that links the img ids with the gene names""" | ||
|
||
script_info['script_usage'] = [] | ||
|
||
usage = ''' | ||
Usage: | ||
python score_blast_butyrate.py -i <blast tabular input> -d <dictionary file> | ||
-o <output text file> | ||
''' | ||
|
||
parser = OptionParser(usage) | ||
parser.add_option("-i", "--input_blast_result", dest="input_file", | ||
help='The blast tabular input [REQUIRED]') | ||
parser.add_option("-d", "--dictionary_file", dest="dictionary_file", | ||
help='The dictionary file [REQUIRED]') | ||
|
||
|
||
def main(argv): | ||
(opts, args) = parser.parse_args() | ||
print '' | ||
print 'Initializing...' | ||
|
||
# initialize the input file, dictionary, and output file | ||
input_file = opts.input_file | ||
dictionary_file = opts.dictionary_file | ||
shortname = re.sub('[.](txt)', '', input_file, re.I) | ||
output_file = shortname + "_summary.txt" | ||
|
||
filedict = open(dictionary_file, 'r') | ||
filein = open(input_file, 'r') | ||
fileout = open(output_file, 'w') | ||
|
||
gene_id_dictionary = {} | ||
for line in filedict: | ||
line = line.rstrip(' ') | ||
line = line.rstrip('\n') | ||
line = line.split('\t') | ||
gene_id = line[0] | ||
gene = line[1] | ||
gene_id_dictionary[gene_id] = gene | ||
|
||
gene_count_dictionary = {} | ||
for line2 in filein: | ||
line2 = line2.lstrip(' ').rstrip(' ') | ||
line2 = line2.strip('\n') | ||
# Split line from results | ||
line2 = line2.split(' ') | ||
subject = line2[1] | ||
line_count = int(line2[0]) | ||
the_gene = gene_id_dictionary.get(subject, 'no_match') | ||
print the_gene | ||
# Get current count and update, if not found use zero | ||
|
||
current_gene_count = gene_count_dictionary.get(the_gene, 0) | ||
new_score = current_gene_count + line_count | ||
gene_count_dictionary[the_gene] = new_score | ||
|
||
for key, value in gene_count_dictionary.iteritems(): | ||
fileout.write("%s\t%s\t%s\n" % (input_file, key, value)) | ||
|
||
# Closing file | ||
filein.close() | ||
filedict.close() | ||
fileout.close() | ||
|
||
|
||
# the main function | ||
main(sys.argv[1:]) |