Changeset 4271
- Timestamp:
- Jan 2, 2012, 5:41:40 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/plugin/src/org/proteios/plugins/CombinedHitsReport.java
r4270 r4271 36 36 import org.proteios.core.ItemQuery; 37 37 import org.proteios.core.ItemResultIterator; 38 import org.proteios.core.ItemResultList;39 38 import org.proteios.core.Permission; 40 39 import org.proteios.core.PermissionDeniedException; … … 365 364 hitQuery.setPermanentParameter("localSampleId", 366 365 localSampleId, null); 367 hitQuery.orderPermanent(Orders.asc(Hql368 .property("peakListFile")));369 hitQuery.orderPermanent(Orders.asc(Hql370 .property("spectrumStringId")));371 366 } 372 367 } … … 385 380 output.write("False discovery rate cutoff: " + Float 386 381 .valueOf((float) fdrCutOff) + "\n"); 387 if (proteins)388 {389 output.write("Protein level report\n");390 hitQuery.orderPermanent(Orders.asc(Hql.property("externalId")));391 }392 else393 {394 output.write("Peptide level report\n");395 hitQuery396 .orderPermanent(Orders.asc(Hql.property("description")));397 }398 382 log.info("CombinedHitsReport: Random text prefix " + reverseText); 399 383 log.info("CombinedHitsReport: FDR cutoff " + fdrCutOff); … … 402 386 Expressions.parameter("protein"))); 403 387 hitQuery.setPermanentParameter("protein", proteins, null); 388 if (proteins) 389 { 390 output.write("Protein level report\n"); 391 } 392 else 393 { 394 output.write("Peptide level report\n"); 395 } 404 396 for (int i = 0; i < score_types.length; i++) 405 397 { … … 408 400 // Restrict so that the score type starts with: 409 401 hitQuery.setParameter("scoretype", score_types[i] + "%", null); 410 ItemResultList<Hit> hitlist = hitQuery.list(dc); 402 Iterator<Hit> hitIt = hitQuery.iterate(dc); 403 List<Hit> hitlist = new ArrayList<Hit>(); 404 while (hitIt.hasNext()) 405 { 406 hitlist.add(hitIt.next()); 407 } 411 408 output.write("Score type:" + score_types[i]); 412 409 int queryhits = hitlist.size(); … … 418 415 actual_score_types++; 419 416 } 417 if (!proteins && localSampleId != null) 418 { 419 Comparator<Hit> hitSorter = new HitFileAndSpectrumStringIdAndDescriptionSortForHit(); 420 Collections.sort(hitlist, hitSorter); 421 } 422 420 423 Iterator<Hit> hitit = hitlist.iterator(); 421 424 if (progress != null) … … 557 560 Integer currentFileId = currenthit 558 561 .getPeakListFile().getId(); 562 log 563 .debug("File ID:" + currentFileId + " spectrum: " + currenthit 564 .getSpectrumStringId() + " description: " + currenthit 565 .getDescription()); 559 566 // If there is a sample id we sort on input 560 567 // filename … … 790 797 double lowestFDR = 1d / (double) combinedHits.size(); 791 798 // Calculate FDR 792 for (int i = 0; i < combinedHits.size(); ++i) 793 { 794 double forwardCount = 0d; 795 for (int j = 0; j < combinedHits.size(); ++j) 796 { 797 if (combinedHits.get(i).count >= combinedHits.get(j).count) 799 int combinedHitsSize = combinedHits.size(); 800 int revCombinedHitsSize = revCombinedHits.size(); 801 for (int i = 0; i < combinedHitsSize; i++) 802 { 803 int forwardCount = 0; 804 int count = combinedHits.get(i).count; 805 for (int j = 0; j < combinedHitsSize; j++) 806 { 807 if (count >= combinedHits.get(j).count) 798 808 { 799 809 forwardCount++; 800 810 } 801 } 802 double reverseCount = 0d; 803 for (int j = 0; j < revCombinedHits.size(); ++j) 804 { 805 if (combinedHits.get(i).count >= revCombinedHits.get(j).count) 811 else 812 break; 813 } 814 int reverseCount = 0; 815 for (int j = 0; j < revCombinedHitsSize; j++) 816 { 817 if (count >= revCombinedHits.get(j).count) 806 818 { 807 819 reverseCount++; 808 820 } 809 } 810 double combinedFDR = (reverseCount / (decoySize * forwardCount)); 821 else 822 break; 823 } 824 double combinedFDR = ((double) reverseCount / (decoySize * (double) forwardCount)); 811 825 // Conservative estimate 812 826 if (combinedFDR == 0) … … 826 840 if (keepDecoys) 827 841 { 828 for (int i = 0; i < revCombinedHits .size(); ++i)842 for (int i = 0; i < revCombinedHitsSize; i++) 829 843 { 830 844 double forwardCount = 0d; 831 for (int j = 0; j < combinedHits.size(); ++j) 845 double count = revCombinedHits.get(i).count; 846 for (int j = 0; j < combinedHitsSize; j++) 832 847 { 833 if ( revCombinedHits.get(i).count >= combinedHits.get(j).count)848 if (count >= combinedHits.get(j).count) 834 849 { 835 850 forwardCount++; 836 851 } 852 else 853 break; 837 854 } 838 855 double reverseCount = 0d; 839 for (int j = 0; j < revCombinedHits .size(); ++j)856 for (int j = 0; j < revCombinedHitsSize; j++) 840 857 { 841 if (revCombinedHits.get(i).count >= revCombinedHits 842 .get(j).count) 858 if (count >= revCombinedHits.get(j).count) 843 859 { 844 860 reverseCount++; 845 861 } 862 else 863 break; 846 864 } 847 865 double combinedFDR = (reverseCount / (decoySize * forwardCount)); … … 877 895 if (progress != null) 878 896 { 879 progress.display(90, "Wrote standardhits to file");897 progress.display(90, "Wrote target hits to file"); 880 898 } 881 899 } … … 917 935 } 918 936 output.close(); 937 if (progress != null) 938 { 939 progress.display(95, "Wrote hits to file. Saving to database."); 940 } 919 941 dc.commit(); 920 942 if (progress != null) … … 933 955 List<CombinedHit> revCombinedHits) 934 956 { 935 for (int i = 0; i < combinedHits.size(); i++) 957 int combinedHitsSize = combinedHits.size(); 958 int revCombinedHitsSize = revCombinedHits.size(); 959 int scoreSize = score_types.length; 960 for (int i = 0; i < combinedHitsSize; i++) 936 961 { 937 962 int scores_above = 0; … … 942 967 * counted. 943 968 */ 944 for (int j = 0; j < revCombinedHits .size(); j++)969 for (int j = 0; j < revCombinedHitsSize; j++) 945 970 { 946 971 boolean count = true; 947 972 boolean above = true; 948 for (int k = 0; k < score _types.length; k++)973 for (int k = 0; k < scoreSize; k++) 949 974 { 950 975 /* … … 969 994 } 970 995 } 971 combinedHits.get(i).count = (double)scores_above;996 combinedHits.get(i).count = scores_above; 972 997 } 973 998 } … … 1022 1047 implements Comparable<CombinedHit> 1023 1048 { 1024 double count = 0D;1049 int count = 0; 1025 1050 double fdr = 0D; 1026 1051 Hit hit; … … 1197 1222 } 1198 1223 1224 public class HitFileAndSpectrumStringIdAndDescriptionSortForHit 1225 implements Comparator<Hit> 1226 { 1227 public int compare(Hit o1, Hit o2) 1228 { 1229 if (Integer.valueOf(o1.getPeakListFile().getId()).equals( 1230 o2.getPeakListFile().getId())) 1231 { 1232 if (o1.getSpectrumStringId().equals(o2.getSpectrumStringId())) 1233 { 1234 return o1.getDescription().compareTo(o2.getDescription()); 1235 } 1236 else 1237 { 1238 return o1.getSpectrumStringId().compareTo( 1239 o2.getSpectrumStringId()); 1240 } 1241 } 1242 else 1243 return (Integer.valueOf(o1.getPeakListFile().getId()) 1244 .compareTo(o2.getPeakListFile().getId())); 1245 } 1246 } 1247 1199 1248 }
Note: See TracChangeset
for help on using the changeset viewer.