Mercurial > repos > jay > pdaug_peptide_data_plotting
annotate PDAUG_TSVtoFASTA/PDAUG_TSVtoFASTA.py @ 5:f647277cac06 draft
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit ac4353ca5c0ac9ce60df9f4bf160ed08b99fbee3"
| author | jay | 
|---|---|
| date | Thu, 28 Jan 2021 04:34:56 +0000 | 
| parents | 1335f334eb13 | 
| children | 
| rev | line source | 
|---|---|
| 4 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 1 | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 2 import pandas as pd | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 3 | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 4 | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 5 def TSVtoFASTA(infile, method, firstdatafile, seconddatafile, outfile, clmpepid, slcclasslabel, peps): | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 6 | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 7 | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 8 fn = [firstdatafile, seconddatafile] | 
| 0 
9e347250e3a1
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
 jay parents: diff
changeset | 9 | 
| 
9e347250e3a1
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
 jay parents: diff
changeset | 10 | 
| 4 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 11 df = pd.read_csv(infile, sep="\t") | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 12 if clmpepid == None: | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 13 pass | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 14 else: | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 15 names = df[clmpepid].tolist() | 
| 0 
9e347250e3a1
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
 jay parents: diff
changeset | 16 | 
| 4 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 17 peps = df[peps].tolist() | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 18 | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 19 if method == "withoutlabel": | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 20 f = open(outfile,'w') | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 21 if clmpepid is not None: | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 22 for i,n in enumerate(peps): | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 23 f.write(">"+names[i]+'\n') | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 24 f.write(n+'\n') | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 25 f.close() | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 26 else: | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 27 for i,n in enumerate(peps): | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 28 f.write(">"+str(i)+'\n') | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 29 f.write(n+'\n') | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 30 f.close() | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 31 | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 32 elif method == "withlabel": | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 33 labels = df[slcclasslabel].tolist() | 
| 0 
9e347250e3a1
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
 jay parents: diff
changeset | 34 | 
| 4 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 35 label = list(set(labels)) | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 36 | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 37 if clmpepid is None: | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 38 for i, l in enumerate(label): | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 39 f = open(fn[i],'w') | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 40 print('ok1') | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 41 for i, L in enumerate(labels): | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 42 if l == L: | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 43 f.write(">"+str(i)+"_"+str(l)+'\n') | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 44 f.write(peps[i]+'\n') | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 45 f.close() | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 46 else: | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 47 for i, l in enumerate(label): | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 48 f = open(fn[i],'w') | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 49 for i, L in enumerate(labels): | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 50 if l == L: | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 51 f.write(">"+names[i]+"_"+l+'\n') | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 52 f.write(peps[i]+'\n') | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 53 f.close() | 
| 0 
9e347250e3a1
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
 jay parents: diff
changeset | 54 | 
| 
9e347250e3a1
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
 jay parents: diff
changeset | 55 if __name__=="__main__": | 
| 
9e347250e3a1
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
 jay parents: diff
changeset | 56 | 
| 
9e347250e3a1
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
 jay parents: diff
changeset | 57 import argparse | 
| 
9e347250e3a1
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
 jay parents: diff
changeset | 58 parser = argparse.ArgumentParser() | 
| 
9e347250e3a1
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
 jay parents: diff
changeset | 59 parser.add_argument("-I", "--InFile", required=True, default=None, help=".fasta or .tsv") | 
| 4 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 60 parser.add_argument("-F", "--FirstDataFile", required=False, default='FirstDataFile.fasta', help="Path to target tsv file") | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 61 parser.add_argument("-S", "--SecondDataFile", required=False, default='SecondDataFile.fasta', help="Path to target tsv file") | 
| 0 
9e347250e3a1
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
 jay parents: diff
changeset | 62 parser.add_argument("-O", "--OutFile", required=False, default='OutFile.fasta', help="Path to target tsv file") | 
| 
9e347250e3a1
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
 jay parents: diff
changeset | 63 parser.add_argument("-M", "--Method", required=True, default=None, help="Path to target tsv file") | 
| 4 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 64 parser.add_argument("-C", "--ClmPepID", required=False, default=None, help="Peptide Column Name") | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 65 parser.add_argument("-L", "--SlcClassLabel", required=False, default="Class_label", help="Class Label Column Name") | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 66 parser.add_argument("-P", "--PeptideColumn", required=True, default=None, help="Class Label Column Name") | 
| 0 
9e347250e3a1
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
 jay parents: diff
changeset | 67 args = parser.parse_args() | 
| 
9e347250e3a1
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
 jay parents: diff
changeset | 68 | 
| 4 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 69 TSVtoFASTA(args.InFile, args.Method, args.FirstDataFile, args.SecondDataFile, args.OutFile, args.ClmPepID, args.SlcClassLabel, args.PeptideColumn) | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 70 | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 71 | 
| 
1335f334eb13
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 45ebf32dcaa1eed91670d3a2491f9cf3dfb535ef"
 jay parents: 
3diff
changeset | 72 | 
