I'm fairly new to python.
I have a list of GI numbers (list 1) and my ultimate goal is to slice sequence data for 5 kb upstream and 5 kb downstream of my target CDS in a genbank file, which is also in a list (list 2). I've made an attempt to do this. I do not get any errors, however I do not get any response from printing the new list (combo_list).
I would really appreciate your help.
from Bio import SeqIO def add_location(gi_list): gb_file = 'file.gb' gb_records = SeqIO.parse(open(gb_file,"r"), "genbank") combo_list =  for gb_record in gb_records : if gb_record.features : for feature in gb_record.features : if feature.qualifiers == "db_xref" : for gi_list in gb_record : start = feature.location._start.position end = feature.location._end.postion combo_list.append(start, end) print combo_list stop() return combo_list def main(): gi_file = "gi.txt" text_file = open("gi.txt", "r").readlines() gi_list =  for line in text_file : gi_list.append(int(line.strip())) location_gi_list = add_location(gi_list) if __name__ == '__main__': main()
From Ram's assistance;
for genome in gbank: for gene in genome.features: if gene.type=="CDS": if 'db_xref' in gene.qualifiers: for gi in gi_list: if str(gi) in gene.qualifiers['db_xref']: