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