Mercurial > repos > public-health-bioinformatics > assign_clades
annotate assign_clades.py @ 0:a971083404a4 draft default tip
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
author | public-health-bioinformatics |
---|---|
date | Thu, 04 Jul 2019 19:34:32 -0400 |
parents | |
children |
rev | line source |
---|---|
0
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
1 #!/usr/bin/env python |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
2 |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
3 '''Accepts fasta files containing amino acid sequence, reading them in as |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
4 amino acid sequence objects. Reads influenza clade defintions (i.e. amino |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
5 acids at certain positions) from .csv file into dictionary structure. Searches |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
6 each of the amino acid sequence objects for a list of matching clades, assigns |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
7 the most 'evolved' (i.e. child as opposed to parent clade) to the sequence. Appends |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
8 "_cladename" to the Sequence name and generates a fasta file of original sequences with |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
9 modified names.''' |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
10 |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
11 '''Author: Diane Eisler, Molecular Microbiology & Genomics, BCCDC Public Health Laboratory, Oct 2017''' |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
12 |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
13 import sys,string,os, time, Bio |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
14 from Bio import Seq, SeqIO, SeqUtils, Alphabet, SeqRecord |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
15 from Bio.SeqRecord import SeqRecord |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
16 from Bio.Alphabet import IUPAC |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
17 from Bio.Seq import Seq |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
18 |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
19 localtime = time.asctime(time.localtime(time.time())) #date and time of analysis |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
20 inFileHandle1 = sys.argv[1] #batch fasta file with sequences to be parsed |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
21 inFileHandle2 = sys.argv[2] # .csv file containing clade definitions and "depth" |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
22 outFileHandle = sys.argv[3] #user-specified name for output file of aa seq's with clade suffixes |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
23 outFile= open(outFileHandle,'w') #open a writable, appendable output file |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
24 seqList = [] #list of aa sequence objects to parse for clade definitions |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
25 cladeList = [] #empty list to hold clade tuples i.e. ("3C.3a", 1 ,{"3":"I", "9":"V"..}) |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
26 |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
27 '''Searches record for required amino acids at defined positions. If found, assigns |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
28 clade name to sequence name by appending underscore and clade name to record id.''' |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
29 def call_clade(record): |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
30 print("---------------------------------------------------------------------") |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
31 print("Parsing %s for matching flu clade definitions..." % (record.id)) |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
32 matchList = [] #empty list to hold clades that match 100% |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
33 #iterate over each tuple in the clade list |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
34 for clade in cladeList: |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
35 cladeName = clade[0] #temp variable for name |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
36 depth = clade[1] #temp variable for depth |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
37 sites = clade[2] #temp variable for aa def dictionary |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
38 shouldFind = len(sites) #number of sites that should match |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
39 found = 0 #a counter to hold matches to antigenic sites |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
40 #iterate over each position in sites dictionary |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
41 for pos, aa in sites.items(): |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
42 #translate pos to corresponding index in target sequence |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
43 index = int(pos) - 1 |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
44 #if record at index has same amino acid as 'aa', increment 'found' |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
45 if record[index] == aa: |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
46 found += 1 |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
47 if (found == shouldFind): |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
48 #add the matching clade tuple to the list of matches |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
49 matchList.append(clade) |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
50 return matchList |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
51 |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
52 '''Compares depth level of clades in a list and returns the most granular one''' |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
53 def decide_clade_by_depth(matchList): |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
54 #empty variable for maximum depth encountered |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
55 max_depth = 0 |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
56 best_match_name = '' #variable to hold most granular clade |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
57 #for each matching clade, check depth of the corresponding tuple |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
58 for clade in matchList: |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
59 #if the current clade is 'deeper' than the one before it |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
60 if clade[1] > max_depth: |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
61 #store this depth |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
62 max_depth = clade[1] |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
63 #store name of the clade |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
64 best_match_name = clade[0] |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
65 return best_match_name |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
66 |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
67 '''opens the .csv file of clade definitions and clade "depth" ''' |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
68 with open (inFileHandle2, 'r') as clade_file: |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
69 #remove whitespace from the end of each line and split elements at commas |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
70 for line in clade_file: |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
71 #print "Current Line in File:" + line |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
72 sites={} #initialize a dictionary for clade |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
73 elementList = line.rstrip().split(',') |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
74 new_list = [] #start a new list to put non-empty strings into |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
75 #remove empty stings in list |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
76 for item in elementList: |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
77 if item != '': |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
78 new_list.append(item) |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
79 name = new_list.pop(0) #move 1st element to name field |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
80 depth = int(new_list.pop(0)) #move 2nd element to depth field |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
81 #read remaining pairs of non-null elements into clade def dictionary |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
82 for i in range(0, len(new_list), 2): |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
83 #move next 2 items from the list into the dict |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
84 pos = new_list[i] |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
85 aa = new_list[i + 1] |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
86 sites[pos] = aa |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
87 #add the clade info as a tuple to the cladeList[] |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
88 oneClade =(name, depth, sites) |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
89 cladeList.append(oneClade) |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
90 print("The List of Clades:") |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
91 for clade in cladeList: |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
92 print("Clade Name: %s Depth: %i Antigenic Sites: %i" % (clade[0], clade[1], len(clade[2]))) |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
93 for pos, aa in clade[2].items(): |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
94 print("Pos: %s\tAA: %s" % (pos,aa)) |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
95 |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
96 '''opens readable input file of sequences to parse using filename from cmd line, |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
97 instantiates as AA Sequence objects, with ppercase sequences''' |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
98 with open(inFileHandle1,'r') as inFile: |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
99 #read in Sequences from fasta file, uppercase and add to seqList |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
100 for record in SeqIO.parse(inFile, "fasta", alphabet=IUPAC.protein): |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
101 record = record.upper() |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
102 seqList.append(record) #add Seq to list of Sequences |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
103 print("\n%i flu HA sequences will be compared to current clade definitions..." % len(seqList)) |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
104 #parse each target sequence object |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
105 for record in seqList: |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
106 clade_call = '' #empty variale for final clade call on sequence |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
107 matchingCladeList = call_clade(record) #holds matching clade tuples |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
108 #if there is more than one clade match |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
109 if len(matchingCladeList) > 1: |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
110 #choose the most granular clade based on depth |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
111 clade_call = decide_clade_by_depth(matchingCladeList) |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
112 #if there is only one clade call |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
113 elif len(matchingCladeList) > 0: |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
114 clade = matchingCladeList[0] #take the first tuple in the list |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
115 clade_call = clade[0] #clade name is the first item in the tuple |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
116 #empty list return, no matches |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
117 else: |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
118 clade_call = "No_Match" |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
119 print(clade_call) |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
120 seq_name = record.id |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
121 mod_name = seq_name + "_" + clade_call |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
122 print("New Sequence Name: " + mod_name) |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
123 record.id = mod_name |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
124 |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
125 |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
126 #output fasta file with clade calls appended to sequence names |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
127 SeqIO.write(seqList,outFile,"fasta") |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
128 |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
129 #print("\n%i Sequences Extracted to Output file: %s" % ((len(extractedSeqList),outFileHandle))) |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
130 inFile.close() |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
131 clade_file.close() |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
132 outFile.close() |
a971083404a4
planemo upload for repository https://github.com/Public-Health-Bioinformatics/flu_classification_suite commit b96b6e06f6eaa6ae8ef4c24630dbb72a4aed7dbe
public-health-bioinformatics
parents:
diff
changeset
|
133 |